Browse Source

fix: block group by using attachment column

pull/6987/head
Pranav C 10 months ago
parent
commit
bb86af6c31
  1. 56
      packages/nc-gui/components/smartsheet/toolbar/GroupByMenu.vue
  2. 10
      packages/nocodb/src/db/BaseModelSqlv2.ts
  3. 3
      packages/nocodb/src/db/generateLookupSelectQuery.ts

56
packages/nc-gui/components/smartsheet/toolbar/GroupByMenu.vue

@ -18,29 +18,7 @@ import {
watch,
} from '#imports'
const groupingUidt = [
UITypes.SingleSelect,
UITypes.MultiSelect,
UITypes.Checkbox,
UITypes.Date,
UITypes.SingleLineText,
UITypes.Number,
UITypes.Rollup,
UITypes.Lookup,
UITypes.Links,
UITypes.Formula,
UITypes.Email,
UITypes.URL,
UITypes.PhoneNumber,
UITypes.Decimal,
UITypes.Currency,
UITypes.Percent,
UITypes.Duration,
UITypes.Rating,
UITypes.Year,
UITypes.DateTime,
UITypes.Time,
]
const excludedGroupingUidt = [UITypes.Attachment]
const meta = inject(MetaInj, ref())
const view = inject(ActiveViewInj, ref())
@ -74,17 +52,17 @@ const groupedByColumnIds = computed(() => groupBy.value.map((g) => g.fk_column_i
const { eventBus } = useSmartsheetStoreOrThrow()
const { isMobileMode } = useGlobal()
const btLookups = ref([])
const supportedLookups = ref([])
const fieldsToGroupBy = computed(() => {
const fields = meta.value?.columns || []
return fields.filter((field) => {
// if (!groupingUidt.includes(field.uidt as UITypes)) return false
//
// if (field.uidt === UITypes.Lookup) {
// return btLookups.value.includes(field.id)
// }
if (excludedGroupingUidt.includes(field.uidt as UITypes)) return false
if (field.uidt === UITypes.Lookup) {
return supportedLookups.value.includes(field.id)
}
return true
})
@ -173,23 +151,20 @@ watch(open, () => {
}
})
const loadBtLookups = async () => {
const loadAllowedLookups = async () => {
const filteredLookupCols = []
try {
for (const col of meta.value?.columns || []) {
if (col.uidt !== UITypes.Lookup) continue
let nextCol = col
let btLookup = true
// check all the relation of nested lookup columns is bt or not
// include the column only if all only if all relations are bt
// check the lookup column is supported type or not
while (btLookup && nextCol && nextCol.uidt === UITypes.Lookup) {
const lookupRelation = (await getMeta(nextCol.fk_model_id))?.columns?.find(
(c) => c.id === (nextCol.colOptions as LookupType).fk_relation_column_id,
)
if ((lookupRelation.colOptions as LinkToAnotherRecordType).type !== RelationTypes.BELONGS_TO) {
btLookup = false
continue
}
@ -202,26 +177,25 @@ const loadBtLookups = async () => {
// if next column is same as root lookup column then break the loop
// since it's going to be a circular loop, and ignore the column
if (nextCol.id === col.id) {
btLookup = false
break
}
}
if (btLookup) filteredLookupCols.push(col.id)
if (nextCol.uidt !== UITypes.Attachment) filteredLookupCols.push(col.id)
}
btLookups.value = filteredLookupCols
supportedLookups.value = filteredLookupCols
} catch (e) {
console.error(e)
}
}
onMounted(async () => {
await loadBtLookups()
await loadAllowedLookups()
})
watch(meta, async () => {
await loadBtLookups()
await loadAllowedLookups()
})
</script>
@ -258,9 +232,7 @@ watch(meta, async () => {
<LazySmartsheetToolbarFieldListAutoCompleteDropdown
v-model="group.fk_column_id"
class="caption nc-sort-field-select"
:columns="
fieldsToGroupBy
"
:columns="fieldsToGroupBy"
:allow-empty="true"
@change="saveGroupBy"
@click.stop

10
packages/nocodb/src/db/BaseModelSqlv2.ts

@ -572,6 +572,11 @@ class BaseModelSqlv2 {
groupByColumns[column.id] = column;
switch (column.uidt) {
case UITypes.Attachment:
NcError.badRequest(
'Group by using attachment column is not supported',
);
break;
case UITypes.Links:
case UITypes.Rollup:
selectors.push(
@ -748,6 +753,11 @@ class BaseModelSqlv2 {
});
switch (column.uidt) {
case UITypes.Attachment:
NcError.badRequest(
'Group by using attachment column is not supported',
);
break;
case UITypes.Rollup:
case UITypes.Links:
selectors.push(

3
packages/nocodb/src/db/generateLookupSelectQuery.ts

@ -258,6 +258,9 @@ export default async function generateLookupSelectQuery({
}
switch (lookupColumn.uidt) {
case UITypes.Attachment:
NcError.badRequest('Group by using attachment column is not supported');
break;
case UITypes.Links:
case UITypes.Rollup:
{

Loading…
Cancel
Save