Add server config modified message to prompt restart (#1668)

* Server config changed message

* Write to settings on unmount

* nit

* Highlight modified config

* Move modified logic to store

* Add jest test

* nit
This commit is contained in:
Chenlei Hu
2024-11-24 13:13:37 -08:00
committed by GitHub
parent 4a4d6d070a
commit c61ed4da37
9 changed files with 138 additions and 24 deletions

View File

@@ -3,7 +3,14 @@ import { defineStore } from 'pinia'
import { computed, ref } from 'vue'
export type ServerConfigWithValue<T> = ServerConfig<T> & {
/**
* Current value.
*/
value: T
/**
* Initial value loaded from settings.
*/
initialValue: T
}
export const useServerConfigStore = defineStore('serverConfig', () => {
@@ -11,6 +18,12 @@ export const useServerConfigStore = defineStore('serverConfig', () => {
const serverConfigs = computed(() => {
return Object.values(serverConfigById.value)
})
const modifiedConfigs = computed<ServerConfigWithValue<any>[]>(() => {
return serverConfigs.value.filter((config) => {
return config.initialValue !== config.value
})
})
const serverConfigsByCategory = computed<
Record<string, ServerConfigWithValue<any>[]>
>(() => {
@@ -55,9 +68,11 @@ export const useServerConfigStore = defineStore('serverConfig', () => {
values: Record<string, any>
) {
for (const config of configs) {
const value = values[config.id] ?? config.defaultValue
serverConfigById.value[config.id] = {
...config,
value: values[config.id] ?? config.defaultValue
value,
initialValue: value
}
}
}
@@ -65,6 +80,7 @@ export const useServerConfigStore = defineStore('serverConfig', () => {
return {
serverConfigById,
serverConfigs,
modifiedConfigs,
serverConfigsByCategory,
serverConfigValues,
launchArgs,