From 2773260b8c98cb70d0f45ff5f7ae022bd0e52a04 Mon Sep 17 00:00:00 2001 From: mertmit Date: Tue, 23 Jul 2024 10:28:42 +0300 Subject: [PATCH] fix: UI Acl & data sources Signed-off-by: mertmit --- .../dashboard/settings/DataSources.vue | 8 + .../components/dashboard/settings/UIAcl.vue | 238 ++++++++++-------- packages/nocodb-sdk/src/lib/formulaHelpers.ts | 2 +- packages/nocodb/src/models/Source.ts | 2 +- 4 files changed, 141 insertions(+), 109 deletions(-) diff --git a/packages/nc-gui/components/dashboard/settings/DataSources.vue b/packages/nc-gui/components/dashboard/settings/DataSources.vue index 85b60bb015..53bc2f4907 100644 --- a/packages/nc-gui/components/dashboard/settings/DataSources.vue +++ b/packages/nc-gui/components/dashboard/settings/DataSources.vue @@ -57,6 +57,13 @@ async function updateIfSourceOrderIsNullOrDuplicate() { if (!hasNullOrDuplicates) return + // make sure default source is always first + sources.value = sources.value.sort((a, b) => { + if (a.is_local || a.is_meta) return -1 + if (b.is_local || b.is_meta) return 1 + return (a.order ?? 0) - (b.order ?? 0) + }) + // update the local state sources.value = sources.value.map((source, i) => { return { @@ -75,6 +82,7 @@ async function updateIfSourceOrderIsNullOrDuplicate() { }) }), ) + await loadProject(base.value.id as string, true) } catch (e: any) { message.error(await extractSdkResponseErrorMsg(e)) } diff --git a/packages/nc-gui/components/dashboard/settings/UIAcl.vue b/packages/nc-gui/components/dashboard/settings/UIAcl.vue index 46696e90f8..0590a0a3a0 100644 --- a/packages/nc-gui/components/dashboard/settings/UIAcl.vue +++ b/packages/nc-gui/components/dashboard/settings/UIAcl.vue @@ -31,12 +31,6 @@ const tables = ref([]) const searchInput = ref('') -const selectAll = ref({ - editor: false, - commenter: false, - viewer: false, -}) - const filteredTables = computed(() => tables.value.filter( (el) => @@ -46,6 +40,24 @@ const filteredTables = computed(() => ), ) +const allSelected = computed(() => { + return roles.value.reduce((acc, role) => { + return { + ...acc, + [role]: tables.value.filter((t) => t.disabled[role]).length === 0, + } + }, {} as Record) +}) + +const toggleSelectAll = (role: Role) => { + const newValue = !allSelected.value[role] + + tables.value.forEach((t) => { + t.disabled[role] = newValue + t.edited = true + }) +} + async function loadTableList() { try { if (!baseId.value) return @@ -81,62 +93,44 @@ async function saveUIAcl() { const onRoleCheck = (record: any, role: Role) => { record.disabled[role] = !record.disabled[role] record.edited = true - - selectAll.value[role as Role] = filteredTables.value.every((t) => !t.disabled[role]) } onMounted(async () => { if (tables.value.length === 0) { await loadTableList() } - - for (const role of roles.value) { - selectAll.value[role as Role] = filteredTables.value.every((t) => !t.disabled[role]) - } }) -const tableHeaderRenderer = (label: string) => () => h('div', { class: 'text-gray-500' }, label) - const columns = [ { - title: tableHeaderRenderer(t('labels.tableName')), + title: t('labels.tableName'), name: 'Table Name', }, { - title: tableHeaderRenderer(t('labels.viewName')), + title: t('labels.viewName'), name: 'View Name', }, { - title: tableHeaderRenderer(t('objects.roleType.editor')), + title: t('objects.roleType.editor'), name: 'editor', width: 120, }, { - title: tableHeaderRenderer(t('objects.roleType.commenter')), + title: t('objects.roleType.commenter'), name: 'commenter', width: 120, }, { - title: tableHeaderRenderer(t('objects.roleType.viewer')), + title: t('objects.roleType.viewer'), name: 'viewer', width: 120, }, ] - -const toggleSelectAll = (role: Role) => { - selectAll.value[role] = !selectAll.value[role] - const enabled = selectAll.value[role] - - filteredTables.value.forEach((t) => { - t.disabled[role] = !enabled - t.edited = true - }) -}