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

helpers: remove empty customization fields [COMPOSER-2204] #2010

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ export const formTimestampLabel = (ts) => {
return tsDisplay;
};

export const cleanEmptyFields = (obj) => {
const cleaned = Object.entries(obj).reduce((fields, [key, value]) => {
if (value === undefined || value === null || value === "") {
return fields;
}
if (typeof value === "object") {
const cleanedValue = cleanEmptyFields(value);
if (Object.keys(cleanedValue).length === 0) {
return fields;
}
return { ...fields, [key]: cleanedValue };
}
return { ...fields, [key]: value };
}, {});
return cleaned;
};

export const blueprintToFormState = (blueprint) => {
if (!blueprint) return {};
const formState = {
Expand Down Expand Up @@ -83,7 +100,7 @@ const formStateToCustomizations = (customizations) => {
};
const filesystem = customizations.filesystem
? customizations.filesystem.map(parseFilesystem)
: [];
: undefined;

let openscap;
if (
Expand Down Expand Up @@ -125,9 +142,11 @@ export const formStateToBlueprint = (formValues) => {
? formStateToCustomizations(formValues?.customizations)
: undefined;

const cleanEmptyCustomizations = cleanEmptyFields(customizations);

const blueprint = {
...formValues.blueprint,
customizations,
customizations: cleanEmptyCustomizations,
packages,
};
return blueprint;
Expand Down
17 changes: 17 additions & 0 deletions test/verify/check-imageWizard
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ class TestImageWizard(composerlib.ComposerCase):
# Cancel upload
b.click("footer button:contains('Cancel')")

@unittest.skipIf(os.environ.get("TEST_OS").split('-')[0] != "rhel", "Skipping test for non RHEL")
def testEdgeImageFields(self):
b = self.browser

self.login_and_go("/composer", superuser=True)
b.wait_visible("#main")

# Select create image from created blueprint
b.click("tr[data-testid=httpd-server] button[aria-label='Create image']")
b.wait_in_text(".pf-c-wizard__main", "httpd-server")
time.sleep(1)
# Edge image type
b.select_PF4("#image-output-select-toggle", "RHEL for Edge Simplified Installer (.iso)")
b.click("button:contains('Next')")

b.click("footer button:contains('Create')")


if __name__ == '__main__':
testlib.test_main()
Loading