From 67d70cf7928520438a51a3132ed0244f826c6310 Mon Sep 17 00:00:00 2001 From: Florian Barbin Date: Tue, 23 Jan 2024 14:36:16 +0100 Subject: [PATCH] [2984] Handle succesPayload messages in Deck MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: https://github.com/eclipse-sirius/sirius-web/issues/2984 Signed-off-by: Florian Barbin Signed-off-by: Florian ROUËNÉ --- CHANGELOG.adoc | 1 + .../sirius-components-core/src/index.ts | 1 + .../src/representation/DeckRepresentation.tsx | 54 +++++++++++-------- .../src/representation/deckMutation.ts | 18 +++++++ .../src/representation/deckMutation.types.ts | 15 ++++++ .../representation/deckSubscription.types.ts | 2 +- .../subscription/GanttSubscription.types.ts | 3 +- 7 files changed, 69 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index ac33ece90d..e85fb943cd 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -16,6 +16,7 @@ === Bug fixes +- https://github.com/eclipse-sirius/sirius-web/issues/2984[#2984] [deck] Handle successPayload messages in Deck representation. === New Features diff --git a/packages/core/frontend/sirius-components-core/src/index.ts b/packages/core/frontend/sirius-components-core/src/index.ts index b2a8e1cc4d..025fa5976a 100644 --- a/packages/core/frontend/sirius-components-core/src/index.ts +++ b/packages/core/frontend/sirius-components-core/src/index.ts @@ -18,6 +18,7 @@ export * from './contexts/ServerContext.types'; export * from './contexts/ToastContext'; export * from './contexts/ToastContext.types'; export * from './dataTransferTypes'; +export * from './graphql/GQLTypes.types'; export * from './icon/IconOverlay'; export * from './materialui'; export * from './modals/share-representation/ShareRepresentationModal'; diff --git a/packages/deck/frontend/sirius-components-deck/src/representation/DeckRepresentation.tsx b/packages/deck/frontend/sirius-components-deck/src/representation/DeckRepresentation.tsx index 5e91b4df30..f4816a5b65 100644 --- a/packages/deck/frontend/sirius-components-deck/src/representation/DeckRepresentation.tsx +++ b/packages/deck/frontend/sirius-components-deck/src/representation/DeckRepresentation.tsx @@ -20,7 +20,7 @@ import { } from '@eclipse-sirius/sirius-components-core'; import Typography from '@material-ui/core/Typography'; import { makeStyles } from '@material-ui/core/styles'; -import { useCallback, useEffect, useState } from 'react'; +import { useEffect, useState } from 'react'; import { Deck } from '../Deck'; import { Card, CardMetadata } from '../Deck.types'; import { convertToTrelloDeckData } from '../utils/deckGQLConverter'; @@ -37,12 +37,16 @@ import { GQLCreateCardData, GQLCreateCardVariables, GQLCreateDeckCardInput, + GQLCreateDeckCardPayload, GQLDeleteCardData, GQLDeleteCardVariables, GQLDeleteDeckCardInput, + GQLDeleteDeckCardPayload, GQLEditCardData, GQLEditCardVariables, GQLEditDeckCardInput, + GQLEditDeckCardPayload, + GQLSuccessPayload, } from './deckMutation.types'; import { createCardMutation, deleteCardMutation, editCardMutation } from './deckMutation'; @@ -59,6 +63,9 @@ const isDeckRefreshedEventPayload = (payload: GQLDeckEventPayload): payload is G const isErrorPayload = (payload: GQLDeckEventPayload): payload is GQLErrorPayload => payload.__typename === 'ErrorPayload'; const isStandardErrorPayload = (field): field is GQLErrorPayload => field.__typename === 'ErrorPayload'; +const isSuccessPayload = ( + payload: GQLDeleteDeckCardPayload | GQLEditDeckCardPayload | GQLCreateDeckCardPayload +): payload is GQLSuccessPayload => payload.__typename === 'SuccessPayload'; export const DeckRepresentation = ({ editingContextId, representationId }: RepresentationComponentProps) => { const classes = useDeckRepresentationStyles(); @@ -137,39 +144,40 @@ export const DeckRepresentation = ({ editingContextId, representationId }: Repre }); } }, [selection]); - const handleError = useCallback( - (loading: boolean, data, error: ApolloError | undefined) => { - if (!loading) { - if (error) { - addErrorMessage(error.message); - } - if (data) { - const keys = Object.keys(data); - if (keys.length > 0) { - const firstKey = keys[0]; - if (firstKey) { - const firstField = data[firstKey]; - if (isStandardErrorPayload(firstField)) { - const { messages } = firstField; - addMessages(messages); - } + const handleError = ( + loading: boolean, + data: GQLEditCardData | GQLDeleteCardData | GQLCreateCardData | null | undefined, + error: ApolloError | undefined + ) => { + if (!loading) { + if (error) { + addErrorMessage(error.message); + } + if (data) { + const keys = Object.keys(data); + if (keys.length > 0) { + const firstKey = keys[0]; + if (firstKey) { + const firstField = data[firstKey]; + if (isStandardErrorPayload(firstField) || isSuccessPayload(firstField)) { + const { messages } = firstField; + addMessages(messages); } } } } - }, - [addErrorMessage, addMessages] - ); + } + }; useEffect(() => { handleError(deleteDeckCardLoading, deleteDeckCardData, deleteDeckCardError); - }, [deleteDeckCardLoading, deleteDeckCardData, deleteDeckCardError, handleError]); + }, [deleteDeckCardLoading, deleteDeckCardData, deleteDeckCardError]); useEffect(() => { handleError(editCardLoading, editCardData, editCardError); - }, [editCardLoading, editCardData, editCardError, handleError]); + }, [editCardLoading, editCardData, editCardError]); useEffect(() => { handleError(createCardLoading, createCardData, createCardError); - }, [createCardLoading, createCardData, createCardError, handleError]); + }, [createCardLoading, createCardData, createCardError]); const handleEditCard = (_laneId: string, card: Card) => { const input: GQLEditDeckCardInput = { diff --git a/packages/deck/frontend/sirius-components-deck/src/representation/deckMutation.ts b/packages/deck/frontend/sirius-components-deck/src/representation/deckMutation.ts index 427c4cdc1a..a94c117152 100644 --- a/packages/deck/frontend/sirius-components-deck/src/representation/deckMutation.ts +++ b/packages/deck/frontend/sirius-components-deck/src/representation/deckMutation.ts @@ -22,6 +22,12 @@ export const deleteCardMutation = gql` level } } + ... on SuccessPayload { + messages { + body + level + } + } } } `; @@ -36,6 +42,12 @@ export const editCardMutation = gql` level } } + ... on SuccessPayload { + messages { + body + level + } + } } } `; @@ -50,6 +62,12 @@ export const createCardMutation = gql` level } } + ... on SuccessPayload { + messages { + body + level + } + } } } `; diff --git a/packages/deck/frontend/sirius-components-deck/src/representation/deckMutation.types.ts b/packages/deck/frontend/sirius-components-deck/src/representation/deckMutation.types.ts index b8c14dc0c8..9a3496e5ef 100644 --- a/packages/deck/frontend/sirius-components-deck/src/representation/deckMutation.types.ts +++ b/packages/deck/frontend/sirius-components-deck/src/representation/deckMutation.types.ts @@ -11,18 +11,23 @@ * Obeo - initial API and implementation *******************************************************************************/ +import { GQLMessage } from '@eclipse-sirius/sirius-components-core'; + export interface GQLDeleteCardVariables { input: GQLDeleteDeckCardInput; } + export interface GQLDeleteDeckCardInput { id: string; editingContextId: string; representationId: string; cardId: string; } + export interface GQLDeleteCardData { deleteDeckCard: GQLDeleteDeckCardPayload; } + export interface GQLDeleteDeckCardPayload { __typename: string; } @@ -30,6 +35,7 @@ export interface GQLDeleteDeckCardPayload { export interface GQLEditCardVariables { input: GQLEditDeckCardInput; } + export interface GQLEditDeckCardInput { id: string; editingContextId: string; @@ -39,9 +45,11 @@ export interface GQLEditDeckCardInput { newDescription: string; newLabel: string; } + export interface GQLEditCardData { editDeckCard: GQLEditDeckCardPayload; } + export interface GQLEditDeckCardPayload { __typename: string; } @@ -49,6 +57,7 @@ export interface GQLEditDeckCardPayload { export interface GQLCreateCardVariables { input: GQLCreateDeckCardInput; } + export interface GQLCreateDeckCardInput { id: string; editingContextId: string; @@ -58,9 +67,15 @@ export interface GQLCreateDeckCardInput { label: string; description: string; } + export interface GQLCreateCardData { createCard: GQLCreateDeckCardPayload; } + export interface GQLCreateDeckCardPayload { __typename: string; } + +export interface GQLSuccessPayload extends GQLCreateDeckCardPayload, GQLDeleteDeckCardPayload, GQLEditDeckCardPayload { + messages: GQLMessage[]; +} diff --git a/packages/deck/frontend/sirius-components-deck/src/representation/deckSubscription.types.ts b/packages/deck/frontend/sirius-components-deck/src/representation/deckSubscription.types.ts index 7ae782ab23..499b187096 100644 --- a/packages/deck/frontend/sirius-components-deck/src/representation/deckSubscription.types.ts +++ b/packages/deck/frontend/sirius-components-deck/src/representation/deckSubscription.types.ts @@ -10,7 +10,7 @@ * Contributors: * Obeo - initial API and implementation *******************************************************************************/ -import { GQLMessage } from '@eclipse-sirius/sirius-components-core/src/graphql/GQLTypes.types'; +import { GQLMessage } from '@eclipse-sirius/sirius-components-core'; export interface GQLDeckEventSubscription { deckEvent: GQLDeckEventPayload; diff --git a/packages/gantt/frontend/sirius-components-gantt/graphql/subscription/GanttSubscription.types.ts b/packages/gantt/frontend/sirius-components-gantt/graphql/subscription/GanttSubscription.types.ts index ba2b2cea30..02a4ff5e63 100644 --- a/packages/gantt/frontend/sirius-components-gantt/graphql/subscription/GanttSubscription.types.ts +++ b/packages/gantt/frontend/sirius-components-gantt/graphql/subscription/GanttSubscription.types.ts @@ -11,7 +11,7 @@ * Obeo - initial API and implementation *******************************************************************************/ import { Task } from '@ObeoNetwork/gantt-task-react'; -import { GQLMessage } from '@eclipse-sirius/sirius-components-core/src/graphql/GQLTypes.types'; +import { GQLMessage } from '@eclipse-sirius/sirius-components-core'; export interface GQLGanttEventSubscription { ganttEvent: GQLGanttEventPayload; @@ -84,6 +84,7 @@ export interface GQLTaskDetail { progress: number; computeStartEndDynamically: boolean; } + export interface GQLTaskStyle { labelColor: string; backgroundColor: string;