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

Packages step - second PR #1461

Merged
merged 2 commits into from
Aug 3, 2022
Merged

Conversation

lucasgarfield
Copy link
Collaborator

No description provided.

@lucasgarfield lucasgarfield force-pushed the packagesStep branch 3 times, most recently from 42dd55d to 7f7a5ae Compare August 1, 2022 15:25
@lucasgarfield lucasgarfield marked this pull request as ready for review August 1, 2022 15:27
Copy link
Collaborator

@jkozol jkozol left a comment

Choose a reason for hiding this comment

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

One edge case to fix: searching with no filter breaks things.

Comment on lines +30 to +35
const wildcardsUsed = filter.includes("*");
const regex = / +|, +/g;
let filterValue = filter.replace(regex, ",");
const regexStrip = /(^,+)|(,+$)/g;
filterValue = filterValue.replace(regexStrip, "");
filterValue = wildcardsUsed ? filterValue : `*${filterValue}*`.replace(/,/g, "*,*");
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know you just copied this over from inputs.js but any chance you can explain what's happening here.

Copy link
Collaborator Author

@lucasgarfield lucasgarfield Aug 2, 2022

Choose a reason for hiding this comment

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

I don't know what the purpose behind every line is because as you pointed out, it has just been copy/pasted it so that the the search results would be the same as before. But overall the purpose is to transform the search query into a form that will actually work with the Weldr API which expects you to use things like leading and trailing wildcards. So for instance, if you want to search for "vim", you actually need to query the Weldr API "*vim*" if you want it to behave as you would expect show packages such as neovim.

Copy link
Member

Choose a reason for hiding this comment

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

  • wildcardsUsed is true if an * appears in the filter
  • regex matches a non-empty sequence of spaces, or a comma followed by a non-empty sequence of spaces
  • filterValue replaces each match of regex with a comma - in other words all spaces are replaced by commas, without inserting repeated commas
  • regexStrip matches any non-empty sequence of commas at the beginning or end of a string
  • filterValue is update to replace leading or trailing strings of commas with the empty string
  • finally, as Lucas said, each match is replaced with wildcard versions, except if wildcards are already used.

I wonder if a future task could be to make weldr search better, if we push the search query into dnf-json we would get more powerful searching (making this logic redundant) and potentially much faster queries.

Comment on lines 106 to 107
const numPackages =
result.blueprints[0].blueprint.packages.length - result.blueprints[0].blueprint.modules.length;
Copy link
Collaborator

Choose a reason for hiding this comment

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

totally fine but we really need to deal with this packages and modules situation. Mind creating an issue to track?

Copy link
Collaborator Author

@lucasgarfield lucasgarfield Aug 2, 2022

Choose a reason for hiding this comment

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

See #1463.

However, with respect to this specific line, since we will now convert any modules to packages, modules.length should always be 0 and we can remove the subtrahend. And actually, this should have been the sum (+) and not the difference!

Comment on lines +45 to +38
const [packagesAvailablePage, setPackagesAvailablePage] = useState(1);
const [packagesAvailablePerPage, setPackagesAvailablePerPage] = useState(100);
const [additionalPackagesAvailableLoading, setAdditionalPackagesAvailableLoading] = useState(false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

At some point I would like to not paginate this so we can implement nicer sorting. Can you create an issue to track this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done, see #1462.

}
}, []);

const updateBlueprintComponents = (packageList) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we move the actual blueprint update to the final step? I would like the actual blueprint update to be on confirmation i.e. Create Image button or a Save Bluepoint button

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Great idea. The current behavior more closely resembles the existing cockpit-composer behavior, where adding or removing packages on the blueprintEdit page modifies the workspace. I would actually prefer it to behave more like Image Builder Front End, which would be the result of implementing your suggestion.

Comment on lines 24 to 29
// the fields isHidden and isSelected should not be included in the package list sent for image creation
const removePackagesDisplayFields = (packages) =>
packages.map((pack) => ({
name: pack.name,
summary: pack.summary,
}));
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a helper specifically for the Packages component so can you include it inside of the Packages function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will do!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In fact, this is actually no longer necessary now that we set the packages form field to the list of package names and can just be removed.

const packageInfo = await composer.getComponentInfo(packageNames);
const selectedPackages = packageInfo.map((pkg) => ({ name: pkg.name, summary: pkg.summary }));
setPackagesChosenSorted(selectedPackages);
change(input.name, removePackagesDisplayFields(selectedPackages));
Copy link
Collaborator

Choose a reason for hiding this comment

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

no need to change the field parameter like this. The packages with name and summary isn't used elsewhere. Instead, you could set the packages form field to the list of package names. That would enable you, on the review page, to load the packages names from the form state and not the blueprint.

Copy link
Collaborator Author

@lucasgarfield lucasgarfield Aug 2, 2022

Choose a reason for hiding this comment

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

Good point! This does add some additional complexity to the review page, though, since the package list is fetched using an async API call. If a user clicks 'next' on the Packages step before the packages are loaded, there is a problem... when the API call completes the form state will be set correctly but the review step won't re-render to reflect this. My solution to this is to use a <FormSpy> to keep track of changes to the form state and re-render the review page when they occur.

Comment on lines 67 to 72
const formPackages = getState()?.values?.["selected-packages"];

if (formPackages) {
setPackagesChosenSorted(formPackages);
} else {
fetchPackagesChosen();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you explain this? It feels unnecessary to me.

Copy link
Collaborator Author

@lucasgarfield lucasgarfield Aug 2, 2022

Choose a reason for hiding this comment

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

The useEffect() this belongs to executes every time the Packages step is rendered. However, we only want to fetch the blueprint packages via API calls the first time the Packages step is opened. If formPackages is undefined it is the first time the Packages step has been opened so we fetch the packages via an API call in the else clause.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ahh I see. Great :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually, after changing the form state so that it is just the list of package names, we no longer keep track of the package summaries. That means that setPackagesChosenSorted(formPackages) no longer works, because it expects an array of objects of form { name, summary }.

I'm going to keep the form state as just the list of package names, and just call fetchPackagesChosen() every time the packages step is open.

This commit adds the packages step to the wizard. It is not functional
at this point, the <Packages> component has been copy/pasted from
image-builder-frontend and its API calls have been disabled.
The packages step is now fully functional, and the number of packages
and dependencies are displayed on the review page.
Copy link
Collaborator

@jkozol jkozol left a comment

Choose a reason for hiding this comment

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

Overall, great work! This is good enough to merge but there are a few issues. Please add issues to track the FormSpy error. And, when adding packages, going to review page, then back to the packages step a user will see no packages added. Can you add an issue to track that as well?

@jkozol
Copy link
Collaborator

jkozol commented Aug 2, 2022

simplescreenrecorder-2022-08-02_22.22.42.mp4

@lucasgarfield
Copy link
Collaborator Author

lucasgarfield commented Aug 3, 2022

Overall, great work! This is good enough to merge but there are a few issues. Please add issues to track the FormSpy error.

Thanks! And done, #1467

And, when adding packages, going to review page, then back to the packages step a user will see no packages added. Can you add an issue to track that as well?

This bug should be fixed in 95a8878.
Actually, not fixed. See #1468.

@lucasgarfield lucasgarfield merged commit 17210e1 into osbuild:unified Aug 3, 2022
@lucasgarfield lucasgarfield deleted the packagesStep branch August 3, 2022 06:28
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

Successfully merging this pull request may close these issues.

3 participants