Browse Source

refactor(nocodb): update comments & remove removeEqualFilters from Duration

pull/5106/head
Wing-Kam Wong 2 years ago
parent
commit
bd4a072ce3
  1. 77
      packages/nocodb/src/lib/version-upgrader/ncFilterUpgrader_0104004.ts

77
packages/nocodb/src/lib/version-upgrader/ncFilterUpgrader_0104004.ts

@ -9,16 +9,30 @@ import { UITypes, SelectOptionsType } from 'nocodb-sdk';
// as of 0.104.3, almost all filter operators are available to all column types // as of 0.104.3, almost all filter operators are available to all column types
// while some of them aren't supposed to be shown // while some of them aren't supposed to be shown
// this upgrader is to remove those unsupported filters / migrate to the correct filter // this upgrader is to remove those unsupported filters / migrate to the correct filter
// changes:
// - remove `>`, `<`, `>=`, `<=` for text-based columns // Change Summary:
// - remove `like`; migrate `null`, and `empty` for numeric-based / singleSelect columns to`blank` // - Text-based columns:
// - remove `equal`; migrate `null` to `checked` for checkbox columns // - remove `>`, `<`, `>=`, `<=`
// - remove `like`; migrate `equal`, `null`, `empty` for multiSelect columns // - Numeric-based / SingleSelect columns:
// - remove `>`, `<`, `>=`, `<=`; migrate `empty`, `equal`, `null` for attachment // - remove `like`
// - remove `>`, `<`, `>=`, `<=`; migrate `empty`, `null` for LTAR columns // - migrate `null`, and `empty` to `blank`
// - migrate `empty`, `null` for Lookup columns // - Checkbox columns:
// - remove `>`, `<`, `>=`, `<=`, `like`, `equal`; migrate `empty`, `null` // - remove `equal`
// - remove `empty`, `like`, `equal`, `null` for duration columns // - migrate `empty` and `null` to `notchecked`
// - MultiSelect columns:
// - remove `like`
// - migrate `equal`, `null`, `empty`
// - Attachment columns:
// - remove `>`, `<`, `>=`, `<=`, `equal`
// - migrate `empty`, `null` to `blank`
// - LTAR columns:
// - remove `>`, `<`, `>=`, `<=`
// - migrate `empty`, `null` to `blank`
// - Lookup columns:
// - migrate `empty`, `null` to `blank`
// - Duration columns:
// - remove `like`
// - migrate `empty`, `null` to `blank`
const removeEqualFilters = async (filter, actions: any[], ncMeta) => { const removeEqualFilters = async (filter, actions: any[], ncMeta) => {
// remove `is equal`, `is not equal` // remove `is equal`, `is not equal`
@ -44,7 +58,11 @@ const removeLikeFilters = async (filter, actions: any[], ncMeta) => {
return actions; return actions;
}; };
const migrateToBlankFilter = async (filter, actions: any[], ncMeta) => { const migrateNullAndEmptyToBlankFilters = async (
filter,
actions: any[],
ncMeta
) => {
if (['empty', 'null'].includes(filter.comparison_op)) { if (['empty', 'null'].includes(filter.comparison_op)) {
// migrate to blank // migrate to blank
actions.push( actions.push(
@ -232,27 +250,50 @@ async function migrateFilters(ncMeta: NcMetaIO) {
].includes(col.uidt) ].includes(col.uidt)
) { ) {
actions = await removeLikeFilters(filter, actions, ncMeta); actions = await removeLikeFilters(filter, actions, ncMeta);
actions = await migrateToBlankFilter(filter, actions, ncMeta); actions = await migrateNullAndEmptyToBlankFilters(
filter,
actions,
ncMeta
);
} else if (col.uidt === UITypes.Checkbox) { } else if (col.uidt === UITypes.Checkbox) {
actions = await migrateToCheckboxFilter(filter, actions, ncMeta); actions = await migrateToCheckboxFilter(filter, actions, ncMeta);
} else if (col.uidt === UITypes.MultiSelect) { } else if (col.uidt === UITypes.MultiSelect) {
actions = await removeLikeFilters(filter, actions, ncMeta); actions = await removeLikeFilters(filter, actions, ncMeta);
actions = await migrateToBlankFilter(filter, actions, ncMeta); actions = await migrateNullAndEmptyToBlankFilters(
filter,
actions,
ncMeta
);
actions = await migrateMultiSelectEq(filter, actions, col, ncMeta); actions = await migrateMultiSelectEq(filter, actions, col, ncMeta);
} else if (col.uidt === UITypes.Attachment) { } else if (col.uidt === UITypes.Attachment) {
actions = await removeArithmeticFilters(filter, actions, ncMeta); actions = await removeArithmeticFilters(filter, actions, ncMeta);
actions = await removeEqualFilters(filter, actions, ncMeta); actions = await removeEqualFilters(filter, actions, ncMeta);
actions = await migrateToBlankFilter(filter, actions, ncMeta); actions = await migrateNullAndEmptyToBlankFilters(
filter,
actions,
ncMeta
);
} else if (col.uidt === UITypes.LinkToAnotherRecord) { } else if (col.uidt === UITypes.LinkToAnotherRecord) {
actions = await removeArithmeticFilters(filter, actions, ncMeta); actions = await removeArithmeticFilters(filter, actions, ncMeta);
actions = await migrateToBlankFilter(filter, actions, ncMeta); actions = await migrateNullAndEmptyToBlankFilters(
filter,
actions,
ncMeta
);
} else if (col.uidt === UITypes.Lookup) { } else if (col.uidt === UITypes.Lookup) {
actions = await removeArithmeticFilters(filter, actions, ncMeta); actions = await removeArithmeticFilters(filter, actions, ncMeta);
actions = await migrateToBlankFilter(filter, actions, ncMeta); actions = await migrateNullAndEmptyToBlankFilters(
filter,
actions,
ncMeta
);
} else if (col.uidt === UITypes.Duration) { } else if (col.uidt === UITypes.Duration) {
actions = await removeLikeFilters(filter, actions, ncMeta); actions = await removeLikeFilters(filter, actions, ncMeta);
actions = await removeEqualFilters(filter, actions, ncMeta); actions = await migrateNullAndEmptyToBlankFilters(
actions = await migrateToBlankFilter(filter, actions, ncMeta); filter,
actions,
ncMeta
);
} }
} }
await Promise.all(actions); await Promise.all(actions);

Loading…
Cancel
Save