-
Notifications
You must be signed in to change notification settings - Fork 285
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
API: Settings: delete keys that are set to null #5830
Conversation
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. |
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.
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.
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.
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)); |
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.
If you're setting changed
here couldn't it be a constant, and we don't need the changed ||= ...
bit at line 520 ?
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 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.
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.
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))); |
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.
Can just return the result of Object.fromEntries(...)
(Same comment for the code that this PR replaces)
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.
Yep, totally doable.
); | ||
const normalizeWslIntegrations = (integrations: Record<string, boolean>, mode: 'diff' | 'submit') => { | ||
const normalizeFn = { | ||
diff: (entries: [string, boolean][]) => entries.filter(([, v]) => v === true), |
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.
If v
is boolean, can we not just say …(([, v]) => v),
?
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.
Yep, was just keeping what the old code did. Changed.
Also simplify the implementation slightly. Signed-off-by: Mark Yen <[email protected]>
ce1b6f0
to
4072065
Compare
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.
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)); |
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 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. |
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.
Added a comment.
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.
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.
This fixes issues where WSL integrations could not be disabled.
Fixes #5805