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

Introduce AfterDataLoad screen controller event #2947

Open
alexbudarov opened this issue Jul 8, 2020 · 1 comment
Open

Introduce AfterDataLoad screen controller event #2947

alexbudarov opened this issue Jul 8, 2020 · 1 comment

Comments

@alexbudarov
Copy link
Member

Environment

  • Platform version: 7.2

Description of the bug or enhancement

We get feedback from some users that they don't understand what event they should listen to if they want to perform some screen initialization based on loaded data (collection containers, or edited entity graph in entity editor).

e.g.
https://www.cuba-platform.com/discuss/t/for-looping-through-child-entity-to-set-edit-ability-of-screen-components/8237/2
or
https://www.cuba-platform.com/discuss/t/geteditedentity-in-edit-screen/12785

In topics above users tried to use InitEvent.
But for most users the most "safe" event to use when you need fully initialized screen - is "BeforeShow" (until you read the JavaDocs).

Because "BeforeShow" intuitively feels like "after all initialization is fully completed, right before showing the screen in the UI (attaching it to the main layout)".
Unfortunately BeforeShow event doesn't work this way. It is fired somewhere in the middle of the screen initialization process:

Event sent right before the screen is shown, i.e. it is not added to the application UI yet. ... Saved component settings are not yet applied to UI components. Data is not loaded yet for screens annotated with @LoadDataBeforeShow.

Contradictory description, isn't it? How it can be "right before" while settings weren't applied yet, and data wasn't loaded yet?

The proper event at the moment is the AfterShowEvent. However for some users it may feel intuitively wrong, because they tend to think that "UI is going to blink if I change something after the screen is shown". It is a false concern, but people have this feeling.

We cannot fix BeforeShowEvent in CUBA 7.2 without making breaking changes.
But we can make compatible change - by introducing new event.

Solution

Introduce new controller event - AfterDataLoad event. It should be listed in the list of "Controller events" in Studio which is displayed in the top of the event list, so that developers can easily find it by eyes.

This name suggests that you should choose this event if you want data to be loaded.

When this event should be triggered?
It should be triggered when all automatic data loading has been done.

  • If screen has @LoadDataBeforeShow - fire after this annotation has done its job
  • If screen has dataLoadCoordinator - fire after coordinator has done its job
  • If screen has neither of above items - what should we do??? To be discussed.
    • If don't fire at all - then we can built some logic into Studio (inspection with quick fix, don't suggest this event, automatically add annotation etc.)
    • If we decide to fire event - it can be misleading, because possibly presented data containers will be left uninitialized
    • throw exception maybe?

Possible alternatives

  • Per-data-loader (or data container?) event
  • Data context event
  • Controller event with other name/meaning, not directly related to data loading. E.g. "FullyReady" event, when all operations are 100% completed including applying UI settings etc.

But in all cases it should be something very simple, targeted to newbies using Studio capabilities. Pro developers shouldn't have problems with reading JavaDocs and relalizing to use AfterShow or listen to DataLoader itemChanged / collectionChanged events.

@alexbudarov
Copy link
Member Author

Related changes to discuss:

  • review controller events in Jmix
  • possibly, regroup events in Studio UI, splitting controller events into two groups: "Main controller events", "Other controller events".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant