-
Notifications
You must be signed in to change notification settings - Fork 343
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
docs: Add new UIB guide for query dependencies #2901
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5ccc7ff
Add new UIB guide for query dependencies
jeromecambon fa8820c
Fix truncated string in card
jeromecambon 24bff34
Minor changes
jeromecambon d352dff
Update modules/applications/pages/ui-builder/how-to-handle-queries-de…
jeromecambon e5ec3f0
Update modules/applications/pages/ui-builder/how-to-handle-queries-de…
jeromecambon 1f16812
Update modules/applications/pages/ui-builder/how-to-handle-queries-de…
jeromecambon 0813a31
Update modules/applications/pages/ui-builder/how-to-handle-queries-de…
jeromecambon 8086d52
Update modules/applications/pages/ui-builder/how-to-handle-queries-de…
jeromecambon 4b41210
Remove unwanted sentence
jeromecambon ec5deef
Fix truncated card content
jeromecambon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
modules/applications/pages/ui-builder/how-to-handle-queries-dependency.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
= How to handle query dependencies | ||
:page-aliases: applications:how-to-handle-queries-dependency.adoc | ||
:description: Learn how to handle dependencies between queries. | ||
|
||
{description} | ||
|
||
* Difficulty: intermediate | ||
* Estimated time: 10 minutes | ||
|
||
If your application needs to run several API calls and some of them depend on the result of others, | ||
you may have issues with the order of execution of the API calls. | ||
|
||
For example, if you want to get the list of users and display the manager of the first one in the list, you need to make two API calls: | ||
|
||
* One to get the list of users | ||
* One to get the manager of the first user (which takes the manager ID of the first user from the first API call as a parameter) | ||
|
||
Note: make sure the first user has a manager. If not, choose another user. | ||
|
||
Since you want to get this information on page load, you *may* have an issue if the second API call is executed *before* the first one is done. | ||
|
||
To handle this kind of situation, let's do the following. | ||
|
||
== 1. Create the API requests | ||
|
||
Go to the `Queries` tab and create a first Bonita query that will fetch the users: | ||
|
||
* `Name`: getUsers | ||
* `Method`: GET | ||
* `URL`: /bonita/API/identity/user | ||
* `Params`: | ||
- `Key`: p | ||
- `Value`: 0 | ||
- `Key`: c | ||
- `Value`: 20 | ||
* `Settings`: | ||
- `Run API on page load`: true | ||
|
||
Next, create a second Bonita query to fetch the manager of the first user: | ||
|
||
* `Name`: getManagerOfFirstUser | ||
* `Method`: GET | ||
* `URL`: /bonita/API/identity/user/{{getUsers.data[0].manager_id}} | ||
* `Settings`: | ||
- `Run API on page load`: true | ||
|
||
|
||
== 2. Configure the interface | ||
|
||
On the interface, drag and drop a Text widget and set its text to `{{First user: {{getUsers.data[0].lastname}}}}`. | ||
|
||
Then, drag and drop a second Text widget and set its text to `{{Manager: {{getManagerOfFirstUser.data.lastname}}}}`. | ||
|
||
Reload the page and *if the second query is called first* you should get an error: `The action "getManagerOfFirstUser" has failed`. | ||
|
||
To solve this (potential) issue, we will create a JS Object that will run the queries in the right order. | ||
|
||
== 3. Create a JS object | ||
|
||
Go to the `JS` tab (between `Queries` and `UI`), create a new JS Object called “runQueries” and copy paste the following code: | ||
|
||
[source, JS] | ||
---- | ||
export default { | ||
runQueries: async () => { | ||
await getUsers.run(); | ||
getManagerOfTheFirstUser.run(); | ||
} | ||
} | ||
---- | ||
|
||
The first query is called synchronously (`await` keyword), and the second one is called only when the first one is done. | ||
|
||
Now, from the `Settings` tab, enable the `Run on page load` option. | ||
|
||
== 4. Disable the running on page load for the queries | ||
|
||
For the 2 queries, from the `Settings` tab, set the `Run API on page load` option to `false`. | ||
|
||
Reload the page: you are now sure that the page will display the first user and its manager! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
:page-aliases: is useless when the page is not an existing page
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 didn't add it initially, but it is required to handle the path (in pages/ui-builder), as it is done for other guides.