Browse Source

fix: block group by using attachment column

pull/6987/head
Pranav C 1 year 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, watch,
} from '#imports' } from '#imports'
const groupingUidt = [ const excludedGroupingUidt = [UITypes.Attachment]
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 meta = inject(MetaInj, ref()) const meta = inject(MetaInj, ref())
const view = inject(ActiveViewInj, 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 { eventBus } = useSmartsheetStoreOrThrow()
const { isMobileMode } = useGlobal() const { isMobileMode } = useGlobal()
const btLookups = ref([]) const supportedLookups = ref([])
const fieldsToGroupBy = computed(() => { const fieldsToGroupBy = computed(() => {
const fields = meta.value?.columns || [] const fields = meta.value?.columns || []
return fields.filter((field) => { return fields.filter((field) => {
// if (!groupingUidt.includes(field.uidt as UITypes)) return false if (excludedGroupingUidt.includes(field.uidt as UITypes)) return false
//
// if (field.uidt === UITypes.Lookup) { if (field.uidt === UITypes.Lookup) {
// return btLookups.value.includes(field.id) return supportedLookups.value.includes(field.id)
// } }
return true return true
}) })
@ -173,23 +151,20 @@ watch(open, () => {
} }
}) })
const loadBtLookups = async () => { const loadAllowedLookups = async () => {
const filteredLookupCols = [] const filteredLookupCols = []
try { try {
for (const col of meta.value?.columns || []) { for (const col of meta.value?.columns || []) {
if (col.uidt !== UITypes.Lookup) continue if (col.uidt !== UITypes.Lookup) continue
let nextCol = col let nextCol = col
let btLookup = true
// check all the relation of nested lookup columns is bt or not // check the lookup column is supported type or not
// include the column only if all only if all relations are bt
while (btLookup && nextCol && nextCol.uidt === UITypes.Lookup) { while (btLookup && nextCol && nextCol.uidt === UITypes.Lookup) {
const lookupRelation = (await getMeta(nextCol.fk_model_id))?.columns?.find( const lookupRelation = (await getMeta(nextCol.fk_model_id))?.columns?.find(
(c) => c.id === (nextCol.colOptions as LookupType).fk_relation_column_id, (c) => c.id === (nextCol.colOptions as LookupType).fk_relation_column_id,
) )
if ((lookupRelation.colOptions as LinkToAnotherRecordType).type !== RelationTypes.BELONGS_TO) { if ((lookupRelation.colOptions as LinkToAnotherRecordType).type !== RelationTypes.BELONGS_TO) {
btLookup = false
continue continue
} }
@ -202,26 +177,25 @@ const loadBtLookups = async () => {
// if next column is same as root lookup column then break the loop // 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 // since it's going to be a circular loop, and ignore the column
if (nextCol.id === col.id) { if (nextCol.id === col.id) {
btLookup = false
break break
} }
} }
if (btLookup) filteredLookupCols.push(col.id) if (nextCol.uidt !== UITypes.Attachment) filteredLookupCols.push(col.id)
} }
btLookups.value = filteredLookupCols supportedLookups.value = filteredLookupCols
} catch (e) { } catch (e) {
console.error(e) console.error(e)
} }
} }
onMounted(async () => { onMounted(async () => {
await loadBtLookups() await loadAllowedLookups()
}) })
watch(meta, async () => { watch(meta, async () => {
await loadBtLookups() await loadAllowedLookups()
}) })
</script> </script>
@ -258,9 +232,7 @@ watch(meta, async () => {
<LazySmartsheetToolbarFieldListAutoCompleteDropdown <LazySmartsheetToolbarFieldListAutoCompleteDropdown
v-model="group.fk_column_id" v-model="group.fk_column_id"
class="caption nc-sort-field-select" class="caption nc-sort-field-select"
:columns=" :columns="fieldsToGroupBy"
fieldsToGroupBy
"
:allow-empty="true" :allow-empty="true"
@change="saveGroupBy" @change="saveGroupBy"
@click.stop @click.stop

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

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

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

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

Loading…
Cancel
Save