github.com/argoproj/argo-cd@v1.8.7/ui/src/app/applications/components/application-urls.tsx (about)

     1  import {DropDownMenu} from 'argo-ui';
     2  import * as React from 'react';
     3  
     4  class ExternalLink {
     5      public title: string;
     6      public ref: string;
     7  
     8      constructor(url: string) {
     9          const parts = url.split('|');
    10          if (parts.length === 2) {
    11              this.title = parts[0];
    12              this.ref = parts[1];
    13          } else {
    14              this.title = url;
    15              this.ref = url;
    16          }
    17      }
    18  }
    19  
    20  export const ApplicationURLs = ({urls}: {urls: string[]}) => {
    21      const externalLinks: ExternalLink[] = [];
    22      for (const url of urls || []) {
    23          externalLinks.push(new ExternalLink(url));
    24      }
    25  
    26      // sorted alphabetically & links with titles first
    27      externalLinks.sort((a, b) => {
    28          if (a.title !== '' && b.title !== '') {
    29              return a.title > b.title ? 1 : -1;
    30          } else if (a.title === '') {
    31              return 1;
    32          } else if (b.title === '') {
    33              return -1;
    34          }
    35          return a.ref > b.ref ? 1 : -1;
    36      });
    37  
    38      return (
    39          ((externalLinks || []).length > 0 && (
    40              <span>
    41                  <a
    42                      title={externalLinks[0].title}
    43                      onClick={e => {
    44                          e.stopPropagation();
    45                          window.open(externalLinks[0].ref);
    46                      }}>
    47                      <i className='fa fa-external-link-alt' />{' '}
    48                      {externalLinks.length > 1 && (
    49                          <DropDownMenu
    50                              anchor={() => <i className='fa fa-caret-down' />}
    51                              items={externalLinks.map(item => ({
    52                                  title: item.title,
    53                                  action: () => window.open(item.ref)
    54                              }))}
    55                          />
    56                      )}
    57                  </a>
    58              </span>
    59          )) ||
    60          null
    61      );
    62  };