From aa92a0419504583d9b7d172baef77d0db470f8e6 Mon Sep 17 00:00:00 2001 From: William Piers Date: Fri, 7 Jun 2024 11:29:58 +0200 Subject: [PATCH] [3553] Add a representationFactory extension point Bug: https://github.com/eclipse-sirius/sirius-web/issues/3553 Signed-off-by: William Piers --- CHANGELOG.adoc | 4 + .../sirius-components-core/src/index.ts | 2 - .../src/workbench/RepresentationContext.ts | 26 ---- .../workbench/RepresentationContext.types.ts | 21 --- .../workbench/RepresentationNavigation.tsx | 8 +- .../RepresentationNavigation.types.ts | 12 +- .../src/workbench/Workbench.tsx | 24 ++-- .../src/workbench/Workbench.types.ts | 10 +- .../src/workbench/WorkbenchExtensionPoints.ts | 7 +- .../src/workbench/WorkbenchMachine.ts | 12 +- .../representations/RepresentationFrame.tsx | 11 +- .../RepresentationFrame.types.ts | 4 +- .../src/application/SiriusWebApplication.tsx | 83 ++--------- .../extension/DefaultExtensionRegistry.tsx | 130 ++++++++++++++++++ .../onboarding/NewRepresentationArea.types.ts | 6 +- .../RepresentationContextProvider.tsx | 58 -------- .../RepresentationContextProvider.types.ts | 16 --- .../views/edit-project/EditProjectView.tsx | 4 +- .../edit-project/EditProjectViewMachine.ts | 10 +- 19 files changed, 206 insertions(+), 242 deletions(-) delete mode 100644 packages/core/frontend/sirius-components-core/src/workbench/RepresentationContext.ts delete mode 100644 packages/core/frontend/sirius-components-core/src/workbench/RepresentationContext.types.ts create mode 100644 packages/sirius-web/frontend/sirius-web-application/src/extension/DefaultExtensionRegistry.tsx delete mode 100644 packages/sirius-web/frontend/sirius-web-application/src/representations/RepresentationContextProvider.tsx delete mode 100644 packages/sirius-web/frontend/sirius-web-application/src/representations/RepresentationContextProvider.types.ts diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index c97331788a..5250d5786e 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -16,6 +16,9 @@ - https://github.com/eclipse-sirius/sirius-web/issues/3562[#3562] [sirius-web] Update displayed default model creation action. + Projects that have a nature and need the action to create an empty model will need to register the empty model action like it is done in `StudioEditingContextActionProvider`. +- https://github.com/eclipse-sirius/sirius-web/issues/3553[#3553] [core] Remove the concepts `RepresentationContext`, `RepresentationContextProvider` and their types which were used to contribute representations for the Sirius Components workbench in favor of an API based on the extension registry. +This is one of the first existing API used to extend Sirius Web deprecated in favor of the new extension registry. +More existing APIs will be migrated to this new common pattern. === Dependency update @@ -54,6 +57,7 @@ - https://github.com/eclipse-sirius/sirius-web/issues/3550[#3550] [core] Add ExtensionRegistry merge strategy - https://github.com/eclipse-sirius/sirius-web/issues/3563[#3563] [sirius-web] Improve NavigationBar extensibility to allow the contribution of components on the left and right of the navigation bar. - https://github.com/eclipse-sirius/sirius-web/issues/3344[#3344] [core] Add support for reloading representations from the database +- https://github.com/eclipse-sirius/sirius-web/issues/3553[#3553] [core] Add RepresentationFactory extension point === Improvements diff --git a/packages/core/frontend/sirius-components-core/src/index.ts b/packages/core/frontend/sirius-components-core/src/index.ts index 1bd99fd3b7..12eda8e831 100644 --- a/packages/core/frontend/sirius-components-core/src/index.ts +++ b/packages/core/frontend/sirius-components-core/src/index.ts @@ -49,8 +49,6 @@ export * from './toast/MultiToast'; export * from './toast/Toast'; export * from './toast/useReporting'; export * from './workbench/Panels'; -export * from './workbench/RepresentationContext'; -export * from './workbench/RepresentationContext.types'; export * from './workbench/Workbench'; export * from './workbench/Workbench.types'; export * from './workbench/WorkbenchExtensionPoints'; diff --git a/packages/core/frontend/sirius-components-core/src/workbench/RepresentationContext.ts b/packages/core/frontend/sirius-components-core/src/workbench/RepresentationContext.ts deleted file mode 100644 index a43cec3ede..0000000000 --- a/packages/core/frontend/sirius-components-core/src/workbench/RepresentationContext.ts +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021, 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 { RepresentationComponentRegistry, RepresentationContextValue } from './RepresentationContext.types'; -import { Representation, RepresentationComponentProps } from './Workbench.types'; - -const registry: RepresentationComponentRegistry = { - getComponent: (_representation: Representation) => { - return (_props: RepresentationComponentProps) => null; - }, -}; - -const value: RepresentationContextValue = { - registry, -}; -export const RepresentationContext = React.createContext(value); diff --git a/packages/core/frontend/sirius-components-core/src/workbench/RepresentationContext.types.ts b/packages/core/frontend/sirius-components-core/src/workbench/RepresentationContext.types.ts deleted file mode 100644 index 2136a72252..0000000000 --- a/packages/core/frontend/sirius-components-core/src/workbench/RepresentationContext.types.ts +++ /dev/null @@ -1,21 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021, 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 { Representation, RepresentationComponent } from './Workbench.types'; - -export type RepresentationComponentRegistry = { - getComponent: (representation: Representation) => RepresentationComponent | null; -}; - -export interface RepresentationContextValue { - registry: RepresentationComponentRegistry; -} diff --git a/packages/core/frontend/sirius-components-core/src/workbench/RepresentationNavigation.tsx b/packages/core/frontend/sirius-components-core/src/workbench/RepresentationNavigation.tsx index 00d39154c7..2835308ccb 100644 --- a/packages/core/frontend/sirius-components-core/src/workbench/RepresentationNavigation.tsx +++ b/packages/core/frontend/sirius-components-core/src/workbench/RepresentationNavigation.tsx @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2019, 2023 Obeo. + * Copyright (c) 2019, 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 @@ -15,7 +15,7 @@ import Tabs from '@material-ui/core/Tabs'; import { makeStyles } from '@material-ui/core/styles'; import CloseIcon from '@material-ui/icons/Close'; import { RepresentationNavigationProps } from './RepresentationNavigation.types'; -import { Representation } from './Workbench.types'; +import { RepresentationMetadata } from './Workbench.types'; const useRepresentationNavigationStyles = makeStyles((theme) => ({ tabsRoot: { @@ -63,7 +63,7 @@ export const RepresentationNavigation = ({ const representationSelected = representations.find((representation) => representation.id === value); if (representationSelected) { const { id, label, kind } = representationSelected; - const representation: Representation = { + const representation: RepresentationMetadata = { id, label, kind, @@ -72,7 +72,7 @@ export const RepresentationNavigation = ({ } }; - const onRepresentationClose = (event: React.MouseEvent, representation: Representation) => { + const onRepresentationClose = (event: React.MouseEvent, representation: RepresentationMetadata) => { event.stopPropagation(); onClose(representation); }; diff --git a/packages/core/frontend/sirius-components-core/src/workbench/RepresentationNavigation.types.ts b/packages/core/frontend/sirius-components-core/src/workbench/RepresentationNavigation.types.ts index 85ad52ee16..892f8ab3eb 100644 --- a/packages/core/frontend/sirius-components-core/src/workbench/RepresentationNavigation.types.ts +++ b/packages/core/frontend/sirius-components-core/src/workbench/RepresentationNavigation.types.ts @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2021, 2022 Obeo. + * 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 @@ -10,11 +10,11 @@ * Contributors: * Obeo - initial API and implementation *******************************************************************************/ -import { Representation } from './Workbench.types'; +import { RepresentationMetadata } from './Workbench.types'; export type RepresentationNavigationProps = { - representations: Representation[]; - displayedRepresentation: Representation; - onRepresentationClick: (representation: Representation) => void; - onClose: (representation: Representation) => void; + representations: RepresentationMetadata[]; + displayedRepresentation: RepresentationMetadata; + onRepresentationClick: (representation: RepresentationMetadata) => void; + onClose: (representation: RepresentationMetadata) => void; }; diff --git a/packages/core/frontend/sirius-components-core/src/workbench/Workbench.tsx b/packages/core/frontend/sirius-components-core/src/workbench/Workbench.tsx index 1a83757c19..b0d5c7a165 100644 --- a/packages/core/frontend/sirius-components-core/src/workbench/Workbench.tsx +++ b/packages/core/frontend/sirius-components-core/src/workbench/Workbench.tsx @@ -13,23 +13,25 @@ import { gql, useSubscription } from '@apollo/client'; import { makeStyles } from '@material-ui/core/styles'; import { useMachine } from '@xstate/react'; -import { useContext, useEffect } from 'react'; +import { useEffect } from 'react'; import { useComponent } from '../extension/useComponent'; import { useData } from '../extension/useData'; import { useSelection } from '../selection/useSelection'; import { Toast } from '../toast/Toast'; import { Panels } from './Panels'; -import { RepresentationContext } from './RepresentationContext'; -import { RepresentationContextValue } from './RepresentationContext.types'; import { RepresentationNavigation } from './RepresentationNavigation'; import { GQLEditingContextEventSubscription, - Representation, RepresentationComponentProps, + RepresentationMetadata, WorkbenchProps, WorkbenchViewContribution, } from './Workbench.types'; -import { workbenchMainAreaExtensionPoint, workbenchViewContributionExtensionPoint } from './WorkbenchExtensionPoints'; +import { + representationFactoryExtensionPoint, + workbenchMainAreaExtensionPoint, + workbenchViewContributionExtensionPoint, +} from './WorkbenchExtensionPoints'; import { HandleCompleteEvent, HandleSubscriptionResultEvent, @@ -76,7 +78,6 @@ export const Workbench = ({ readOnly, }: WorkbenchProps) => { const classes = useWorkbenchStyles(); - const { registry } = useContext(RepresentationContext); const [{ value, context }, dispatch] = useMachine(workbenchMachine, { context: { displayedRepresentation: initialRepresentationSelected, @@ -86,6 +87,7 @@ export const Workbench = ({ const { toast } = value as SchemaValue; const { id, representations, displayedRepresentation, message } = context; const { selection, setSelection } = useSelection(); + const { data: representationFactories } = useData(representationFactoryExtensionPoint); const { error } = useSubscription(editingContextEventSubscription, { variables: { @@ -117,7 +119,7 @@ export const Workbench = ({ }, [error, dispatch]); useEffect(() => { - const representations: Representation[] = selection.entries.filter((entry) => + const representations: RepresentationMetadata[] = selection.entries.filter((entry) => entry.kind.startsWith('siriusComponents://representation') ); const updateSelectedRepresentation: UpdateSelectedRepresentationEvent = { @@ -127,11 +129,11 @@ export const Workbench = ({ dispatch(updateSelectedRepresentation); }, [selection, dispatch]); - const onRepresentationClick = (representation: Representation) => { + const onRepresentationClick = (representation: RepresentationMetadata) => { setSelection({ entries: [{ id: representation.id, label: representation.label, kind: representation.kind }] }); }; - const onClose = (representation: Representation) => { + const onClose = (representation: RepresentationMetadata) => { const hideRepresentationEvent: HideRepresentationEvent = { type: 'HIDE_REPRESENTATION', representation }; dispatch(hideRepresentationEvent); }; @@ -160,7 +162,9 @@ export const Workbench = ({ let main = ; if (displayedRepresentation) { - const RepresentationComponent = registry.getComponent(displayedRepresentation); + const RepresentationComponent = representationFactories + .map((representationFactory) => representationFactory(displayedRepresentation)) + .find((component) => component != null); const props: RepresentationComponentProps = { editingContextId, readOnly, diff --git a/packages/core/frontend/sirius-components-core/src/workbench/Workbench.types.ts b/packages/core/frontend/sirius-components-core/src/workbench/Workbench.types.ts index e022e8b14a..500b35b649 100644 --- a/packages/core/frontend/sirius-components-core/src/workbench/Workbench.types.ts +++ b/packages/core/frontend/sirius-components-core/src/workbench/Workbench.types.ts @@ -26,7 +26,7 @@ export type GQLEditingContextEventSubscription = { editingContextEvent: GQLEditingContextEventPayload; }; -export type Representation = { +export type RepresentationMetadata = { id: string; label: string; kind: string; @@ -53,8 +53,8 @@ export interface MainAreaComponentProps { export type WorkbenchProps = { editingContextId: string; - initialRepresentationSelected: Representation | null; - onRepresentationSelected: (representation: Representation | null) => void; + initialRepresentationSelected: RepresentationMetadata | null; + onRepresentationSelected: (representation: RepresentationMetadata | null) => void; readOnly: boolean; }; @@ -65,3 +65,7 @@ export type RepresentationComponentProps = { }; export type RepresentationComponent = React.ComponentType; + +export type RepresentationComponentFactory = { + (representationMetadata: RepresentationMetadata): RepresentationComponent | null; +}; diff --git a/packages/core/frontend/sirius-components-core/src/workbench/WorkbenchExtensionPoints.ts b/packages/core/frontend/sirius-components-core/src/workbench/WorkbenchExtensionPoints.ts index 5b8b0df3d4..7935f017f4 100644 --- a/packages/core/frontend/sirius-components-core/src/workbench/WorkbenchExtensionPoints.ts +++ b/packages/core/frontend/sirius-components-core/src/workbench/WorkbenchExtensionPoints.ts @@ -12,7 +12,7 @@ *******************************************************************************/ import { ComponentExtensionPoint, DataExtensionPoint } from '../extension/ExtensionRegistry.types'; -import { MainAreaComponentProps, WorkbenchViewContribution } from './Workbench.types'; +import { MainAreaComponentProps, RepresentationComponentFactory, WorkbenchViewContribution } from './Workbench.types'; export const workbenchMainAreaExtensionPoint: ComponentExtensionPoint = { identifier: 'workbench#mainArea', @@ -23,3 +23,8 @@ export const workbenchViewContributionExtensionPoint: DataExtensionPoint> = { + identifier: 'workbench#representationFactory', + fallback: [], +}; diff --git a/packages/core/frontend/sirius-components-core/src/workbench/WorkbenchMachine.ts b/packages/core/frontend/sirius-components-core/src/workbench/WorkbenchMachine.ts index 0bd7cf0fa9..ca3d5d49ea 100644 --- a/packages/core/frontend/sirius-components-core/src/workbench/WorkbenchMachine.ts +++ b/packages/core/frontend/sirius-components-core/src/workbench/WorkbenchMachine.ts @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2021, 2023 Obeo. + * 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 @@ -16,7 +16,7 @@ import { GQLEditingContextEventPayload, GQLEditingContextEventSubscription, GQLRepresentationRenamedEventPayload, - Representation, + RepresentationMetadata, } from './Workbench.types'; export interface WorkbenchStateSchema { @@ -43,15 +43,15 @@ export type SchemaValue = { export interface WorkbenchContext { id: string; - representations: Representation[]; - displayedRepresentation: Representation | null; + representations: RepresentationMetadata[]; + displayedRepresentation: RepresentationMetadata | null; message: string | null; } -export type HideRepresentationEvent = { type: 'HIDE_REPRESENTATION'; representation: Representation }; +export type HideRepresentationEvent = { type: 'HIDE_REPRESENTATION'; representation: RepresentationMetadata }; export type UpdateSelectedRepresentationEvent = { type: 'UPDATE_SELECTED_REPRESENTATION'; - representations: Representation[]; + representations: RepresentationMetadata[]; }; export type ShowToastEvent = { type: 'SHOW_TOAST'; message: string }; diff --git a/packages/portals/frontend/sirius-components-portals/src/representations/RepresentationFrame.tsx b/packages/portals/frontend/sirius-components-portals/src/representations/RepresentationFrame.tsx index 4f48145d61..ebab308ded 100644 --- a/packages/portals/frontend/sirius-components-portals/src/representations/RepresentationFrame.tsx +++ b/packages/portals/frontend/sirius-components-portals/src/representations/RepresentationFrame.tsx @@ -13,14 +13,13 @@ import { RepresentationComponentProps, - RepresentationContext, - RepresentationContextValue, + representationFactoryExtensionPoint, + useData, } from '@eclipse-sirius/sirius-components-core'; import IconButton from '@material-ui/core/IconButton'; import Typography from '@material-ui/core/Typography'; import { makeStyles } from '@material-ui/core/styles'; import CloseOutlinedIcon from '@material-ui/icons/CloseOutlined'; -import { useContext } from 'react'; import { RepresentationFrameProps } from './RepresentationFrame.types'; const useFrameStyles = makeStyles((theme) => ({ @@ -59,8 +58,10 @@ export const RepresentationFrame = ({ portalMode, onDelete, }: RepresentationFrameProps) => { - const { registry } = useContext(RepresentationContext); - const RepresentationComponent = registry.getComponent(representation); + const { data: representationFactories } = useData(representationFactoryExtensionPoint); + const RepresentationComponent = representationFactories + .map((representationFactory) => representationFactory(representation)) + .find((component) => component != null); if (RepresentationComponent) { const classes = useFrameStyles(); diff --git a/packages/portals/frontend/sirius-components-portals/src/representations/RepresentationFrame.types.ts b/packages/portals/frontend/sirius-components-portals/src/representations/RepresentationFrame.types.ts index b019f9f684..ff2208470a 100644 --- a/packages/portals/frontend/sirius-components-portals/src/representations/RepresentationFrame.types.ts +++ b/packages/portals/frontend/sirius-components-portals/src/representations/RepresentationFrame.types.ts @@ -10,12 +10,12 @@ * Contributors: * Obeo - initial API and implementation *******************************************************************************/ -import { Representation } from '@eclipse-sirius/sirius-components-core'; +import { RepresentationMetadata } from '@eclipse-sirius/sirius-components-core'; import { PortalRepresentationMode } from './PortalRepresentation.types'; export type RepresentationFrameProps = { editingContextId: string; - representation: Representation; + representation: RepresentationMetadata; onDelete: () => void; portalMode: PortalRepresentationMode; }; diff --git a/packages/sirius-web/frontend/sirius-web-application/src/application/SiriusWebApplication.tsx b/packages/sirius-web/frontend/sirius-web-application/src/application/SiriusWebApplication.tsx index 6c775bdfac..24ced3d54f 100644 --- a/packages/sirius-web/frontend/sirius-web-application/src/application/SiriusWebApplication.tsx +++ b/packages/sirius-web/frontend/sirius-web-application/src/application/SiriusWebApplication.tsx @@ -13,29 +13,13 @@ import { ConfirmationDialogContextProvider, ExtensionProvider, - ExtensionRegistry, RepresentationPathContext, ServerContext, - WorkbenchViewContribution, - workbenchMainAreaExtensionPoint, - workbenchViewContributionExtensionPoint, } from '@eclipse-sirius/sirius-components-core'; import { NodeTypeContext, NodeTypeContextValue } from '@eclipse-sirius/sirius-components-diagrams'; -import { - DetailsView, - PropertySectionContext, - RelatedElementsView, - RepresentationsView, -} from '@eclipse-sirius/sirius-components-forms'; -import { ExplorerView } from '@eclipse-sirius/sirius-components-trees'; -import { ValidationView } from '@eclipse-sirius/sirius-components-validation'; +import { PropertySectionContext } from '@eclipse-sirius/sirius-components-forms'; import CssBaseline from '@material-ui/core/CssBaseline'; import { Theme, ThemeProvider } from '@material-ui/core/styles'; -import AccountTreeIcon from '@material-ui/icons/AccountTree'; -import Filter from '@material-ui/icons/Filter'; -import LinkIcon from '@material-ui/icons/Link'; -import MenuIcon from '@material-ui/icons/Menu'; -import WarningIcon from '@material-ui/icons/Warning'; import React from 'react'; import { BrowserRouter } from 'react-router-dom'; import { ToastProvider } from '../../src/toast/ToastProvider'; @@ -44,11 +28,10 @@ import { defaultNodeTypeRegistry, } from '../diagrams/DiagramRepresentationConfiguration'; import { DiagramRepresentationConfigurationProps } from '../diagrams/DiagramRepresentationConfiguration.types'; +import { defaultExtensionRegistry } from '../extension/DefaultExtensionRegistry'; import { DefaultExtensionRegistryMergeStrategy } from '../extension/DefaultExtensionRegistryMergeStrategy'; import { propertySectionsRegistry } from '../forms/defaultPropertySectionRegistry'; import { ApolloGraphQLProvider } from '../graphql/ApolloGraphQLProvider'; -import { OnboardArea } from '../onboarding/OnboardArea'; -import { RepresentationContextProvider } from '../representations/RepresentationContextProvider'; import { Router } from '../router/Router'; import { siriusWebTheme as defaultTheme } from '../theme/siriusWebTheme'; import { SiriusWebApplicationProps } from './SiriusWebApplication.types'; @@ -85,57 +68,15 @@ export const SiriusWebApplication = ({ return `/projects/${editingContextId}/edit/${representationId}`; }; - const workbenchViewContributions: WorkbenchViewContribution[] = [ - { - side: 'left', - title: 'Explorer', - icon: , - component: ExplorerView, - }, - { - side: 'left', - title: 'Validation', - icon: , - component: ValidationView, - }, - { - side: 'right', - title: 'Details', - icon: , - component: DetailsView, - }, - { - side: 'right', - title: 'Representations', - icon: , - component: RepresentationsView, - }, - { - side: 'right', - title: 'Related Elements', - icon: , - component: RelatedElementsView, - }, - ]; - - const internalExtensionRegistry = new ExtensionRegistry(); - internalExtensionRegistry.addComponent(workbenchMainAreaExtensionPoint, { - identifier: 'siriusweb_workbench#mainArea', - Component: OnboardArea, - }); - internalExtensionRegistry.putData(workbenchViewContributionExtensionPoint, { - identifier: 'siriusweb_workbench#viewContribution', - data: workbenchViewContributions, - }); if (extensionRegistry) { - internalExtensionRegistry.addAll( + defaultExtensionRegistry.addAll( extensionRegistry, extensionRegistryMergeStrategy ? extensionRegistryMergeStrategy : new DefaultExtensionRegistryMergeStrategy() ); } return ( - + @@ -144,15 +85,13 @@ export const SiriusWebApplication = ({ - - - -
- -
-
-
-
+ + +
+ +
+
+
diff --git a/packages/sirius-web/frontend/sirius-web-application/src/extension/DefaultExtensionRegistry.tsx b/packages/sirius-web/frontend/sirius-web-application/src/extension/DefaultExtensionRegistry.tsx new file mode 100644 index 0000000000..c28289cd53 --- /dev/null +++ b/packages/sirius-web/frontend/sirius-web-application/src/extension/DefaultExtensionRegistry.tsx @@ -0,0 +1,130 @@ +/******************************************************************************* + * 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 { + ExtensionRegistry, + RepresentationComponentFactory, + RepresentationMetadata, + WorkbenchViewContribution, + representationFactoryExtensionPoint, + workbenchMainAreaExtensionPoint, + workbenchViewContributionExtensionPoint, +} from '@eclipse-sirius/sirius-components-core'; +import { DeckRepresentation } from '@eclipse-sirius/sirius-components-deck'; +import { DiagramRepresentation } from '@eclipse-sirius/sirius-components-diagrams'; +import { FormDescriptionEditorRepresentation } from '@eclipse-sirius/sirius-components-formdescriptioneditors'; +import { + DetailsView, + FormRepresentation, + RelatedElementsView, + RepresentationsView, +} from '@eclipse-sirius/sirius-components-forms'; +import { GanttRepresentation } from '@eclipse-sirius/sirius-components-gantt'; +import { PortalRepresentation } from '@eclipse-sirius/sirius-components-portals'; +import { ExplorerView } from '@eclipse-sirius/sirius-components-trees'; +import { ValidationView } from '@eclipse-sirius/sirius-components-validation'; +import AccountTreeIcon from '@material-ui/icons/AccountTree'; +import Filter from '@material-ui/icons/Filter'; +import LinkIcon from '@material-ui/icons/Link'; +import MenuIcon from '@material-ui/icons/Menu'; +import WarningIcon from '@material-ui/icons/Warning'; +import { OnboardArea } from '../onboarding/OnboardArea'; + +const getType = (representation: RepresentationMetadata): string | null => { + const query = representation.kind.substring(representation.kind.indexOf('?') + 1, representation.kind.length); + const params = new URLSearchParams(query); + const type = params.get('type'); + return type; +}; + +const defaultExtensionRegistry = new ExtensionRegistry(); + +/******************************************************************************* + * + * Workbench main area + * + * Used to register the component used by default when no representation is opened + * + *******************************************************************************/ +defaultExtensionRegistry.addComponent(workbenchMainAreaExtensionPoint, { + identifier: `siriusweb_${workbenchMainAreaExtensionPoint.identifier}`, + Component: OnboardArea, +}); + +/******************************************************************************* + * + * Workbench views + * + * Used to register all the views available in the left and right of the workbench + * + *******************************************************************************/ +const workbenchViewContributions: WorkbenchViewContribution[] = [ + { + side: 'left', + title: 'Explorer', + icon: , + component: ExplorerView, + }, + { + side: 'left', + title: 'Validation', + icon: , + component: ValidationView, + }, + { + side: 'right', + title: 'Details', + icon: , + component: DetailsView, + }, + { + side: 'right', + title: 'Representations', + icon: , + component: RepresentationsView, + }, + { + side: 'right', + title: 'Related Elements', + icon: , + component: RelatedElementsView, + }, +]; +defaultExtensionRegistry.putData(workbenchViewContributionExtensionPoint, { + identifier: `siriusweb_${workbenchViewContributionExtensionPoint.identifier}`, + data: workbenchViewContributions, +}); + +/******************************************************************************* + * + * Workbench representation factories + * + * Used to register all the type of representations that are supported in Sirius Web + * + *******************************************************************************/ + +const representationFactories: RepresentationComponentFactory[] = [ + (representationMetadata) => (getType(representationMetadata) === 'Diagram' ? DiagramRepresentation : null), + (representationMetadata) => (getType(representationMetadata) === 'Form' ? FormRepresentation : null), + (representationMetadata) => + getType(representationMetadata) === 'FormDescriptionEditor' ? FormDescriptionEditorRepresentation : null, + (representationMetadata) => (getType(representationMetadata) === 'Gantt' ? GanttRepresentation : null), + (representationMetadata) => (getType(representationMetadata) === 'Deck' ? DeckRepresentation : null), + (representationMetadata) => (getType(representationMetadata) === 'Portal' ? PortalRepresentation : null), +]; + +defaultExtensionRegistry.putData(representationFactoryExtensionPoint, { + identifier: `siriusweb_${representationFactoryExtensionPoint.identifier}`, + data: representationFactories, +}); + +export { defaultExtensionRegistry }; diff --git a/packages/sirius-web/frontend/sirius-web-application/src/onboarding/NewRepresentationArea.types.ts b/packages/sirius-web/frontend/sirius-web-application/src/onboarding/NewRepresentationArea.types.ts index 296450d598..8c241f6a20 100644 --- a/packages/sirius-web/frontend/sirius-web-application/src/onboarding/NewRepresentationArea.types.ts +++ b/packages/sirius-web/frontend/sirius-web-application/src/onboarding/NewRepresentationArea.types.ts @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2021, 2023 Obeo. + * 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 @@ -10,7 +10,7 @@ * Contributors: * Obeo - initial API and implementation *******************************************************************************/ -import { Representation } from '@eclipse-sirius/sirius-components-core'; +import { RepresentationMetadata } from '@eclipse-sirius/sirius-components-core'; export interface NewRepresentationAreaState { message: string; @@ -30,7 +30,7 @@ export interface NewRepresentationAreaProps { export interface GQLCreateRepresentationPayload { __typename: string; - representation: Representation; + representation: RepresentationMetadata; } export interface GQLErrorPayload extends GQLCreateRepresentationPayload { diff --git a/packages/sirius-web/frontend/sirius-web-application/src/representations/RepresentationContextProvider.tsx b/packages/sirius-web/frontend/sirius-web-application/src/representations/RepresentationContextProvider.tsx deleted file mode 100644 index 51fa16035a..0000000000 --- a/packages/sirius-web/frontend/sirius-web-application/src/representations/RepresentationContextProvider.tsx +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2023, 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 { - Representation, - RepresentationComponent, - RepresentationComponentRegistry, - RepresentationContext, - RepresentationContextValue, -} from '@eclipse-sirius/sirius-components-core'; -import { DeckRepresentation } from '@eclipse-sirius/sirius-components-deck'; -import { DiagramRepresentation } from '@eclipse-sirius/sirius-components-diagrams'; -import { FormDescriptionEditorRepresentation } from '@eclipse-sirius/sirius-components-formdescriptioneditors'; -import { FormRepresentation } from '@eclipse-sirius/sirius-components-forms'; -import { GanttRepresentation } from '@eclipse-sirius/sirius-components-gantt'; -import { PortalRepresentation } from '@eclipse-sirius/sirius-components-portals'; - -import { RepresentationContextProviderProps } from './RepresentationContextProvider.types'; - -export const RepresentationContextProvider = ({ children }: RepresentationContextProviderProps) => { - const registry: RepresentationComponentRegistry = { - getComponent: (representation: Representation): RepresentationComponent | null => { - const query = representation.kind.substring(representation.kind.indexOf('?') + 1, representation.kind.length); - const params = new URLSearchParams(query); - const type = params.get('type'); - if (type === 'Diagram') { - return DiagramRepresentation; - } else if (type === 'Form') { - return FormRepresentation; - } else if (type === 'FormDescriptionEditor') { - return FormDescriptionEditorRepresentation; - } else if (type === 'Gantt') { - return GanttRepresentation; - } else if (type === 'Deck') { - return DeckRepresentation; - } else if (type === 'Portal') { - return PortalRepresentation; - } - return null; - }, - }; - - const representationContextValue: RepresentationContextValue = { - registry, - }; - - return {children}; -}; diff --git a/packages/sirius-web/frontend/sirius-web-application/src/representations/RepresentationContextProvider.types.ts b/packages/sirius-web/frontend/sirius-web-application/src/representations/RepresentationContextProvider.types.ts deleted file mode 100644 index 2242836837..0000000000 --- a/packages/sirius-web/frontend/sirius-web-application/src/representations/RepresentationContextProvider.types.ts +++ /dev/null @@ -1,16 +0,0 @@ -/******************************************************************************* - * 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 RepresentationContextProviderProps { - children: React.ReactNode; -} diff --git a/packages/sirius-web/frontend/sirius-web-application/src/views/edit-project/EditProjectView.tsx b/packages/sirius-web/frontend/sirius-web-application/src/views/edit-project/EditProjectView.tsx index bb973d9276..1daeec6395 100644 --- a/packages/sirius-web/frontend/sirius-web-application/src/views/edit-project/EditProjectView.tsx +++ b/packages/sirius-web/frontend/sirius-web-application/src/views/edit-project/EditProjectView.tsx @@ -12,7 +12,7 @@ *******************************************************************************/ import { gql, useQuery } from '@apollo/client'; import { - Representation, + RepresentationMetadata, Selection, SelectionContextProvider, Toast, @@ -148,7 +148,7 @@ export const EditProjectView = () => { let main = null; if (editProjectView === 'loaded' && project) { - const onRepresentationSelected = (representationSelected: Representation) => { + const onRepresentationSelected = (representationSelected: RepresentationMetadata) => { const selectRepresentationEvent: SelectRepresentationEvent = { type: 'SELECT_REPRESENTATION', representation: representationSelected, diff --git a/packages/sirius-web/frontend/sirius-web-application/src/views/edit-project/EditProjectViewMachine.ts b/packages/sirius-web/frontend/sirius-web-application/src/views/edit-project/EditProjectViewMachine.ts index 7eaf2c304e..7cfda0f695 100644 --- a/packages/sirius-web/frontend/sirius-web-application/src/views/edit-project/EditProjectViewMachine.ts +++ b/packages/sirius-web/frontend/sirius-web-application/src/views/edit-project/EditProjectViewMachine.ts @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2021, 2023 Obeo. + * 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 @@ -10,7 +10,7 @@ * Contributors: * Obeo - initial API and implementation *******************************************************************************/ -import { Representation } from '@eclipse-sirius/sirius-components-core'; +import { RepresentationMetadata } from '@eclipse-sirius/sirius-components-core'; import { Machine, assign } from 'xstate'; import { GQLGetProjectQueryData, Project } from './EditProjectView.types'; @@ -39,14 +39,14 @@ export type SchemaValue = { export interface EditProjectViewContext { project: Project | null; - representation: Representation | null; + representation: RepresentationMetadata | null; message: string | null; } export type ShowToastEvent = { type: 'SHOW_TOAST'; message: string }; export type HideToastEvent = { type: 'HIDE_TOAST' }; export type HandleFetchedProjectEvent = { type: 'HANDLE_FETCHED_PROJECT'; data: GQLGetProjectQueryData }; -export type SelectRepresentationEvent = { type: 'SELECT_REPRESENTATION'; representation: Representation }; +export type SelectRepresentationEvent = { type: 'SELECT_REPRESENTATION'; representation: RepresentationMetadata }; export type EditProjectViewEvent = | HandleFetchedProjectEvent | SelectRepresentationEvent @@ -130,7 +130,7 @@ export const editProjectViewMachine = Machine