-
Notifications
You must be signed in to change notification settings - Fork 68
Storage: show skeletons only when needed #1171
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
Changes from 7 commits
837a880
d093d36
f535c4d
358e04a
30f8d7a
4583eaf
83eccdf
a143e22
5d231ca
bc2cd45
db04da1
da9ec7d
2f954fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,8 +97,10 @@ describe("when set as loading", () => { | |
| }); | ||
|
|
||
| it("renders a loading hint", () => { | ||
| installerRender(<InstallationDeviceField {...props} />); | ||
| screen.getByText("Waiting for information about selected device"); | ||
| const { container } = installerRender(<InstallationDeviceField {...props} />); | ||
|
|
||
| // a PF skeleton is displayed | ||
| expect(container.querySelector("div.pf-v5-c-skeleton")).toBeVisible(); | ||
|
||
| }); | ||
| }); | ||
|
|
||
|
|
||
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 allows lazy evaluation of the branches. The problem is that
<If>evaluates both branches and then returns one of them.So for example this
crashes when
dataisundefinedbecause it evaluates theelsebranch too early.With this improvement you can pass a function which can be evaluated only when the result is needed. (Passing functions is quite common in Javascript to allow the lazy evaluation.)
Then the fix is trivial, just add
() =>before the value:@dgdavid are you OK with this change?
I'll add some example into the
<If>documentation if you agree with this improvement.Uh oh!
There was an error while loading. Please reload this 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.
Thanks @lslezak
Let's say that I have no strong opinion about it. At first sight, it looks reasonable to prevent not needed evaluations. But on the other hand it's weird to me to accept a function as content of the branches. IMHO it should be limited to ReactNode (Although technically a component is a function too).
That said, I fully understand the proposal looking at the code written at https://github.com/openSUSE/agama/pull/1171/files#diff-994f1f4ff00fecec1797a2aaa799dbbeddc4e8fb2c1ae666fedbb95b7c499770R155-R178
But I would go for a different implementation instead. For me, what is in the else should be a component that React should be able to understand. Let's say
<SpacePolicyForm />. Then, the component should be aware about what it needs for return either, an output or nothing.I.e., the key for me is to write more robust components.
Of course, I might be wrong, so maybe another view here could help to decide what way to go.
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 was assuming the
elsebranch is not evaluated if the condition is true. So, probably, I have written unsafe code.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.
BTW, as far as I can see I think that this set of changes reveals another change we could address: to add the
isLoadingprop to core/Popup and make it show the spinner or its children based on the prop value. That way, we could reduce the<If condition={isLoading} then={...repetition and have more clean WhateverDialog.jsx components.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.
After reading this I decided to revert the
<If>change. It seems it is not safe and it can have some nasty side effects in some cases.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.
@joseivanlopez Actually I do not think you have written "unsafe" code. The
Formitself is not executed (@dgdavid and me has done some tests with another example). The problem is thedata.foowhendatais undefined (that's the code that gets executed).