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

API: Settings: delete keys that are set to null #5830

Merged
merged 2 commits into from
Oct 25, 2023

Conversation

mook-as
Copy link
Contributor

@mook-as mook-as commented Oct 25, 2023

This fixes issues where WSL integrations could not be disabled.

Fixes #5805

This fixes issues where WSL integrations could not be disabled.

Signed-off-by: Mark Yen <[email protected]>
* Normalize WSL integrations configuration.
* @param integrations The source collection, containing all WSL integrations.
* @param mode How normalization should take place
* @returns Returns a new object with normalized WSL configuration.
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you defined what normalization actually means?

For example, the v || null in the submit function maps false to null, and I don't understand why you want this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a comment.

@@ -511,10 +511,10 @@ export default class SettingsValidator {
return false;
}

let changed = false;
let changed = Object.keys(currentValue).some(k => !(k in desiredValue));
Copy link
Contributor

Choose a reason for hiding this comment

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

If you're setting changed here couldn't it be a constant, and we don't need the changed ||= ... bit at line 520 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This only covers where the current value is a superset of desired value; the other part covers where they both have a key, but it's different.

Copy link
Contributor

@ericpromislow ericpromislow left a comment

Choose a reason for hiding this comment

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

When I disable an integration, it's completely removed from the settings {... WSL: { integrations: {...}}} instead of staying there but set to false.

If I wanted to manage my integrations from rdctl or the API, it's harder, because I no longer see existing but disabled integrations. I don't see why this would be a requirement.

Also a couple of comments about the code...

diff: (entries: [string, boolean][]) => entries.filter(([, v]) => v === true),
submit: (entries: [string, boolean][]) => entries.map(([k, v]) => [k, v || null] as const),
}[mode];
const someVal = Object.fromEntries(normalizeFn(Object.entries(integrations)));
Copy link
Contributor

Choose a reason for hiding this comment

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

Can just return the result of Object.fromEntries(...) (Same comment for the code that this PR replaces)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, totally doable.

);
const normalizeWslIntegrations = (integrations: Record<string, boolean>, mode: 'diff' | 'submit') => {
const normalizeFn = {
diff: (entries: [string, boolean][]) => entries.filter(([, v]) => v === true),
Copy link
Contributor

Choose a reason for hiding this comment

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

If v is boolean, can we not just say …(([, v]) => v), ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, was just keeping what the old code did. Changed.

Also simplify the implementation slightly.

Signed-off-by: Mark Yen <[email protected]>
Copy link
Contributor Author

@mook-as mook-as left a comment

Choose a reason for hiding this comment

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

We remove unset integrations because otherwise it will just keep growing. You can always get a list of WSL distributions from wsl --list. There should be no existing-but-disabled integrations (that's why we're doing all the syncing)…

@@ -511,10 +511,10 @@ export default class SettingsValidator {
return false;
}

let changed = false;
let changed = Object.keys(currentValue).some(k => !(k in desiredValue));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This only covers where the current value is a superset of desired value; the other part covers where they both have a key, but it's different.

* Normalize WSL integrations configuration.
* @param integrations The source collection, containing all WSL integrations.
* @param mode How normalization should take place
* @returns Returns a new object with normalized WSL configuration.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a comment.

Copy link
Contributor

@ericpromislow ericpromislow left a comment

Choose a reason for hiding this comment

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

It works. Mark explained that he sets the unintegrated distros to undefined and drops them so we don't end up carrying a bunch of deleted distros in the prefs. They existing ones get read in each time anyway.

@ericpromislow ericpromislow merged commit 6f5a6a7 into rancher-sandbox:main Oct 25, 2023
10 checks passed
@mook-as mook-as deleted the wsl/integration-disable branch October 25, 2023 22:47
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.

WSL Integrations cannot be disabled from UI
2 participants