Skip to content
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a5b7d63
Add color map to DirectoryItemInput so we can give different color by…
basseche Aug 22, 2025
af23c4d
Merge branch 'main' into contingencyListByFilter
basseche Aug 22, 2025
154a34e
Merge branch 'main' into contingencyListByFilter
basseche Sep 2, 2025
cef7aef
fix directoryItemsInput
basseche Sep 2, 2025
e1105c2
Improve interface
basseche Sep 3, 2025
3274603
restore useless changes
basseche Sep 4, 2025
bf01977
remove useless changes
basseche Sep 4, 2025
20e1f4d
add field
basseche Sep 9, 2025
1c942b0
Improve Function
basseche Sep 10, 2025
5dfb28d
Merge branch 'main' into contingencyListByFilter
basseche Sep 11, 2025
1387f3f
Merge branch 'main' into contingencyListByFilter
basseche Sep 16, 2025
de3b700
Merge branch 'main' into contingencyListByFilter
basseche Sep 16, 2025
4cd653e
Merge branch 'main' into contingencyListByFilter
basseche Sep 17, 2025
fcdec69
review
basseche Sep 22, 2025
6c0770a
add element not found
basseche Sep 22, 2025
9f2f6e2
merge from main
thangqp Sep 22, 2025
c488c87
Merge branch 'main' into contingencyListByFilter
basseche Sep 23, 2025
89d1391
review
basseche Sep 23, 2025
a0a380b
review2
basseche Sep 23, 2025
88f6146
review
basseche Sep 23, 2025
ff49f89
Update src/components/inputs/reactHookForm/DirectoryItemsInput.tsx
basseche Sep 23, 2025
d3488e3
fix build
basseche Sep 24, 2025
6fd4573
Merge branch 'main' into contingencyListByFilter
basseche Sep 24, 2025
759ed02
review
basseche Sep 24, 2025
1e50e3f
fix regression
basseche Sep 24, 2025
606d27f
move condition
thangqp Sep 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/components/filter/expert/expertFilterUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
RuleGroupTypeExport,
RuleTypeExport,
} from './expertFilter.type';
import { FIELDS_OPTIONS, OPERATOR_OPTIONS, RULES } from './expertFilterConstants';
import { EXPERT_FILTER_EQUIPMENTS, FIELDS_OPTIONS, OPERATOR_OPTIONS, RULES } from './expertFilterConstants';
import { convertInputValue, convertOutputValue, isBlankOrEmpty } from '../../../utils/conversionUtils';
import { FieldType } from '../../../utils/types/fieldType';

Expand Down Expand Up @@ -524,3 +524,10 @@ export function recursiveRemove(query: RuleGroupTypeAny, path: number[]): RuleGr

return remove(query, path);
}

export function getFilterEquipmentTypeLabel(equipmentType: string | undefined): string {
if (!equipmentType) {
return '';
}
return EXPERT_FILTER_EQUIPMENTS[equipmentType as keyof typeof EXPERT_FILTER_EQUIPMENTS]?.label ?? '';
}
75 changes: 47 additions & 28 deletions src/components/inputs/reactHookForm/DirectoryItemsInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,25 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { Chip, FormControl, Grid, IconButton, Tooltip } from '@mui/material';
import { Box, Chip, FormControl, FormHelperText, Grid, IconButton, 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, type MuiStyles } from '../../../utils/styles';
import { type MuiStyles } 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 { ElementAttributes, mergeSx } from '../../../utils';
import { NAME } from './constants';
import { getFilterEquipmentTypeLabel } from '../../filter/expert/expertFilterUtils';

const styles = {
formDirectoryElements1: {
Expand Down Expand Up @@ -67,6 +66,7 @@ export interface DirectoryItemsInputProps {
disable?: boolean;
allowMultiSelect?: boolean;
labelRequiredFromContext?: boolean;
equipmentColorsMap?: Map<string, string>;
}

export function DirectoryItemsInput({
Expand All @@ -82,6 +82,7 @@ export function DirectoryItemsInput({
disable = false,
allowMultiSelect = true,
labelRequiredFromContext = true,
equipmentColorsMap,
}: Readonly<DirectoryItemsInputProps>) {
const { snackError } = useSnackMessage();
const intl = useIntl();
Expand All @@ -90,13 +91,10 @@ export function DirectoryItemsInput({
const [multiSelect, setMultiSelect] = useState(allowMultiSelect);
const types = useMemo(() => [elementType], [elementType]);
const [directoryItemSelectorOpen, setDirectoryItemSelectorOpen] = useState(false);
const {
fields: elements,
append,
remove,
} = useFieldArray({
const { fields, append, remove } = useFieldArray({
name,
});
const elements: TreeViewFinderNodeProps[] = fields as unknown as TreeViewFinderNodeProps[];

const formContext = useCustomFormContext();
const { getValues, validationSchema } = formContext;
Expand Down Expand Up @@ -189,18 +187,39 @@ export function DirectoryItemsInput({
{elements?.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%' }}
/>
}
/>
<Box key={item.id} sx={{ display: 'flex', flexDirection: 'column', gap: 1 }}>
<Chip
size="small"
sx={{
backgroundColor:
item?.specificMetadata?.equipmentType &&
equipmentColorsMap?.get(item?.specificMetadata?.equipmentType),
}}
onDelete={() => removeElements(index)}
onClick={() => handleChipClick(index)}
label={
<OverflowableText
text={
getValues(`${name}.${index}.${NAME}`) ? (
<RawReadOnlyInput name={`${name}.${index}.${NAME}`} />
) : (
intl.formatMessage({ id: 'elementNotFound' })
)
}
sx={{ width: '100%' }}
/>
}
/>
<FormHelperText>
{item?.specificMetadata?.equipmentType ? (
<FormattedMessage
id={getFilterEquipmentTypeLabel(item.specificMetadata.equipmentType)}
/>
) : (
''
)}
</FormHelperText>
</Box>
))}
</FormControl>
)}
Expand Down
3 changes: 3 additions & 0 deletions src/components/treeViewFinder/TreeViewFinder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ export interface TreeViewFinderNodeProps {
childrenCount?: number;
children?: TreeViewFinderNodeProps[];
parents?: TreeViewFinderNodeProps[];
specificMetadata?: {
equipmentType: string;
};
}

interface TreeViewFinderNodeMapProps {
Expand Down
1 change: 1 addition & 0 deletions src/translations/en/filterEn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ export const filterEn = {
nameAlreadyUsed: 'This name is already used',
nameValidityCheckErrorMsg: 'Error while checking name validity',
cantSubmitWhileValidating: 'Impossible to submit the form while validating a field',
elementNotFound: 'element not found',
};
1 change: 1 addition & 0 deletions src/translations/fr/filterFr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ export const filterFr = {
nameAlreadyUsed: 'Ce nom est déjà utilisé',
nameValidityCheckErrorMsg: 'Erreur lors de la vérification de la validité du nom',
cantSubmitWhileValidating: "Impossible de soumettre le formulaire durant la validation d'un champ",
elementNotFound: 'Élément inexistant',
};
2 changes: 2 additions & 0 deletions src/utils/constants/fieldConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export enum FieldConstants {
EQUIPMENT_TABLE = 'equipmentTable',
EQUIPMENT_TYPE = 'equipmentType',
FILTER_TYPE = 'filterType',
FILTERS = 'filters',
FOLDER_ID = 'folderId',
FOLDER_NAME = 'folderName',
FORMATTED_CASE_PARAMETERS = 'formattedCaseParameters',
Expand All @@ -37,6 +38,7 @@ export enum FieldConstants {
NOMINAL_VOLTAGE_3 = 'nominalVoltage3',
NOMINAL_VOLTAGE = 'nominalVoltage',
OPERATION_TYPE = 'type',
TYPE = 'type',
PROPERTY_NAME = 'propertyName',
PROPERTY_OPERATOR = 'propertyOperator',
PROPERTY = 'PROPERTY',
Expand Down
Loading