Browse Source

Merge pull request #4795 from nocodb/fix/filters

fix: filters logic
pull/4803/head
աɨռɢӄաօռɢ 2 years ago committed by GitHub
parent
commit
f08841abbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      packages/nc-gui/components/smartsheet/toolbar/ColumnFilter.vue
  2. 2
      packages/nocodb/src/lib/Noco.ts
  3. 13
      packages/nocodb/src/lib/models/Filter.ts
  4. 2
      packages/nocodb/src/lib/version-upgrader/NcUpgrader.ts
  5. 34
      packages/nocodb/src/lib/version-upgrader/ncFilterUpgrader.ts

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

@ -236,7 +236,7 @@ defineExpose({
:key="`${i}_7`"
v-model:value="filter.value"
class="nc-filter-value-select"
:disabled="filter.readOnly"
:disabled="filter.readOnly || !filter.fk_column_id"
@click.stop
@input="saveOrUpdate(filter, i)"
/>

2
packages/nocodb/src/lib/Noco.ts

@ -104,7 +104,7 @@ export default class Noco {
constructor() {
process.env.PORT = process.env.PORT || '8080';
// todo: move
process.env.NC_VERSION = '0098005';
process.env.NC_VERSION = '0100002';
// if env variable NC_MINIMAL_DBS is set, then disable project creation with external sources
if (process.env.NC_MINIMAL_DBS) {

13
packages/nocodb/src/lib/models/Filter.ts

@ -1,6 +1,7 @@
import Noco from '../Noco';
import Model from './Model';
import Column from './Column';
import Hook from './Hook';
import {
CacheDelDirection,
CacheGetType,
@ -10,6 +11,7 @@ import {
import View from './View';
import { FilterType, UITypes } from 'nocodb-sdk';
import NocoCache from '../cache/NocoCache';
import { NcError } from '../meta/helpers/catchError';
export default class Filter {
id: string;
@ -90,7 +92,16 @@ export default class Filter {
}),
};
if (!(filter.project_id && filter.base_id)) {
const model = await Column.get({ colId: filter.fk_column_id }, ncMeta);
let model: { project_id?: string; base_id?: string };
if (filter.fk_view_id) {
model = await View.get(filter.fk_view_id, ncMeta);
} else if (filter.fk_hook_id) {
model = await Hook.get(filter.fk_hook_id, ncMeta);
} else if (filter.fk_column_id) {
model = await Column.get({ colId: filter.fk_column_id }, ncMeta);
} else {
NcError.badRequest('Invalid filter');
}
insertObj.project_id = model.project_id;
insertObj.base_id = model.base_id;
}

2
packages/nocodb/src/lib/version-upgrader/NcUpgrader.ts

@ -8,6 +8,7 @@ import ncProjectEnvUpgrader0011045 from './ncProjectEnvUpgrader0011045';
import ncProjectUpgraderV2_0090000 from './ncProjectUpgraderV2_0090000';
import ncDataTypesUpgrader from './ncDataTypesUpgrader';
import ncProjectRolesUpgrader from './ncProjectRolesUpgrader';
import ncFilterUpgrader from './ncFilterUpgrader';
const log = debug('nc:version-upgrader');
import boxen from 'boxen';
@ -35,6 +36,7 @@ export default class NcUpgrader {
{ name: '0090000', handler: ncProjectUpgraderV2_0090000 },
{ name: '0098004', handler: ncDataTypesUpgrader },
{ name: '0098005', handler: ncProjectRolesUpgrader },
{ name: '0100002', handler: ncFilterUpgrader },
];
if (!(await ctx.ncMeta.knexConnection?.schema?.hasTable?.('nc_store'))) {
return;

34
packages/nocodb/src/lib/version-upgrader/ncFilterUpgrader.ts

@ -0,0 +1,34 @@
import { NcUpgraderCtx } from './NcUpgrader';
import { MetaTable } from '../utils/globals';
import View from '../models/View';
import Hook from '../models/Hook';
import Column from '../models/Column';
// before 0.101.0, an incorrect project_id was inserted when
// a filter is created without specifying the column
// this upgrader is to retrieve the correct project id from either view, hook, or column
// and update the project id
export default async function ({ ncMeta }: NcUpgraderCtx) {
const filters = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP);
for (const filter of filters) {
let model: { project_id?: string; base_id?: string };
if (filter.fk_view_id) {
model = await View.get(filter.fk_view_id, ncMeta);
} else if (filter.fk_hook_id) {
model = await Hook.get(filter.fk_hook_id, ncMeta);
} else if (filter.fk_column_id) {
model = await Column.get({ colId: filter.fk_column_id }, ncMeta);
} else {
continue;
}
if (filter.project_id != model.project_id) {
await ncMeta.metaUpdate(
null,
null,
MetaTable.FILTER_EXP,
{ base_id: model.base_id, project_id: model.project_id },
filter.id
);
}
}
}
Loading…
Cancel
Save