From 1799a44933bcc33ab2fe497282d89603ad58a0e5 Mon Sep 17 00:00:00 2001 From: yuda Date: Fri, 1 Nov 2024 16:55:38 +0900 Subject: [PATCH 1/3] fix: show only `use: true` vars properties Signed-off-by: yuda --- .../components/dashboard-detail/DashboardVariablesV2.vue | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/web/src/services/dashboards/components/dashboard-detail/DashboardVariablesV2.vue b/apps/web/src/services/dashboards/components/dashboard-detail/DashboardVariablesV2.vue index 70f7b70142..8c5d89012e 100644 --- a/apps/web/src/services/dashboards/components/dashboard-detail/DashboardVariablesV2.vue +++ b/apps/web/src/services/dashboards/components/dashboard-detail/DashboardVariablesV2.vue @@ -65,9 +65,10 @@ const state = reactive({ }), newGlobalVariables: computed(() => { const properties = dashboardDetailGetters.dashboardVarsSchemaProperties as Record; + const _usedProperties: DashboardGlobalVariable[] = Object.values(properties).filter((d) => d.use); const _presetKeys: string[] = Object.keys(DOMAIN_DASHBOARD_VARS_SCHEMA_PRESET.properties); - const _presetItems = Object.values(properties).filter((d) => _presetKeys.includes(d.key)); - const _customItems = Object.values(properties).filter((d) => !_presetKeys.includes(d.key)); + const _presetItems = _usedProperties.filter((d) => _presetKeys.includes(d.key)); + const _customItems = _usedProperties.filter((d) => !_presetKeys.includes(d.key)); return [ ...orderBy(_presetItems, 'name', 'asc'), ...orderBy(_customItems, 'name', 'asc'), From f8ed095c855eec2eb9db8e668afa6d48a3ad667f Mon Sep 17 00:00:00 2001 From: yuda Date: Fri, 1 Nov 2024 16:56:59 +0900 Subject: [PATCH 2/3] fix: reset vars when `use` is set to false Signed-off-by: yuda --- .../dashboard-detail/DashboardVariablesMoreButton.vue | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apps/web/src/services/dashboards/components/dashboard-detail/DashboardVariablesMoreButton.vue b/apps/web/src/services/dashboards/components/dashboard-detail/DashboardVariablesMoreButton.vue index 9b47073db1..fe6f576217 100644 --- a/apps/web/src/services/dashboards/components/dashboard-detail/DashboardVariablesMoreButton.vue +++ b/apps/web/src/services/dashboards/components/dashboard-detail/DashboardVariablesMoreButton.vue @@ -89,6 +89,11 @@ onClickOutside(containerRef, hideContextMenu); const toggleUseDashboardVarsSchema = debounce(async (dashboardId: string, variableKey: string) => { try { const _dashboardVarsSchemaProperties: Record = cloneDeep(dashboardDetailGetters.dashboardVarsSchemaProperties); + const _use = !_dashboardVarsSchemaProperties[variableKey].use; + const _vars = cloneDeep(dashboardDetailGetters.dashboardInfo?.vars || {}); + if (!_use) { + delete _vars[variableKey]; + } await dashboardStore.updateDashboard(dashboardId, { dashboard_id: dashboardId, vars_schema: { @@ -100,6 +105,7 @@ const toggleUseDashboardVarsSchema = debounce(async (dashboardId: string, variab }, }, }, + vars: _vars, }); showSuccessMessage(i18n.t('DASHBOARDS.DETAIL.VARIABLES.ALT_S_UPDATE_DASHBOARD_VARS_SCHEMA'), ''); } catch (e) { From c5518ce664fd7ba032224e258d9c6cd0e96b6b90 Mon Sep 17 00:00:00 2001 From: yuda Date: Fri, 1 Nov 2024 16:57:26 +0900 Subject: [PATCH 3/3] fix: use saved `created_by` when update vars schema Signed-off-by: yuda --- .../dashboard-detail/DashboardVariablesFormModal.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/web/src/services/dashboards/components/dashboard-detail/DashboardVariablesFormModal.vue b/apps/web/src/services/dashboards/components/dashboard-detail/DashboardVariablesFormModal.vue index 2b22b97d59..2a4c6e6ce2 100644 --- a/apps/web/src/services/dashboards/components/dashboard-detail/DashboardVariablesFormModal.vue +++ b/apps/web/src/services/dashboards/components/dashboard-detail/DashboardVariablesFormModal.vue @@ -173,13 +173,13 @@ const createDashboardVarsSchema = async (dashboardId: string) => { const updateDashboardVarsSchema = async (dashboardId: string) => { try { const _originalKey = state.targetVariable?.key; - const _use = state.targetVariable?.use || false; if (!_originalKey) return; const _newVarsSchemaProperties = cloneDeep(dashboardDetailGetters.dashboardVarsSchemaProperties); delete _newVarsSchemaProperties[_originalKey]; _newVarsSchemaProperties[state.dashboardGlobalVariable.key] = { ...state.dashboardGlobalVariable, - use: _use, + use: state.targetVariable?.use || false, + created_by: state.targetVariable?.created_by, }; const _vars = cloneDeep(dashboardDetailGetters.dashboardInfo?.vars || {}); delete _vars[_originalKey];