Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into jorism/remove-free-solo
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMaskedTurtle committed Jun 3, 2024
2 parents 42ce2a3 + d97ca2c commit 1b0d542
Show file tree
Hide file tree
Showing 52 changed files with 1,299 additions and 1,093 deletions.
11 changes: 9 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gridsuite/commons-ui",
"version": "0.58.0",
"version": "0.59.0",
"description": "common react components for gridsuite applications",
"engines": {
"npm": ">=9",
Expand Down Expand Up @@ -81,6 +81,7 @@
"@types/eslint-config-prettier": "^6.11.3",
"@types/json-logic-js": "^2.0.7",
"@types/license-checker": "^25.0.6",
"@types/localized-countries": "^2.0.3",
"@types/node": "^18.19.31",
"@types/prop-types": "^15.7.12",
"@types/react": "^18.2.75",
Expand Down
4 changes: 2 additions & 2 deletions src/components/AuthenticationRouter/AuthenticationRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export interface AuthenticationRouterProps {
showAuthenticationRouterLogin: boolean;
dispatch: Dispatch<unknown>;
navigate: () => void;
location: () => void;
location: Location;
}

const AuthenticationRouter = ({
Expand Down Expand Up @@ -119,7 +119,7 @@ const AuthenticationRouter = ({
<Logout
disabled={userManager.instance === null}
onLogoutClick={() =>
logout(location, userManager.instance)
logout(dispatch, userManager.instance)
}
/>
</Grid>
Expand Down
149 changes: 61 additions & 88 deletions src/components/DirectoryItemSelector/directory-item-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ import {
} from '../TreeViewFinder/TreeViewFinder';
import { UUID } from 'crypto';
import { useSnackMessage } from '../../hooks/useSnackMessage';
import { ElementAttributes } from '../../utils/types';
import {
fetchDirectoryContent,
fetchElementsInfos,
fetchRootFolders,
} from '../../services';

const styles = {
icon: (theme: Theme) => ({
Expand All @@ -37,16 +41,6 @@ interface DirectoryItemSelectorProps extends TreeViewFinderProps {
types: string[];
equipmentTypes?: string[];
itemFilter?: any;
fetchDirectoryContent?: (
directoryUuid: UUID,
elementTypes: string[]
) => Promise<ElementAttributes[]>;
fetchRootFolders?: (types: string[]) => Promise<ElementAttributes[]>;
fetchElementsInfos?: (
ids: UUID[],
elementTypes: string[],
equipmentTypes: string[]
) => Promise<ElementAttributes[]>;
classes?: any;
contentText?: string;
defaultExpanded?: string[];
Expand All @@ -64,9 +58,6 @@ const DirectoryItemSelector: FunctionComponent<DirectoryItemSelectorProps> = ({
types,
equipmentTypes,
itemFilter,
fetchDirectoryContent,
fetchRootFolders,
fetchElementsInfos,
expanded,
...otherTreeViewFinderProps
}) => {
Expand Down Expand Up @@ -142,88 +133,70 @@ const DirectoryItemSelector: FunctionComponent<DirectoryItemSelectorProps> = ({
);

const updateRootDirectories = useCallback(() => {
fetchRootFolders &&
fetchRootFolders(types)
.then((data) => {
let [nrs, mdr] = updatedTree(
rootsRef.current,
nodeMap.current,
null,
data
);
setRootDirectories(nrs);
nodeMap.current = mdr;
setData(convertRoots(nrs));
})
.catch((error) => {
snackError({
messageTxt: error.message,
headerId: 'DirectoryItemSelector',
});
fetchRootFolders(types)
.then((data) => {
let [nrs, mdr] = updatedTree(
rootsRef.current,
nodeMap.current,
null,
data
);
setRootDirectories(nrs);
nodeMap.current = mdr;
setData(convertRoots(nrs));
})
.catch((error) => {
snackError({
messageTxt: error.message,
headerId: 'DirectoryItemSelector',
});
}, [convertRoots, types, snackError, fetchRootFolders]);
});
}, [convertRoots, types, snackError]);

const fetchDirectory = useCallback(
(nodeId: UUID): void => {
const typeList = types.includes(ElementType.DIRECTORY) ? [] : types;
fetchDirectoryContent &&
fetchDirectoryContent(nodeId, typeList)
.then((children) => {
const childrenMatchedTypes = children.filter(
(item: any) => contentFilter().has(item.type)
);
fetchDirectoryContent(nodeId, typeList)
.then((children) => {
const childrenMatchedTypes = children.filter((item: any) =>
contentFilter().has(item.type)
);

if (
childrenMatchedTypes.length > 0 &&
equipmentTypes &&
equipmentTypes.length > 0
) {
fetchElementsInfos &&
fetchElementsInfos(
childrenMatchedTypes.map(
(e: any) => e.elementUuid
),
types,
equipmentTypes
).then((childrenWithMetadata) => {
const children = itemFilter
? childrenWithMetadata.filter(
(val: any) => {
// Accept every directory
if (
val.type ===
ElementType.DIRECTORY
) {
return true;
}
// otherwise filter with the custom itemFilter func
return itemFilter(val);
}
)
: childrenWithMetadata;
// update directory content
addToDirectory(nodeId, children);
});
} else {
if (
childrenMatchedTypes.length > 0 &&
equipmentTypes &&
equipmentTypes.length > 0
) {
fetchElementsInfos(
childrenMatchedTypes.map((e: any) => e.elementUuid),
types,
equipmentTypes
).then((childrenWithMetadata) => {
const children = itemFilter
? childrenWithMetadata.filter((val: any) => {
// Accept every directory
if (val.type === ElementType.DIRECTORY) {
return true;
}
// otherwise filter with the custom itemFilter func
return itemFilter(val);
})
: childrenWithMetadata;
// update directory content
addToDirectory(nodeId, childrenMatchedTypes);
}
})
.catch((error) => {
console.warn(
`Could not update subs (and content) of '${nodeId}' : ${error.message}`
);
});
addToDirectory(nodeId, children);
});
} else {
// update directory content
addToDirectory(nodeId, childrenMatchedTypes);
}
})
.catch((error) => {
console.warn(
`Could not update subs (and content) of '${nodeId}' : ${error.message}`
);
});
},
[
types,
equipmentTypes,
itemFilter,
contentFilter,
addToDirectory,
fetchDirectoryContent,
fetchElementsInfos,
]
[types, equipmentTypes, itemFilter, contentFilter, addToDirectory]
);

useEffect(() => {
Expand Down
9 changes: 2 additions & 7 deletions src/components/ElementSearchDialog/equipment-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,15 @@ import match from 'autosuggest-highlight/match';
import parse from 'autosuggest-highlight/parse';
import clsx from 'clsx';
import { FormattedMessage } from 'react-intl';
import { EQUIPMENT_TYPE, EquipmentType } from '../../utils/EquipmentType';
import { EQUIPMENT_TYPE, EquipmentInfos } from '../../utils/EquipmentType';
import { Box, SxProps } from '@mui/material';
import OverflowableText from '../OverflowableText';
import { mergeSx } from '../../utils/styles';

export interface EquipmentItemProps {
inputValue: string;
suffixRenderer: typeof TagRenderer;
element: {
key: string;
label: string;
type: EquipmentType;
voltageLevelLabel: string;
};
element: EquipmentInfos;
showsJustText: boolean;
classes?: {
result?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/components/ElementSearchDialog/tag-renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface TagRendererProps {
};
element: {
type: EquipmentType;
voltageLevelLabel: string;
voltageLevelLabel?: string;
};
}

Expand Down
Loading

0 comments on commit 1b0d542

Please sign in to comment.