MCPcopy Create free account
hub / github.com/HelloCSV/HelloCSV / useMappingAvailableSelectOptions

Function useMappingAvailableSelectOptions

src/mapper/utils.ts:145–171  ·  view source on GitHub ↗
(
  sheetDefinitions: SheetDefinition[],
  currentMapping: ColumnMapping[]
)

Source from the content-addressed store, hash-verified

143}
144
145export 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
173function sortByGroupAndLabel(
174 a: { label: string; group: string },

Callers 1

HeaderMapperFunction · 0.90

Calls 5

useTranslationsFunction · 0.90
fieldIsRequiredFunction · 0.90
allowUserToMapColumnFunction · 0.85
tFunction · 0.85
sortByGroupAndLabelFunction · 0.85

Tested by

no test coverage detected