( sheetDefinitions: SheetDefinition[], currentMapping: ColumnMapping[] )
| 143 | } |
| 144 | |
| 145 | export function useMappingAvailableSelectOptions( |
| 146 | sheetDefinitions: SheetDefinition[], |
| 147 | currentMapping: ColumnMapping[] |
| 148 | ) { |
| 149 | const { t } = useTranslations(); |
| 150 | |
| 151 | const options = sheetDefinitions.flatMap((sheetDefinition) => |
| 152 | sheetDefinition.columns |
| 153 | .filter((column) => allowUserToMapColumn(column)) |
| 154 | .map((column) => ({ |
| 155 | label: `${column.label}${fieldIsRequired(column) ? ' *' : ''}`, |
| 156 | value: { |
| 157 | sheetId: sheetDefinition.id, |
| 158 | sheetColumnId: column.id, |
| 159 | }, |
| 160 | group: currentMapping.some( |
| 161 | (mapping) => |
| 162 | mapping.sheetId === sheetDefinition.id && |
| 163 | mapping.sheetColumnId === column.id |
| 164 | ) |
| 165 | ? t('mapper.used') |
| 166 | : t('mapper.unused'), |
| 167 | })) |
| 168 | ); |
| 169 | |
| 170 | return options.sort((a, b) => sortByGroupAndLabel(a, b, t('mapper.unused'))); |
| 171 | } |
| 172 | |
| 173 | function sortByGroupAndLabel( |
| 174 | a: { label: string; group: string }, |
no test coverage detected