From 07f1f4887f219e753dfdcafd824ff2511be7ce87 Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Sun, 29 Dec 2024 21:19:09 +0530 Subject: [PATCH] fix: cache user settings --- frontend/src/components/Controls/Grid.vue | 13 +++++++------ .../components/Controls/GridFieldsEditorModal.vue | 6 +++--- frontend/src/stores/meta.js | 12 ++++++------ 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/frontend/src/components/Controls/Grid.vue b/frontend/src/components/Controls/Grid.vue index d5a3b9ab..9aff9133 100644 --- a/frontend/src/components/Controls/Grid.vue +++ b/frontend/src/components/Controls/Grid.vue @@ -4,7 +4,10 @@ {{ __(label) }} -
+
@@ -73,7 +75,6 @@ :style="{ gridTemplateColumns: gridTemplateColumns }" >
{ - let gridSettings = getGridSettings() + let gridSettings = getGridSettings(props.parentDoctype) let gridFields = getFields() if (gridSettings.length) { let d = gridSettings.map((gs) => @@ -266,7 +267,7 @@ function getFieldObj(field) { const gridTemplateColumns = computed(() => { if (!fields.value?.length) return '1fr' // for the checkbox & sr no. columns - let gridSettings = getGridSettings() + let gridSettings = getGridSettings(props.parentDoctype) if (gridSettings.length) { return gridSettings.map((gs) => `minmax(0, ${gs.columns || 2}fr)`).join(' ') } diff --git a/frontend/src/components/Controls/GridFieldsEditorModal.vue b/frontend/src/components/Controls/GridFieldsEditorModal.vue index 961ea639..28639ad0 100644 --- a/frontend/src/components/Controls/GridFieldsEditorModal.vue +++ b/frontend/src/components/Controls/GridFieldsEditorModal.vue @@ -123,7 +123,7 @@ const dirty = computed(() => { const oldFields = computed(() => { let _fields = getFields() - let gridSettings = getGridSettings() + let gridSettings = getGridSettings(props.parentDoctype) if (gridSettings.length) { return gridSettings.map((field) => { @@ -161,7 +161,7 @@ function removeField(field) { function update() { loading.value = true - let updateFields = fields.value.map((field, idx) => { + let updateFields = fields.value.map((field) => { return { fieldname: field.fieldname, columns: field.columns, @@ -176,7 +176,7 @@ function update() { saveUserSettings(props.parentDoctype, 'GridView', updateFields, () => { loading.value = false show.value = false - userSettings.value['GridView'][props.doctype] = updateFields + userSettings[props.parentDoctype]['GridView'][props.doctype] = updateFields }) } diff --git a/frontend/src/stores/meta.js b/frontend/src/stores/meta.js index 80ced62f..8b34777f 100644 --- a/frontend/src/stores/meta.js +++ b/frontend/src/stores/meta.js @@ -3,7 +3,7 @@ import { formatCurrency, formatNumber } from '@/utils/numberFormat.js' import { ref, reactive } from 'vue' const doctypeMeta = reactive({}) -const userSettings = ref({}) +const userSettings = reactive({}) export function getMeta(doctype) { const meta = createResource({ @@ -20,7 +20,7 @@ export function getMeta(doctype) { doctypeMeta[dtMeta.name] = dtMeta } - userSettings.value = JSON.parse(res.user_settings) + userSettings[doctype] = JSON.parse(res.user_settings) }, }) @@ -55,10 +55,10 @@ export function getMeta(doctype) { return formatCurrency(doc[fieldname], '', currency, precision) } - function getGridSettings(dt = null) { + function getGridSettings(parentDoctype, dt = null) { dt = dt || doctype - if (!userSettings.value['GridView']?.[doctype]) return {} - return userSettings.value['GridView'][doctype] + if (!userSettings[parentDoctype]['GridView']?.[doctype]) return {} + return userSettings[parentDoctype]['GridView'][doctype] } function getFields(dt = null) { @@ -77,7 +77,7 @@ export function getMeta(doctype) { } function saveUserSettings(parentDoctype, key, value, callback) { - let oldUserSettings = userSettings.value + let oldUserSettings = userSettings[parentDoctype] let newUserSettings = JSON.parse(JSON.stringify(oldUserSettings)) newUserSettings[key][doctype] = value