mirror of
				https://github.com/ClusterCockpit/cc-backend
				synced 2025-10-31 07:55:06 +01:00 
			
		
		
		
	fix systemsView config laod and mutation, fix metricSelection checked
This commit is contained in:
		| @@ -23,6 +23,7 @@ | |||||||
|   } from "@sveltestrap/sveltestrap"; |   } from "@sveltestrap/sveltestrap"; | ||||||
|   import { |   import { | ||||||
|     gql, |     gql, | ||||||
|  |     getContextClient, | ||||||
|     mutationStore, |     mutationStore, | ||||||
|   } from "@urql/svelte"; |   } from "@urql/svelte"; | ||||||
|  |  | ||||||
| @@ -49,6 +50,7 @@ | |||||||
|  |  | ||||||
|   /* Const Init */ |   /* Const Init */ | ||||||
|   const { query: initq } = init(); |   const { query: initq } = init(); | ||||||
|  |   const client = getContextClient(); | ||||||
|   const displayNodeOverview = (displayType === 'OVERVIEW'); |   const displayNodeOverview = (displayType === 'OVERVIEW'); | ||||||
|   const ccconfig = getContext("cc-config"); |   const ccconfig = getContext("cc-config"); | ||||||
|   const initialized = getContext("initialized"); |   const initialized = getContext("initialized"); | ||||||
| @@ -73,24 +75,41 @@ | |||||||
|   /* Derived States */ |   /* Derived States */ | ||||||
|   const systemMetrics = $derived($initialized ? [...globalMetrics.filter((gm) => gm?.availability.find((av) => av.cluster == cluster))] : []); |   const systemMetrics = $derived($initialized ? [...globalMetrics.filter((gm) => gm?.availability.find((av) => av.cluster == cluster))] : []); | ||||||
|   const presetSystemUnits = $derived(loadUnits(systemMetrics)); |   const presetSystemUnits = $derived(loadUnits(systemMetrics)); | ||||||
|   let selectedMetric = $derived(( |   let selectedMetric = $derived.by(() => { | ||||||
|       ccconfig[`nodeOverview_selectedMetric:${cluster}:${subCluster}`] || |     let configKey = `nodeOverview_selectedMetric`; | ||||||
|       ccconfig[`nodeOverview_selectedMetric:${cluster}`] |     if (cluster) configKey += `:${cluster}`; | ||||||
|     ) ||  |     if (subCluster) configKey += `:${subCluster}`; | ||||||
|     systemMetrics ? systemMetrics[0] : "" |  | ||||||
|   ); |     if ($initialized) { | ||||||
|   let selectedMetrics = $derived(( |       if (ccconfig[configKey]) return ccconfig[configKey] | ||||||
|       ccconfig[`nodeList_selectedMetrics:${cluster}:${subCluster}`] || |       else if (systemMetrics.length !== 0) return systemMetrics[0].name | ||||||
|       ccconfig[`nodeList_selectedMetrics:${cluster}`] |     } | ||||||
|     ) ||  |     return "" | ||||||
|     systemMetrics ? [systemMetrics[0], systemMetrics[1], systemMetrics[2]] : [] |   }); | ||||||
|   ); |   let selectedMetrics = $derived.by(() => { | ||||||
|  |     let configKey = `nodeList_selectedMetrics`; | ||||||
|  |     if (cluster) configKey += `:${cluster}`; | ||||||
|  |     if (subCluster) configKey += `:${subCluster}`; | ||||||
|  |  | ||||||
|  |     if ($initialized) { | ||||||
|  |       if (ccconfig[configKey]) return ccconfig[configKey] | ||||||
|  |       else if (systemMetrics.length >= 3) return [systemMetrics[0].name, systemMetrics[1].name, systemMetrics[2].name] | ||||||
|  |     } | ||||||
|  |     return [] | ||||||
|  |   }); | ||||||
|  |  | ||||||
|  |   // $inspect('System', systemMetrics) | ||||||
|  |   // $inspect('List', selectedMetrics) | ||||||
|  |   // $inspect('Overview', selectedMetric) | ||||||
|  |   // console.log('Config', ccconfig) | ||||||
|  |   // console.log('Config List', ccconfig[`nodeOverview_selectedMetrics:${cluster}`], cluster) | ||||||
|  |   // console.log('Config Overview', ccconfig[`nodeOverview_selectedMetric:${cluster}`], cluster) | ||||||
|  |  | ||||||
|   /* Effects */ |   /* Effects */ | ||||||
|   $effect(() => { |   $effect(() => { | ||||||
|     // OnMount: Ping Var, without this, OVERVIEW metric select is empty (reason tbd)  |     if (displayNodeOverview) { | ||||||
|     // systemMetrics |       updateOverviewMetric(selectedMetric) | ||||||
|     updateOverviewMetric(selectedMetric) |     } | ||||||
|   }); |   }); | ||||||
|  |  | ||||||
|   /* Functions */ |   /* Functions */ | ||||||
| @@ -113,16 +132,13 @@ | |||||||
|   }; |   }; | ||||||
|  |  | ||||||
|   function updateOverviewMetric(newMetric) { |   function updateOverviewMetric(newMetric) { | ||||||
|     let configKey; |     let configKey = `nodeOverview_selectedMetric`; | ||||||
|     if (subCluster) { |     if (cluster) configKey += `:${cluster}`; | ||||||
|       configKey = `nodeOverview_selectedMetric:${cluster}:${subCluster}`; |     if (subCluster) configKey += `:${subCluster}`; | ||||||
|     } else { |  | ||||||
|       configKey = `nodeOverview_selectedMetric:${cluster}`; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     updateConfigurationMutation({ |     updateConfigurationMutation({ | ||||||
|       name: configKey, |       name: configKey, | ||||||
|       value: newMetric, |       value: JSON.stringify(newMetric), | ||||||
|     }).subscribe((res) => { |     }).subscribe((res) => { | ||||||
|       if (res.fetching === false && res.error) { |       if (res.fetching === false && res.error) { | ||||||
|         throw res.error; |         throw res.error; | ||||||
|   | |||||||
| @@ -57,12 +57,12 @@ | |||||||
|   }; |   }; | ||||||
|  |  | ||||||
|   /* State Init */ |   /* State Init */ | ||||||
|   let pendingMetrics = $state(presetMetrics); |  | ||||||
|   let pendingShowFootprint = $state(!!showFootprint); |   let pendingShowFootprint = $state(!!showFootprint); | ||||||
|   let listedMetrics = $state([]); |   let listedMetrics = $state([]); | ||||||
|   let columnHovering = $state(null); |   let columnHovering = $state(null); | ||||||
|  |  | ||||||
|   /* Derives States */ |   /* Derives States */ | ||||||
|  |   let pendingMetrics = $derived(presetMetrics); | ||||||
|   const allMetrics = $derived(loadAvailable(preInitialized || $initialized)); |   const allMetrics = $derived(loadAvailable(preInitialized || $initialized)); | ||||||
|  |  | ||||||
|   /* Reactive Effects */ |   /* Reactive Effects */ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user