diff --git a/src/pages/ExportRequest/components/ExportForm/index.tsx b/src/pages/ExportRequest/components/ExportForm/index.tsx index e188375d7..2b6699eb3 100644 --- a/src/pages/ExportRequest/components/ExportForm/index.tsx +++ b/src/pages/ExportRequest/components/ExportForm/index.tsx @@ -27,30 +27,10 @@ import { } from 'services/aphp/serviceExportCohort' import { Cohort } from 'types' +import { TableSetting, TableInfo } from 'types/export' import useStyles from '../../styles' -export type TableSetting = { - tableName: string | null - isChecked: boolean | null - columns: string[] | null - fhirFilter: { - uuid: string - owner: string - deleted: boolean | null - deleted_by_cascade: boolean - created_at: string - modified_at: string - fhir_resource: string - fhir_version: string - query_version: string - name: string - filter: string - auto_generated: boolean - } | null - respectTableRelationships: boolean -} - const tableSettingsInitialState: TableSetting[] = [ { tableName: 'person', @@ -69,13 +49,14 @@ const ExportForm: React.FC = () => { const [tablesSettings, setTablesSettings] = useState(tableSettingsInitialState) const [exportCohort, setExportCohort] = useState(null) const [exportCohortList, setExportCohortList] = useState([]) - const [exportTableList, setExportTableList] = useState(null) + const [exportTableList, setExportTableList] = useState(null) const checkedTables = tablesSettings.filter((tableSetting) => tableSetting.isChecked) const [compatibilitiesTables, setCompatibilitiesTables] = useState(null) const [conditions, setConditions] = useState(false) const [motivation, setMotivation] = useState('') - console.log('manelle compatibilitiesTables', compatibilitiesTables) + console.log('manelle compatibilitiesTables', exportTableList) + console.log('manelle exportTableList', exportTableList) const _fetchExportableCohorts = useCallback(async () => { try { @@ -315,14 +296,14 @@ const ExportForm: React.FC = () => { - {exportTableList?.map((_exportTable: any, index: number) => ( + {exportTableList?.map((exportTable, index: number) => (
void - addNewTableSetting: (newTableSetting: any) => void + addNewTableSetting: (newTableSetting: TableSetting) => void onChangeTableSettings: (tableName: string, key: string, value: any) => void - compatibilitiesTables: any - exportTypeFile: any - oneFile: any + compatibilitiesTables: string[] | null + exportTypeFile: 'xlsx' | 'csv' + oneFile: boolean } const AlertLimitXlsx: React.FC = () => { @@ -51,10 +54,10 @@ const ExportTable: React.FC = ({ const [countError, setCountError] = useState(false) const cohortId = exportCohort?.group_id const exportColumns = exportTable.columns || [] - const tableSetting = exportTableSettings.filter((e: any) => e.tableName === exportTable.name)[0] + const tableSetting = exportTableSettings.filter((e) => e.tableName === exportTable.name)[0] const exportTableResourceType = getResourceType(exportTable.name) const tableLabel = getExportTableLabel(exportTable.name) - const [checkedTable, setCheckedTable] = useState(tableSetting?.isChecked || false) + const [checkedTable, setCheckedTable] = useState(tableSetting.isChecked || false) const appConfig = useContext(AppConfig) const limit = appConfig.features.export.exportLinesLimit @@ -72,7 +75,7 @@ const ExportTable: React.FC = ({ const getFilterCount = useCallback(async () => { try { setCountLoading(true) - const count = await fetchResourceCount2(cohortId, exportTableResourceType, tableSetting?.fhirFilter) + const count = await fetchResourceCount2(cohortId ?? '', exportTableResourceType, tableSetting?.fhirFilter) setCount(count) setCountLoading(false) } catch (error) { @@ -82,7 +85,9 @@ const ExportTable: React.FC = ({ }, [cohortId, exportTableResourceType, setError, tableSetting?.fhirFilter]) useEffect(() => { - setCheckedTable(tableSetting?.isChecked) + if (tableSetting?.isChecked !== null) { + setCheckedTable(tableSetting?.isChecked) + } }, [tableSetting?.isChecked]) useEffect(() => { @@ -105,7 +110,7 @@ const ExportTable: React.FC = ({ }) const isCompatibleTable = (tableName: string) => { - const table = compatibilitiesTables?.find((table: any) => table === tableName) + const table = compatibilitiesTables?.find((table) => table === tableName) return table } @@ -250,11 +255,12 @@ const ExportTable: React.FC = ({ )} - {count !== null && count > limit && ( + {count !== null && (exportTableResourceType === ResourceType.DOCUMENTS ? count > 5000 : count > limit) && ( La table sélectionnée dépasse la limite de{' '} - {exportTable.resourceType === ResourceType.DOCUMENTS ? 5000 : limit} lignes autorisées. Veuillez affiner + <>{console.log('manelle exportTableResourceType', exportTableResourceType)} + {exportTableResourceType === ResourceType.DOCUMENTS ? 5000 : limit} lignes autorisées. Veuillez affiner votre sélection à l'aide de filtres ou désélectionner la table. diff --git a/src/services/aphp/callApi.ts b/src/services/aphp/callApi.ts index 67c141d55..8172ad4d9 100644 --- a/src/services/aphp/callApi.ts +++ b/src/services/aphp/callApi.ts @@ -1225,7 +1225,7 @@ export const fetchExportableCohorts = async () => { type fetchExportTableInfoProps = { tableNames?: string - relationLink?: (string | null)[] + relationLink?: string[] } export const fetchExportTableInfo = async (args: fetchExportTableInfoProps) => { diff --git a/src/services/aphp/serviceExportCohort.ts b/src/services/aphp/serviceExportCohort.ts index c6201a84e..0de3d225a 100644 --- a/src/services/aphp/serviceExportCohort.ts +++ b/src/services/aphp/serviceExportCohort.ts @@ -3,7 +3,7 @@ import { getConfig } from 'config' import { AxiosResponse, isAxiosError, AxiosError } from 'axios' import { Export, Cohort } from 'types' import apiBackend from 'services/apiBackend' -import { TableSetting } from 'pages/ExportRequest/components/ExportForm' +import { TableSetting } from 'types/export' export const fetchExportTablesInfo = () => { try { @@ -14,7 +14,7 @@ export const fetchExportTablesInfo = () => { } } -export const fetchExportTablesRelationsInfo = async (tableList: (string | null)[]) => { +export const fetchExportTablesRelationsInfo = async (tableList: string[]) => { try { const call = await fetchExportTableInfo({ relationLink: tableList }) const hamiltonian =