Skip to content

Commit

Permalink
[cleanup] Extract the default extension registry in a dedicated file
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Bégaudeau <[email protected]>
  • Loading branch information
sbegaudeau committed Jun 11, 2024
1 parent e22d731 commit 0fd1db4
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,13 @@
import {
ConfirmationDialogContextProvider,
ExtensionProvider,
ExtensionRegistry,
RepresentationMetadata,
RepresentationPathContext,
ServerContext,
WorkbenchViewContribution,
representationFactoryExtensionPoint,
workbenchMainAreaExtensionPoint,
workbenchViewContributionExtensionPoint,
} from '@eclipse-sirius/sirius-components-core';
import { DeckRepresentation } from '@eclipse-sirius/sirius-components-deck';
import {
DiagramRepresentation,
NodeTypeContext,
NodeTypeContextValue,
} from '@eclipse-sirius/sirius-components-diagrams';
import { FormDescriptionEditorRepresentation } from '@eclipse-sirius/sirius-components-formdescriptioneditors';
import {
DetailsView,
FormRepresentation,
PropertySectionContext,
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 { NodeTypeContext, NodeTypeContextValue } from '@eclipse-sirius/sirius-components-diagrams';
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';
Expand All @@ -55,10 +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 { Router } from '../router/Router';
import { siriusWebTheme as defaultTheme } from '../theme/siriusWebTheme';
import { SiriusWebApplicationProps } from './SiriusWebApplication.types';
Expand All @@ -70,13 +43,6 @@ const style = {
minHeight: '100vh',
};

const getType = (representation: RepresentationMetadata): string => {
const query = representation.kind.substring(representation.kind.indexOf('?') + 1, representation.kind.length);
const params = new URLSearchParams(query);
const type = params.get('type');
return type;
};

export const SiriusWebApplication = ({
httpOrigin,
wsOrigin,
Expand All @@ -102,86 +68,15 @@ export const SiriusWebApplication = ({
return `/projects/${editingContextId}/edit/${representationId}`;
};

const workbenchViewContributions: WorkbenchViewContribution[] = [
{
side: 'left',
title: 'Explorer',
icon: <AccountTreeIcon />,
component: ExplorerView,
},
{
side: 'left',
title: 'Validation',
icon: <WarningIcon />,
component: ValidationView,
},
{
side: 'right',
title: 'Details',
icon: <MenuIcon />,
component: DetailsView,
},
{
side: 'right',
title: 'Representations',
icon: <Filter />,
component: RepresentationsView,
},
{
side: 'right',
title: 'Related Elements',
icon: <LinkIcon />,
component: RelatedElementsView,
},
];

const internalExtensionRegistry = new ExtensionRegistry();
internalExtensionRegistry.addComponent(workbenchMainAreaExtensionPoint, {
identifier: 'siriusweb_workbench#mainArea',
Component: OnboardArea,
});
internalExtensionRegistry.putData(workbenchViewContributionExtensionPoint, {
identifier: 'siriusweb_workbench#viewContribution',
data: workbenchViewContributions,
});

internalExtensionRegistry.putData(representationFactoryExtensionPoint, {
identifier: 'siriusweb_workbench#representationFactory_diagram',
data: [(representation) => (getType(representation) === 'Diagram' ? DiagramRepresentation : null)],
});
internalExtensionRegistry.putData(representationFactoryExtensionPoint, {
identifier: 'siriusweb_workbench#representationFactory_form',
data: [(representation) => (getType(representation) === 'Form' ? FormRepresentation : null)],
});
internalExtensionRegistry.putData(representationFactoryExtensionPoint, {
identifier: 'siriusweb_workbench#representationFactory_formdescriptioneditor',
data: [
(representation) =>
getType(representation) === 'FormDescriptionEditor' ? FormDescriptionEditorRepresentation : null,
],
});
internalExtensionRegistry.putData(representationFactoryExtensionPoint, {
identifier: 'siriusweb_workbench#representationFactory_gantt',
data: [(representation) => (getType(representation) === 'Gantt' ? GanttRepresentation : null)],
});
internalExtensionRegistry.putData(representationFactoryExtensionPoint, {
identifier: 'siriusweb_workbench#representationFactory_deck',
data: [(representation) => (getType(representation) === 'Deck' ? DeckRepresentation : null)],
});
internalExtensionRegistry.putData(representationFactoryExtensionPoint, {
identifier: 'siriusweb_workbench#representationFactory_portal',
data: [(representation) => (getType(representation) === 'Portal' ? PortalRepresentation : null)],
});

if (extensionRegistry) {
internalExtensionRegistry.addAll(
defaultExtensionRegistry.addAll(
extensionRegistry,
extensionRegistryMergeStrategy ? extensionRegistryMergeStrategy : new DefaultExtensionRegistryMergeStrategy()
);
}

return (
<ExtensionProvider registry={internalExtensionRegistry}>
<ExtensionProvider registry={defaultExtensionRegistry}>
<ApolloGraphQLProvider httpOrigin={httpOrigin} wsOrigin={wsOrigin}>
<BrowserRouter>
<ThemeProvider theme={siriusWebTheme}>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/*******************************************************************************
* 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,
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: <AccountTreeIcon />,
component: ExplorerView,
},
{
side: 'left',
title: 'Validation',
icon: <WarningIcon />,
component: ValidationView,
},
{
side: 'right',
title: 'Details',
icon: <MenuIcon />,
component: DetailsView,
},
{
side: 'right',
title: 'Representations',
icon: <Filter />,
component: RepresentationsView,
},
{
side: 'right',
title: 'Related Elements',
icon: <LinkIcon />,
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
*
*******************************************************************************/

defaultExtensionRegistry.putData(representationFactoryExtensionPoint, {
identifier: `siriusweb_${representationFactoryExtensionPoint.identifier}_diagram`,
data: [(representation) => (getType(representation) === 'Diagram' ? DiagramRepresentation : null)],
});
defaultExtensionRegistry.putData(representationFactoryExtensionPoint, {
identifier: `siriusweb_${representationFactoryExtensionPoint.identifier}_form`,
data: [(representation) => (getType(representation) === 'Form' ? FormRepresentation : null)],
});
defaultExtensionRegistry.putData(representationFactoryExtensionPoint, {
identifier: `siriusweb_${representationFactoryExtensionPoint.identifier}_formdescriptioneditor`,
data: [
(representation) =>
getType(representation) === 'FormDescriptionEditor' ? FormDescriptionEditorRepresentation : null,
],
});
defaultExtensionRegistry.putData(representationFactoryExtensionPoint, {
identifier: `siriusweb_${representationFactoryExtensionPoint.identifier}_gantt`,
data: [(representation) => (getType(representation) === 'Gantt' ? GanttRepresentation : null)],
});
defaultExtensionRegistry.putData(representationFactoryExtensionPoint, {
identifier: `siriusweb_${representationFactoryExtensionPoint.identifier}_deck`,
data: [(representation) => (getType(representation) === 'Deck' ? DeckRepresentation : null)],
});
defaultExtensionRegistry.putData(representationFactoryExtensionPoint, {
identifier: `siriusweb_${representationFactoryExtensionPoint.identifier}_portal`,
data: [(representation) => (getType(representation) === 'Portal' ? PortalRepresentation : null)],
});

export { defaultExtensionRegistry };

0 comments on commit 0fd1db4

Please sign in to comment.