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

[3344] Add support for reloading representation from the database #3348

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

pcdavid
Copy link
Member

@pcdavid pcdavid commented Apr 8, 2024

Bug: #3344
Signed-off-by: Pierre-Charles David pierre-charles.david@obeo.fr

Pull request template

General purpose

What is the main goal of this pull request?

  • Bug fixes
  • New features
  • Documentation
  • Cleanup
  • Tests
  • Build / releng

Project management

  • Has the pull request been added to the relevant project and milestone? (Only if you know that your work is part of a specific iteration such as the current one)
  • Have the priority: and pr: labels been added to the pull request? (In case of doubt, start with the labels priority: low and pr: to review later)
  • Have the relevant issues been added to the pull request?
  • Have the relevant labels been added to the issues? (area:, difficulty:, type:)
  • Have the relevant issues been added to the same project and milestone as the pull request?
  • Has the CHANGELOG.adoc been updated to reference the relevant issues?
  • Have the relevant API breaks been described in the CHANGELOG.adoc? (Including changes in the GraphQL API)
  • In case of a change with a visual impact, are there any screenshots in the CHANGELOG.adoc? For example in doc/screenshots/2022.5.0-my-new-feature.png

Architectural decision records (ADR)

  • Does the title of the commit contributing the ADR start with [doc]?
  • Are the ADRs mentioned in the relevant section of the CHANGELOG.adoc?

Dependencies

  • Are the new / upgraded dependencies mentioned in the relevant section of the CHANGELOG.adoc?
  • Are the new dependencies justified in the CHANGELOG.adoc?

Frontend

This section is not relevant if your contribution does not come with changes to the frontend.

General purpose

  • Is the code properly tested? (Plain old JavaScript tests for business code and tests based on React Testing Library for the components)

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).

  • Variables have a proper type
  • Functions’ arguments have a proper type
  • Functions’ return type are specified
  • Hooks are properly typed:
    • useMutation<DATA_TYPE, VARIABLE_TYPE>(…)
    • useQuery<DATA_TYPE, VARIABLE_TYPE>(…)
    • useSubscription<DATA_TYPE, VARIABLE_TYPE>(…)
    • useMachine<CONTEXT_TYPE, EVENTS_TYPE>(…)
    • useState<STATE_TYPE>(…)
  • All components have a proper typing for their props
  • No useless optional chaining with ?. (if the GraphQL API specifies that a field cannot be null, do not treat it has potentially null for example)
  • Nullable values have a proper type (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

  • Are all the event handlers tested?
  • Are the event processor tested?
  • Is the business code (services) tested?
  • Are diagram layout changes tested?

Architecture

  • Are data structure classes properly separated from behavioral classes?
  • Are all the relevant fields final?
  • Is any data structure mutable? If so, please write a comment indicating why
  • Are behavioral classes either stateless or side effect free?

Review

How to test this PR?

Please describe here the various use cases to test this pull request

  • Has the Kiwi TCMS test suite been updated with tests for this contribution?

@pcdavid pcdavid added this to the 2024.5.0 milestone Apr 8, 2024
@pcdavid pcdavid linked an issue Apr 8, 2024 that may be closed by this pull request
@pcdavid pcdavid force-pushed the pcd/enh/reload-representation branch 3 times, most recently from 0250015 to db47907 Compare April 11, 2024 07:28
@@ -29,6 +29,8 @@ public record DiagramRefreshedEventPayload(UUID id, Diagram diagram, String caus

public static final String CAUSE_LAYOUT = "layout";

public static final String CAUSE_RELOAD = "reload";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a bug here: the new value is not added in the GraphQL Schema and not handled by the front (in DiagramRenderer.tsx). I'm investigating how exactly it should be handled.

Copy link
Member

@sbegaudeau sbegaudeau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we agreed on the way to move forward on this issue by starting on #3303, then #3304 and finally #3305. Why choose instead seven different ways to reload the state?

@pcdavid pcdavid force-pushed the pcd/enh/reload-representation branch from db47907 to d0f6a38 Compare April 15, 2024 13:44
@pcdavid pcdavid force-pushed the pcd/enh/reload-representation branch from d0f6a38 to b618808 Compare April 24, 2024 12:16
@sbegaudeau sbegaudeau force-pushed the pcd/enh/reload-representation branch from b618808 to 9cff301 Compare April 26, 2024 06:51
Comment on lines 132 to 137
} else if (changeDescription.getKind().equals(ChangeKind.RELOAD_REPRESENTATION) && changeDescription.getSourceId().equals(this.formDescriptionEditorContext.getFormDescriptionEditor().getId())) {
Optional<FormDescriptionEditor> reloadedFormDescriptionEditor = this.representationSearchService.findById(this.editingContext, this.formDescriptionEditorContext.getFormDescriptionEditor().getId(), FormDescriptionEditor.class);
if (reloadedFormDescriptionEditor.isPresent()) {
this.formDescriptionEditorContext.update(reloadedFormDescriptionEditor.get());
this.formDescriptionEditorEventFlux.formDescriptionEditorRefreshed(changeDescription.getInput(), reloadedFormDescriptionEditor.get());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took upon myself to add tests last week to make this PR go through the continuous integration without issues and there something I don't understand here because I can't succeed in making this code work. The data structure persisted in the database is not the same as the one sent back to the frontend, the refresh is needed to compute the whole structure since it is not persisted. See these two PRs that you've reviewed before (#1484 and #1963) for additional details.

Without a new refresh and unless I've missed something, I think this will only reload an empty representation. I suspect that the same would be true for at least for the form representation which behave the same way, see CreateFormEventHandler#handle which does not store the real content of the form in the database. Have you ever seen this code work for forms or form description editors?

I'll push in another commit the tests that I've started to add, could you make the form description editor test succeed and contribute a XxxxLifecycleControllerTests for each representation kind (I've successfully done the Gantt one) to ensure that the mechanism works please.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm on it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed. I've added a small test for portals to increase the coverage. There's still a coverage issue with the Hierarchy representation, but it's not clear how to properly test it or of its even relevant.

Bug: #3344
Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
@pcdavid pcdavid force-pushed the pcd/enh/reload-representation branch 3 times, most recently from 16e8bd8 to 6a1fb7e Compare May 2, 2024 14:34
Signed-off-by: Stéphane Bégaudeau <stephane.begaudeau@obeo.fr>
Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
@pcdavid pcdavid force-pushed the pcd/enh/reload-representation branch from 6a1fb7e to 8e726e2 Compare May 6, 2024 13:06
@@ -55,7 +55,9 @@ public void hierarchyRefreshed(IInput input, Hierarchy newHierarchy) {
}

public Flux<IPayload> getFlux(IInput input) {
var initialRefresh = Mono.fromCallable(() -> new HierarchyRefreshedEventPayload(input.id(), this.currentHierarchy));
var initialRefresh = Mono.fromCallable(() -> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anything that should change here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake. I had changed the formatting to put a breakpoint on the inside of the lambda and forgot to revert.

var input = new CreateRepresentationInput(UUID.randomUUID(), TestIdentifiers.ECORE_SAMPLE_PROJECT.toString(), PortalDescriptionProvider.DESCRIPTION_ID, TestIdentifiers.EPACKAGE_OBJECT.toString(), "Sample Portal");
var flux = this.givenCreatedPortalSubscription.createAndSubscribe(input);

Consumer<PortalRefreshedEventPayload> initialPortalContentConsumer = payload -> Optional.of(payload)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what this test adds, why not test the feature that you have added?

* @author pcdavid
*/
@SubscriptionDataFetcher(type = "Subscription", field = "hierarchyEvent")
public class SubscriptionHierarchyEventDataFetcher implements IDataFetcherWithFieldCoordinates<Publisher<IPayload>> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is that in a test folder?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have a sirius-components-charts-graphql module yet and it felt overkill to create one just to host this single class only used in a test, especially as we do not have actual UI to create hierarchy representations.

Comment on lines +143 to +154
var deleteWidgetInput = new DeleteWidgetInput(
UUID.randomUUID(),
StudioIdentifiers.SAMPLE_STUDIO_PROJECT.toString(),
formDescriptionEditorId.get(),
newWidgetId.get());
var result = this.deleteWidgetMutationRunner.run(deleteWidgetInput);
String typename = JsonPath.read(result, "$.data.deleteWidget.__typename");
assertThat(typename).isEqualTo(SuccessPayload.class.getSimpleName());

TestTransaction.flagForCommit();
TestTransaction.end();
TestTransaction.start();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will trigger a refresh of the form description editor by itself, wouldn't that make the test "work" even without the reload after that? Unless I missed something, written this way the test does not prove that the feature works.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test should probably change to show the feature working

Comment on lines +185 to +192
} else if (changeDescription.getKind().equals(ChangeKind.RELOAD_REPRESENTATION) && changeDescription.getSourceId().equals(this.currentForm.get().getId())) {
Optional<Form> reloadedForm = this.representationSearchService.findById(this.editingContext, this.currentForm.get().getId(), Form.class);
if (reloadedForm.isPresent()) {
this.currentForm.set(reloadedForm.get());
this.emitNewForm(changeDescription);
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would that really work for forms? Wouldn't that reload the empty form from the database and send it back as is to the frontend making everything go blank?

Could you add the relevant tests for all representations to prove that your contribution is working please?

Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
@pcdavid pcdavid force-pushed the pcd/enh/reload-representation branch from 5823ed2 to 8c1aec8 Compare May 21, 2024 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for reloading representation from the database
2 participants