|
|
@ -14,9 +14,88 @@ import { UITypes } from 'nocodb-sdk'; |
|
|
|
// - remove `like`, `null`, `equal` and `empty` for multiSelect columns
|
|
|
|
// - remove `like`, `null`, `equal` and `empty` for multiSelect columns
|
|
|
|
// - remove `>`, `<`, `>=`, `<=`, `is empty`, `is not empty`, `is equal`, `is not equal` for attachment columns
|
|
|
|
// - remove `>`, `<`, `>=`, `<=`, `is empty`, `is not empty`, `is equal`, `is not equal` for attachment columns
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const removeEqualFilters = async ( |
|
|
|
|
|
|
|
filter, |
|
|
|
|
|
|
|
actions: any[], |
|
|
|
|
|
|
|
ncMeta, |
|
|
|
|
|
|
|
migrateFn = () => {} |
|
|
|
|
|
|
|
) => { |
|
|
|
|
|
|
|
// remove `is equal`, `is not equal`
|
|
|
|
|
|
|
|
if (['eq', 'neq'].includes(filter.comparison_op)) { |
|
|
|
|
|
|
|
actions.push(await Filter.delete(filter, ncMeta)); |
|
|
|
|
|
|
|
if (migrateFn) migrateFn(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return actions; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const removeArithmeticFilters = async ( |
|
|
|
|
|
|
|
filter, |
|
|
|
|
|
|
|
actions: any[], |
|
|
|
|
|
|
|
ncMeta, |
|
|
|
|
|
|
|
migrateFn = () => {} |
|
|
|
|
|
|
|
) => { |
|
|
|
|
|
|
|
// remove `>`, `<`, `>=`, `<=`
|
|
|
|
|
|
|
|
if (['gt', 'lt', 'gte', 'lte'].includes(filter.comparison_op)) { |
|
|
|
|
|
|
|
actions.push(await Filter.delete(filter, ncMeta)); |
|
|
|
|
|
|
|
if (migrateFn) migrateFn(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return actions; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const removeLikeFilters = async ( |
|
|
|
|
|
|
|
filter, |
|
|
|
|
|
|
|
actions: any[], |
|
|
|
|
|
|
|
ncMeta, |
|
|
|
|
|
|
|
migrateFn = () => {} |
|
|
|
|
|
|
|
) => { |
|
|
|
|
|
|
|
// remove `is like`, `is not like`
|
|
|
|
|
|
|
|
if (['like', 'nlike'].includes(filter.comparison_op)) { |
|
|
|
|
|
|
|
actions.push(await Filter.delete(filter, ncMeta)); |
|
|
|
|
|
|
|
if (migrateFn) migrateFn(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return actions; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const removeNullFilters = async ( |
|
|
|
|
|
|
|
filter, |
|
|
|
|
|
|
|
actions: any[], |
|
|
|
|
|
|
|
ncMeta, |
|
|
|
|
|
|
|
migrateFn = () => {} |
|
|
|
|
|
|
|
) => { |
|
|
|
|
|
|
|
// remove `is null`, `is not null`
|
|
|
|
|
|
|
|
if (['null', 'notnull'].includes(filter.comparison_op)) { |
|
|
|
|
|
|
|
actions.push(await Filter.delete(filter, ncMeta)); |
|
|
|
|
|
|
|
if (migrateFn) migrateFn(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return actions; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const removeEmptyFilters = async ( |
|
|
|
|
|
|
|
filter, |
|
|
|
|
|
|
|
actions: any[], |
|
|
|
|
|
|
|
ncMeta, |
|
|
|
|
|
|
|
migrateFn = () => {} |
|
|
|
|
|
|
|
) => { |
|
|
|
|
|
|
|
// remove `is empty`, `is not empty`
|
|
|
|
|
|
|
|
if (['empty', 'notempty'].includes(filter.comparison_op)) |
|
|
|
|
|
|
|
if (migrateFn) migrateFn(); |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
actions.push(await Filter.delete(filter, ncMeta)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return actions; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const migrateToBlankFilter = async () => { |
|
|
|
|
|
|
|
// TODO:
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const migrateToCheckboxFilter = async () => { |
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export default async function ({ ncMeta }: NcUpgraderCtx) { |
|
|
|
export default async function ({ ncMeta }: NcUpgraderCtx) { |
|
|
|
const filters = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP); |
|
|
|
const filters = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP); |
|
|
|
const actions = []; |
|
|
|
let actions = []; |
|
|
|
for (const filter of filters) { |
|
|
|
for (const filter of filters) { |
|
|
|
const col = await Column.get({ colId: filter.fk_column_id }, ncMeta); |
|
|
|
const col = await Column.get({ colId: filter.fk_column_id }, ncMeta); |
|
|
|
if (!col || !col.uidt) { |
|
|
|
if (!col || !col.uidt) { |
|
|
@ -32,10 +111,7 @@ export default async function ({ ncMeta }: NcUpgraderCtx) { |
|
|
|
UITypes.URL, |
|
|
|
UITypes.URL, |
|
|
|
].includes(col.uidt) |
|
|
|
].includes(col.uidt) |
|
|
|
) { |
|
|
|
) { |
|
|
|
// remove `>`, `<`, `>=`, `<=` for text-based columns
|
|
|
|
actions = await removeArithmeticFilters(filter, actions, ncMeta); |
|
|
|
if (['gt', 'lt', 'gte', 'lte'].includes(filter.comparison_op)) { |
|
|
|
|
|
|
|
actions.push(await Filter.delete(filter, ncMeta)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else if ( |
|
|
|
} else if ( |
|
|
|
[ |
|
|
|
[ |
|
|
|
// numeric fields
|
|
|
|
// numeric fields
|
|
|
@ -50,49 +126,53 @@ export default async function ({ ncMeta }: NcUpgraderCtx) { |
|
|
|
UITypes.SingleSelect, |
|
|
|
UITypes.SingleSelect, |
|
|
|
].includes(col.uidt) |
|
|
|
].includes(col.uidt) |
|
|
|
) { |
|
|
|
) { |
|
|
|
if (['like', 'nlike'].includes(filter.comparison_op)) { |
|
|
|
actions = await removeLikeFilters(filter, actions, ncMeta); |
|
|
|
// remove `is like`, `is not like`
|
|
|
|
actions = await removeNullFilters( |
|
|
|
actions.push(await Filter.delete(filter, ncMeta)); |
|
|
|
filter, |
|
|
|
} else if ( |
|
|
|
actions, |
|
|
|
['null', 'notnull', 'empty', 'notempty'].includes(filter.comparison_op) |
|
|
|
ncMeta, |
|
|
|
) { |
|
|
|
migrateToBlankFilter |
|
|
|
// remove `is null`, `is not null`, `is empty`, `is not empty`
|
|
|
|
); |
|
|
|
actions.push(await Filter.delete(filter, ncMeta)); |
|
|
|
actions = await removeEmptyFilters( |
|
|
|
// TODO: migrate to blank / not blank
|
|
|
|
filter, |
|
|
|
} |
|
|
|
actions, |
|
|
|
|
|
|
|
ncMeta, |
|
|
|
|
|
|
|
migrateToBlankFilter |
|
|
|
|
|
|
|
); |
|
|
|
} else if (col.uidt === UITypes.Checkbox) { |
|
|
|
} else if (col.uidt === UITypes.Checkbox) { |
|
|
|
if (['eq', 'neq'].includes(filter.comparison_op)) { |
|
|
|
actions = await removeEqualFilters( |
|
|
|
actions.push(await Filter.delete(filter, ncMeta)); |
|
|
|
filter, |
|
|
|
// TODO: migrate to `checked` or `not-checked`
|
|
|
|
actions, |
|
|
|
} else if (['null', 'notnull'].includes(filter.comparison_op)) { |
|
|
|
ncMeta, |
|
|
|
// remove `is null`, `is not null`
|
|
|
|
migrateToCheckboxFilter |
|
|
|
actions.push(await Filter.delete(filter, ncMeta)); |
|
|
|
); |
|
|
|
} |
|
|
|
actions = await removeNullFilters(filter, actions, ncMeta); |
|
|
|
} else if (col.uidt === UITypes.MultiSelect) { |
|
|
|
} else if (col.uidt === UITypes.MultiSelect) { |
|
|
|
if (['eq', 'neq'].includes(filter.comparison_op)) { |
|
|
|
// TODO: migrate to "contains any of" or "contains all of"
|
|
|
|
// TODO: migrate to "contains any of" or "contains all of"
|
|
|
|
// TODO: migrate to "doesnt contain any of" or "doesnt contain all of"
|
|
|
|
// TODO: migrate to "doesnt contain any of" or "doesnt contain all of"
|
|
|
|
actions = await removeEqualFilters(filter, actions, ncMeta); |
|
|
|
} else if (['like', 'nlike'].includes(filter.comparison_op)) { |
|
|
|
actions = await removeLikeFilters(filter, actions, ncMeta); |
|
|
|
// remove `is like`, `is not like`
|
|
|
|
actions = await removeNullFilters( |
|
|
|
actions.push(await Filter.delete(filter, ncMeta)); |
|
|
|
filter, |
|
|
|
} else if ( |
|
|
|
actions, |
|
|
|
['null', 'notnull', 'empty', 'notempty'].includes(filter.comparison_op) |
|
|
|
ncMeta, |
|
|
|
) { |
|
|
|
migrateToBlankFilter |
|
|
|
// remove `is null`, `is not null`, `is empty`, `is not empty`
|
|
|
|
); |
|
|
|
actions.push(await Filter.delete(filter, ncMeta)); |
|
|
|
actions = await removeEmptyFilters( |
|
|
|
// TODO: migrate to blank / not blank
|
|
|
|
filter, |
|
|
|
} |
|
|
|
actions, |
|
|
|
|
|
|
|
ncMeta, |
|
|
|
|
|
|
|
migrateToBlankFilter |
|
|
|
|
|
|
|
); |
|
|
|
} else if (col.uidt === UITypes.Attachment) { |
|
|
|
} else if (col.uidt === UITypes.Attachment) { |
|
|
|
// remove `>`, `<`, `>=`, `<=`
|
|
|
|
actions = await removeArithmeticFilters(filter, actions, ncMeta); |
|
|
|
// remove `is empty`, `is not empty`
|
|
|
|
actions = await removeEmptyFilters(filter, actions, ncMeta); |
|
|
|
// remove `is equal`, `is not equal`
|
|
|
|
actions = await removeEqualFilters( |
|
|
|
if ( |
|
|
|
filter, |
|
|
|
['gt', 'lt', 'gte', 'lte', 'empty', 'notempty', 'eq', 'neq'].includes( |
|
|
|
actions, |
|
|
|
filter.comparison_op |
|
|
|
ncMeta, |
|
|
|
) |
|
|
|
migrateToCheckboxFilter |
|
|
|
) { |
|
|
|
); |
|
|
|
actions.push(await Filter.delete(filter, ncMeta)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
await Promise.all(actions); |
|
|
|
await Promise.all(actions); |
|
|
|