-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[2759] Reactivate the SelectionDialog
In addtion, this commit introduce the generic concept of Dialog to make it possible to define any kind of dialog for diagram node tools. Bug:#2759 Signed-off-by: Florian Barbin <[email protected]>
- Loading branch information
1 parent
a66d309
commit 6eb29cc
Showing
58 changed files
with
1,797 additions
and
1,108 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
packages/diagrams/frontend/sirius-components-diagrams/src/dialog/DialogContext.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Obeo and others. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
import { useData } from '@eclipse-sirius/sirius-components-core'; | ||
import React, { useState } from 'react'; | ||
import { DialogContextProviderState, DialogContextValue, ToolVariable } from './DialogContext.types'; | ||
import { diagramDialogContributionExtensionPoint } from './diagramDialogExtensionPoint'; | ||
import { DiagramDialogContribution, DialogComponentProps } from './diagramDialogExtensionPoint.types'; | ||
|
||
const defaultValue: DialogContextValue = { | ||
showDialog: () => {}, | ||
}; | ||
|
||
export const DialogContext = React.createContext<DialogContextValue>(defaultValue); | ||
|
||
export const DialogContextProvider = ({ children }) => { | ||
const [state, setState] = useState<DialogContextProviderState>({ | ||
dialogDescriptionId: undefined, | ||
dialogKindId: undefined, | ||
editingContextId: undefined, | ||
targetObjectId: undefined, | ||
onConfirm: () => {}, | ||
open: false, | ||
}); | ||
|
||
const { data: dialogContributions } = useData<DiagramDialogContribution[]>(diagramDialogContributionExtensionPoint); | ||
const showDialog = ( | ||
dialogKindId: string, | ||
editingContextId: string, | ||
dialogDescriptionId, | ||
targetObjectId, | ||
onConfirm: (variables: ToolVariable[]) => void | ||
) => { | ||
setState({ open: true, dialogKindId, editingContextId, dialogDescriptionId, targetObjectId, onConfirm }); | ||
}; | ||
|
||
const onFinish = (toolVariables: ToolVariable[]) => { | ||
state.onConfirm(toolVariables); | ||
setState((prevState) => ({ ...prevState, open: false, dialogKindId: undefined })); | ||
}; | ||
|
||
const onClose = () => { | ||
setState((prevState) => ({ ...prevState, open: false, dialogKindId: undefined })); | ||
}; | ||
|
||
let DialogComponent: React.ComponentType<DialogComponentProps> | undefined; | ||
const dialogComponentProps: DialogComponentProps = { | ||
dialogDescriptionId: state.dialogDescriptionId ?? '', | ||
editingContextId: state.editingContextId ?? '', | ||
targetObjectId: state.targetObjectId ?? '', | ||
onFinish, | ||
onClose, | ||
}; | ||
if (state.open && state.dialogKindId) { | ||
const dialogContribution: DiagramDialogContribution | undefined = dialogContributions.find((dialogContribution) => | ||
dialogContribution.canHandle(state.dialogKindId as string) | ||
); | ||
if (dialogContribution) { | ||
DialogComponent = dialogContribution.component; | ||
} | ||
} | ||
return ( | ||
<DialogContext.Provider value={{ showDialog }}> | ||
{children} | ||
{state.open && DialogComponent && <DialogComponent {...dialogComponentProps} />} | ||
</DialogContext.Provider> | ||
); | ||
}; |
43 changes: 43 additions & 0 deletions
43
packages/diagrams/frontend/sirius-components-diagrams/src/dialog/DialogContext.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Obeo and others. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
export interface DialogContextValue { | ||
showDialog: ( | ||
dialogKindId: string, | ||
editingContextId: string, | ||
dialogDescriptionId: string, | ||
targetObjectId: string, | ||
onConfirm: (variables: ToolVariable[]) => void | ||
) => void; | ||
} | ||
|
||
export interface ToolVariable { | ||
name: string; | ||
value: string; | ||
type: ToolVariableType; | ||
} | ||
|
||
export enum ToolVariableType { | ||
String, | ||
ObjectId, | ||
ObjectIdArray, | ||
} | ||
|
||
export interface DialogContextProviderState { | ||
open: boolean; | ||
dialogKindId: string | undefined; | ||
editingContextId: string | undefined; | ||
dialogDescriptionId: string | undefined; | ||
targetObjectId: string | undefined; | ||
onConfirm: (variables: ToolVariable[]) => void; | ||
} |
19 changes: 19 additions & 0 deletions
19
...es/diagrams/frontend/sirius-components-diagrams/src/dialog/diagramDialogExtensionPoint.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
import { DataExtensionPoint } from '@eclipse-sirius/sirius-components-core'; | ||
import { DiagramDialogContribution } from './diagramDialogExtensionPoint.types'; | ||
|
||
export const diagramDialogContributionExtensionPoint: DataExtensionPoint<Array<DiagramDialogContribution>> = { | ||
identifier: 'diagram#diagramDialogContribution', | ||
fallback: [], | ||
}; |
26 changes: 26 additions & 0 deletions
26
...grams/frontend/sirius-components-diagrams/src/dialog/diagramDialogExtensionPoint.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
import { ToolVariable } from './DialogContext.types'; | ||
export interface DiagramDialogContribution { | ||
canHandle: (dialogKindId: string) => boolean; | ||
component: React.ComponentType<DialogComponentProps>; | ||
} | ||
|
||
export interface DialogComponentProps { | ||
editingContextId: string; | ||
dialogDescriptionId: string; | ||
targetObjectId: string; | ||
onClose: () => void; | ||
onFinish: (variables: ToolVariable[]) => void; | ||
} |
Oops, something went wrong.