Browse Source

fix: import- self link, empty options

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>
pull/3760/head
Raju Udava 2 years ago
parent
commit
4cdec73684
  1. 43
      packages/nocodb/src/lib/meta/api/sync/helpers/job.ts
  2. 5
      packages/nocodb/src/lib/meta/api/sync/helpers/readAndProcessData.ts

43
packages/nocodb/src/lib/meta/api/sync/helpers/job.ts

@ -16,17 +16,17 @@ import { importData, importLTARData } from './readAndProcessData';
dayjs.extend(utc); dayjs.extend(utc);
const selectColors = { const selectColors = {
"blue": "#cfdfff", blue: '#cfdfff',
"cyan": "#d0f0fd", cyan: '#d0f0fd',
"teal": "#c2f5e9", teal: '#c2f5e9',
"green": "#d1f7c4", green: '#d1f7c4',
"orange": "#fee2d5", orange: '#fee2d5',
"yellow": "#ffeab6", yellow: '#ffeab6',
"red": "#ffdce5", red: '#ffdce5',
"pink": "#ffdaf6", pink: '#ffdaf6',
"purple": "#ede2fe", purple: '#ede2fe',
"gray": "#eee" gray: '#eee',
} };
export default async ( export default async (
syncDB: AirtableSyncConfig, syncDB: AirtableSyncConfig,
@ -411,13 +411,15 @@ export default async (
// TODO fix record mapping (this causes every record to map first option, we can't handle them using data api as they don't provide option id within data we might instead get the correct mapping from schema file ) // TODO fix record mapping (this causes every record to map first option, we can't handle them using data api as they don't provide option id within data we might instead get the correct mapping from schema file )
let dupNo = 1; let dupNo = 1;
const defaultName = (value as any).name; const defaultName = (value as any).name;
while (options.find(el => el.title === (value as any).name)) { while (options.find((el) => el.title === (value as any).name)) {
(value as any).name = `${defaultName}_${dupNo++}`; (value as any).name = `${defaultName}_${dupNo++}`;
} }
options.push({ options.push({
order: order++, order: order++,
title: (value as any).name, title: (value as any).name,
color: selectColors[(value as any).color] ? selectColors[(value as any).color] : null color: selectColors[(value as any).color]
? selectColors[(value as any).color]
: null,
}); });
sMap.addToMappingTbl( sMap.addToMappingTbl(
@ -538,9 +540,11 @@ export default async (
case 'select': case 'select':
case 'multiSelect': case 'multiSelect':
ncCol.colOptions = { ncCol.colOptions = {
options: [...colOptions.data] options: [...colOptions.data],
} };
ncCol.dtxp = colOptions.data.map(el => `'${el.title}'`).join(','); // if options are empty, configure '' as default option
ncCol.dtxp =
colOptions.data.map((el) => `'${el.title}'`).join(',') || "''";
break; break;
case undefined: case undefined:
break; break;
@ -1362,12 +1366,14 @@ export default async (
break; break;
case UITypes.MultiSelect: case UITypes.MultiSelect:
rec[key] = value.map((v) => { rec[key] = value
.map((v) => {
if (v === '') { if (v === '') {
return 'nc_empty'; return 'nc_empty';
} }
return `${v.replace(/,/g, '.')}`; return `${v.replace(/,/g, '.')}`;
}).join(','); })
.join(',');
break; break;
case UITypes.Attachment: case UITypes.Attachment:
@ -2215,6 +2221,7 @@ export default async (
logDetailed, logDetailed,
records: recordsMap[ncTbl.id], records: recordsMap[ncTbl.id],
atNcAliasRef, atNcAliasRef,
ncLinkMappingTable,
}); });
} }

5
packages/nocodb/src/lib/meta/api/sync/helpers/readAndProcessData.ts

@ -136,6 +136,7 @@ export async function importLTARData({
logBasic = (_str) => {}, logBasic = (_str) => {},
records, records,
atNcAliasRef, atNcAliasRef,
ncLinkMappingTable,
}: { }: {
projectName: string; projectName: string;
table: { title?: string; id?: string }; table: { title?: string; id?: string };
@ -151,6 +152,7 @@ export async function importLTARData({
[ncTitle: string]: string; [ncTitle: string]: string;
}; };
}; };
ncLinkMappingTable: Record<string, Record<string, any>>[];
}) { }) {
const assocTableMetas: Array<{ const assocTableMetas: Array<{
modelMeta: { id?: string; title?: string }; modelMeta: { id?: string; title?: string };
@ -182,6 +184,9 @@ export async function importLTARData({
// skip if already inserted // skip if already inserted
if (colMeta.colOptions.fk_mm_model_id in insertedAssocRef) continue; if (colMeta.colOptions.fk_mm_model_id in insertedAssocRef) continue;
// self links: skip if the column under consideration is the add-on column NocoDB creates
if (ncLinkMappingTable.every((a) => a.nc.title !== colMeta.title)) continue;
// mark as inserted // mark as inserted
insertedAssocRef[colMeta.colOptions.fk_mm_model_id] = true; insertedAssocRef[colMeta.colOptions.fk_mm_model_id] = true;

Loading…
Cancel
Save