Skip to content

Commit

Permalink
Modifications after review
Browse files Browse the repository at this point in the history
Signed-off-by: Franck LECUYER <[email protected]>
  • Loading branch information
FranckLecuyer committed Jan 22, 2025
1 parent f70d6e4 commit 1692dd9
Show file tree
Hide file tree
Showing 19 changed files with 75 additions and 55 deletions.
3 changes: 1 addition & 2 deletions src/components/authentication/utils/userManagerMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ class Events implements UserManagerEvents {
this.userLoadedCallbacks.push(callback);
}

// eslint-disable-next-line
addSilentRenewError(callback: (data: Error) => void) {
addSilentRenewError() {
// Nothing to do
}

Expand Down
17 changes: 3 additions & 14 deletions src/components/directoryItemSelector/DirectoryItemSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
*/

import { useCallback, useEffect, useRef, useState } from 'react';
import { ButtonProps, SxProps, Theme } from '@mui/material';
import { SxProps, Theme } from '@mui/material';
import { UUID } from 'crypto';
import { TreeViewClasses } from '@mui/x-tree-view';
import { getFileIcon } from '../../utils/mapper/getFileIcon';
import { ElementType } from '../../utils/types/elementType';
import { TreeViewFinder, TreeViewFinderNodeProps, TreeViewFinderProps } from '../treeViewFinder/TreeViewFinder';
Expand Down Expand Up @@ -149,19 +148,9 @@ function updatedTree(
}

export interface DirectoryItemSelectorProps extends TreeViewFinderProps {
open: boolean;
types: string[];
equipmentTypes?: string[];
itemFilter?: (val: ElementAttributes) => boolean;
classes?: Partial<TreeViewClasses>;
contentText?: string;
defaultExpanded?: string[];
defaultSelected?: string[];
validationButtonText?: string;
className?: string;
cancelButtonProps?: ButtonProps;
onlyLeaves?: boolean;
multiselect?: boolean;
expanded?: UUID[];
selected?: UUID[];
}
Expand Down Expand Up @@ -207,7 +196,7 @@ export function DirectoryItemSelector({
children: e.type === ElementType.DIRECTORY ? convertChildren(e.children) : undefined,
childrenCount: e.type === ElementType.DIRECTORY ? e.subdirectoriesCount : undefined,
};
}) as TreeViewFinderNodeProps[];
});
}, []);

const convertRoots = useCallback(
Expand Down Expand Up @@ -258,7 +247,7 @@ export function DirectoryItemSelector({
(nodeId: UUID): void => {
const typeList = types.includes(ElementType.DIRECTORY) ? [] : types;
fetchDirectoryContent(nodeId, typeList)
.then((children: ElementAttributes[]) => {
.then((children) => {
const childrenMatchedTypes = children.filter((item: ElementAttributes) =>
contentFilter().has(item.type)
);
Expand Down
5 changes: 3 additions & 2 deletions src/components/filter/FilterCreationDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ import { useSnackMessage } from '../../hooks/useSnackMessage';
import { CustomMuiDialog } from '../dialogs/customMuiDialog/CustomMuiDialog';
import {
explicitNamingFilterSchema,
FILTER_EQUIPMENTS_ATTRIBUTES,
getExplicitNamingFilterEmptyFormData,
} from './explicitNaming/ExplicitNamingFilterForm';
import { FieldConstants } from '../../utils/constants/fieldConstants';
import yup from '../../utils/yupConfig';
import { FilterForm } from './FilterForm';
import { EXPERT_FILTER_QUERY, expertFilterSchema, getExpertFilterEmptyFormData } from './expert/ExpertFilterForm';
import { expertFilterSchema, getExpertFilterEmptyFormData } from './expert/ExpertFilterForm';
import { FilterType } from './constants/FilterConstants';
import { ElementExistsType } from '../../utils/types/elementType';
import { MAX_CHAR_DESCRIPTION } from '../../utils/constants/uiConstants';
import { EXPERT_FILTER_QUERY } from './expert/expertFilterConstants';
import { FILTER_EQUIPMENTS_ATTRIBUTES } from './explicitNaming/ExplicitNamingFilterConstants';

const emptyFormData = {
[FieldConstants.NAME]: '',
Expand Down
18 changes: 11 additions & 7 deletions src/components/filter/expert/ExpertFilterEditionDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import { FilterType, NO_ITEM_SELECTION_FOR_COPY } from '../constants/FilterConst
import { FilterEditionProps } from '../filter.type';
import { FilterForm } from '../FilterForm';
import { saveExpertFilter } from '../utils/filterApi';
import { EXPERT_FILTER_QUERY, expertFilterSchema } from './ExpertFilterForm';
import { expertFilterSchema } from './ExpertFilterForm';
import { importExpertRules } from './expertFilterUtils';
import { HeaderFilterSchema } from '../HeaderFilterForm';
import { RuleGroupTypeExport } from './expertFilter.type';
import { catchErrorHandler } from '../../../services';
import { EXPERT_FILTER_QUERY } from './expertFilterConstants';

const formSchema = yup
.object()
Expand Down Expand Up @@ -66,7 +68,7 @@ export function ExpertFilterEditionDialog({
if (id && open) {
setDataFetchStatus(FetchStatus.FETCHING);
getFilterById(id)
.then((response: { [prop: string]: RuleGroupTypeExport | string }) => {
.then((response) => {
setDataFetchStatus(FetchStatus.FETCH_SUCCESS);
reset({
[FieldConstants.NAME]: name,
Expand All @@ -76,11 +78,13 @@ export function ExpertFilterEditionDialog({
[EXPERT_FILTER_QUERY]: importExpertRules(response[EXPERT_FILTER_QUERY] as RuleGroupTypeExport),
});
})
.catch((error: { message: string }) => {
setDataFetchStatus(FetchStatus.FETCH_ERROR);
snackError({
messageTxt: error.message,
headerId: 'cannotRetrieveFilter',
.catch((error: Error) => {
catchErrorHandler(error, (message: string) => {
setDataFetchStatus(FetchStatus.FETCH_ERROR);
snackError({
messageTxt: message,
headerId: 'cannotRetrieveFilter',
});
});
});
}
Expand Down
3 changes: 1 addition & 2 deletions src/components/filter/expert/ExpertFilterForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
COMBINATOR_OPTIONS,
EXPERT_FILTER_EQUIPMENTS,
EXPERT_FILTER_FIELDS,
EXPERT_FILTER_QUERY,
OPERATOR_OPTIONS,
RULES,
} from './expertFilterConstants';
Expand All @@ -44,8 +45,6 @@ yup.setLocale({
},
});

export const EXPERT_FILTER_QUERY = 'rules';

function isSupportedEquipmentType(equipmentType: string): boolean {
return Object.values(EXPERT_FILTER_EQUIPMENTS)
.map((equipments) => equipments.id)
Expand Down
2 changes: 2 additions & 0 deletions src/components/filter/expert/expertFilterConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export enum RULES {
BETWEEN_RULE = 'betweenRule',
}

export const EXPERT_FILTER_QUERY = 'rules';

export const EXPERT_FILTER_EQUIPMENTS = {
SUBSTATION: {
id: 'SUBSTATION',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Copyright (c) 2024, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

export const FILTER_EQUIPMENTS_ATTRIBUTES = 'filterEquipmentsAttributes';
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ import { FieldConstants } from '../../../utils/constants/fieldConstants';
import yup from '../../../utils/yupConfig';
import { CustomMuiDialog } from '../../dialogs/customMuiDialog/CustomMuiDialog';
import { saveExplicitNamingFilter } from '../utils/filterApi';
import { explicitNamingFilterSchema, FILTER_EQUIPMENTS_ATTRIBUTES } from './ExplicitNamingFilterForm';
import { explicitNamingFilterSchema } from './ExplicitNamingFilterForm';

import { FetchStatus } from '../../../utils/constants/fetchStatus';
import { FilterForm } from '../FilterForm';
import { FilterType, NO_ITEM_SELECTION_FOR_COPY } from '../constants/FilterConstants';
import { FilterEditionProps } from '../filter.type';
import { HeaderFilterSchema } from '../HeaderFilterForm';
import { FILTER_EQUIPMENTS_ATTRIBUTES } from './ExplicitNamingFilterConstants';

const formSchema = yup
.object()
Expand Down Expand Up @@ -75,7 +76,7 @@ export function ExplicitNamingFilterEditionDialog({
[FieldConstants.DESCRIPTION]: description,
[FieldConstants.FILTER_TYPE]: FilterType.EXPLICIT_NAMING.id,
[FieldConstants.EQUIPMENT_TYPE]: response[FieldConstants.EQUIPMENT_TYPE],
[FILTER_EQUIPMENTS_ATTRIBUTES]: response[FILTER_EQUIPMENTS_ATTRIBUTES].map((row: any) => ({
[FILTER_EQUIPMENTS_ATTRIBUTES]: response[FILTER_EQUIPMENTS_ATTRIBUTES]?.map((row: any) => ({
[FieldConstants.AG_GRID_ROW_UUID]: uuid4(),
...row,
})),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ import { ModifyElementSelection } from '../../dialogs/modifyElementSelection/Mod
import { exportFilter } from '../../../services/study';
import { EquipmentType } from '../../../utils/types/equipmentType';
import { unscrollableDialogStyles } from '../../dialogs';

export const FILTER_EQUIPMENTS_ATTRIBUTES = 'filterEquipmentsAttributes';
import { FILTER_EQUIPMENTS_ATTRIBUTES } from './ExplicitNamingFilterConstants';

function isGeneratorOrLoad(equipmentType: string): boolean {
return equipmentType === Generator.type || equipmentType === Load.type;
Expand Down
1 change: 1 addition & 0 deletions src/components/filter/explicitNaming/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
*/
export * from './ExplicitNamingFilterEditionDialog';
export * from './ExplicitNamingFilterForm';
export * from './ExplicitNamingFilterConstants';
10 changes: 8 additions & 2 deletions src/components/filter/filter.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
*/

import { UUID } from 'crypto';
import { ElementExistsType } from '../../utils';
import { ElementExistsType, FieldConstants } from '../../utils';
import { RuleGroupTypeExport } from './expert/expertFilter.type';
import { EXPERT_FILTER_QUERY } from './expert/expertFilterConstants';
import { FILTER_EQUIPMENTS_ATTRIBUTES } from './explicitNaming/ExplicitNamingFilterConstants';

/**
* Represent an item/object in directories.
Expand All @@ -30,7 +32,11 @@ export interface FilterEditionProps {
broadcastChannel: BroadcastChannel;
itemSelectionForCopy: ItemSelectionForCopy;
setItemSelectionForCopy: (selection: ItemSelectionForCopy) => void;
getFilterById: (id: string) => Promise<{ [prop: string]: any }>;
getFilterById: (id: string) => Promise<{
[FieldConstants.EQUIPMENT_TYPE]: string;
[EXPERT_FILTER_QUERY]?: RuleGroupTypeExport;
[FILTER_EQUIPMENTS_ATTRIBUTES]?: any[];
}>;
activeDirectory?: UUID;
elementExists?: ElementExistsType;
language?: string;
Expand Down
9 changes: 7 additions & 2 deletions src/components/filter/utils/filterApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Generator, Load } from '../../../utils/types/equipmentTypes';
import { exportExpertRules } from '../expert/expertFilterUtils';
import { DISTRIBUTION_KEY, FilterType } from '../constants/FilterConstants';
import { createFilter, saveFilter } from '../../../services/explore';
import { catchErrorHandler } from '../../../services';

export const saveExplicitNamingFilter = (
tableValues: any[],
Expand Down Expand Up @@ -105,7 +106,9 @@ export const saveExpertFilter = (
onClose();
})
.catch((error: Error) => {
onError(error.message);
catchErrorHandler(error, (message: string) => {
onError(message);
});
});
} else {
saveFilter(
Expand All @@ -123,7 +126,9 @@ export const saveExpertFilter = (
onClose();
})
.catch((error: Error) => {
onError(error.message);
catchErrorHandler(error, (message: string) => {
onError(message);
});
});
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class NumericEditor implements ICellEditorComp {
this.eInput.value = params.value;
}

this.eInput.addEventListener('keydown', (event: KeyboardEvent) => {
this.eInput.addEventListener('keydown', (event) => {
if (!event.key || event.key.length !== 1) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export function BooleanInput({ name, label, formProps, Input }: BooleanInputProp
);

const CustomInput = (
// @ts-ignore
<Input
checked={value}
onChange={(e: ChangeEvent<HTMLInputElement>) => handleChangeValue(e)}
Expand Down
4 changes: 2 additions & 2 deletions src/components/inputs/reactQueryBuilder/ValueEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ export function ValueEditor(props: ValueEditorProps) {
return (
// we do not authorize to use an expert filter in the rules of
// another expert filter, to prevent potential cycle problems
(filterValue?.specificMetadata?.type as unknown as string) !== FilterType.EXPERT.id &&
filterValue?.specificMetadata?.type !== FilterType.EXPERT.id &&
((field === FieldType.ID &&
filterValue?.specificMetadata?.equipmentType === getValues(FieldConstants.EQUIPMENT_TYPE)) ||
((field === FieldType.VOLTAGE_LEVEL_ID ||
field === FieldType.VOLTAGE_LEVEL_ID_1 ||
field === FieldType.VOLTAGE_LEVEL_ID_2 ||
field === FieldType.VOLTAGE_LEVEL_ID_3) &&
(filterValue?.specificMetadata?.equipmentType as unknown as string) === VoltageLevel.type))
filterValue?.specificMetadata?.equipmentType === VoltageLevel.type))
);
}
return true;
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/useSnackMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useIntlRef } from './useIntlRef';
interface SnackInputs extends Omit<OptionsObject, 'variant' | 'style'> {
messageTxt?: string;
messageId?: string;
messageValues?: { [key: string]: string };
messageValues?: Record<string, string>;
headerTxt?: string;
headerId?: string;
headerValues?: Record<string, string>;
Expand All @@ -26,7 +26,7 @@ export interface UseSnackMessageReturn {
closeSnackbar: typeof closeSnackbarFromNotistack;
}

function checkInputs(txt?: string, id?: string, values?: { [key: string]: string } | Record<string, string>) {
function checkInputs(txt?: string, id?: string, values?: SnackInputs['messageValues']) {
if (txt && (id || values)) {
console.warn('Snack inputs should be [*Txt] OR [*Id, *Values]');
}
Expand All @@ -36,7 +36,7 @@ function checkAndTranslateIfNecessary(
intlRef: MutableRefObject<IntlShape>,
txt?: string,
id?: string,
values?: { [key: string]: string } | Record<string, string>
values?: SnackInputs['messageValues']
) {
checkInputs(txt, id, values);
return (
Expand Down
7 changes: 7 additions & 0 deletions src/module-mui.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import '@mui/material/Switch';

// used to customize mui theme
// https://mui.com/material-ui/customization/theming/#typescript
Expand All @@ -19,3 +20,9 @@ declare module '@mui/material/styles/createTheme' {
};
}
}

declare module '@mui/material/Switch' {
interface SwitchPropsSizeOverrides {
large: true;
}
}
19 changes: 7 additions & 12 deletions src/utils/algos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

export function equalsArray(
a: [Record<string, number | string | undefined>, number][] | null,
b: [Record<string, number | string | undefined>, number][]
) {
export function equalsArray<T>(a: T[] | null, b: T[]) {
if (b === a) {
return true;
}
Expand All @@ -20,16 +17,14 @@ export function equalsArray(
}

for (let i = 0, l = a.length; i < l; i++) {
if (a[i] instanceof Array && b[i] instanceof Array) {
if (
!equalsArray(
a[i] as unknown as [Record<string, number | string | undefined>, number][] | null,
b[i] as unknown as [Record<string, number | string | undefined>, number][]
)
) {
const newA = a[i];
const newB = b[i];

if (newA instanceof Array && newB instanceof Array) {
if (!equalsArray(newA, newB)) {
return false;
}
} else if (a[i] !== b[i]) {
} else if (newA !== newB) {
// Warning - two different object instances will never be equal: {x:20} != {x:20}
return false;
}
Expand Down
7 changes: 6 additions & 1 deletion src/utils/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ export type ElementAttributes = {
lastModifiedByLabel?: string; // enrich with user identity server
children: ElementAttributes[];
parentUuid: null | UUID;
specificMetadata: Record<string, object>;
specificMetadata: {
type: string;
equipmentType: string;
sheetType?: string;
format?: string;
};
uploading?: boolean;
hasMetadata?: boolean;
subtype?: string;
Expand Down

0 comments on commit 1692dd9

Please sign in to comment.