Browse Source

feat: restrict usage of different logical operations within same filter group

pull/8396/head
Pranav C 7 months ago
parent
commit
75c9c45bc5
  1. 20
      packages/nc-gui/components/smartsheet/toolbar/ColumnFilter.vue
  2. 4
      packages/nc-gui/composables/useViewFilters.ts

20
packages/nc-gui/components/smartsheet/toolbar/ColumnFilter.vue

@ -371,6 +371,22 @@ watch(
immediate: true,
},
)
const isLogicalOpChangeAllowed = computed(() => {
return new Set(filters.value.slice(1).map((filter) => filter.logical_op)).size > 1
})
const onLogicalOpUpdate = async (filter: Filter, index: number) => {
if (index === 1 && filters.value.slice(2).every((siblingFilter) => siblingFilter.logical_op !== filter.logical_op)) {
await Promise.all(
filters.value.slice(2).map(async (siblingFilter, i) => {
siblingFilter.logical_op = filter.logical_op
saveOrUpdate(siblingFilter, i + 2, false, false, true)
}),
)
}
await filterUpdateCondition(filter, index)
}
</script>
<template>
@ -455,9 +471,9 @@ watch(
:dropdown-match-select-width="false"
class="h-full !min-w-20 !max-w-20 capitalize"
hide-details
:disabled="filter.readOnly"
:disabled="filter.readOnly || (i > 1 && !isLogicalOpChangeAllowed)"
dropdown-class-name="nc-dropdown-filter-logical-op"
@change="filterUpdateCondition(filter, i)"
@change="onLogicalOpUpdate(filter, i)"
@click.stop
>
<a-select-option v-for="op of logicalOps" :key="op.value" :value="op.value">

4
packages/nc-gui/composables/useViewFilters.ts

@ -307,7 +307,7 @@ export function useViewFilters(
}
}
const saveOrUpdate = async (filter: Filter, i: number, force = false, undo = false) => {
const saveOrUpdate = async (filter: Filter, i: number, force = false, undo = false, skipDataReload = false) => {
if (!view.value) return
if (!undo) {
@ -372,7 +372,7 @@ export function useViewFilters(
lastFilters.value = clone(filters.value)
if (!isWebhook) reloadData?.()
if (!isWebhook && !skipDataReload) reloadData?.()
}
function deleteFilterGroupFromAllFilters(filter: Filter) {

Loading…
Cancel
Save