Browse Source

fix: lookup column rename issuea

Signed-off-by: Pranav C <61551451+pranavxc@users.noreply.github.com>
pull/401/head
Pranav C 3 years ago
parent
commit
b23d11392e
  1. 6
      packages/nc-gui/components/dynamicStyle.js
  2. 3
      packages/nc-gui/components/project/spreadsheet/mixins/spreadsheet.js
  3. 3
      packages/nc-gui/components/project/spreadsheet/rowsXcDataTable.vue
  4. 15
      packages/nc-gui/components/project/spreadsheet/views/xcGridView.vue
  5. 116
      packages/nocodb/src/lib/noco/common/BaseApiBuilder.ts
  6. 1
      packages/nocodb/src/lib/noco/gql/GqlApiBuilder.ts

6
packages/nc-gui/components/dynamicStyle.js

@ -0,0 +1,6 @@
export default {
name: 'DynamicStyle',
render(createElement) {
return createElement('style', this.$slots.default)
}
}

3
packages/nc-gui/components/project/spreadsheet/mixins/spreadsheet.js

@ -253,6 +253,9 @@ export default {
}
},
watch: {
meta() {
this.mapFieldsAndShowFields()
},
'viewStatus.type'() {
if (!this.loadingMeta || !this.loadingData) {
this.syncDataDebounce(this)

3
packages/nc-gui/components/project/spreadsheet/rowsXcDataTable.vue

@ -941,9 +941,6 @@ export default {
if (col) {
this.$set(this.showFields, col, true)
}
if (this.selectedViewId === tableMeta.id) {
this.columnsWidth = qp.columnsWidth || this.columnsWidth
}
} catch (e) {
}
}

15
packages/nc-gui/components/project/spreadsheet/views/xcGridView.vue

@ -208,11 +208,17 @@
</table>
<div is="style" v-html="style" />
<div is="style" v-html="resizeColStyle" />
<!-- <div is="style" v-html="resizeColStyle" />-->
<dynamic-style>
<template v-if="resizingCol">
[data-col="{{ resizingCol }}"]{min-width:{{ resizingColWidth }};max-width:{{ resizingColWidth }};width:{{ resizingColWidth }};}
</template>
</dynamic-style>
</div>
</template>
<script>
import DynamicStyle from '@/components/dynamicStyle'
import HeaderCell from '@/components/project/spreadsheet/components/headerCell'
import EditableCell from '@/components/project/spreadsheet/components/editableCell'
import EditColumn from '@/components/project/spreadsheet/components/editColumn'
@ -225,6 +231,7 @@ import VirtualHeaderCell from '@/components/project/spreadsheet/components/virtu
export default {
name: 'XcGridView',
components: {
DynamicStyle,
VirtualHeaderCell,
VirtualCell,
TableCell,
@ -299,10 +306,10 @@ export default {
}
return style
},
resizeColStyle() {
return this.resizingCol ? ` [data-col="${this.resizingCol}"]{min-width:${this.resizingColWidth};max-width:${this.resizingColWidth};width:${this.resizingColWidth};}` : ''
}
// resizeColStyle() {
// return this.resizingCol ? ` [data-col="${this.resizingCol}"]{min-width:${this.resizingColWidth};max-width:${this.resizingColWidth};width:${this.resizingColWidth};}` : ''
// }
},
watch: {
data() {

116
packages/nocodb/src/lib/noco/common/BaseApiBuilder.ts

@ -342,10 +342,11 @@ export default abstract class BaseApiBuilder<T extends Noco> implements XcDynami
title: tn
})
let queryParams;
let queryParams: any;
try {
queryParams = JSON.parse(oldModelRow.query_params);
} catch (e) {
queryParams = {}
}
@ -434,7 +435,8 @@ export default abstract class BaseApiBuilder<T extends Noco> implements XcDynami
aclOper.push(async () => this.modifyColumnNameInACL(tn, column.cno, column.cn));
// virtual views param update
for (const qp of virtualViewsParamsArr) {
for (const qp of [queryParams, ...virtualViewsParamsArr]) {
if (!qp) continue
// @ts-ignore
const {filters, sortList, showFields} = qp;
/* update sort field */
@ -533,8 +535,8 @@ export default abstract class BaseApiBuilder<T extends Noco> implements XcDynami
// update lookup columns
this.metas[mm.rtn].v?.forEach(v => {
if (v.lk &&v.lk.ltn === tn && v.lk.lcn === column.cno) {
relationTableMetas.add(this.metas[mm.tn])
if (v.lk && v.lk.ltn === tn && v.lk.lcn === column.cno) {
relationTableMetas.add(this.metas[mm.rtn])
v.lk.lcn = column.cn;
v.lk._lcn = column._cn;
}
@ -626,9 +628,9 @@ export default abstract class BaseApiBuilder<T extends Noco> implements XcDynami
if (newMeta.manyToMany?.length) {
for (const mm of newMeta.manyToMany) {
// filter out lookup columns which maps to current col
this.metas[mm.rtn].v=this.metas[mm.rtn].v?.filter(v => {
this.metas[mm.rtn].v = this.metas[mm.rtn].v?.filter(v => {
if (v.lk && v.lk.ltn === tn && v.lk.lcn === column.cn) {
relationTableMetas.add(this.metas[mm.tn])
relationTableMetas.add(this.metas[mm.rtn])
return false;
}
return true;
@ -668,12 +670,27 @@ export default abstract class BaseApiBuilder<T extends Noco> implements XcDynami
}
}
// update relation tables metadata
for (const relMeta of relationTableMetas) {
await this.xcMeta.metaUpdate(this.projectId, this.dbAlias, 'nc_models', {
meta: JSON.stringify(relMeta)
}, {
title: relMeta.tn
});
this.models[relMeta.tn] = this.getBaseModel(relMeta);
XcCache.del([this.projectId, this.dbAlias, 'table', relMeta.tn].join('::'));
}
await this.xcMeta.metaUpdate(this.projectId, this.dbAlias, 'nc_models', {
meta: JSON.stringify(newMeta),
...(queryParams ? {query_params: JSON.stringify(queryParams)} : {})
}, {
title: tn
});
XcCache.del([this.projectId, this.dbAlias, 'table', tn].join('::'));
this.models[tn] = this.getBaseModel(newMeta);
await this.xcMeta.metaUpdate(this.projectId, this.dbAlias, 'nc_acl', {
acl: JSON.stringify(acl)
@ -691,21 +708,11 @@ export default abstract class BaseApiBuilder<T extends Noco> implements XcDynami
}
this.baseLog(`onTableUpdate : Generating model instance for '%s' table`, tn)
this.models[tn] = this.getBaseModel(newMeta);
await NcHelp.executeOperations(aclOper, this.connectionConfig.client);
// update relation tables metadata
for (const relMeta of relationTableMetas) {
await this.xcMeta.metaUpdate(this.projectId, this.dbAlias, 'nc_models', {
meta: JSON.stringify(relMeta)
}, {
title: relMeta.tn
});
this.models[relMeta.tn] = this.getBaseModel(relMeta);
XcCache.del([this.projectId, this.dbAlias, 'table', relMeta.tn].join('::'));
}
}
@ -903,8 +910,8 @@ export default abstract class BaseApiBuilder<T extends Noco> implements XcDynami
// filter lookup and relation virtual columns
parentMeta.v = parentMeta.v.filter(({mm, ...rest}) => (!mm || !(mm.tn === parent && mm.rtn === child || mm.tn === child && mm.rtn === parent))
// check for lookup
&& !(rest.lk && rest.lk.type === 'mm' && (rest.lk.tn === parent && rest.lk.rtn === child || rest.lk.tn === child && rest.lk.rtn === parent))
// check for lookup
&& !(rest.lk && rest.lk.type === 'mm' && (rest.lk.tn === parent && rest.lk.rtn === child || rest.lk.tn === child && rest.lk.rtn === parent))
)
childMeta.v = childMeta.v.filter(({mm, ...rest}) => (!mm || !(mm.tn === parent && mm.rtn === child || mm.tn === child && mm.rtn === parent))
// check for lookup
@ -945,47 +952,50 @@ export default abstract class BaseApiBuilder<T extends Noco> implements XcDynami
protected initDbDriver(): void {
if (!this.dbDriver) {
if (this.connectionConfig?.connection?.ssl && typeof this.connectionConfig?.connection?.ssl === 'object') {
if (this.connectionConfig.connection.ssl.caFilePath) {
this.connectionConfig.connection.ssl.ca = fs
.readFileSync(this.connectionConfig.connection.ssl.caFilePath)
.toString();
}
if (this.connectionConfig.connection.ssl.keyFilePath) {
this.connectionConfig.connection.ssl.key = fs
.readFileSync(this.connectionConfig.connection.ssl.keyFilePath)
.toString();
}
if (this.connectionConfig.connection.ssl.certFilePath) {
this.connectionConfig.connection.ssl.cert = fs
.readFileSync(this.connectionConfig.connection.ssl.certFilePath)
.toString();
if(this.projectBuilder?.prefix){
this.dbDriver = this.xcMeta.knex
}else {
if (this.connectionConfig?.connection?.ssl && typeof this.connectionConfig?.connection?.ssl === 'object') {
if (this.connectionConfig.connection.ssl.caFilePath) {
this.connectionConfig.connection.ssl.ca = fs
.readFileSync(this.connectionConfig.connection.ssl.caFilePath)
.toString();
}
if (this.connectionConfig.connection.ssl.keyFilePath) {
this.connectionConfig.connection.ssl.key = fs
.readFileSync(this.connectionConfig.connection.ssl.keyFilePath)
.toString();
}
if (this.connectionConfig.connection.ssl.certFilePath) {
this.connectionConfig.connection.ssl.cert = fs
.readFileSync(this.connectionConfig.connection.ssl.certFilePath)
.toString();
}
}
}
const isSqlite = this.connectionConfig.client === 'sqlite3';
this.baseLog(`initDbDriver : initializing db driver first time`)
this.dbDriver = XKnex(isSqlite ?
this.connectionConfig.connection as Knex.Config :
{
...this.connectionConfig, connection: {
...this.connectionConfig.connection,
typeCast(_field, next) {
const res = next();
if (res instanceof Buffer) {
return [...res].map(v => ('00' + v.toString(16)).slice(-2)).join('');
const isSqlite = this.connectionConfig.client === 'sqlite3';
this.baseLog(`initDbDriver : initializing db driver first time`)
this.dbDriver = XKnex(isSqlite ?
this.connectionConfig.connection as Knex.Config :
{
...this.connectionConfig, connection: {
...this.connectionConfig.connection,
typeCast(_field, next) {
const res = next();
if (res instanceof Buffer) {
return [...res].map(v => ('00' + v.toString(16)).slice(-2)).join('');
}
return res;
}
return res;
}
}
} as any);
if (isSqlite) {
this.dbDriver.raw(`PRAGMA journal_mode=WAL;`).then(() => {
})
} as any);
if (isSqlite) {
this.dbDriver.raw(`PRAGMA journal_mode=WAL;`).then(() => {
})
}
}
}
if (!this.sqlClient) {
this.sqlClient = SqlClientFactory.create(this.connectionConfig) as MysqlClient;
// close knex connection in sqlclient and reuse existing connection
this.sqlClient.knex.destroy();

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

@ -77,7 +77,6 @@ export class GqlApiBuilder extends BaseApiBuilder<Noco> implements XcMetaMgr {
super(app, projectBuilder, config, connectionConfig);
this.config = config;
this.connectionConfig = connectionConfig;
this.models = {};
this.resolvers = {};
this.schemas = {};
this.types = {};

Loading…
Cancel
Save