Browse Source

fix: BelongsTo in expanded form

Signed-off-by: Pranav C <61551451+pranavxc@users.noreply.github.com>
pull/341/head
Pranav C 3 years ago
parent
commit
b7157e751e
  1. 4
      packages/nc-gui/components/project/spreadsheet/components/editColumn/linkedToAnotherOptions.vue
  2. 6
      packages/nc-gui/components/project/spreadsheet/components/expandedForm.vue
  3. 16
      packages/nc-gui/components/project/spreadsheet/components/virtualCell/belogsToCell.vue
  4. 2
      packages/nc-gui/components/project/spreadsheet/components/virtualCell/components/listChildItems.vue
  5. 4
      packages/nc-gui/components/project/spreadsheet/components/virtualCell/hasManyCell.vue
  6. 3
      packages/nc-gui/nuxt.config.js
  7. 32
      packages/nocodb/src/lib/noco/gql/GqlApiBuilder.ts

4
packages/nc-gui/components/project/spreadsheet/components/editColumn/linkedToAnotherOptions.vue

@ -147,11 +147,11 @@ export default {
if (this.type === 'mm')
return !(this.meta.manyToMany || [])
.some(mm => mm.tn === v && mm.rtn === this.meta.tn || mm.rtn === v && mm.tn === this.meta.tn)
|| 'Duplicate relation is not allowed at the moment';
|| 'Duplicate many to many relation is not allowed at the moment';
if (this.type === 'hm')
return !(this.meta.hasMany || [])
.some(hm => hm.tn === v)
|| 'Duplicate relation is not allowed at the moment';
|| 'Duplicate has many relation is not allowed at the moment';
},
]
}

6
packages/nc-gui/components/project/spreadsheet/components/expandedForm.vue

@ -77,7 +77,7 @@
v-if="col.virtual"
:disabledColumns="disabledColumns"
:column="col"
:row="value"
:row="localState"
:nodes="nodes"
:meta="meta"
:api="api"
@ -87,7 +87,7 @@
:is-form="true"
:breadcrumbs="localBreadcrumbs"
@updateCol="updateCol"
@newRecordsSaved="$listeners.loadTableData || (() => {})"
@newRecordsSaved="$listeners.loadTableData|| reload"
></virtual-cell>
<div
@ -357,7 +357,7 @@ export default {
},
async reload() {
// const id = this.meta.columns.filter((c) => c.pk).map(c => this.localState[c._cn]).join('___');
const where = this.meta.columns.filter((c) => c.pk).map(c => `(${c._cn},eq,${this.localState[c._cn]})`).join('~and');
const where = this.meta.columns.filter((c) => c.pk).map(c => `(${c._cn},eq,${this.value[c._cn]})`).join('~and');
this.$set(this, 'changedColumns', {});
// this.localState = await this.api.read(id);
const data = await this.api.list({...(this.queryParams || {}), where}) || [{}];

16
packages/nc-gui/components/project/spreadsheet/components/virtualCell/belogsToCell.vue

@ -21,6 +21,7 @@
</div>
</template>
<list-items
:key="parentId"
v-if="newRecordModal"
:size="10"
:meta="parentMeta"
@ -29,7 +30,7 @@
v-model="newRecordModal"
:api="parentApi"
@add-new-record="insertAndMapNewParentRecord"
@add="addParentToChild"
@add="addChildToParent"
:query-params="parentQueryParams"
/>
@ -52,7 +53,7 @@
@new-record="showNewRecordModal"
@edit="editParent"
@unlink="unlink"
:bt="true"
:bt="value"
/>
<v-dialog
@ -133,6 +134,7 @@ export default {
isNewParent: false,
expandFormModal: false,
localState: null,
pid: null
}),
async mounted() {
if (this.isForm) {
@ -142,7 +144,7 @@ export default {
methods: {
async onParentSave(parent) {
if (this.isNewParent) {
await this.addParentToChild(parent)
await this.addChildToParent(parent)
} else {
this.$emit('loadTableData')
}
@ -193,6 +195,7 @@ export default {
} else {
const id = this.parentMeta.columns.filter((c) => c.pk).map(c => child[c._cn]).join('___');
await this.parentApi.delete(id)
this.pid = null;
this.dialogShow = false;
this.$emit('loadTableData')
if (this.isForm && this.$refs.childList) {
@ -222,7 +225,7 @@ export default {
await this.loadParentMeta();
this.newRecordModal = true;
},
async addParentToChild(parent) {
async addChildToParent(parent) {
const pid = this.parentMeta.columns.filter((c) => c.pk).map(c => parent[c._cn]).join('___');
const id = this.meta.columns.filter((c) => c.pk).map(c => this.row[c._cn]).join('___');
@ -238,8 +241,9 @@ export default {
await this.api.update(id, {
[_cn]: +pid
}, {
[_cn]: parent[this.parentPrimaryKey]
[_cn]: this.value && this.value[this.parentPrimaryKey]
});
this.pid = pid;
this.newRecordModal = false;
@ -268,7 +272,7 @@ export default {
this.parentMeta && this.parentMeta._tn, this.parentMeta && this.parentMeta.columns, this, this.parentMeta) : null;
},
parentId() {
return this.value && this.parentMeta && this.parentMeta.columns.filter((c) => c.pk).map(c => this.value[c._cn]).join('___')
return this.pid ?? (this.value && this.parentMeta && this.parentMeta.columns.filter((c) => c.pk).map(c => this.value[c._cn]).join('___'))
},
parentPrimaryCol() {
return this.parentMeta && (this.parentMeta.columns.find(c => c.pv) || {})._cn

2
packages/nc-gui/components/project/spreadsheet/components/virtualCell/components/listChildItems.vue

@ -108,7 +108,7 @@ export default {
components: {Pagination},
props: {
isForm: Boolean,
bt: Boolean,
bt: Object,
localState: [Array],
isNew: Boolean,
value: Boolean,

4
packages/nc-gui/components/project/spreadsheet/components/virtualCell/hasManyCell.vue

@ -163,9 +163,7 @@ export default {
localState: []
}),
async mounted() {
if (this.isForm) {
await this.loadChildMeta()
}
await this.loadChildMeta()
},
methods: {
async showChildListModal() {

3
packages/nc-gui/nuxt.config.js

@ -127,6 +127,9 @@ export default {
publicPath: process.env.NODE_ENV === 'production' ? `./_nuxt/` : undefined,
extend(config, {isDev, isClient}) {
if (isDev) {
config.devtool = isClient ? 'source-map' : 'inline-source-map'
}
config.externals = config.externals || {};
config.externals ['@microsoft/typescript-etw'] = 'FakeModule';

32
packages/nocodb/src/lib/noco/gql/GqlApiBuilder.ts

@ -1886,6 +1886,38 @@ export class GqlApiBuilder extends BaseApiBuilder<Noco> implements XcMetaMgr {
await this.reInitializeGraphqlEndpoint();
}
protected async ncUpManyToMany(): Promise<any> {
const metas = await super.ncUpManyToMany();
if (!metas) {
return;
}
for (const meta of metas) {
const ctx = this.generateContextForTable(meta.tn, meta.columns, [], meta.hasMany, meta.belongsTo, meta.type, meta._tn);
/* generate gql schema of the table */
const schema = GqlXcSchemaFactory.create(this.connectionConfig, {
dir: '',
ctx,
filename: ''
}).getString();
/* update schema in metadb */
await this.xcMeta.metaUpdate(this.projectId, this.dbAlias, 'nc_models', {
schema
}, {
title: meta.tn
})
// todo : add loaders
}
}
}
/**

Loading…
Cancel
Save