Skip to content

Commit

Permalink
Remove a maximum occurrences of 'any' type (#671)
Browse files Browse the repository at this point in the history
* Remove a maximum ocurrences of 'any' type ...

Signed-off-by: Franck LECUYER <[email protected]>
  • Loading branch information
FranckLecuyer authored Jan 24, 2025
1 parent 7ee19dd commit 9986a23
Show file tree
Hide file tree
Showing 33 changed files with 155 additions and 90 deletions.
7 changes: 3 additions & 4 deletions src/components/authentication/utils/userManagerMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ import {
} from 'oidc-client';

class Events implements UserManagerEvents {
userLoadedCallbacks: ((data: any) => void)[] = [];
userLoadedCallbacks: ((data: User) => void)[] = [];

addUserLoaded(callback: (data: any) => void) {
addUserLoaded(callback: (data: User) => void) {
this.userLoadedCallbacks.push(callback);
}

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

Expand Down
28 changes: 10 additions & 18 deletions src/components/directoryItemSelector/DirectoryItemSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function refreshedUpNodes(
const parent = nodeMap[newElement.parentUuid];
const nextChildren = parent.children.map((c) => (c.elementUuid === newElement.elementUuid ? newElement : c));
const nextParent = { ...parent, children: nextChildren };
return [newElement, ...refreshedUpNodes(nodeMap, nextParent)];
return [newElement, ...refreshedUpNodes(nodeMap, nextParent as ElementAttributesBase)];
}

/**
Expand Down Expand Up @@ -148,19 +148,9 @@ function updatedTree(
}

export interface DirectoryItemSelectorProps extends TreeViewFinderProps {
open: boolean;
types: string[];
equipmentTypes?: string[];
itemFilter?: any;
classes?: any;
contentText?: string;
defaultExpanded?: string[];
defaultSelected?: string[];
validationButtonText?: string;
className?: string;
cancelButtonProps?: any;
onlyLeaves?: boolean;
multiselect?: boolean;
itemFilter?: (val: ElementAttributes) => boolean;
expanded?: UUID[];
selected?: UUID[];
}
Expand Down Expand Up @@ -196,7 +186,7 @@ export function DirectoryItemSelector({
const { snackError } = useSnackMessage();
const contentFilter = useCallback(() => new Set([ElementType.DIRECTORY, ...types]), [types]);

const convertChildren = useCallback((children: any[]): any[] => {
const convertChildren = useCallback((children: ElementAttributes[]): TreeViewFinderNodeProps[] => {
return children.map((e) => {
return {
id: e.elementUuid,
Expand All @@ -210,7 +200,7 @@ export function DirectoryItemSelector({
}, []);

const convertRoots = useCallback(
(newRoots: ElementAttributes[]) => {
(newRoots: ElementAttributes[]): TreeViewFinderNodeProps[] => {
return newRoots.map((e) => {
return {
id: e.elementUuid,
Expand Down Expand Up @@ -258,16 +248,18 @@ export function DirectoryItemSelector({
const typeList = types.includes(ElementType.DIRECTORY) ? [] : types;
fetchDirectoryContent(nodeId, typeList)
.then((children) => {
const childrenMatchedTypes = children.filter((item: any) => contentFilter().has(item.type));
const childrenMatchedTypes = children.filter((item: ElementAttributes) =>
contentFilter().has(item.type)
);

if (childrenMatchedTypes.length > 0 && equipmentTypes && equipmentTypes.length > 0) {
fetchElementsInfos(
childrenMatchedTypes.map((e: any) => e.elementUuid),
childrenMatchedTypes.map((e: ElementAttributes) => e.elementUuid),
types,
equipmentTypes
).then((childrenWithMetadata) => {
).then((childrenWithMetadata: ElementAttributes[]) => {
const filtredChildren = itemFilter
? childrenWithMetadata.filter((val: any) => {
? childrenWithMetadata.filter((val: ElementAttributes) => {
// Accept every directory
if (val.type === ElementType.DIRECTORY) {
return true;
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
20 changes: 12 additions & 8 deletions src/components/filter/expert/ExpertFilterEditionDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ 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 { catchErrorHandler } from '../../../services';
import { EXPERT_FILTER_QUERY } from './expertFilterConstants';

const formSchema = yup
.object()
Expand Down Expand Up @@ -65,21 +67,23 @@ export function ExpertFilterEditionDialog({
if (id && open) {
setDataFetchStatus(FetchStatus.FETCHING);
getFilterById(id)
.then((response: { [prop: string]: any }) => {
.then((response) => {
setDataFetchStatus(FetchStatus.FETCH_SUCCESS);
reset({
[FieldConstants.NAME]: name,
[FieldConstants.DESCRIPTION]: description,
[FieldConstants.FILTER_TYPE]: FilterType.EXPERT.id,
[FieldConstants.EQUIPMENT_TYPE]: response[FieldConstants.EQUIPMENT_TYPE],
[EXPERT_FILTER_QUERY]: importExpertRules(response[EXPERT_FILTER_QUERY]),
[EXPERT_FILTER_QUERY]: importExpertRules(response[EXPERT_FILTER_QUERY]!),
});
})
.catch((error: { message: any }) => {
setDataFetchStatus(FetchStatus.FETCH_ERROR);
snackError({
messageTxt: error.message,
headerId: 'cannotRetrieveFilter',
.catch((error: unknown) => {
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';
24 changes: 22 additions & 2 deletions src/components/filter/filter.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +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 @@ -20,6 +23,11 @@ export type ItemSelectionForCopy = {
specificTypeItem: string | null;
};

type EquipmentsFilter = {
equipmentID: string;
distributionKey?: number;
};

export interface FilterEditionProps {
id: string;
name: string;
Expand All @@ -29,9 +37,21 @@ 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]?: EquipmentsFilter[];
}>;
activeDirectory?: UUID;
elementExists?: ElementExistsType;
language?: string;
description?: string;
}

export interface NewFilterType {
id: string | null;
type: string;
equipmentType: string;
rules?: RuleGroupTypeExport;
filterEquipmentsAttributes?: EquipmentsFilter[];
}
17 changes: 12 additions & 5 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 @@ -40,6 +41,7 @@ export const saveExplicitNamingFilter = (
if (isFilterCreation) {
createFilter(
{
id: null,
type: FilterType.EXPLICIT_NAMING.id,
equipmentType,
filterEquipmentsAttributes: cleanedTableValues,
Expand Down Expand Up @@ -82,14 +84,15 @@ export const saveExpertFilter = (
name: string,
description: string,
isFilterCreation: boolean,
activeDirectory: any,
activeDirectory: UUID | undefined | null,
onClose: () => void,
onError: (message: string) => void,
token?: string
) => {
if (isFilterCreation) {
createFilter(
{
id: null,
type: FilterType.EXPERT.id,
equipmentType,
rules: exportExpertRules(query),
Expand All @@ -102,8 +105,10 @@ export const saveExpertFilter = (
.then(() => {
onClose();
})
.catch((error: any) => {
onError(error.message);
.catch((error: unknown) => {
catchErrorHandler(error, (message: string) => {
onError(message);
});
});
} else {
saveFilter(
Expand All @@ -120,8 +125,10 @@ export const saveExpertFilter = (
.then(() => {
onClose();
})
.catch((error: any) => {
onError(error.message);
.catch((error: unknown) => {
catchErrorHandler(error, (message: string) => {
onError(message);
});
});
}
};
4 changes: 2 additions & 2 deletions src/components/flatParameters/FlatParameters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const IntegerRE = /^-?\d*$/;
const ListRE = /^\[(.*)]$/;
const sepRE = /[, ]/;

export function extractDefault(paramDescription: any) {
export function extractDefault(paramDescription: Parameter) {
const d = paramDescription.defaultValue;
if (paramDescription.type === 'BOOLEAN') {
return !!d;
Expand Down Expand Up @@ -95,7 +95,7 @@ export type Parameter = {
type: 'BOOLEAN' | 'DOUBLE' | 'INTEGER' | 'STRING_LIST' | 'STRING';
description?: string;
name: string;
possibleValues: any;
possibleValues: string[];
defaultValue: any;
};

Expand Down
Loading

0 comments on commit 9986a23

Please sign in to comment.