-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[2252] Add the possibility to contribute component tools in the palette
Bug: #2252 Signed-off-by: Florian ROUËNÉ <florian.rouene@obeosoft.com>
- Loading branch information
1 parent
43efc4f
commit 1b57f6f
Showing
9 changed files
with
211 additions
and
38 deletions.
There are no files selected for viewing
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
16 changes: 16 additions & 0 deletions
16
...nd/sirius-components-diagrams-reactflow/src/renderer/palette/DiagramPaletteToolContext.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,16 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 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 React from 'react'; | ||
import { DiagramPaletteToolContextValue } from './DiagramPalette.types'; | ||
|
||
export const DiagramPaletteToolContext = React.createContext<DiagramPaletteToolContextValue>([]); |
18 changes: 18 additions & 0 deletions
18
...ius-components-diagrams-reactflow/src/renderer/palette/DiagramPaletteToolContribution.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,18 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 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 { DiagramPaletteToolContributionProps } from './DiagramPaletteToolContribution.types'; | ||
|
||
export const DiagramPaletteToolContribution = ({}: DiagramPaletteToolContributionProps) => { | ||
return null; // Do nothing on purpose | ||
}; |
22 changes: 22 additions & 0 deletions
22
...omponents-diagrams-reactflow/src/renderer/palette/DiagramPaletteToolContribution.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,22 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 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 | ||
*******************************************************************************/ | ||
|
||
export interface DiagramPaletteToolContributionProps { | ||
canHandle: (diagramId: string, diagramElementId: string) => boolean; | ||
component: (props: DiagramPaletteToolContributionComponentProps) => JSX.Element | null; | ||
} | ||
|
||
export interface DiagramPaletteToolContributionComponentProps { | ||
diagramElementId: string; | ||
key: string; | ||
} |
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
65 changes: 65 additions & 0 deletions
65
...ews/edit-project/ToolContributions/PapayaOperationActivityLabelDetailToolContribution.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,65 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 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 { | ||
DiagramPaletteToolContributionComponentProps, | ||
NodeData, | ||
} from '@eclipse-sirius/sirius-components-diagrams-reactflow'; | ||
import Dialog from '@material-ui/core/Dialog'; | ||
import DialogContent from '@material-ui/core/DialogContent'; | ||
import DialogContentText from '@material-ui/core/DialogContentText'; | ||
import IconButton from '@material-ui/core/IconButton'; | ||
import { Slideshow } from '@material-ui/icons'; | ||
import { Fragment, useState } from 'react'; | ||
import { useNodes } from 'reactflow'; | ||
|
||
type Modal = 'dialog'; | ||
export const PapayaOperationActivityLabelDetailToolContribution = ({ | ||
diagramElementId, | ||
}: DiagramPaletteToolContributionComponentProps) => { | ||
const [modal, setModal] = useState<Modal | null>(null); | ||
|
||
const nodes = useNodes<NodeData>(); | ||
const targetedNode = nodes.find((node) => node.id === diagramElementId); | ||
|
||
const onClose = () => { | ||
setModal(null); | ||
}; | ||
|
||
let modalElement: JSX.Element | null = null; | ||
if (modal === 'dialog' && targetedNode) { | ||
modalElement = ( | ||
<> | ||
<Dialog open={true} onClose={onClose} fullWidth> | ||
<DialogContent> | ||
<DialogContentText>{targetedNode.data.label.text}</DialogContentText> | ||
</DialogContent> | ||
</Dialog> | ||
</> | ||
); | ||
} | ||
|
||
return ( | ||
<Fragment key="label-detail-modal-contribution"> | ||
<IconButton | ||
size="small" | ||
color="inherit" | ||
aria-label="Label detail" | ||
title="Label detail" | ||
onClick={() => setModal('dialog')} | ||
data-testid="label-detail"> | ||
<Slideshow /> | ||
</IconButton> | ||
{modalElement} | ||
</Fragment> | ||
); | ||
}; |