-
Notifications
You must be signed in to change notification settings - Fork 45
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
[3389] Add support for DateTime widget #3390
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
first review of the code, I didn't test it yet.
...a/org/eclipse/sirius/components/formdescriptioneditors/components/DateTimeStyleProvider.java
Outdated
Show resolved
Hide resolved
...main/java/org/eclipse/sirius/components/view/form/provider/GroupDescriptionItemProvider.java
Show resolved
Hide resolved
...form-edit/src/main/java/org/eclipse/sirius/components/view/form/provider/FormEditPlugin.java
Outdated
Show resolved
Hide resolved
...s-forms/src/main/java/org/eclipse/sirius/components/forms/elements/DateTimeElementProps.java
Outdated
Show resolved
Hide resolved
...s-forms/src/main/java/org/eclipse/sirius/components/forms/elements/DateTimeElementProps.java
Outdated
Show resolved
Hide resolved
...s-forms/src/main/java/org/eclipse/sirius/components/forms/elements/DateTimeElementProps.java
Outdated
Show resolved
Hide resolved
packages/sirius-web/backend/sirius-web/src/main/resources/application.properties
Outdated
Show resolved
Hide resolved
packages/view/backend/sirius-components-view-form/src/main/resources/model/form.ecore
Outdated
Show resolved
Hide resolved
Could you please rebase this PR on master instead on one of your own branch? |
function useErrorReporting<T>( | ||
result: MutationResult<T>, | ||
extractPayload: (data: T | null) => GQLPayload | undefined, | ||
addErrorMessage: (message: string) => any, | ||
addMessages: (messages: any) => any | ||
) { | ||
useEffect(() => { | ||
const { loading, data, error } = result; | ||
if (!loading) { | ||
if (error) { | ||
addErrorMessage(error.message); | ||
} | ||
const payload: GQLPayload | undefined = extractPayload(data || null); | ||
if (payload && (isSuccessPayload(payload) || isErrorPayload(payload))) { | ||
const { messages } = payload; | ||
addMessages(messages); | ||
} | ||
} | ||
}, [result.loading, result.data, result.error]); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like this should probably be a hook in sirius-components-core directly to be usable by all downstream projects. The hook in question should have the dependency to addErrorMessage
/ addMessages
and given the pattern used by our mutation data fetchers (on purpose), I'm pretty sure you don't need anyone to tell you how to extract the payload.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes but not in the PR. We must define the scope of this change because currently useErrorReporting
pattern is used in portal, deck, gantt and DateTimeWidget. Ideally, we should use it everywhere it is needed. It implies lots of changes including GQLPayloadXxx that are define everywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could simplify useErrorReporting
by using useMultiToast
inside. Then we would have only result and extractPayload parameters.
We could even force all GQLxxxMutationData
to have a payload attribute of type GQLPayload
(defined in sirius-components-core) and then only the result parameter would be necessary. (isErrorPayload and isSuccessPayload would be included in useErrorReporting
too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes but not in the PR. We must define the scope of this change because currently useErrorReporting pattern is used in portal, deck, gantt and DateTimeWidget.
Yes in this PR. I don't know why this kind of situation happens again and again where people try to improve just their own piece of code. This code should either be removed or in sirius-components-core and that's the same for its other occurences.
It implies lots of changes including GQLPayloadXxx that are define everywhere.
I'm not asking for all pieces of code where errors are treated to be updated, I'm just asking for this specific piece of code, those 20 lines of code, to be accessible by everybody by being in sirius-components-core. And if they are moved there, it should be very easy to update both the portal and gantt part too instead of copying and pasting stuff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
be56d56
to
29db510
Compare
e29fc09
to
a3691f8
Compare
0f6187f
to
3074ded
Compare
36ba2bc
to
bb61155
Compare
bb61155
to
5f60759
Compare
5f60759
to
5fcaf96
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll handle the comments that I've made and update the PR accordingly
@@ -16,6 +16,7 @@ export interface GQLMessage { | |||
level: string; | |||
} | |||
|
|||
export interface GQLErrorPayload { | |||
export interface GQLPayload { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no generic GQLPayload in the GraphQL API with such signature
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed it since it was wrong
packages/core/frontend/sirius-components-core/src/toast/useReporting.ts
Outdated
Show resolved
Hide resolved
packages/deck/frontend/sirius-components-deck/src/representation/useDeckMutation.types.ts
Outdated
Show resolved
Hide resolved
packages/deck/frontend/sirius-components-deck/src/representation/useDeckMutations.ts
Outdated
Show resolved
Hide resolved
...mdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/DateTimeWidget.tsx
Outdated
Show resolved
Hide resolved
packages/gantt/frontend/sirius-components-gantt/src/graphql/mutation/useGanttMutations.ts
Outdated
Show resolved
Hide resolved
packages/gantt/frontend/sirius-components-gantt/src/graphql/mutation/useGanttMutations.ts
Outdated
Show resolved
Hide resolved
packages/portals/frontend/sirius-components-portals/src/hooks/usePortalMutations.ts
Outdated
Show resolved
Hide resolved
packages/portals/frontend/sirius-components-portals/src/hooks/usePortalMutations.types.ts
Outdated
Show resolved
Hide resolved
...iew-emf/src/main/java/org/eclipse/sirius/components/view/emf/form/DateTimeStyleProvider.java
Outdated
Show resolved
Hide resolved
packages/portals/frontend/sirius-components-portals/src/hooks/usePortalMutations.types.ts
Outdated
Show resolved
Hide resolved
130a461
to
179b13d
Compare
@@ -259,7 +237,7 @@ export const useDeckMutations = (editingContextId: string, representationId: str | |||
const [rawcreateCard, rawCreateCardResult] = useMutation<GQLCreateCardData, GQLCreateCardVariables>( | |||
createCardMutation | |||
); | |||
useErrorReporting(rawCreateCardResult, (data) => data?.createCard); | |||
useReporting(rawCreateCardResult, (data: GQLCreateCardData) => data.createCard); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong, it's not your fault, the error has been on master for quite some time. We have a simple pattern where everything follows a logic yet people want to change things and they make mistakes. The name of the mutation is not createCard
so the name of the payload, type etc should change. Because of that, here we are extracting a payload which do not exist. The existing code either did not properly execute the code or made incorrect assumptions.
179b13d
to
a74404d
Compare
Bug: #3389 Signed-off-by: Laurent Fasani <laurent.fasani@obeo.fr>
Signed-off-by: Stéphane Bégaudeau <stephane.begaudeau@obeo.fr>
a74404d
to
e3d59a3
Compare
Bug: #3389
Pull request template
General purpose
What is the main goal of this pull request?
Project management
priority:
andpr:
labels been added to the pull request? (In case of doubt, start with the labelspriority: low
andpr: to review later
)area:
,difficulty:
,type:
)CHANGELOG.adoc
been updated to reference the relevant issues?CHANGELOG.adoc
? (Including changes in the GraphQL API)CHANGELOG.adoc
? For example indoc/screenshots/2022.5.0-my-new-feature.png
Architectural decision records (ADR)
[doc]
?CHANGELOG.adoc
?Dependencies
CHANGELOG.adoc
?CHANGELOG.adoc
?Frontend
This section is not relevant if your contribution does not come with changes to the frontend.
General purpose
Typing
We need to improve the typing of our code, as such, we require every contribution to come with proper TypeScript typing for both changes contributing new files and those modifying existing files.
Please ensure that the following statements are true for each file created or modified (this may require you to improve code outside of your contribution).
useMutation<DATA_TYPE, VARIABLE_TYPE>(…)
useQuery<DATA_TYPE, VARIABLE_TYPE>(…)
useSubscription<DATA_TYPE, VARIABLE_TYPE>(…)
useMachine<CONTEXT_TYPE, EVENTS_TYPE>(…)
useState<STATE_TYPE>(…)
?.
(if the GraphQL API specifies that a field cannot benull
, do not treat it has potentiallynull
for example)let diagram: Diagram | null = null;
)Backend
This section is not relevant if your contribution does not come with changes to the backend.
General purpose
Architecture
Review
How to test this PR?
Please describe here the various use cases to test this pull request