diff --git a/packages/state/src/utils/index.ts b/packages/state/src/utils/index.ts index abbc3b5f..fbcd4d13 100644 --- a/packages/state/src/utils/index.ts +++ b/packages/state/src/utils/index.ts @@ -1,8 +1,8 @@ export * from './build'; export * from './field/model'; -export * from './/field/add-fields'; -export * from './/field/remove-field'; -export * from './/field/sort-fields'; +export * from './field/add-fields'; +export * from './field/remove-field'; +export * from './field/sort-fields'; export * from './view'; export * from './common'; export * from './record/add-records'; diff --git a/packages/state/src/utils/record/filter.ts b/packages/state/src/utils/record/filter.ts index b8f87b39..2dc3aaab 100644 --- a/packages/state/src/utils/record/filter.ts +++ b/packages/state/src/utils/record/filter.ts @@ -1,9 +1,8 @@ -import { AITable, AITableRecord, FieldValue } from '@ai-table/grid'; +import { AITableFieldType, AITableRecord, FieldValue, isSystemField, SystemFieldTypes } from '@ai-table/grid'; import { AITableFilterCondition, AITableFilterConditions, AITableFilterLogical, - AITableFilterOperation, AITableView, AITableViewField, AITableViewFields, @@ -11,7 +10,6 @@ import { AIViewTable } from '../../types'; import { ViewOperationMap } from '../field/model'; -import { isEmpty } from '../common'; export function getFilteredRecords(aiTable: AIViewTable, records: AITableViewRecords, fields: AITableViewFields, activeView: AITableView) { const { conditions, condition_logical } = activeView.settings || {}; @@ -24,7 +22,7 @@ export function getFilteredRecords(aiTable: AIViewTable, records: AITableViewRec } const recordsWillHidden = aiTable.recordsWillHidden(); return records.filter((record) => { - if(recordsWillHidden && recordsWillHidden.length && recordsWillHidden.includes(record._id)){ + if (recordsWillHidden && recordsWillHidden.length && recordsWillHidden.includes(record._id)) { return true; } return checkConditions(fields, record, { conditions: illegalConditions, condition_logical }); @@ -49,8 +47,8 @@ function checkConditions(fields: AITableViewFields, record: AITableRecord, filte } function doFilterOperations(fields: AITableViewFields, record: AITableRecord, condition: AITableFilterCondition) { - const field = fields.find((item) => item._id === condition.field_id); - const cellValue = record.values[condition.field_id]; + const { field, cellValue } = getFilterValue(fields, record, condition); + try { return field && doFilter(condition, field, cellValue); } catch (error) { @@ -59,13 +57,6 @@ function doFilterOperations(fields: AITableViewFields, record: AITableRecord, co } export function doFilter(condition: AITableFilterCondition, field: AITableViewField, cellValue: FieldValue) { - if (condition.operation === AITableFilterOperation.empty) { - return isEmpty(cellValue); - } - if (condition.operation === AITableFilterOperation.exists) { - return !isEmpty(cellValue); - } - return ViewOperationMap[field.type].isMeetFilter(condition, cellValue); } @@ -81,3 +72,22 @@ export function getDefaultRecordDataByFilter( } return recordValues; } + +export function getFilterValue(fields: AITableViewFields, record: AITableRecord, condition: AITableFilterCondition) { + const field = fields.find((item) => item._id === condition.field_id); + let cellValue = null; + if (field && isSystemField(field)) { + if ([AITableFieldType.createdAt, AITableFieldType.updatedAt].includes(field.type)) { + cellValue = { timestamp: record[field.type as SystemFieldTypes] }; + } else { + cellValue = record[field.type as SystemFieldTypes]; + } + } else { + cellValue = record.values[condition.field_id]; + } + + return { + field, + cellValue + }; +} diff --git a/src/app/utils/utils.ts b/src/app/utils/utils.ts index e44f56cb..f5301811 100644 --- a/src/app/utils/utils.ts +++ b/src/app/utils/utils.ts @@ -9,10 +9,18 @@ export function sortDataByView(data: AITableViewRecords | AITableViewFields, act return data; } -export const getDefaultTrackableEntity = () => { - const member = 'member_01'; - const time = new Date('2024-10-01').getTime(); - return { created_by: member, created_at: time, updated_by: member, updated_at: time }; +export const getDefaultTrackableEntity = (options?: { + [AITableFieldType.createdBy]?: string; + [AITableFieldType.createdAt]?: string; + [AITableFieldType.updatedBy]?: string; + [AITableFieldType.updatedAt]?: string; +}) => { + return { + created_by: options?.[AITableFieldType.createdBy] || 'member_01', + created_at: new Date(options?.[AITableFieldType.createdAt] || '2024-12-15').getTime() / 1000, + updated_by: options?.[AITableFieldType.updatedBy] || 'member_01', + updated_at: new Date(options?.[AITableFieldType.updatedAt] || '2024-12-17').getTime() / 1000 + }; }; export function getDefaultValue() { @@ -24,7 +32,7 @@ export function getDefaultValue() { { _id: 'row-1', short_id: `row-short-id-${1}`, - ...getDefaultTrackableEntity(), + ...getDefaultTrackableEntity({ updated_at: '2024-12-19' }), positions: { view1: 0, view2: 1 @@ -36,18 +44,18 @@ export function getDefaultValue() { 'column-21': ['66b31d0c8097a908f74bcd8a'], 'column-22': ['66b31d0c8097a908f74bcd8a'], 'column-3': 1, - 'column-4': { timestamp: 1682235946 }, + 'column-4': { timestamp: 1734636127 }, 'column-5': ['member_01'], 'column-6': 10, 'column-7': 3, 'column-8': { url: 'https://www.baidu.com', text: '百度链接' - }, - 'column-9': ['member_01'], - 'column-10': 1682235946, - 'column-11': ['member_02'], - 'column-12': 1720490727 + } + // 'column-9': ['member_01'], + // 'column-10': 1682235946, + // 'column-11': ['member_02'], + // 'column-12': 1720490727 } }, { @@ -69,11 +77,11 @@ export function getDefaultValue() { 'column-5': ['member_01', 'member_02'], 'column-6': 50, 'column-7': 1, - 'column-8': {}, - 'column-9': ['member_01'], - 'column-10': 1682235946, - 'column-11': ['member_02'], - 'column-12': 1720490727 + 'column-8': {} + // 'column-9': ['member_01'], + // 'column-10': 1682235946, + // 'column-11': ['member_02'], + // 'column-12': 1720490727 } }, { @@ -110,11 +118,11 @@ export function getDefaultValue() { 'column-5': [], 'column-6': 100, 'column-7': 1, - 'column-8': {}, - 'column-9': [], - 'column-10': 1682235946, - 'column-11': ['member_02'], - 'column-12': 1720490727 + 'column-8': {} + // 'column-9': [], + // 'column-10': 1682235946, + // 'column-11': ['member_02'], + // 'column-12': 1720490727 } } ], @@ -419,7 +427,7 @@ export function getCanvasDefaultValue() { { _id: 'row-1', short_id: `row-short-id-${1}`, - ...getDefaultTrackableEntity(), + ...getDefaultTrackableEntity({ updated_at: '2024-12-19' }), positions: { view1: 0, view2: 1 @@ -435,7 +443,7 @@ export function getCanvasDefaultValue() { 'column-112': ['tag_1'], 'column-20': ['66b31d0c8097a908f74bcd8a'], 'column-3': 1, - 'column-4': { timestamp: 1682235946 }, + 'column-4': { timestamp: 1734636127 }, 'column-5': ['member_01'], 'column-6': 10, 'column-7': 5, @@ -443,10 +451,10 @@ export function getCanvasDefaultValue() { url: 'https://www.baidu.com', text: '百度链接' }, - 'column-9': ['member_01'], - 'column-10': { timestamp: 1682235946 }, - 'column-11': ['member_02'], - 'column-12': { timestamp: 1720490727 }, + // 'column-9': ['member_01'], + // 'column-10': { timestamp: 1682235946 }, + // 'column-11': ['member_02'], + // 'column-12': { timestamp: 1720490727 }, 'column-21': ['66b31d0c8097a908f74bcd8a'], 'column-22': ['66b31d0c8097a908f74bcd8b', '66b31d0c8097a908f74bcd8a'], 'column-23': ['66b31d0c8097a908f74bcd8e', '66b31d0c8097a908f74bcd8a', '66b31d0c8097a908f74bcd8b'] @@ -474,10 +482,10 @@ export function getCanvasDefaultValue() { 'column-6': 50, 'column-7': 4, 'column-8': {}, - 'column-9': ['member_01'], - 'column-10': { timestamp: 1682235946 }, - 'column-11': ['member_02'], - 'column-12': { timestamp: 1720490727 }, + // 'column-9': ['member_01'], + // 'column-10': { timestamp: 1682235946 }, + // 'column-11': ['member_02'], + // 'column-12': { timestamp: 1720490727 }, 'column-21': ['66b31d0c8097a908f74bcd8a'], 'column-22': ['66b31d0c8097a908f74bcd8b', '66b31d0c8097a908f74bcd8a'], 'column-23': ['66b31d0c8097a908f74bcd8e', '66b31d0c8097a908f74bcd8a', '66b31d0c8097a908f74bcd8b'] @@ -510,10 +518,10 @@ export function getCanvasDefaultValue() { 'column-6': 100, 'column-7': 3, 'column-8': {}, - 'column-9': [], - 'column-10': { timestamp: 1727254598 }, - 'column-11': ['member_02'], - 'column-12': { timestamp: 1720490727 }, + // 'column-9': [], + // 'column-10': { timestamp: 1727254598 }, + // 'column-11': ['member_02'], + // 'column-12': { timestamp: 1720490727 }, 'column-21': ['66b31d0c8097a908f74bcd8a'], 'column-22': ['66b31d0c8097a908f74bcd8b', '66b31d0c8097a908f74bcd8a'], 'column-23': ['66b31d0c8097a908f74bcd8e', '66b31d0c8097a908f74bcd8a', '66b31d0c8097a908f74bcd8b'] @@ -990,11 +998,11 @@ export function getBigData() { 'column-5': ['member_01', 'member_02'], 'column-6': 50, 'column-7': 3, - 'column-8': {}, - 'column-9': ['member_01'], - 'column-10': { timestamp: 1682235946 }, - 'column-11': ['member_02'], - 'column-12': { timestamp: 1720490727 } + 'column-8': {} + // 'column-9': ['member_01'], + // 'column-10': { timestamp: 1682235946 }, + // 'column-11': ['member_02'], + // 'column-12': { timestamp: 1720490727 } } }); }