Browse Source

feat: advanced sync options

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/2175/head
mertmit 2 years ago committed by Raju Udava
parent
commit
1285916cf4
  1. 92
      packages/nc-gui/components/import/ImportFromAirtable.vue
  2. 26
      packages/nocodb/src/lib/noco/meta/api/sync/helpers/job.ts

92
packages/nc-gui/components/import/ImportFromAirtable.vue

@ -21,7 +21,7 @@
> >
<template v-if="step === 1"> <template v-if="step === 1">
<div class="d-flex flex-column justify-center align-center pt-2 pb-6"> <div class="d-flex flex-column justify-center align-center pt-2 pb-6">
<span class="subtitle-1 font-weight-medium" @dblclick="$set(syncSource.details,'syncViews',true)"> <span class="subtitle-1 font-weight-medium" @dblclick="$set(syncSource.details.options,'syncViews',true)">
Credentials Credentials
</span> </span>
@ -55,7 +55,47 @@
:rules="[(v) => !!v || 'Shared Base ID / URL is required']" :rules="[(v) => !!v || 'Shared Base ID / URL is required']"
/> />
</div> </div>
</v-form> <v-card-actions class="justify-center pb-6"> <v-expansion-panels class="mx-auto" style="width: 50%;" flat>
<v-expansion-panel>
<v-expansion-panel-header>Advanced Options</v-expansion-panel-header>
<v-expansion-panel-content>
<v-checkbox
v-model="syncSource.details.options.syncData"
label="Import Data"
hide-details
dense
/>
<v-checkbox
v-model="syncSource.details.options.syncRollup"
label="Import Rollup Columns"
hide-details
dense
/>
<v-checkbox
v-model="syncSource.details.options.syncLookup"
label="Import Lookup Columns"
hide-details
dense
/>
<v-tooltip bottom>
<template #activator="{ on }">
<div v-on="on">
<v-checkbox
v-model="syncSource.details.options.syncFormula"
label="Import Formula Columns"
hide-details
dense
disabled
/>
</div>
</template>
<span>Coming Soon!</span>
</v-tooltip>
</v-expansion-panel-content>
</v-expansion-panel>
</v-expansion-panels>
</v-form>
<v-card-actions class="justify-center pb-6">
<v-btn <v-btn
v-t="['c:sync-airtable:save-and-sync']" v-t="['c:sync-airtable:save-and-sync']"
class="nc-btn-airtable-import" class="nc-btn-airtable-import"
@ -139,7 +179,23 @@ export default {
socket: null, socket: null,
step: 1, step: 1,
progress: [], progress: [],
syncSource: null, syncSource: {
type: 'Airtable',
details: {
syncInterval: '15mins',
syncDirection: 'Airtable to NocoDB',
syncRetryCount: 1,
apiKey: '',
shareId: '',
options: {
syncViews: false,
syncData: true,
syncRollup: false,
syncLookup: true,
syncFormula: false
}
}
},
syncSourceUrlOrId: '' syncSourceUrlOrId: ''
}), }),
computed: { computed: {
@ -221,7 +277,7 @@ export default {
const { data: { list: srcs } } = await this.$axios.get(`/api/v1/db/meta/projects/${this.projectId}/syncs`) const { data: { list: srcs } } = await this.$axios.get(`/api/v1/db/meta/projects/${this.projectId}/syncs`)
if (srcs && srcs[0]) { if (srcs && srcs[0]) {
srcs[0].details = srcs[0].details || {} srcs[0].details = srcs[0].details || {}
this.syncSource = srcs[0] this.syncSource = this.migrateSync(srcs[0])
this.syncSourceUrlOrId = srcs[0].details.shareId this.syncSourceUrlOrId = srcs[0].details.shareId
} else { } else {
this.syncSource = { this.syncSource = {
@ -230,11 +286,15 @@ export default {
syncInterval: '15mins', syncInterval: '15mins',
syncDirection: 'Airtable to NocoDB', syncDirection: 'Airtable to NocoDB',
syncRetryCount: 1, syncRetryCount: 1,
syncViews: false,
apiKey: '', apiKey: '',
shareId: '' shareId: '',
options: {
syncViews: false,
syncData: true,
syncRollup: false,
syncLookup: true,
syncFormula: false
}
} }
} }
} }
@ -252,8 +312,22 @@ export default {
} }
}, },
enableTurbo() { enableTurbo() {
this.$set(this.syncSource.details, 'syncViews', true) this.$set(this.syncSource.details.options, 'syncViews', true)
this.$toast.success('🚀🚀 Ludicrous mode activated! Let\'s go! 🚀🚀').goAway(3000) this.$toast.success('🚀🚀 Ludicrous mode activated! Let\'s go! 🚀🚀').goAway(3000)
},
migrateSync(src) {
if (!src.details?.options) {
src.details.options = {
syncViews: false,
syncData: true,
syncRollup: false,
syncLookup: true,
syncFormula: false
}
src.details.options.syncViews = src.syncViews
delete src.syncViews
}
return src
} }
} }
} }

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

@ -70,7 +70,6 @@ export default async (
let base, baseId; let base, baseId;
const start = Date.now(); const start = Date.now();
const enableErrorLogs = false; const enableErrorLogs = false;
const process_aTblData = true;
const generate_migrationStats = true; const generate_migrationStats = true;
const debugMode = false; const debugMode = false;
let api: Api<any>; let api: Api<any>;
@ -387,7 +386,7 @@ export default async (
for (let i = 0; i < tblSchema.length; ++i) { for (let i = 0; i < tblSchema.length; ++i) {
const table: any = {}; const table: any = {};
if (syncDB.syncViews) { if (syncDB.options.syncViews) {
rtc.view.total += tblSchema[i].views.reduce( rtc.view.total += tblSchema[i].views.reduce(
(acc, cur) => (acc, cur) =>
['grid', 'form', 'gallery'].includes(cur.type) ? ++acc : acc, ['grid', 'form', 'gallery'].includes(cur.type) ? ++acc : acc,
@ -1506,7 +1505,7 @@ export default async (
} }
async function nocoConfigureGalleryView(sDB, aTblSchema) { async function nocoConfigureGalleryView(sDB, aTblSchema) {
if (!sDB.syncViews) return; if (!sDB.options.syncViews) return;
for (let idx = 0; idx < aTblSchema.length; idx++) { for (let idx = 0; idx < aTblSchema.length; idx++) {
const tblId = (await nc_getTableSchema(aTblSchema[idx].name)).id; const tblId = (await nc_getTableSchema(aTblSchema[idx].name)).id;
const galleryViews = aTblSchema[idx].views.filter( const galleryViews = aTblSchema[idx].views.filter(
@ -1545,7 +1544,7 @@ export default async (
} }
async function nocoConfigureFormView(sDB, aTblSchema) { async function nocoConfigureFormView(sDB, aTblSchema) {
if (!sDB.syncViews) return; if (!sDB.options.syncViews) return;
for (let idx = 0; idx < aTblSchema.length; idx++) { for (let idx = 0; idx < aTblSchema.length; idx++) {
const tblId = sMap.getNcIdFromAtId(aTblSchema[idx].id); const tblId = sMap.getNcIdFromAtId(aTblSchema[idx].id);
const formViews = aTblSchema[idx].views.filter(x => x.type === 'form'); const formViews = aTblSchema[idx].views.filter(x => x.type === 'form');
@ -1623,11 +1622,11 @@ export default async (
const gridViews = aTblSchema[idx].views.filter(x => x.type === 'grid'); const gridViews = aTblSchema[idx].views.filter(x => x.type === 'grid');
let viewCnt = idx; let viewCnt = idx;
if (syncDB.syncViews) if (syncDB.options.syncViews)
viewCnt = rtc.view.grid + rtc.view.gallery + rtc.view.form; viewCnt = rtc.view.grid + rtc.view.gallery + rtc.view.form;
rtc.view.grid += gridViews.length; rtc.view.grid += gridViews.length;
for (let i = 0; i < (sDB.syncViews ? gridViews.length : 1); i++) { for (let i = 0; i < (sDB.options.syncViews ? gridViews.length : 1); i++) {
logDetailed(` Axios fetch view-data`); logDetailed(` Axios fetch view-data`);
// fetch viewData JSON // fetch viewData JSON
const vData = await getViewData(gridViews[i].id); const vData = await getViewData(gridViews[i].id);
@ -2113,21 +2112,26 @@ export default async (
await nocoCreateLinkToAnotherRecord(aTblSchema); await nocoCreateLinkToAnotherRecord(aTblSchema);
logDetailed('Migrating LTAR columns completed'); logDetailed('Migrating LTAR columns completed');
if (syncDB.options.syncLookup) {
logDetailed(`Configuring Lookup`); logDetailed(`Configuring Lookup`);
// add look-ups // add look-ups
await nocoCreateLookups(aTblSchema); await nocoCreateLookups(aTblSchema);
logDetailed('Migrating Lookup columns completed'); logDetailed('Migrating Lookup columns completed');
}
if (syncDB.options.syncRollup) {
logDetailed('Configuring Rollup'); logDetailed('Configuring Rollup');
// add roll-ups // add roll-ups
await nocoCreateRollup(aTblSchema); await nocoCreateRollup(aTblSchema);
logDetailed('Migrating Rollup columns completed'); logDetailed('Migrating Rollup columns completed');
if (syncDB.options.syncLookup) {
logDetailed('Migrating Lookup form Rollup columns'); logDetailed('Migrating Lookup form Rollup columns');
// lookups for rollup // lookups for rollup
await nocoLookupForRollup(); await nocoLookupForRollup();
logDetailed('Migrating Lookup form Rollup columns completed'); logDetailed('Migrating Lookup form Rollup columns completed');
}
}
logDetailed('Configuring Primary value column'); logDetailed('Configuring Primary value column');
// configure primary values // configure primary values
await nocoSetPrimary(aTblSchema); await nocoSetPrimary(aTblSchema);
@ -2148,7 +2152,7 @@ export default async (
await nocoConfigureGalleryView(syncDB, aTblSchema); await nocoConfigureGalleryView(syncDB, aTblSchema);
logDetailed('Syncing views completed'); logDetailed('Syncing views completed');
if (process_aTblData) { if (syncDB.options.syncData) {
try { try {
// await nc_DumpTableSchema(); // await nc_DumpTableSchema();
const _perfStart = recordPerfStart(); const _perfStart = recordPerfStart();
@ -2254,5 +2258,11 @@ export interface AirtableSyncConfig {
projectId?: string; projectId?: string;
apiKey: string; apiKey: string;
shareId: string; shareId: string;
options: {
syncViews: boolean; syncViews: boolean;
syncData: boolean;
syncRollup: boolean;
syncLookup: boolean;
syncFormula: boolean;
}
} }

Loading…
Cancel
Save