Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3758] Store property and form payload in a context #3759

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ As a result, the following maven modules have been deleted: `sirius-web-sample-a
=== New Features

- https://github.com/eclipse-sirius/sirius-web/issues/3748[#3748] [diagram] Store current diagram payload in `DiagramContext`

- https://github.com/eclipse-sirius/sirius-web/issues/3758[#3578] [form] Store property and form payload in a context

=== Improvements

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*******************************************************************************
* 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 React from 'react';
import { FormContextValue } from './FormContext.types';

const value: FormContextValue = {
payload: null,
};

export const FormContext = React.createContext<FormContextValue>(value);
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*******************************************************************************
* 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 { GQLFormEventPayload } from '../form/FormEventFragments.types';

export interface FormContextValue {
payload: GQLFormEventPayload | null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
export { FormContext } from './contexts/FormContext';
export type { FormContextValue } from './contexts/FormContext.types';
export * from './form/Form.types';
export * from './form/FormEventFragments';
export type * from './form/FormEventFragments.types';
Expand All @@ -28,6 +30,7 @@ export * from './propertysections/ListPropertySection';
export type { ListStyleProps } from './propertysections/ListPropertySection.types';
export type { MultiSelectStyleProps } from './propertysections/MultiSelectPropertySection.types';
export * from './propertysections/PropertySectionLabel';
export type { PropertySectionLabelDecoratorProps } from './propertysections/PropertySectionLabel.types';
export * from './propertysections/PropertySectionLabelExtensionPoints';
export type { RadioStyleProps } from './propertysections/RadioPropertySection.types';
export type { SelectStyleProps } from './propertysections/SelectPropertySection.types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ import { RepresentationComponentProps, Toast } from '@eclipse-sirius/sirius-comp
import Typography from '@material-ui/core/Typography';
import { makeStyles } from '@material-ui/core/styles';
import { useMachine } from '@xstate/react';
import { useEffect } from 'react';
import { useEffect, useState } from 'react';
import { FormContext } from '../contexts/FormContext';
import { Form } from '../form/Form';
import { formRefreshedEventPayloadFragment } from '../form/FormEventFragments';
import { GQLFormEventSubscription } from '../form/FormEventFragments.types';
import { Page } from '../pages/Page';
import { ToolbarAction } from '../toolbaraction/ToolbarAction';
import { FormRepresentationState } from './FormRepresentation.types';
import {
FormRepresentationContext,
FormRepresentationEvent,
Expand Down Expand Up @@ -89,6 +91,9 @@ export const FormRepresentation = ({ editingContextId, representationId, readOnl
);
const { toast, formRepresentation } = value as SchemaValue;
const { id, formId, form, message } = context;
const [state, setState] = useState<FormRepresentationState>({
payload: null,
});

/**
* Displays an other form if the selection indicates that we should display another properties view.
Expand All @@ -110,6 +115,10 @@ export const FormRepresentation = ({ editingContextId, representationId, readOnl
},
fetchPolicy: 'no-cache',
onData: ({ data }) => {
if (data.data) {
const { formEvent } = data.data;
setState((prevState) => ({ ...prevState, payload: formEvent }));
}
const handleDataEvent: HandleSubscriptionResultEvent = {
type: 'HANDLE_SUBSCRIPTION_RESULT',
result: data,
Expand Down Expand Up @@ -171,12 +180,17 @@ export const FormRepresentation = ({ editingContextId, representationId, readOnl

return (
<div data-representation-kind="form">
{content}
<Toast
message={message}
open={toast === 'visible'}
onClose={() => dispatch({ type: 'HIDE_TOAST' } as HideToastEvent)}
/>
<FormContext.Provider
value={{
payload: state.payload,
}}>
{content}
<Toast
message={message}
open={toast === 'visible'}
onClose={() => dispatch({ type: 'HIDE_TOAST' } as HideToastEvent)}
/>
</FormContext.Provider>
</div>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*******************************************************************************
* 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 { GQLFormEventPayload } from '../form/FormEventFragments.types';

export interface FormRepresentationState {
payload: GQLFormEventPayload | null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export { useCurrentProject } from './views/edit-project/useCurrentProject';
export type { UseCurrentProjectValue } from './views/edit-project/useCurrentProject.types';
export type { GQLProject } from './views/edit-project/useProjectAndRepresentationMetadata.types';
export { DetailsView } from './views/edit-project/workbench-views/DetailsView';
export type { GQLDetailsEventPayload } from './views/edit-project/workbench-views/useDetailsViewSubscription.types';
export { type CreateProjectAreaCardProps } from './views/project-browser/create-projects-area/CreateProjectArea.types';
export { createProjectAreaCardExtensionPoint } from './views/project-browser/create-projects-area/CreateProjectAreaExtensionPoints';
export { projectActionButtonMenuItemExtensionPoint } from './views/project-browser/list-projects-area/ProjectActionButtonExtensionPoints';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Obeo - initial API and implementation
*******************************************************************************/
import { useSelection, WorkbenchViewComponentProps } from '@eclipse-sirius/sirius-components-core';
import { FormBasedView } from '@eclipse-sirius/sirius-components-forms';
import { FormBasedView, FormContext } from '@eclipse-sirius/sirius-components-forms';
import Typography from '@material-ui/core/Typography';
import { makeStyles } from '@material-ui/core/styles';
import { useEffect, useState } from 'react';
Expand Down Expand Up @@ -52,7 +52,7 @@ export const DetailsView = ({ editingContextId, readOnly }: WorkbenchViewCompone

const objectIds: string[] = state.currentSelection.entries.map((entry) => entry.id);
const skip = objectIds.length === 0;
const { form } = useDetailsViewSubscription(editingContextId, objectIds, skip);
const { form, payload } = useDetailsViewSubscription(editingContextId, objectIds, skip);

const classes = useDetailsViewStyles();

Expand All @@ -63,5 +63,14 @@ export const DetailsView = ({ editingContextId, readOnly }: WorkbenchViewCompone
</div>
);
}
return <FormBasedView editingContextId={editingContextId} form={form} readOnly={readOnly} />;
return (
<div data-representation-kind="form-details">
<FormContext.Provider
value={{
payload: payload,
}}>
<FormBasedView editingContextId={editingContextId} form={form} readOnly={readOnly} />
</FormContext.Provider>
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const useDetailsViewSubscription = (
id: crypto.randomUUID(),
form: null,
complete: false,
payload: null,
});

const input: GQLDetailsEventInput = {
Expand All @@ -63,6 +64,7 @@ export const useDetailsViewSubscription = (
const { data: gqlDetailsEventSubscription } = data;
if (gqlDetailsEventSubscription) {
const { detailsEvent: payload } = gqlDetailsEventSubscription;
setState((prevState) => ({ ...prevState, payload }));
if (isFormRefreshedEventPayload(payload)) {
const { form } = payload;
setState((prevState) => ({ ...prevState, form }));
Expand Down Expand Up @@ -93,6 +95,7 @@ export const useDetailsViewSubscription = (
return {
loading,
form: state.form,
payload: state.payload,
complete: state.complete,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ import { GQLForm } from '@eclipse-sirius/sirius-components-forms';
export interface UseDetailsViewSubscriptionValue {
loading: boolean;
form: GQLForm | null;
payload: GQLDetailsEventPayload | null;
complete: boolean;
}

export interface UseDetailsViewSubscriptionState {
id: string;
form: GQLForm | null;
complete: boolean;
payload: GQLDetailsEventPayload | null;
}

export interface GQLDetailsEventInput {
Expand Down
Loading