Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehdi-BOUYAHIA committed Dec 9, 2024
1 parent 9e3f688 commit 9e6774a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 43 deletions.
33 changes: 7 additions & 26 deletions src/pages/ExportRequest/components/ExportForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,10 @@ import {
} from 'services/aphp/serviceExportCohort'

import { Cohort } from 'types'
import { TableSetting, TableInfo } from 'types/export'

Check failure on line 30 in src/pages/ExportRequest/components/ExportForm/index.tsx

View workflow job for this annotation

GitHub Actions / test

Cannot find module 'types/export' or its corresponding type declarations.

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',
Expand All @@ -69,13 +49,14 @@ const ExportForm: React.FC = () => {
const [tablesSettings, setTablesSettings] = useState<TableSetting[]>(tableSettingsInitialState)
const [exportCohort, setExportCohort] = useState<Cohort | null>(null)
const [exportCohortList, setExportCohortList] = useState<Cohort[] | []>([])
const [exportTableList, setExportTableList] = useState<any>(null)
const [exportTableList, setExportTableList] = useState<TableInfo[] | null>(null)
const checkedTables = tablesSettings.filter((tableSetting) => tableSetting.isChecked)
const [compatibilitiesTables, setCompatibilitiesTables] = useState<string[] | null>(null)
const [conditions, setConditions] = useState<boolean>(false)
const [motivation, setMotivation] = useState<string>('')

console.log('manelle compatibilitiesTables', compatibilitiesTables)
console.log('manelle compatibilitiesTables', exportTableList)
console.log('manelle exportTableList', exportTableList)

const _fetchExportableCohorts = useCallback(async () => {
try {
Expand Down Expand Up @@ -315,14 +296,14 @@ const ExportForm: React.FC = () => {
</Grid>

<Grid>
{exportTableList?.map((_exportTable: any, index: number) => (
{exportTableList?.map((exportTable, index: number) => (
<div
style={{ padding: '5px 0px 5px 12px', backgroundColor: 'white', marginBottom: '10px' }}
key={_exportTable.name + index}
key={exportTable.name + index}
>
<ExportTable
exportCohort={exportCohort}
exportTable={_exportTable}
exportTable={exportTable}
exportTableSettings={tablesSettings}
setError={setError}
addNewTableSetting={addNewTableSetting}
Expand Down
34 changes: 20 additions & 14 deletions src/pages/ExportRequest/components/ExportTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@ import { getProviderFilters } from 'services/aphp/serviceFilters'
import { useAppSelector } from 'state'
import { AppConfig } from 'config'

import { Cohort } from 'types'
import { TableInfo, TableSetting } from 'types/export'

Check failure on line 13 in src/pages/ExportRequest/components/ExportTable/index.tsx

View workflow job for this annotation

GitHub Actions / test

Cannot find module 'types/export' or its corresponding type declarations.

type ExportTableProps = {
exportTable: any
exportTableSettings: any
exportCohort: any
exportTable: TableInfo
exportTableSettings: TableSetting[]
exportCohort: Cohort | null
setError: (arg: any) => 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 = () => {
Expand Down Expand Up @@ -51,10 +54,10 @@ const ExportTable: React.FC<ExportTableProps> = ({
const [countError, setCountError] = useState<boolean>(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<boolean>(tableSetting?.isChecked || false)
const [checkedTable, setCheckedTable] = useState<boolean>(tableSetting.isChecked || false)
const appConfig = useContext(AppConfig)
const limit = appConfig.features.export.exportLinesLimit

Expand All @@ -72,7 +75,7 @@ const ExportTable: React.FC<ExportTableProps> = ({
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) {
Expand All @@ -82,7 +85,9 @@ const ExportTable: React.FC<ExportTableProps> = ({
}, [cohortId, exportTableResourceType, setError, tableSetting?.fhirFilter])

useEffect(() => {
setCheckedTable(tableSetting?.isChecked)
if (tableSetting?.isChecked !== null) {
setCheckedTable(tableSetting?.isChecked)
}
}, [tableSetting?.isChecked])

useEffect(() => {
Expand All @@ -105,7 +110,7 @@ const ExportTable: React.FC<ExportTableProps> = ({
})

const isCompatibleTable = (tableName: string) => {
const table = compatibilitiesTables?.find((table: any) => table === tableName)
const table = compatibilitiesTables?.find((table) => table === tableName)
return table
}

Expand Down Expand Up @@ -250,11 +255,12 @@ const ExportTable: React.FC<ExportTableProps> = ({
)}
</Grid>
</Grid>
{count !== null && count > limit && (
{count !== null && (exportTableResourceType === ResourceType.DOCUMENTS ? count > 5000 : count > limit) && (
<Grid>
<Typography color={'red'} fontWeight={'bold'} fontSize={12}>
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.
</Typography>
</Grid>
Expand Down
2 changes: 1 addition & 1 deletion src/services/aphp/callApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ export const fetchExportableCohorts = async () => {

type fetchExportTableInfoProps = {
tableNames?: string
relationLink?: (string | null)[]
relationLink?: string[]
}

export const fetchExportTableInfo = async (args: fetchExportTableInfoProps) => {
Expand Down
4 changes: 2 additions & 2 deletions src/services/aphp/serviceExportCohort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Check failure on line 6 in src/services/aphp/serviceExportCohort.ts

View workflow job for this annotation

GitHub Actions / test

Cannot find module 'types/export' or its corresponding type declarations.

export const fetchExportTablesInfo = () => {
try {
Expand All @@ -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 =
Expand Down

0 comments on commit 9e6774a

Please sign in to comment.