Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Lens
Commits
dd819bb5
Unverified
Commit
dd819bb5
authored
3 years ago
by
Sebastian Malton
Committed by
GitHub
3 years ago
Browse files
Options
Download
Email Patches
Plain Diff
Refine UserStore from/to usage (#3292)
parent
600bd659
master
better-release-script
catalog-entity-detail-registry
consolidate-running-of-setups-on-application-start
dependabot/npm_and_yarn/react-select-5.3.2
dependabot/npm_and_yarn/react-window-1.8.7
dependabot/npm_and_yarn/types/node-14.18.16
dependabot/npm_and_yarn/types/webpack-env-1.16.4
di-stores
docs/api-all-exported
enhancement-node-vertical-metric-bars
extensions/lens-version-check
feature/auto-update
feature/context-providers
fix-change-os-theme-crash
fix-linter-errors
fix-optimise-update-events-from-buffer
fix-reload-list-items-on-mount
fix-remove-watch-flush-headers
fix-reseting-select-value
fix-resource-applier
fix/log-store-loading
fix/search_input_autofocus
front-end-routes-ocp-2
front-end-routes-ocp-3
helm-repo-manager-removal
issue-1909
issue-3498
issue-3797
issue-4997
issue-5141
issue-5165
issue-5173
issue-5177
issue-5238
more-places-to-check-for-updates
release/v5.4
remove-unused-telemetry
show-extension-preferences-in-separate-page
squashed-update-injectable
turn-on-strict
ui-table-empty-state-lines
update-electon-builder-to-3-0-8
validate-cluster-model
v5.5.0-beta.0
v5.4.6
v5.4.5
v5.4.4
v5.4.3
v5.4.2
v5.4.1
v5.4.0
v5.4.0-beta.5
v5.4.0-beta.4
v5.4.0-beta.3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/common/user-store/user-store.ts
+26
-49
src/common/user-store/user-store.ts
src/common/utils/objects.ts
+5
-1
src/common/utils/objects.ts
with
31 additions
and
50 deletions
+31
-50
src/common/user-store/user-store.ts
+
26
-
49
View file @
dd819bb5
...
...
@@ -5,14 +5,15 @@
import
{
app
,
ipcMain
}
from
"
electron
"
;
import
semver
,
{
SemVer
}
from
"
semver
"
;
import
{
action
,
computed
,
makeObservable
,
o
bservable
,
reaction
}
from
"
mobx
"
;
import
{
action
,
computed
,
observable
,
reaction
,
makeObservable
,
isO
bservable
Array
,
isObservableSet
,
isObservableMap
}
from
"
mobx
"
;
import
{
BaseStore
}
from
"
../base-store
"
;
import
migrations
,
{
fileNameMigration
}
from
"
../../migrations/user-store
"
;
import
{
getAppVersion
}
from
"
../utils/app-version
"
;
import
{
kubeConfigDefaultPath
}
from
"
../kube-helpers
"
;
import
{
appEventBus
}
from
"
../app-event-bus/event-bus
"
;
import
{
getOrInsertSet
,
toggle
,
toJS
}
from
"
../../renderer/utils
"
;
import
{
DESCRIPTORS
,
EditorConfiguration
,
ExtensionRegistry
,
KubeconfigSyncValue
,
UserPreferencesModel
,
TerminalConfig
}
from
"
./preferences-helpers
"
;
import
{
getOrInsertSet
,
toggle
,
toJS
,
entries
,
fromEntries
}
from
"
../../renderer/utils
"
;
import
{
DESCRIPTORS
}
from
"
./preferences-helpers
"
;
import
type
{
EditorConfiguration
,
ExtensionRegistry
,
KubeconfigSyncValue
,
UserPreferencesModel
,
TerminalConfig
}
from
"
./preferences-helpers
"
;
import
logger
from
"
../../main/logger
"
;
export
interface
UserStoreModel
{
...
...
@@ -164,55 +165,31 @@ export class UserStore extends BaseStore<UserStoreModel> /* implements UserStore
this
.
lastSeenAppVersion
=
lastSeenAppVersion
;
}
this
.
httpsProxy
=
DESCRIPTORS
.
httpsProxy
.
fromStore
(
preferences
?.
httpsProxy
);
this
.
shell
=
DESCRIPTORS
.
shell
.
fromStore
(
preferences
?.
shell
);
this
.
colorTheme
=
DESCRIPTORS
.
colorTheme
.
fromStore
(
preferences
?.
colorTheme
);
this
.
terminalTheme
=
DESCRIPTORS
.
terminalTheme
.
fromStore
(
preferences
?.
terminalTheme
);
this
.
localeTimezone
=
DESCRIPTORS
.
localeTimezone
.
fromStore
(
preferences
?.
localeTimezone
);
this
.
allowUntrustedCAs
=
DESCRIPTORS
.
allowUntrustedCAs
.
fromStore
(
preferences
?.
allowUntrustedCAs
);
this
.
allowTelemetry
=
DESCRIPTORS
.
allowTelemetry
.
fromStore
(
preferences
?.
allowTelemetry
);
this
.
allowErrorReporting
=
DESCRIPTORS
.
allowErrorReporting
.
fromStore
(
preferences
?.
allowErrorReporting
);
this
.
downloadMirror
=
DESCRIPTORS
.
downloadMirror
.
fromStore
(
preferences
?.
downloadMirror
);
this
.
downloadKubectlBinaries
=
DESCRIPTORS
.
downloadKubectlBinaries
.
fromStore
(
preferences
?.
downloadKubectlBinaries
);
this
.
downloadBinariesPath
=
DESCRIPTORS
.
downloadBinariesPath
.
fromStore
(
preferences
?.
downloadBinariesPath
);
this
.
kubectlBinariesPath
=
DESCRIPTORS
.
kubectlBinariesPath
.
fromStore
(
preferences
?.
kubectlBinariesPath
);
this
.
openAtLogin
=
DESCRIPTORS
.
openAtLogin
.
fromStore
(
preferences
?.
openAtLogin
);
this
.
hiddenTableColumns
.
replace
(
DESCRIPTORS
.
hiddenTableColumns
.
fromStore
(
preferences
?.
hiddenTableColumns
));
this
.
syncKubeconfigEntries
.
replace
(
DESCRIPTORS
.
syncKubeconfigEntries
.
fromStore
(
preferences
?.
syncKubeconfigEntries
));
this
.
editorConfiguration
=
DESCRIPTORS
.
editorConfiguration
.
fromStore
(
preferences
?.
editorConfiguration
);
this
.
terminalCopyOnSelect
=
DESCRIPTORS
.
terminalCopyOnSelect
.
fromStore
(
preferences
?.
terminalCopyOnSelect
);
this
.
terminalConfig
=
DESCRIPTORS
.
terminalConfig
.
fromStore
(
preferences
?.
terminalConfig
);
this
.
updateChannel
=
DESCRIPTORS
.
updateChannel
.
fromStore
(
preferences
?.
updateChannel
);
this
.
extensionRegistryUrl
=
DESCRIPTORS
.
extensionRegistryUrl
.
fromStore
(
preferences
?.
extensionRegistryUrl
);
for
(
const
[
key
,
{
fromStore
}]
of
entries
(
DESCRIPTORS
))
{
const
curVal
=
this
[
key
];
const
newVal
=
fromStore
((
preferences
)?.[
key
]
as
never
)
as
never
;
if
(
isObservableArray
(
curVal
)
||
isObservableSet
(
curVal
)
||
isObservableMap
(
curVal
)
)
{
curVal
.
replace
(
newVal
);
}
else
{
this
[
key
]
=
newVal
;
}
}
}
toJSON
():
UserStoreModel
{
const
model
:
UserStoreModel
=
{
const
preferences
=
fromEntries
(
entries
(
DESCRIPTORS
)
.
map
(([
key
,
{
toStore
}])
=>
[
key
,
toStore
(
this
[
key
]
as
never
)]),
)
as
UserPreferencesModel
;
return
toJS
({
lastSeenAppVersion
:
this
.
lastSeenAppVersion
,
preferences
:
{
httpsProxy
:
DESCRIPTORS
.
httpsProxy
.
toStore
(
this
.
httpsProxy
),
shell
:
DESCRIPTORS
.
shell
.
toStore
(
this
.
shell
),
colorTheme
:
DESCRIPTORS
.
colorTheme
.
toStore
(
this
.
colorTheme
),
terminalTheme
:
DESCRIPTORS
.
terminalTheme
.
toStore
(
this
.
terminalTheme
),
localeTimezone
:
DESCRIPTORS
.
localeTimezone
.
toStore
(
this
.
localeTimezone
),
allowUntrustedCAs
:
DESCRIPTORS
.
allowUntrustedCAs
.
toStore
(
this
.
allowUntrustedCAs
),
allowTelemetry
:
DESCRIPTORS
.
allowTelemetry
.
toStore
(
this
.
allowTelemetry
),
allowErrorReporting
:
DESCRIPTORS
.
allowErrorReporting
.
toStore
(
this
.
allowErrorReporting
),
downloadMirror
:
DESCRIPTORS
.
downloadMirror
.
toStore
(
this
.
downloadMirror
),
downloadKubectlBinaries
:
DESCRIPTORS
.
downloadKubectlBinaries
.
toStore
(
this
.
downloadKubectlBinaries
),
downloadBinariesPath
:
DESCRIPTORS
.
downloadBinariesPath
.
toStore
(
this
.
downloadBinariesPath
),
kubectlBinariesPath
:
DESCRIPTORS
.
kubectlBinariesPath
.
toStore
(
this
.
kubectlBinariesPath
),
openAtLogin
:
DESCRIPTORS
.
openAtLogin
.
toStore
(
this
.
openAtLogin
),
hiddenTableColumns
:
DESCRIPTORS
.
hiddenTableColumns
.
toStore
(
this
.
hiddenTableColumns
),
syncKubeconfigEntries
:
DESCRIPTORS
.
syncKubeconfigEntries
.
toStore
(
this
.
syncKubeconfigEntries
),
editorConfiguration
:
DESCRIPTORS
.
editorConfiguration
.
toStore
(
this
.
editorConfiguration
),
terminalCopyOnSelect
:
DESCRIPTORS
.
terminalCopyOnSelect
.
toStore
(
this
.
terminalCopyOnSelect
),
terminalConfig
:
DESCRIPTORS
.
terminalConfig
.
toStore
(
this
.
terminalConfig
),
updateChannel
:
DESCRIPTORS
.
updateChannel
.
toStore
(
this
.
updateChannel
),
extensionRegistryUrl
:
DESCRIPTORS
.
extensionRegistryUrl
.
toStore
(
this
.
extensionRegistryUrl
),
},
};
return
toJS
(
model
);
preferences
,
});
}
}
This diff is collapsed.
Click to expand it.
src/common/utils/objects.ts
+
5
-
1
View file @
dd819bb5
...
...
@@ -7,6 +7,10 @@
* A better typed version of `Object.fromEntries` where the keys are known to
* be a specific subset
*/
export
function
fromEntries
<
T
,
Key
extends
string
>
(
entries
:
Iterable
<
readonly
[
Key
,
T
]
>
):
{
[
k
in
Key
]:
T
}
{
export
function
fromEntries
<
T
,
Key
extends
string
>
(
entries
:
Iterable
<
readonly
[
Key
,
T
]
>
):
Record
<
Key
,
T
>
{
return
Object
.
fromEntries
(
entries
)
as
{
[
k
in
Key
]:
T
};
}
export
function
entries
<
T
extends
Record
<
string
,
any
>>
(
obj
:
T
):
[
keyof
T
,
T
[
keyof
T
]][]
{
return
Object
.
entries
(
obj
);
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help