-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[889] Remove New Object/Representation menu entries for libraries
Bug: #889 Signed-off-by: Gwendal Daniel <gwendal.daniel@obeosoft.com>
- Loading branch information
Showing
10 changed files
with
378 additions
and
0 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
97 changes: 97 additions & 0 deletions
97
frontend/syson/src/extensions/SysONDocumentTreeItemContextMenuContribution.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,97 @@ | ||
/******************************************************************************* | ||
* 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 { Selection, ServerContext, ServerContextValue, useSelection } from '@eclipse-sirius/sirius-components-core'; | ||
import { TreeItemContextMenuComponentProps } from '@eclipse-sirius/sirius-components-trees'; | ||
import AddIcon from '@mui/icons-material/Add'; | ||
import GetAppIcon from '@mui/icons-material/GetApp'; | ||
import ListItemIcon from '@mui/material/ListItemIcon'; | ||
import ListItemText from '@mui/material/ListItemText'; | ||
import MenuItem from '@mui/material/MenuItem'; | ||
import { Fragment, forwardRef, useContext, useState } from 'react'; | ||
import { NewRootObjectModal } from '@eclipse-sirius/sirius-web-application'; | ||
|
||
type Modal = 'CreateNewRootObject'; | ||
|
||
export const SysONDocumentTreeItemContextMenuContribution = forwardRef( | ||
( | ||
{ editingContextId, treeId, item, readOnly, expandItem, onClose }: TreeItemContextMenuComponentProps, | ||
ref: React.ForwardedRef<HTMLLIElement> | ||
) => { | ||
const { httpOrigin } = useContext<ServerContextValue>(ServerContext); | ||
const [modal, setModal] = useState<Modal | null>(null); | ||
const { setSelection } = useSelection(); | ||
|
||
if (!treeId.startsWith('explorer://') || !item.kind.startsWith('siriusWeb://document')) { | ||
return null; | ||
} | ||
|
||
const onObjectCreated = (selection: Selection) => { | ||
setSelection(selection); | ||
expandItem(); | ||
onClose(); | ||
}; | ||
|
||
let modalElement = null; | ||
if (modal === 'CreateNewRootObject') { | ||
modalElement = ( | ||
<NewRootObjectModal | ||
editingContextId={editingContextId} | ||
item={item} | ||
onObjectCreated={onObjectCreated} | ||
onClose={onClose} | ||
/> | ||
); | ||
} | ||
|
||
let menuItems = []; | ||
if (item.editable) { | ||
menuItems.push( | ||
<MenuItem | ||
key="new-object" | ||
data-testid="new-object" | ||
onClick={() => setModal('CreateNewRootObject')} | ||
ref={ref} | ||
disabled={readOnly} | ||
aria-disabled> | ||
<ListItemIcon> | ||
<AddIcon fontSize="small" /> | ||
</ListItemIcon> | ||
<ListItemText primary="New object" /> | ||
</MenuItem> | ||
); | ||
} | ||
menuItems.push( | ||
<MenuItem | ||
key="download" | ||
divider | ||
onClick={onClose} | ||
component="a" | ||
href={`${httpOrigin}/api/editingcontexts/${editingContextId}/documents/${item.id}`} | ||
type="application/octet-stream" | ||
data-testid="download" | ||
aria-disabled> | ||
<ListItemIcon> | ||
<GetAppIcon fontSize="small" /> | ||
</ListItemIcon> | ||
<ListItemText primary="Download" aria-disabled /> | ||
</MenuItem> | ||
); | ||
|
||
return ( | ||
<Fragment key="document-tree-item-context-menu-contribution"> | ||
{menuItems} | ||
{modalElement} | ||
</Fragment> | ||
); | ||
} | ||
); |
42 changes: 42 additions & 0 deletions
42
frontend/syson/src/extensions/SysONExtensionRegistryMergeStrategy.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,42 @@ | ||
/******************************************************************************* | ||
* 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 { ComponentExtension, ExtensionRegistryMergeStrategy } from '@eclipse-sirius/sirius-components-core'; | ||
import { DefaultExtensionRegistryMergeStrategy } from '@eclipse-sirius/sirius-web-application'; | ||
import { treeItemContextMenuEntryExtensionPoint } from '@eclipse-sirius/sirius-components-trees'; | ||
|
||
export class SysONExtensionRegistryMergeStrategy | ||
extends DefaultExtensionRegistryMergeStrategy | ||
implements ExtensionRegistryMergeStrategy | ||
{ | ||
public override mergeComponentExtensions( | ||
_identifier: string, | ||
existingValues: ComponentExtension<any>[], | ||
newValues: ComponentExtension<any>[] | ||
): ComponentExtension<any>[] { | ||
if (_identifier === treeItemContextMenuEntryExtensionPoint.identifier) { | ||
return super.mergeComponentExtensions( | ||
_identifier, | ||
existingValues.filter((contribution) => { | ||
// Discard default versions of these extensions, we want to replace them with our own. | ||
return ( | ||
contribution.identifier !== `siriusweb_${treeItemContextMenuEntryExtensionPoint.identifier}_object` && | ||
contribution.identifier !== `siriusweb_${treeItemContextMenuEntryExtensionPoint.identifier}_document` | ||
); | ||
}), | ||
newValues | ||
); | ||
} | ||
return super.mergeComponentExtensions(_identifier, existingValues, newValues); | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
frontend/syson/src/extensions/SysONObjectTreeItemContextMenuContribution.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,102 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021, 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 { Selection, useSelection } from '@eclipse-sirius/sirius-components-core'; | ||
import { TreeItemContextMenuComponentProps } from '@eclipse-sirius/sirius-components-trees'; | ||
import AddIcon from '@mui/icons-material/Add'; | ||
import ListItemIcon from '@mui/material/ListItemIcon'; | ||
import ListItemText from '@mui/material/ListItemText'; | ||
import MenuItem from '@mui/material/MenuItem'; | ||
import { Fragment, forwardRef, useState } from 'react'; | ||
import { NewObjectModal } from '@eclipse-sirius/sirius-web-application'; | ||
import { NewRepresentationModal } from '@eclipse-sirius/sirius-web-application'; | ||
|
||
type Modal = 'CreateNewObject' | 'CreateNewRepresentation'; | ||
|
||
export const SysONObjectTreeItemContextMenuContribution = forwardRef( | ||
( | ||
{ editingContextId, treeId, item, readOnly, expandItem, onClose }: TreeItemContextMenuComponentProps, | ||
ref: React.ForwardedRef<HTMLLIElement> | ||
) => { | ||
const [modal, setModal] = useState<Modal>(null); | ||
const { setSelection } = useSelection(); | ||
|
||
if (!treeId.startsWith('explorer://') || !item.kind.startsWith('siriusComponents://semantic')) { | ||
return null; | ||
} | ||
|
||
const onObjectCreated = (selection: Selection) => { | ||
setSelection(selection); | ||
expandItem(); | ||
onClose(); | ||
}; | ||
|
||
let modalElement = null; | ||
if (modal === 'CreateNewObject') { | ||
modalElement = ( | ||
<NewObjectModal | ||
editingContextId={editingContextId} | ||
item={item} | ||
onObjectCreated={onObjectCreated} | ||
onClose={onClose} | ||
/> | ||
); | ||
} else if (modal === 'CreateNewRepresentation') { | ||
modalElement = ( | ||
<NewRepresentationModal | ||
editingContextId={editingContextId} | ||
item={item} | ||
onRepresentationCreated={onObjectCreated} | ||
onClose={onClose} | ||
/> | ||
); | ||
} | ||
|
||
let menuItems = []; | ||
if (item.editable) { | ||
menuItems.push( | ||
<MenuItem | ||
key="new-object" | ||
onClick={() => setModal('CreateNewObject')} | ||
data-testid="new-object" | ||
disabled={readOnly} | ||
ref={ref} | ||
aria-disabled> | ||
<ListItemIcon> | ||
<AddIcon fontSize="small" /> | ||
</ListItemIcon> | ||
<ListItemText primary="New object" /> | ||
</MenuItem> | ||
); | ||
menuItems.push( | ||
<MenuItem | ||
key="new-representation" | ||
onClick={() => setModal('CreateNewRepresentation')} | ||
data-testid="new-representation" | ||
disabled={readOnly} | ||
aria-disabled> | ||
<ListItemIcon> | ||
<AddIcon fontSize="small" /> | ||
</ListItemIcon> | ||
<ListItemText primary="New representation" /> | ||
</MenuItem> | ||
); | ||
} | ||
|
||
return ( | ||
<Fragment key="object-tree-item-context-menu-contribution"> | ||
{menuItems} | ||
{modalElement} | ||
</Fragment> | ||
); | ||
} | ||
); |
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
Oops, something went wrong.