Skip to content

Commit

Permalink
[2570] Allow details view to change its content
Browse files Browse the repository at this point in the history
Bug: eclipse-sirius#2570
Signed-off-by: William Piers <[email protected]>
  • Loading branch information
wpiers committed Nov 15, 2023
1 parent ea752ec commit 6b1f2cc
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 4 deletions.
3 changes: 3 additions & 0 deletions packages/forms/frontend/sirius-components-forms/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,8 @@ export * from './propertysections/getTextDecorationLineValue';
export * from './propertysections/useClickHandler';
export * from './representations/FormRepresentation';
export * from './views/DetailsView';
export * from './views/DetailsViewConfiguration';
export * from './views/DetailsViewConfiguration.types';
export * from './views/FormConverter.types';
export * from './views/RelatedElementsView';
export * from './views/RepresentationsView';
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
* Obeo - initial API and implementation
*******************************************************************************/
import { WorkbenchViewComponentProps } from '@eclipse-sirius/sirius-components-core';
import { useDetailsViewConfiguration } from './DetailsViewConfiguration';
import { FormBasedView } from './FormBasedView';

export const DetailsView = (props: WorkbenchViewComponentProps) => (
<FormBasedView {...props} subscriptionName="propertiesEvent" />
);
export const DetailsView = (props: WorkbenchViewComponentProps) => {
const { converter } = useDetailsViewConfiguration();
return <FormBasedView {...props} subscriptionName="propertiesEvent" converter={converter} />;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*******************************************************************************
* 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 { DetailsViewConfigurationProps, UseDetailsViewConfigurationValue } from './DetailsViewConfiguration.types';
import { DetailsViewContext } from './DetailsViewContext';

export const DetailsViewConfiguration = ({ children, converter }: DetailsViewConfigurationProps) => {
return <DetailsViewContext.Provider value={{ converter }}>{children}</DetailsViewContext.Provider>;
};

export const useDetailsViewConfiguration = (): UseDetailsViewConfigurationValue => {
const { converter } = React.useContext<UseDetailsViewConfigurationValue>(DetailsViewContext);
return {
converter,
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*******************************************************************************
* 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 { ReactNode } from 'react';
import { FormConverter } from './FormConverter.types';

export interface DetailsViewConfigurationProps {
converter: FormConverter;
children: ReactNode;
}

export interface UseDetailsViewConfigurationValue {
converter: FormConverter;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*******************************************************************************
* 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 { DetailsViewContextValue } from './DetailsViewContext.types';
import { FormConverter } from './FormConverter.types';

const converter: FormConverter = {
convert: (form) => form,
};

const defaultContext: DetailsViewContextValue = {
converter,
};

export const DetailsViewContext = React.createContext(defaultContext);
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*******************************************************************************
* 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 { FormConverter } from './FormConverter.types';
export interface DetailsViewContextValue {
converter: FormConverter;
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export const FormBasedView = ({
setSelection,
readOnly,
subscriptionName,
converter,
}: FormBasedViewProps) => {
const classes = useFormBasedViewStyles();
const [{ value, context }, dispatch] = useMachine<FormBasedViewContext, FormBasedViewEvent>(formBasedViewMachine);
Expand Down Expand Up @@ -156,7 +157,7 @@ export const FormBasedView = ({
content = (
<Form
editingContextId={editingContextId}
form={form}
form={converter.convert(form)}
widgetSubscriptions={widgetSubscriptions}
setSelection={setSelection}
readOnly={readOnly}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
* Obeo - initial API and implementation
*******************************************************************************/
import { Selection, WorkbenchViewComponentProps } from '@eclipse-sirius/sirius-components-core';
import { FormConverter } from './FormConverter.types';

export interface FormBasedViewProps extends WorkbenchViewComponentProps {
editingContextId: string;
selection: Selection;
setSelection: (selection: Selection) => void;
readOnly: boolean;
subscriptionName: string;
converter: FormConverter;
}
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 { GQLForm } from '../form/FormEventFragments.types';

export interface FormConverter {
convert(form: GQLForm): GQLForm;
}

0 comments on commit 6b1f2cc

Please sign in to comment.