From b09f325e8d2996c0bc04ed65b26b4a403e963609 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20ROU=C3=8BN=C3=89?= Date: Tue, 10 Sep 2024 16:26:13 +0200 Subject: [PATCH] [3987] Transform widgetFields fragment to retrieve custom widget fields MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: https://github.com/eclipse-sirius/sirius-web/issues/3987 Signed-off-by: Florian ROUËNÉ --- CHANGELOG.adoc | 1 + .../ReferenceWidgetDocumentTransform.ts | 39 ++++++++----------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 058783a7fa..515d2526be 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -38,6 +38,7 @@ - https://github.com/eclipse-sirius/sirius-web/issues/2604[#2604] [diagram] Expand a tool section when the mouse is over it - https://github.com/eclipse-sirius/sirius-web/issues/3887[#3887] [diagram] Memoize diagram representation (improve performance when selecting an element on large diagram) +- https://github.com/eclipse-sirius/sirius-web/issues/3987[#3987] [sirius-web] Transform `widgetFields` fragment to retrieve custom widget fields == v2024.9.0 diff --git a/packages/sirius-web/frontend/sirius-web-application/src/extension/ReferenceWidgetDocumentTransform.ts b/packages/sirius-web/frontend/sirius-web-application/src/extension/ReferenceWidgetDocumentTransform.ts index e5e8917003..af190319be 100644 --- a/packages/sirius-web/frontend/sirius-web-application/src/extension/ReferenceWidgetDocumentTransform.ts +++ b/packages/sirius-web/frontend/sirius-web-application/src/extension/ReferenceWidgetDocumentTransform.ts @@ -12,26 +12,23 @@ *******************************************************************************/ import { DocumentTransform } from '@apollo/client'; -import { DocumentNode, FieldNode, InlineFragmentNode, Kind, SelectionNode, visit, FragmentSpreadNode } from 'graphql'; +import { DocumentNode, FragmentDefinitionNode, InlineFragmentNode, Kind, SelectionNode, visit } from 'graphql'; const shouldTransform = (document: DocumentNode) => { - return ( - document.definitions[0] && - document.definitions[0].kind === Kind.OPERATION_DEFINITION && - (document.definitions[0].name?.value === 'detailsEvent' || document.definitions[0].name?.value === 'formEvent') + return document.definitions.some( + (definition) => + definition.kind === Kind.OPERATION_DEFINITION && + (definition.name?.value === 'detailsEvent' || + definition.name?.value === 'formEvent' || + definition.name?.value === 'formDescriptionEditorEvent' || + definition.name?.value === 'representationsEvent' || + definition.name?.value === 'relatedElementsEvent' || + definition.name?.value === 'diagramFilterEvent') ); }; -const isWidgetFragment = (field: FieldNode) => { - if (field.name.value === 'widgets' || field.name.value === 'children') { - const fragmentSpreads = field.selectionSet.selections - .filter((selection: SelectionNode): selection is FragmentSpreadNode => selection.kind === Kind.FRAGMENT_SPREAD) - .map((fragmentSpread: FragmentSpreadNode) => fragmentSpread.name.value); - if (fragmentSpreads.includes('widgetFields')) { - return true; - } - } - return false; +const isWidgetFragmentDefinition = (node: FragmentDefinitionNode) => { + return node.name.value === 'widgetFields'; }; const labelField: SelectionNode = { @@ -201,12 +198,10 @@ const styleField: SelectionNode = { export const referenceWidgetDocumentTransform = new DocumentTransform((document) => { if (shouldTransform(document)) { return visit(document, { - Field(field) { - if (!isWidgetFragment(field)) { + FragmentDefinition(node) { + if (!isWidgetFragmentDefinition(node)) { return undefined; } - const selections = field.selectionSet?.selections ?? []; - const referenceWidgetInlineFragment: InlineFragmentNode = { kind: Kind.INLINE_FRAGMENT, selectionSet: { @@ -231,10 +226,10 @@ export const referenceWidgetDocumentTransform = new DocumentTransform((document) }; return { - ...field, + ...node, selectionSet: { - ...field.selectionSet, - selections: [...selections, referenceWidgetInlineFragment], + ...node.selectionSet, + selections: [...node.selectionSet.selections, referenceWidgetInlineFragment], }, }; },