|
| 1 | +import React, { FC } from 'react' |
| 2 | +import classNames from 'classnames' |
| 3 | +import { ProjectFlag, VCSProvider } from 'common/types/responses' |
| 4 | +import FeatureName from './FeatureName' |
| 5 | +import FeatureDescription from './FeatureDescription' |
| 6 | +import TagValues from 'components/tags/TagValues' |
| 7 | +import VCSProviderTag from 'components/tags/VCSProviderTag' |
| 8 | +import Utils from 'common/utils/utils' |
| 9 | + |
| 10 | +export interface ProjectFeatureRowProps { |
| 11 | + projectFlag: ProjectFlag |
| 12 | + index: number |
| 13 | + isSelected?: boolean |
| 14 | + onSelect?: (projectFlag: ProjectFlag) => void |
| 15 | + className?: string |
| 16 | + actions?: React.ReactNode |
| 17 | +} |
| 18 | + |
| 19 | +const ProjectFeatureRow: FC<ProjectFeatureRowProps> = ({ |
| 20 | + actions, |
| 21 | + className, |
| 22 | + index, |
| 23 | + isSelected, |
| 24 | + onSelect, |
| 25 | + projectFlag, |
| 26 | +}) => { |
| 27 | + const { description } = projectFlag |
| 28 | + |
| 29 | + const isCodeReferencesEnabled = Utils.getFlagsmithHasFeature( |
| 30 | + 'git_code_references', |
| 31 | + ) |
| 32 | + const hasScannedCodeReferences = |
| 33 | + isCodeReferencesEnabled && projectFlag?.code_references_counts?.length > 0 |
| 34 | + const codeReferencesCounts = isCodeReferencesEnabled |
| 35 | + ? projectFlag?.code_references_counts?.reduce( |
| 36 | + (acc, curr) => acc + curr.count, |
| 37 | + 0, |
| 38 | + ) || 0 |
| 39 | + : 0 |
| 40 | + |
| 41 | + return ( |
| 42 | + <> |
| 43 | + {/* Desktop */} |
| 44 | + <div |
| 45 | + className={classNames( |
| 46 | + 'd-none d-lg-flex align-items-lg-center flex-lg-row list-item py-0 list-item-xs fs-small', |
| 47 | + className, |
| 48 | + )} |
| 49 | + data-test={`cleanup-feature-item-${index}`} |
| 50 | + > |
| 51 | + {onSelect && ( |
| 52 | + <div |
| 53 | + className='table-column px-2 align-items-center' |
| 54 | + onClick={(e) => { |
| 55 | + e.stopPropagation() |
| 56 | + }} |
| 57 | + > |
| 58 | + <input |
| 59 | + type='checkbox' |
| 60 | + checked={!!isSelected} |
| 61 | + onChange={() => onSelect(projectFlag)} |
| 62 | + /> |
| 63 | + </div> |
| 64 | + )} |
| 65 | + <div className='table-column ps-2 px-0 align-items-center flex-1'> |
| 66 | + <div className='mx-0 flex-1 flex-column'> |
| 67 | + <div className='d-flex align-items-center'> |
| 68 | + <FeatureName name={projectFlag.name} /> |
| 69 | + {isCodeReferencesEnabled && hasScannedCodeReferences && ( |
| 70 | + <Tooltip |
| 71 | + title={ |
| 72 | + <VCSProviderTag |
| 73 | + count={codeReferencesCounts} |
| 74 | + isWarning={codeReferencesCounts === 0} |
| 75 | + vcsProvider={VCSProvider.GITHUB} |
| 76 | + /> |
| 77 | + } |
| 78 | + place='top' |
| 79 | + > |
| 80 | + {`Scanned ${codeReferencesCounts} times in ${projectFlag?.code_references_counts?.length} repositories`} |
| 81 | + </Tooltip> |
| 82 | + )} |
| 83 | + <TagValues |
| 84 | + projectId={`${projectFlag.project}`} |
| 85 | + value={projectFlag.tags} |
| 86 | + /> |
| 87 | + </div> |
| 88 | + <FeatureDescription description={description} /> |
| 89 | + </div> |
| 90 | + </div> |
| 91 | + {actions && ( |
| 92 | + <div className='table-column px-2 align-items-center'>{actions}</div> |
| 93 | + )} |
| 94 | + </div> |
| 95 | + |
| 96 | + {/* Mobile */} |
| 97 | + <div |
| 98 | + className={classNames( |
| 99 | + 'd-flex flex-column justify-content-center px-2 list-item py-1 d-lg-none', |
| 100 | + )} |
| 101 | + > |
| 102 | + <div className='d-flex gap-2 align-items-center'> |
| 103 | + {onSelect && ( |
| 104 | + <div |
| 105 | + onClick={(e) => { |
| 106 | + e.stopPropagation() |
| 107 | + }} |
| 108 | + > |
| 109 | + <input |
| 110 | + type='checkbox' |
| 111 | + checked={!!isSelected} |
| 112 | + onChange={() => onSelect(projectFlag)} |
| 113 | + /> |
| 114 | + </div> |
| 115 | + )} |
| 116 | + <div className='flex-1 align-items-center flex-wrap'> |
| 117 | + <FeatureName name={projectFlag.name} /> |
| 118 | + {isCodeReferencesEnabled && hasScannedCodeReferences && ( |
| 119 | + <Tooltip |
| 120 | + title={ |
| 121 | + <VCSProviderTag |
| 122 | + count={codeReferencesCounts} |
| 123 | + isWarning={codeReferencesCounts === 0} |
| 124 | + vcsProvider={VCSProvider.GITHUB} |
| 125 | + /> |
| 126 | + } |
| 127 | + place='top' |
| 128 | + > |
| 129 | + {`Scanned ${codeReferencesCounts} times in ${projectFlag?.code_references_counts?.length} repositories`} |
| 130 | + </Tooltip> |
| 131 | + )} |
| 132 | + <TagValues |
| 133 | + projectId={`${projectFlag.project}`} |
| 134 | + value={projectFlag.tags} |
| 135 | + /> |
| 136 | + </div> |
| 137 | + {actions} |
| 138 | + </div> |
| 139 | + </div> |
| 140 | + </> |
| 141 | + ) |
| 142 | +} |
| 143 | + |
| 144 | +export default ProjectFeatureRow |
0 commit comments