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

[4208] Improve performance of details view rendering on selection change #4209

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ Note that you may need to encode special characters like `[`(by `%5B`) and `]` (
To achieve that a new concept, `ProjectSemanticData` has been added along with a dedicated table to keep the information previously contained in `SemanticData`
- https://github.com/eclipse-sirius/sirius-web/issues/4501[#4501] [browser] Extract the model browser into reusable modules
- https://github.com/eclipse-sirius/sirius-web/issues/4514[#4514] [sirius-web] Added support for Ctrl+Shift+Z (Linux/macOS) to trigger redo in addition to Ctrl+Y (Windows)
- https://github.com/eclipse-sirius/sirius-web/issues/4208[#4208] [form] Improve performance of details view rendering on selection change

== v2025.1.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Obeo - initial API and implementation
*******************************************************************************/
import { DataExtension, useData } from '@eclipse-sirius/sirius-components-core';
import { memo } from 'react';
import { Form } from '../form/Form';
import { GQLForm } from '../form/FormEventFragments.types';
import { FormBasedViewProps, FormConverter } from './FormBasedView.types';
Expand All @@ -19,7 +20,7 @@ import { formBasedViewFormConverterExtensionPoint } from './FormBasedViewExtensi
/**
* Used to define workbench views based on a form.
*/
export const FormBasedView = ({ editingContextId, form, readOnly, postProcessor }: FormBasedViewProps) => {
export const FormBasedView = memo(({ editingContextId, form, readOnly, postProcessor }: FormBasedViewProps) => {
const { data: formConverters }: DataExtension<FormConverter[]> = useData(formBasedViewFormConverterExtensionPoint);

let convertedForm: GQLForm = form;
Expand All @@ -31,4 +32,4 @@ export const FormBasedView = ({ editingContextId, form, readOnly, postProcessor
return postProcessor({ editingContextId, readOnly }, convertedForm);
}
return <Form editingContextId={editingContextId} form={convertedForm} readOnly={readOnly} />;
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,12 @@ const isFormRefreshedEventPayload = (payload: GQLDetailsEventPayload): payload i

export const DetailsView = ({ editingContextId, readOnly }: WorkbenchViewComponentProps) => {
const [state, setState] = useState<DetailsViewState>({
currentSelection: { entries: [] },
form: null,
});

const { selection } = useSelection();

/**
* Displays another form if the selection indicates that we should display another properties view.
*/
const currentSelectionKey: string = state.currentSelection.entries
.map((entry) => entry.id)
.sort()
.join(':');
const newSelectionKey: string = selection.entries
.map((entry) => entry.id)
.sort()
.join(':');

useEffect(() => {
if (selection.entries.length > 0 && currentSelectionKey !== newSelectionKey) {
setState((prevState) => ({ ...prevState, currentSelection: selection }));
} else if (selection.entries.length === 0) {
setState((prevState) => ({ ...prevState, currentSelection: { entries: [] } }));
}
}, [currentSelectionKey, newSelectionKey]);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
* Obeo - initial API and implementation
*******************************************************************************/

import { Selection } from '@eclipse-sirius/sirius-components-core';
import { GQLForm } from '@eclipse-sirius/sirius-components-forms';

export interface DetailsViewState {
currentSelection: Selection;
form: GQLForm | null;
}
Loading