-
Notifications
You must be signed in to change notification settings - Fork 4
Add color map to DirectoryItemInput so we can give different color by equipmentType and add Fields needed for contingency list by filter #839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
a5b7d63
af23c4d
154a34e
cef7aef
e1105c2
3274603
bf01977
20e1f4d
1c942b0
5dfb28d
1387f3f
de3b700
4cd653e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -5,25 +5,22 @@ | |||||||||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||||||||||||||
*/ | ||||||||||||||
|
||||||||||||||
import { Chip, FormControl, Grid, IconButton, Theme, Tooltip } from '@mui/material'; | ||||||||||||||
import { Box, Chip, FormControl, FormHelperText, Grid, IconButton, Theme, Tooltip } from '@mui/material'; | ||||||||||||||
import { Folder as FolderIcon } from '@mui/icons-material'; | ||||||||||||||
import { useCallback, useMemo, useState } from 'react'; | ||||||||||||||
import { FieldValues, useController, useFieldArray } from 'react-hook-form'; | ||||||||||||||
import { useIntl } from 'react-intl'; | ||||||||||||||
import { FormattedMessage, useIntl } from 'react-intl'; | ||||||||||||||
import { UUID } from 'crypto'; | ||||||||||||||
import { RawReadOnlyInput } from './RawReadOnlyInput'; | ||||||||||||||
import { FieldLabel } from './utils/FieldLabel'; | ||||||||||||||
import { useCustomFormContext } from './provider/useCustomFormContext'; | ||||||||||||||
import { isFieldRequired } from './utils/functions'; | ||||||||||||||
import { ErrorInput } from './errorManagement/ErrorInput'; | ||||||||||||||
import { useSnackMessage } from '../../../hooks/useSnackMessage'; | ||||||||||||||
import { FieldLabel, isFieldRequired } from './utils'; | ||||||||||||||
import { useCustomFormContext } from './provider'; | ||||||||||||||
import { ErrorInput, MidFormError } from './errorManagement'; | ||||||||||||||
import { useSnackMessage } from '../../../hooks'; | ||||||||||||||
import { TreeViewFinderNodeProps } from '../../treeViewFinder'; | ||||||||||||||
import { mergeSx } from '../../../utils/styles'; | ||||||||||||||
import { OverflowableText } from '../../overflowableText'; | ||||||||||||||
import { MidFormError } from './errorManagement/MidFormError'; | ||||||||||||||
import { DirectoryItemSelector } from '../../directoryItemSelector/DirectoryItemSelector'; | ||||||||||||||
import { DirectoryItemSelector } from '../../directoryItemSelector'; | ||||||||||||||
import { fetchDirectoryElementPath } from '../../../services'; | ||||||||||||||
import { ElementAttributes } from '../../../utils'; | ||||||||||||||
import { getBasicEquipmentLabel, ElementAttributes, mergeSx } from '../../../utils'; | ||||||||||||||
import { NAME } from './constants'; | ||||||||||||||
|
||||||||||||||
const styles = { | ||||||||||||||
|
@@ -67,6 +64,7 @@ export interface DirectoryItemsInputProps { | |||||||||||||
disable?: boolean; | ||||||||||||||
allowMultiSelect?: boolean; | ||||||||||||||
labelRequiredFromContext?: boolean; | ||||||||||||||
equipmentColorsMap?: Map<string, string>; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
export function DirectoryItemsInput({ | ||||||||||||||
|
@@ -82,6 +80,7 @@ export function DirectoryItemsInput({ | |||||||||||||
disable = false, | ||||||||||||||
allowMultiSelect = true, | ||||||||||||||
labelRequiredFromContext = true, | ||||||||||||||
equipmentColorsMap, | ||||||||||||||
}: Readonly<DirectoryItemsInputProps>) { | ||||||||||||||
const { snackError } = useSnackMessage(); | ||||||||||||||
const intl = useIntl(); | ||||||||||||||
|
@@ -97,6 +96,7 @@ export function DirectoryItemsInput({ | |||||||||||||
} = useFieldArray({ | ||||||||||||||
name, | ||||||||||||||
}); | ||||||||||||||
const elementsWithMetaData: TreeViewFinderNodeProps[] = elements as unknown as TreeViewFinderNodeProps[]; | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On est sûr que les champs correspondent toujours à ce type TreeViewFinderNodeProps ? |
||||||||||||||
|
||||||||||||||
const formContext = useCustomFormContext(); | ||||||||||||||
const { getValues, validationSchema } = formContext; | ||||||||||||||
|
@@ -180,27 +180,45 @@ export function DirectoryItemsInput({ | |||||||||||||
)} | ||||||||||||||
error={!!error?.message} | ||||||||||||||
> | ||||||||||||||
{elements?.length === 0 && label && ( | ||||||||||||||
{elementsWithMetaData?.length === 0 && label && ( | ||||||||||||||
<FieldLabel | ||||||||||||||
label={label} | ||||||||||||||
optional={labelRequiredFromContext && !isFieldRequired(name, validationSchema, getValues())} | ||||||||||||||
/> | ||||||||||||||
)} | ||||||||||||||
{elements?.length > 0 && ( | ||||||||||||||
{elementsWithMetaData?.length > 0 && ( | ||||||||||||||
<FormControl sx={styles.formDirectoryElements2}> | ||||||||||||||
{elements.map((item, index) => ( | ||||||||||||||
<Chip | ||||||||||||||
key={item.id} | ||||||||||||||
size="small" | ||||||||||||||
onDelete={() => removeElements(index)} | ||||||||||||||
onClick={() => handleChipClick(index)} | ||||||||||||||
label={ | ||||||||||||||
<OverflowableText | ||||||||||||||
text={<RawReadOnlyInput name={`${name}.${index}.${NAME}`} />} | ||||||||||||||
sx={{ width: '100%' }} | ||||||||||||||
/> | ||||||||||||||
} | ||||||||||||||
/> | ||||||||||||||
{elementsWithMetaData.map((item, index) => ( | ||||||||||||||
<Box key={`Box${item.id}`} sx={{ display: 'flex', flexDirection: 'column', gap: 1 }}> | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. C'est pas quelque chose dont on risque d'avoir besoin ailleurs ? il faudrait peut-être sortir ce code et en faire un composant ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Petite question, pourquoi mettre box devant l'id ? |
||||||||||||||
<Chip | ||||||||||||||
key={item.id} | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Il y a toujours besoin de la prop key vu qu'il a été ajouté sur la box au-dessus ? |
||||||||||||||
size="small" | ||||||||||||||
sx={{ | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Au lieu d'utiliser sx et la variable css backgroundcolor, pas possible d'utiliser tout simplement color de Chip ? |
||||||||||||||
backgroundColor: | ||||||||||||||
item.specificMetadata?.equipmentType && | ||||||||||||||
equipmentColorsMap?.has(item.specificMetadata?.equipmentType) | ||||||||||||||
? equipmentColorsMap.get(item.specificMetadata.equipmentType) | ||||||||||||||
: undefined, | ||||||||||||||
Comment on lines
+198
to
+201
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Corrigez moi si je me trompe mais je crois que du coup ça revient exactement a la même chose |
||||||||||||||
}} | ||||||||||||||
onDelete={() => removeElements(index)} | ||||||||||||||
onClick={() => handleChipClick(index)} | ||||||||||||||
label={ | ||||||||||||||
<OverflowableText | ||||||||||||||
text={<RawReadOnlyInput name={`${name}.${index}.${NAME}`} />} | ||||||||||||||
sx={{ width: '100%' }} | ||||||||||||||
/> | ||||||||||||||
} | ||||||||||||||
/> | ||||||||||||||
<FormHelperText> | ||||||||||||||
{item?.specificMetadata?.equipmentType ? ( | ||||||||||||||
<FormattedMessage | ||||||||||||||
id={getBasicEquipmentLabel(item.specificMetadata.equipmentType)} | ||||||||||||||
/> | ||||||||||||||
) : ( | ||||||||||||||
'' | ||||||||||||||
)} | ||||||||||||||
</FormHelperText> | ||||||||||||||
</Box> | ||||||||||||||
))} | ||||||||||||||
</FormControl> | ||||||||||||||
)} | ||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,6 +136,15 @@ export const BASE_EQUIPMENTS: Partial<Record<EquipmentType, { id: EquipmentType; | |
}, | ||
}; | ||
|
||
export function getBasicEquipmentLabel(equipmentType: string | undefined): string { | ||
if (!equipmentType) { | ||
return ''; | ||
} | ||
return equipmentType !== EquipmentType.HVDC_LINE | ||
? (BASE_EQUIPMENTS[equipmentType as EquipmentType]?.label ?? '') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pourquoi ne pas rajouter ce type d'équipement dans BASE_EQUIPMENTS ? |
||
: 'HvdcLines'; | ||
} | ||
|
||
export const EQUIPMENT_TYPE: Partial< | ||
Record< | ||
EquipmentType | ExtendedEquipmentType, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
À mon avis il n'y a plus besoin de renommer fields ici vu qu'il est déjà renommé en bas, autant garder le nom d'origine ici plutôt que de le changer 2 fois