All files / src/Views/ColumnMapperView/Columns commonActions.tsx

66.67% Statements 14/21
75% Branches 3/4
14.29% Functions 1/7
70% Lines 14/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172                              2x                 2x             2x   2x                         2x 24x 24x 24x 24x 24x 24x 24x 24x   24x                                                                                                                                                                                                                                      
/*
    Copyright (C) 2017 Red Hat, Inc.
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
 
            http://www.apache.org/licenses/LICENSE-2.0
 
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/
import {
  Button,
  DropdownItem,
  DropdownToggle,
  Split,
  SplitItem,
  Title,
  Tooltip,
} from '@patternfly/react-core';
import {
  ExchangeAltIcon,
  LinkIcon,
  ProjectDiagramIcon,
  UnlinkIcon,
} from '@patternfly/react-icons';
 
import { AutoDropdown } from '../../../UI';
import { IAtlasmapMapping } from '../../../Views';
import React from 'react';
 
export interface ICommonActionsProps {
  connectedMappings: IAtlasmapMapping[];
  onShowMappingDetails: (mapping: IAtlasmapMapping) => void;
  canAddFieldToSelectedMapping: boolean;
  onAddToSelectedMapping: () => void;
  canRemoveFromSelectedMapping: boolean;
  onRemoveFromSelectedMapping: () => void;
  canStartMapping: boolean;
  onStartMapping: () => void;
}
 
export function commonActions({
  connectedMappings,
  onShowMappingDetails,
  canAddFieldToSelectedMapping,
  onAddToSelectedMapping,
  canRemoveFromSelectedMapping,
  onRemoveFromSelectedMapping,
  canStartMapping,
  onStartMapping,
}: ICommonActionsProps) {
  return [
    <Tooltip
      key={'select-mapping'}
      position={'top'}
      enableFlip={true}
      content={<div>Show mapping details</div>}
    >
      {connectedMappings.length > 1 ? (
        <AutoDropdown
          toggle={({ toggleOpen }) => (
            <DropdownToggle
              toggleIndicator={null}
              aria-label="Show mapping details"
              onToggle={toggleOpen}
            >
              <ExchangeAltIcon />
            </DropdownToggle>
          )}
          isPlain={true}
          position={'right'}
          dropdownItems={connectedMappings.map((m) => (
            <DropdownItem key={m.id} onClick={() => onShowMappingDetails(m)}>
              <Title headingLevel="h2" size="lg">
                {m.name}
              </Title>
              <Split hasGutter>
                <SplitItem>
                  <Title headingLevel="h2" size="md">
                    Sources
                  </Title>
                  {m.sourceFields.map((s) => (
                    <div key={s.id}>{s.name}</div>
                  ))}
                </SplitItem>
                <SplitItem>
                  <Title headingLevel="h2" size="md">
                    Targets
                  </Title>
                  {m.targetFields.map((t) => (
                    <div key={t.id}>{t.name}</div>
                  ))}
                </SplitItem>
              </Split>
            </DropdownItem>
          ))}
          disabled={connectedMappings.length === 0}
        />
      ) : (
        <Button
          variant="plain"
          onClick={() => onShowMappingDetails(connectedMappings[0])}
          aria-label="Show mapping details"
          tabIndex={0}
          isDisabled={connectedMappings.length === 0}
          data-testid={'show-mapping-details-button'}
        >
          <ExchangeAltIcon />
        </Button>
      )}
    </Tooltip>,
    canRemoveFromSelectedMapping ? (
      <Tooltip
        key={'quick-remove'}
        position={'top'}
        enableFlip={true}
        content={<div>Disconnect from the selected mapping</div>}
      >
        <Button
          variant="plain"
          onClick={onRemoveFromSelectedMapping}
          aria-label={'Disconnect from the selected mapping'}
          data-testid={'disconnect-from-the-selected-mapping-button'}
          tabIndex={0}
        >
          <UnlinkIcon />
        </Button>
      </Tooltip>
    ) : (
      <Tooltip
        key={'quick-add'}
        position={'top'}
        enableFlip={true}
        content={<div>Connect to the selected mapping</div>}
      >
        <Button
          variant="plain"
          onClick={onAddToSelectedMapping}
          aria-label={'Connect to the selected mapping'}
          tabIndex={0}
          isDisabled={!canAddFieldToSelectedMapping}
          data-testid={'connect-to-the-selected-mapping-button'}
        >
          <LinkIcon />
        </Button>
      </Tooltip>
    ),
    <Tooltip
      key={'add'}
      position={'top'}
      enableFlip={true}
      content={<div>Create new mapping</div>}
    >
      <Button
        variant="plain"
        onClick={onStartMapping}
        aria-label={'Create new mapping'}
        tabIndex={0}
        isDisabled={!canStartMapping}
        data-testid={'create-new-mapping-button'}
      >
        <ProjectDiagramIcon />
      </Button>
    </Tooltip>,
  ];
}