π₯ π₯ π₯ A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
Fix lookup quick search to LongText
Fendy Heryanto0d649a4a32d2
diff --git a/packages/nc-gui/composables/useFieldQuery.ts b/packages/nc-gui/composables/useFieldQuery.tsindex 356be75d3d..439ad3e694 100644--- a/packages/nc-gui/composables/useFieldQuery.ts+++ b/packages/nc-gui/composables/useFieldQuery.ts@@ -106,7 +106,7 @@ export function useFieldQuery() {(col.uidt !== UITypes.Formula || getFormulaColDataType(col) !== FormulaDataTypes.NUMERIC) &&!isNumericCol(col) &&sqlUi &&- ['text', 'string'].includes(sqlUi.getAbstractType(col)) &&+ ['text', 'string', 'json'].includes(sqlUi.getAbstractType(col)) &&col.dt !== 'bigint') {if (params.getWhereQueryAs === 'object') {diff --git a/packages/nocodb-sdk/src/lib/columnHelper/columns/Lookup.spec.ts b/packages/nocodb-sdk/src/lib/columnHelper/columns/Lookup.spec.tsnew file mode 100644index 0000000000..c392281404--- /dev/null+++ b/packages/nocodb-sdk/src/lib/columnHelper/columns/Lookup.spec.ts@@ -0,0 +1,613 @@+import { LookupHelper } from './Lookup';+import { ComputedTypePasteError } from '~/lib/error';+import UITypes from '~/lib/UITypes';+import { ColumnType, LinkToAnotherRecordType, LookupType, TableType } from '~/lib/Api';++describe('LookupHelper', () => {+ const helper = new LookupHelper();++ describe('serializeValue', () => {+ describe('when serializeSearchQuery is false', () => {+ it('throws ComputedTypePasteError for normal paste', () => {+ const params = {+ isMultipleCellPaste: false,+ serializeSearchQuery: false,+ col: {} as ColumnType,+ } as any;++ expect(() => helper.serializeValue('some value', params)).toThrow(+ ComputedTypePasteError+ );+ });++ it('returns undefined for multiple cell paste', () => {+ const params = {+ isMultipleCellPaste: true,+ serializeSearchQuery: false,+ col: {} as ColumnType,+ } as any;++ expect(helper.serializeValue('some value', params)).toBeUndefined();+ });+ });++ describe('when serializeSearchQuery is true', () => {+ it('returns null for null value', () => {+ const params = {+ serializeSearchQuery: true,+ col: {} as ColumnType,+ } as any;++ expect(helper.serializeValue(null, params)).toBeNull();+ });++ it('returns null for undefined value', () => {+ const params = {+ serializeSearchQuery: true,+ col: {} as ColumnType,+ } as any;++ expect(helper.serializeValue(undefined, params)).toBeNull();+ });++ it('returns null for empty string', () => {+ const params = {+ serializeSearchQuery: true,+ col: {} as ColumnType,+ } as any;++ expect(helper.serializeValue('', params)).toBeNull();+ });++ it('returns value when child column is not found', () => {+ const lookupColumn: ColumnType = {+ id: 'col1',+ uidt: UITypes.Lookup,+ colOptions: {+ fk_relation_column_id: 'rel_col1',+ fk_lookup_column_id: 'lookup_col1',+ } as LookupType,+ } as ColumnType;++ const relationColumn: ColumnType = {+ id: 'rel_col1',+ uidt: UITypes.LinkToAnotherRecord,+ colOptions: {+ fk_related_model_id: 'related_table_id',+ } as LinkToAnotherRecordType,+ } as ColumnType;++ const meta: TableType = {+ id: 'table1',+ base_id: 'base1',+ columns: [lookupColumn, relationColumn],+ } as TableType;++ const relatedMeta: TableType = {+ id: 'related_table_id',+ base_id: 'base1',+ columns: [], // No child column with matching id+ } as TableType;++ const params = {+ serializeSearchQuery: true,+ col: lookupColumn,+ meta,+ metas: {+ 'base1:related_table_id': relatedMeta,+ },+ } as any;++ expect(helper.serializeValue('test value', params)).toBe('test value');+ });++ it('serializes single value using child column helper (SingleLineText)', () => {+ const childColumn: ColumnType = {+ id: 'child_col1',+ uidt: UITypes.SingleLineText,+ } as ColumnType;++ const lookupColumn: ColumnType = {+ id: 'col1',+ uidt: UITypes.Lookup,+ colOptions: {+ fk_relation_column_id: 'rel_col1',+ fk_lookup_column_id: 'child_col1',+ } as LookupType,+ } as ColumnType;++ const relationColumn: ColumnType = {+ id: 'rel_col1',+ uidt: UITypes.LinkToAnotherRecord,+ colOptions: {+ fk_related_model_id: 'related_table_id',+ } as LinkToAnotherRecordType,+ } as ColumnType;++ const meta: TableType = {+ id: 'table1',+ base_id: 'base1',+ columns: [lookupColumn, relationColumn],+ } as TableType;++ const relatedMeta: TableType = {+ id: 'related_table_id',+ base_id: 'base1',+ columns: [childColumn],+ } as TableType;++ const params = {+ serializeSearchQuery: true,+ col: lookupColumn,+ meta,+ metas: {+ 'base1:related_table_id': relatedMeta,+ },+ } as any;++ expect(helper.serializeValue('test value', params)).toBe('test value');+ });++ it('serializes array values using child column helper and joins with comma', () => {+ const childColumn: ColumnType = {+ id: 'child_col1',+ uidt: UITypes.SingleLineText,+ } as ColumnType;++ const lookupColumn: ColumnType = {+ id: 'col1',+ uidt: UITypes.Lookup,+ colOptions: {+ fk_relation_column_id: 'rel_col1',+ fk_lookup_column_id: 'child_col1',+ } as LookupType,+ } as ColumnType;++ const relationColumn: ColumnType = {+ id: 'rel_col1',+ uidt: UITypes.LinkToAnotherRecord,+ colOptions: {+ fk_related_model_id: 'related_table_id',+ } as LinkToAnotherRecordType,+ } as ColumnType;++ const meta: TableType = {+ id: 'table1',+ base_id: 'base1',+ columns: [lookupColumn, relationColumn],+ } as TableType;++ const relatedMeta: TableType = {+ id: 'related_table_id',+ base_id: 'base1',+ columns: [childColumn],+ } as TableType;++ const params = {+ serializeSearchQuery: true,+ col: lookupColumn,+ meta,+ metas: {+ 'base1:related_table_id': relatedMeta,+ },+ } as any;++ expect(helper.serializeValue(['value1', 'value2', 'value3'], params)).toBe(+ 'value1, value2, value3'+ );+ });++ it('serializes number values using child Number column', () => {+ const childColumn: ColumnType = {+ id: 'child_col1',+ uidt: UITypes.Number,+ } as ColumnType;++ const lookupColumn: ColumnType = {+ id: 'col1',+ uidt: UITypes.Lookup,+ colOptions: {+ fk_relation_column_id: 'rel_col1',+ fk_lookup_column_id: 'child_col1',+ } as LookupType,+ } as ColumnType;++ const relationColumn: ColumnType = {+ id: 'rel_col1',+ uidt: UITypes.LinkToAnotherRecord,+ colOptions: {+ fk_related_model_id: 'related_table_id',+ } as LinkToAnotherRecordType,+ } as ColumnType;++ const meta: TableType = {+ id: 'table1',+ base_id: 'base1',+ columns: [lookupColumn, relationColumn],+ } as TableType;++ const relatedMeta: TableType = {+ id: 'related_table_id',+ base_id: 'base1',+ columns: [childColumn],+ } as TableType;++ const params = {+ serializeSearchQuery: true,+ col: lookupColumn,+ meta,+ metas: {+ 'base1:related_table_id': relatedMeta,+ },+ } as any;++ expect(helper.serializeValue(42, params)).toBe(42);+ });++ it('serializes checkbox values using child Checkbox column', () => {+ const childColumn: ColumnType = {+ id: 'child_col1',+ uidt: UITypes.Checkbox,+ } as ColumnType;++ const lookupColumn: ColumnType = {+ id: 'col1',+ uidt: UITypes.Lookup,+ colOptions: {+ fk_relation_column_id: 'rel_col1',+ fk_lookup_column_id: 'child_col1',+ } as LookupType,+ } as ColumnType;++ const relationColumn: ColumnType = {+ id: 'rel_col1',+ uidt: UITypes.LinkToAnotherRecord,+ colOptions: {+ fk_related_model_id: 'related_table_id',+ } as LinkToAnotherRecordType,+ } as ColumnType;++ const meta: TableType = {+ id: 'table1',+ base_id: 'base1',+ columns: [lookupColumn, relationColumn],+ } as TableType;++ const relatedMeta: TableType = {+ id: 'related_table_id',+ base_id: 'base1',+ columns: [childColumn],+ } as TableType;++ const params = {+ serializeSearchQuery: true,+ col: lookupColumn,+ meta,+ metas: {+ 'base1:related_table_id': relatedMeta,+ },+ } as any;++ expect(helper.serializeValue(true, params)).toBe(true);+ // Note: false is treated as falsy and returns null due to !value check+ expect(helper.serializeValue(false, params)).toBeNull();+ });++ it('handles lookup with different base_id (fk_related_base_id)', () => {+ const childColumn: ColumnType = {+ id: 'child_col1',+ uidt: UITypes.SingleLineText,+ } as ColumnType;++ const lookupColumn: ColumnType = {+ id: 'col1',+ uidt: UITypes.Lookup,+ colOptions: {+ fk_relation_column_id: 'rel_col1',+ fk_lookup_column_id: 'child_col1',+ } as LookupType,+ } as ColumnType;++ const relationColumn: ColumnType = {+ id: 'rel_col1',+ uidt: UITypes.LinkToAnotherRecord,+ colOptions: {+ fk_related_model_id: 'related_table_id',+ fk_related_base_id: 'base2', // Different base+ } as LinkToAnotherRecordType,+ } as ColumnType;++ const meta: TableType = {+ id: 'table1',+ base_id: 'base1',+ columns: [lookupColumn, relationColumn],+ } as TableType;++ const relatedMeta: TableType = {+ id: 'related_table_id',+ base_id: 'base2',+ columns: [childColumn],+ } as TableType;++ const params = {+ serializeSearchQuery: true,+ col: lookupColumn,+ meta,+ metas: {+ 'base2:related_table_id': relatedMeta, // Uses different base_id+ },+ } as any;++ expect(helper.serializeValue('cross-base value', params)).toBe(+ 'cross-base value'+ );+ });++ it('handles array with empty values', () => {+ const childColumn: ColumnType = {+ id: 'child_col1',+ uidt: UITypes.SingleLineText,+ } as ColumnType;++ const lookupColumn: ColumnType = {+ id: 'col1',+ uidt: UITypes.Lookup,+ colOptions: {+ fk_relation_column_id: 'rel_col1',+ fk_lookup_column_id: 'child_col1',+ } as LookupType,+ } as ColumnType;++ const relationColumn: ColumnType = {+ id: 'rel_col1',+ uidt: UITypes.LinkToAnotherRecord,+ colOptions: {+ fk_related_model_id: 'related_table_id',+ } as LinkToAnotherRecordType,+ } as ColumnType;++ const meta: TableType = {+ id: 'table1',+ base_id: 'base1',+ columns: [lookupColumn, relationColumn],+ } as TableType;++ const relatedMeta: TableType = {+ id: 'related_table_id',+ base_id: 'base1',+ columns: [childColumn],+ } as TableType;++ const params = {+ serializeSearchQuery: true,+ col: lookupColumn,+ meta,+ metas: {+ 'base1:related_table_id': relatedMeta,+ },+ } as any;++ expect(helper.serializeValue(['value1', null, '', 'value2'], params)).toBe(+ 'value1, , , value2'+ );+ });+ });+ });++ describe('parseValue', () => {+ it('returns null for null value', () => {+ const params = {+ col: {} as ColumnType,+ } as any;++ expect(helper.parseValue(null, params)).toBeNull();+ });++ it('returns null for undefined value', () => {+ const params = {+ col: {} as ColumnType,+ } as any;++ expect(helper.parseValue(undefined, params)).toBeNull();+ });++ it('returns null for empty string', () => {+ const params = {+ col: {} as ColumnType,+ } as any;++ expect(helper.parseValue('', params)).toBeNull();+ });++ it('returns value as-is when child column is not found', () => {+ const lookupColumn: ColumnType = {+ id: 'col1',+ uidt: UITypes.Lookup,+ colOptions: {+ fk_relation_column_id: 'rel_col1',+ fk_lookup_column_id: 'lookup_col1',+ } as LookupType,+ } as ColumnType;++ const relationColumn: ColumnType = {+ id: 'rel_col1',+ uidt: UITypes.LinkToAnotherRecord,+ colOptions: {+ fk_related_model_id: 'related_table_id',+ } as LinkToAnotherRecordType,+ } as ColumnType;++ const meta: TableType = {+ id: 'table1',+ base_id: 'base1',+ columns: [lookupColumn, relationColumn],+ } as TableType;++ const relatedMeta: TableType = {+ id: 'related_table_id',+ base_id: 'base1',+ columns: [], // No child column+ } as TableType;++ const params = {+ col: lookupColumn,+ meta,+ metas: {+ 'base1::related_table_id': relatedMeta,+ },+ } as any;++ expect(helper.parseValue('test value', params)).toBe('test value');+ });++ it('parses single value using child column helper', () => {+ const childColumn: ColumnType = {+ id: 'child_col1',+ uidt: UITypes.SingleLineText,+ } as ColumnType;++ const lookupColumn: ColumnType = {+ id: 'col1',+ uidt: UITypes.Lookup,+ colOptions: {+ fk_relation_column_id: 'rel_col1',+ fk_lookup_column_id: 'child_col1',+ } as LookupType,+ } as ColumnType;++ const relationColumn: ColumnType = {+ id: 'rel_col1',+ uidt: UITypes.LinkToAnotherRecord,+ colOptions: {+ fk_related_model_id: 'related_table_id',+ } as LinkToAnotherRecordType,+ } as ColumnType;++ const meta: TableType = {+ id: 'table1',+ base_id: 'base1',+ columns: [lookupColumn, relationColumn],+ } as TableType;++ const relatedMeta: TableType = {+ id: 'related_table_id',+ base_id: 'base1',+ columns: [childColumn],+ } as TableType;++ const params = {+ col: lookupColumn,+ meta,+ metas: {+ 'base1::related_table_id': relatedMeta,+ },+ } as any;++ expect(helper.parseValue('test value', params)).toBe('test value');+ });++ it('parses array values using child column helper and joins with comma', () => {+ const childColumn: ColumnType = {+ id: 'child_col1',+ uidt: UITypes.SingleLineText,+ } as ColumnType;++ const lookupColumn: ColumnType = {+ id: 'col1',+ uidt: UITypes.Lookup,+ colOptions: {+ fk_relation_column_id: 'rel_col1',+ fk_lookup_column_id: 'child_col1',+ } as LookupType,+ } as ColumnType;++ const relationColumn: ColumnType = {+ id: 'rel_col1',+ uidt: UITypes.LinkToAnotherRecord,+ colOptions: {+ fk_related_model_id: 'related_table_id',+ } as LinkToAnotherRecordType,+ } as ColumnType;++ const meta: TableType = {+ id: 'table1',+ base_id: 'base1',+ columns: [lookupColumn, relationColumn],+ } as TableType;++ const relatedMeta: TableType = {+ id: 'related_table_id',+ base_id: 'base1',+ columns: [childColumn],+ } as TableType;++ const params = {+ col: lookupColumn,+ meta,+ metas: {+ 'base1:related_table_id': relatedMeta,+ },+ } as any;++ expect(helper.parseValue(['value1', 'value2', 'value3'], params)).toBe(+ 'value1, value2, value3'+ );+ });+ });++ describe('parsePlainCellValue', () => {+ it('returns empty string for null value', () => {+ const params = {+ col: {} as ColumnType,+ } as any;++ expect(helper.parsePlainCellValue(null, params)).toBe('');+ });++ it('returns parsed value for valid input', () => {+ const childColumn: ColumnType = {+ id: 'child_col1',+ uidt: UITypes.SingleLineText,+ } as ColumnType;++ const lookupColumn: ColumnType = {+ id: 'col1',+ uidt: UITypes.Lookup,+ colOptions: {+ fk_relation_column_id: 'rel_col1',+ fk_lookup_column_id: 'child_col1',+ } as LookupType,+ } as ColumnType;++ const relationColumn: ColumnType = {+ id: 'rel_col1',+ uidt: UITypes.LinkToAnotherRecord,+ colOptions: {+ fk_related_model_id: 'related_table_id',+ } as LinkToAnotherRecordType,+ } as ColumnType;++ const meta: TableType = {+ id: 'table1',+ base_id: 'base1',+ columns: [lookupColumn, relationColumn],+ } as TableType;++ const relatedMeta: TableType = {+ id: 'related_table_id',+ base_id: 'base1',+ columns: [childColumn],+ } as TableType;++ const params = {+ col: lookupColumn,+ meta,+ metas: {+ 'base1::related_table_id': relatedMeta,+ },+ } as any;++ expect(helper.parsePlainCellValue('test value', params)).toBe('test value');+ });+ });+});diff --git a/packages/nocodb-sdk/src/lib/columnHelper/columns/Lookup.ts b/packages/nocodb-sdk/src/lib/columnHelper/columns/Lookup.tsindex a618f09eb3..40cfd5bdbc 100644--- a/packages/nocodb-sdk/src/lib/columnHelper/columns/Lookup.ts+++ b/packages/nocodb-sdk/src/lib/columnHelper/columns/Lookup.ts@@ -18,7 +18,49 @@ export class LookupHelper extends AbstractColumnHelper {params: SerializerOrParserFnProps['params']): string | null {if (params.serializeSearchQuery) {- return this.parseValue(value, params);+ if (!value) return null;++ // Get the child column being looked up+ const { col, meta, metas } = params;+ const baseId = meta?.base_id;+ const colOptions = col.colOptions as LookupType;+ const relationColumnOptions = colOptions.fk_relation_column_id+ ? (meta?.columns?.find((c) => c.id === colOptions.fk_relation_column_id)+ ?.colOptions as LinkToAnotherRecordType)+ : null;+ const relatedBaseId = relationColumnOptions?.fk_related_base_id || baseId;+ const relatedTableMeta =+ relationColumnOptions?.fk_related_model_id &&+ getMetaWithCompositeKey(+ metas,+ relatedBaseId,+ relationColumnOptions.fk_related_model_id as string+ );++ let childColumn = relatedTableMeta?.columns.find(+ (c: ColumnType) => c.id === colOptions.fk_lookup_column_id+ ) as ColumnType | undefined;++ if (!childColumn) return value;++ childColumn = clone(childColumn);++ // Use serializeValue on child column to get raw search value+ if (ncIsArray(value)) {+ return value+ .map((v) => {+ return ColumnHelper.serializeValue(v, {+ ...params,+ col: childColumn!,+ });+ })+ .join(', ');+ }++ return ColumnHelper.serializeValue(value, {+ ...params,+ col: childColumn!,+ });}if (params.isMultipleCellPaste) {