Skip to content
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

Fix/clear on close type #540

Merged
merged 7 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dependencies": {
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.5",
"@gridsuite/commons-ui": "0.71.1",
"@gridsuite/commons-ui": "0.72.0",
"@hookform/resolvers": "^3.3.4",
"@mui/icons-material": "^5.15.14",
"@mui/lab": "5.0.0-alpha.169",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
} from '@gridsuite/commons-ui';
import { useForm } from 'react-hook-form';
import { yupResolver } from '@hookform/resolvers/yup/dist/yup';
import { SyntheticEvent } from 'react';
import { createContingencyList } from '../../../../utils/rest-api';
import ContingencyListCreationForm from './contingency-list-creation-form';
import {
Expand Down Expand Up @@ -47,7 +46,7 @@ const schema = yup.object().shape({
const emptyFormData = getContingencyListEmptyFormData();

export interface ContingencyListCreationDialogProps {
onClose: (event?: SyntheticEvent) => void;
onClose: () => void;
open: boolean;
titleId: string;
}
Expand Down Expand Up @@ -75,9 +74,9 @@ export default function ContingencyListCreationDialog({
const nameError = errors[FieldConstants.NAME];
const isValidating = errors.root?.isValidating;

const closeAndClear = (event?: SyntheticEvent) => {
const closeAndClear = () => {
reset(emptyFormData);
onClose(event);
onClose();
};

const onSubmit = (data: ContingencyListFormDataWithRequiredCriteria) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from '@gridsuite/commons-ui';
import { useForm } from 'react-hook-form';
import { yupResolver } from '@hookform/resolvers/yup/dist/yup';
import { SyntheticEvent, useEffect, useState } from 'react';
import { useEffect, useState } from 'react';
import { getContingencyList, saveCriteriaBasedContingencyList } from 'utils/rest-api';
import { useDispatch, useSelector } from 'react-redux';
import { AppState } from '../../../../../redux/types';
Expand All @@ -41,7 +41,7 @@ export interface CriteriaBasedEditionDialogProps {
contingencyListId: string;
contingencyListType: string;
open: boolean;
onClose: (event?: SyntheticEvent) => void;
onClose: () => void;
titleId: string;
name: string;
broadcastChannel: BroadcastChannel;
Expand Down Expand Up @@ -92,9 +92,9 @@ export default function CriteriaBasedEditionDialog({
.finally(() => setIsFetching(false));
}, [contingencyListId, contingencyListType, name, reset, snackError]);

const closeAndClear = (event?: SyntheticEvent) => {
const closeAndClear = () => {
reset(emptyFormData());
onClose(event);
onClose();
};

const onSubmit = (contingencyList: CriteriaBasedEditionFormData) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from '@gridsuite/commons-ui';
import { useForm } from 'react-hook-form';
import { yupResolver } from '@hookform/resolvers/yup/dist/yup';
import { SyntheticEvent, useEffect, useState } from 'react';
import { useEffect, useState } from 'react';
import { getContingencyList, saveExplicitNamingContingencyList } from 'utils/rest-api';
import { prepareContingencyListForBackend } from 'components/dialogs/contingency-list-helper';
import { useDispatch, useSelector } from 'react-redux';
Expand Down Expand Up @@ -48,7 +48,7 @@ export interface ExplicitNamingEditionDialogProps {
contingencyListId: string;
contingencyListType: string;
open: boolean;
onClose: (event?: SyntheticEvent) => void;
onClose: () => void;
titleId: string;
name: string;
broadcastChannel: BroadcastChannel;
Expand Down Expand Up @@ -97,9 +97,9 @@ export default function ExplicitNamingEditionDialog({
.finally(() => setIsFetching(false));
}, [contingencyListId, contingencyListType, name, reset, snackError]);

const closeAndClear = (event?: SyntheticEvent) => {
const closeAndClear = () => {
reset(emptyFormData());
onClose(event);
onClose();
};

const editContingencyList = (contingencyListId2: string, contingencyList: ExplicitNamingEditionFormData) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from '@gridsuite/commons-ui';
import { useForm } from 'react-hook-form';
import { yupResolver } from '@hookform/resolvers/yup/dist/yup';
import { SyntheticEvent, useEffect, useState } from 'react';
import { useEffect, useState } from 'react';
import { getContingencyList, saveScriptContingencyList } from 'utils/rest-api';
import { useDispatch, useSelector } from 'react-redux';
import { getContingencyListEmptyFormData, getScriptFormDataFromFetchedElement } from '../../contingency-list-utils';
Expand All @@ -40,7 +40,7 @@ export interface ScriptEditionDialogProps {
contingencyListId: string;
contingencyListType: string;
open: boolean;
onClose: (event?: SyntheticEvent) => void;
onClose: () => void;
titleId: string;
name: string;
broadcastChannel: BroadcastChannel;
Expand Down Expand Up @@ -91,9 +91,9 @@ export default function ScriptEditionDialog({
.finally(() => setIsFetching(false));
}, [contingencyListId, contingencyListType, name, reset, snackError]);

const closeAndClear = (event?: SyntheticEvent) => {
const closeAndClear = () => {
reset(emptyFormData());
onClose(event);
onClose();
};

const editContingencyList = (contingencyListId2: string, contingencyList: ScriptEditionFormData) => {
Expand Down
8 changes: 2 additions & 6 deletions src/components/dialogs/copy-to-script-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const emptyFormData = {
export interface CopyToScriptDialogProps {
id: string;
open: boolean;
onClose: (...args: any[]) => void;
onClose: () => void;
onValidate: (...args: any[]) => void;
currentName: string;
title: string;
Expand Down Expand Up @@ -83,10 +83,6 @@ export default function CopyToScriptDialog({
onValidate(id, data[FieldConstants.NAME]);
};

const handleClose = () => {
onClose();
};

const handleGenerateNameError = useCallback(
() => handleError(intl.formatMessage({ id: 'generateCopyScriptNameError' }, { itemName: currentName })),
[currentName, handleError, intl]
Expand All @@ -112,7 +108,7 @@ export default function CopyToScriptDialog({
return (
<CustomMuiDialog
open={open}
onClose={handleClose}
onClose={onClose}
onSave={onSubmit}
formSchema={schema}
formMethods={methods}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ interface IFormData {
}

export interface CreateCaseDialogProps {
onClose: (e?: unknown, nextSelectedDirectoryId?: string | null) => void;
onClose: () => void;
open: boolean;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/dialogs/create-directory-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { useNameField } from './field-hook';

export interface CreateDirectoryDialogProps {
open: boolean;
onClose: (e?: unknown, nextSelectedDirectoryId?: string | null) => void;
onClose: () => void;
onClick: (newName: string) => void;
title: string;
parentDirectory?: UUID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function formatCaseImportParameters(params: Parameter[]): Parameter[] {

export interface CreateStudyDialogProps {
open: boolean;
onClose: (e?: unknown, nextSelectedDirectoryId?: string | null) => void;
onClose: () => void;
providedExistingCase?: ElementAttributes;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/dialogs/delete-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { CancelButton, ElementAttributes, OverflowableText } from '@gridsuite/co

export interface DeleteDialogProps {
open: boolean;
onClose: (e?: unknown, nextSelectedDirectoryId?: string | null) => void;
onClose: () => void;
onClick: () => void;
items: ElementAttributes[];
multipleDeleteFormatMessageId: string;
Expand Down
2 changes: 1 addition & 1 deletion src/components/dialogs/rename-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface RenameDialogProps {
/** Is the dialog open ? */
open: boolean;
/** Event to close the dialog */
onClose: (e?: unknown, nextSelectedDirectoryId?: string | null) => void;
onClose: () => void;
/** Event to submit the renaming */
onClick: (newName: string) => void;
/** Title of the dialog */
Expand Down
7 changes: 2 additions & 5 deletions src/components/menus/common-contextual-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export type MenuItemType =
};

export interface CommonContextualMenuProps extends MenuProps {
onClose?: (e?: unknown, nextSelectedDirectoryId?: string | null) => void;
menuItems?: MenuItemType[];
}

Expand All @@ -57,9 +56,7 @@ export const defaultAnchorStates: AnchorStatesType = {
anchorReference: 'anchorPosition',
};

export default function CommonContextualMenu(props: Readonly<CommonContextualMenuProps>) {
const { menuItems, ...others } = props;

export default function CommonContextualMenu({ menuItems, ...menuProps }: Readonly<CommonContextualMenuProps>) {
function makeMenuItem(
key: number,
messageDescriptorId?: string,
Expand Down Expand Up @@ -89,7 +86,7 @@ export default function CommonContextualMenu(props: Readonly<CommonContextualMen

let dividerCount = 0;
return (
<StyledMenu keepMounted {...others}>
<StyledMenu keepMounted {...menuProps}>
{menuItems?.map((menuItem, index) => {
if (menuItem.isDivider) {
dividerCount += 1;
Expand Down
29 changes: 17 additions & 12 deletions src/components/menus/directory-tree-contextual-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ import { AppState } from '../../redux/types';
import MoveDialog from '../dialogs/move-dialog';
import { buildPathToFromMap } from '../treeview-utils';

export interface DirectoryTreeContextualMenuProps extends CommonContextualMenuProps {
export interface DirectoryTreeContextualMenuProps extends Omit<CommonContextualMenuProps, 'onClose'> {
directory: ElementAttributes | null;
onClose: (e: unknown, nextSelectedDirectoryId?: string | null) => void;
onClose: (nextSelectedDirectoryId?: string | null) => void;
openDialog: string;
setOpenDialog: (dialogId: string) => void;
restrictMenuItems: boolean;
}

export default function DirectoryTreeContextualMenu(props: Readonly<DirectoryTreeContextualMenuProps>) {
const { directory, open, onClose, openDialog, setOpenDialog, restrictMenuItems, ...others } = props;
const { directory, open, onClose, openDialog, setOpenDialog, restrictMenuItems, ...otherProps } = props;
const userId = useSelector((state: AppState) => state.user?.profile.sub);

const intl = useIntl();
Expand All @@ -80,8 +80,8 @@ export default function DirectoryTreeContextualMenu(props: Readonly<DirectoryTre
};

const handleCloseDialog = useCallback(
(e: unknown, nextSelectedDirectoryId: string | null = null) => {
onClose(e, nextSelectedDirectoryId);
(nextSelectedDirectoryId: string | null = null) => {
onClose(nextSelectedDirectoryId);
setOpenDialog(DialogsId.NONE);
setHideMenu(false);
setDeleteError('');
Expand All @@ -91,7 +91,7 @@ export default function DirectoryTreeContextualMenu(props: Readonly<DirectoryTre

const [renameCB, renameState] = useDeferredFetch(
renameElement,
() => handleCloseDialog(null, null),
handleCloseDialog,
(HTTPStatusCode: number) => {
if (HTTPStatusCode === 403) {
return intl.formatMessage({ id: 'renameDirectoryError' });
Expand All @@ -103,12 +103,12 @@ export default function DirectoryTreeContextualMenu(props: Readonly<DirectoryTre
);

const [insertDirectoryCB, insertDirectoryState] = useDeferredFetch(insertDirectory, (response: ElementAttributes) =>
handleCloseDialog(null, response?.elementUuid)
handleCloseDialog(response?.elementUuid)
);

const [insertRootDirectoryCB, insertRootDirectoryState] = useDeferredFetch(
insertRootDirectory,
(response: ElementAttributes) => handleCloseDialog(null, response?.elementUuid)
(response: ElementAttributes) => handleCloseDialog(response?.elementUuid)
);

const selectionForCopy = useSelector((state: AppState) => state.selectionForCopy);
Expand All @@ -130,7 +130,7 @@ export default function DirectoryTreeContextualMenu(props: Readonly<DirectoryTre
function pasteElement(directoryUuid: UUID, selectionForPaste: any) {
if (!selectionForPaste.sourceItemUuid) {
handleError(intl.formatMessage({ id: 'elementPasteFailed404' }));
handleCloseDialog(null);
handleCloseDialog();
} else {
console.info('Pasting element %s into directory %s', selectionForPaste.nameItem, directoryUuid);

Expand Down Expand Up @@ -180,15 +180,15 @@ export default function DirectoryTreeContextualMenu(props: Readonly<DirectoryTre
);
}

handleCloseDialog(null);
handleCloseDialog();
}
}

const handleDeleteElement = useCallback(
(elementsUuid: UUID) => {
setDeleteError('');
deleteElement(elementsUuid)
.then(() => handleCloseDialog(null, directory?.parentUuid))
.then(() => handleCloseDialog(directory?.parentUuid))
.catch((error: any) => {
// show the error message and don't close the dialog
setDeleteError(error.message);
Expand Down Expand Up @@ -406,7 +406,12 @@ export default function DirectoryTreeContextualMenu(props: Readonly<DirectoryTre
return (
<>
{open && (
<CommonContextualMenu {...others} menuItems={buildMenu()} open={open && !hideMenu} onClose={onClose} />
<CommonContextualMenu
{...otherProps}
menuItems={buildMenu()}
open={open && !hideMenu}
onClose={() => onClose()}
TheMaskedTurtle marked this conversation as resolved.
Show resolved Hide resolved
/>
)}
{renderDialog()}
</>
Expand Down
Loading