Browse Source

fix: replace view id with view name, view rename bugs, form view bugs

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/642/head
Pranav C 3 years ago
parent
commit
ed3551aa33
  1. 36
      .github/workflows/ci-cd.yml
  2. 7
      packages/nc-gui/components/project/spreadsheet/components/spreadsheetNavDrawer.vue
  3. 3
      packages/nc-gui/components/project/spreadsheet/rowsXcDataTable.vue
  4. 12
      packages/nc-gui/components/project/spreadsheet/views/formView.vue
  5. 3
      packages/nocodb/src/lib/noco/NcProjectBuilder.ts
  6. 14
      packages/nocodb/src/lib/noco/common/BaseApiBuilder.ts
  7. 32
      packages/nocodb/src/lib/noco/meta/NcMetaMgr.ts

36
.github/workflows/ci-cd.yml

@ -9,24 +9,24 @@ on:
branches: [ master ] branches: [ master ]
jobs: jobs:
cypress-run: # cypress-run:
runs-on: ubuntu-20.04 # runs-on: ubuntu-20.04
steps: # steps:
- name: Checkout # - name: Checkout
uses: actions/checkout@v2 # uses: actions/checkout@v2
with: # with:
fetch-depth: 0 # fetch-depth: 0
- name: Check for update # - name: Check for update
run: | # run: |
echo "CHANGED=$([[ $(lerna ls --since ${{github.event.before}} | grep nc-gui) = nc-gui ]] && echo 'OK')" >> $GITHUB_ENV # echo "CHANGED=$([[ $(lerna ls --since ${{github.event.before}} | grep nc-gui) = nc-gui ]] && echo 'OK')" >> $GITHUB_ENV
#
- name: Cypress run # - name: Cypress run
if: ${{ env.CHANGED == 'OK' }} # if: ${{ env.CHANGED == 'OK' }}
uses: cypress-io/github-action@v2 # uses: cypress-io/github-action@v2
with: # with:
start: docker-compose -f ./docker-compose-cypress.yml up -d # start: docker-compose -f ./docker-compose-cypress.yml up -d
wait-on: 'http://localhost:3000' # wait-on: 'http://localhost:3000'
wait-on-timeout: 900 # wait-on-timeout: 900
docker: docker:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:

7
packages/nc-gui/components/project/spreadsheet/components/spreadsheetNavDrawer.vue

@ -695,10 +695,10 @@ export default {
this.clipboardSuccessHandler() this.clipboardSuccessHandler()
}, },
async updateViewName(view, index) { async updateViewName(view, index) {
if (view.title_temp === view.title || !view.edit) { this.$set(view, 'edit', false); return } if (view.title_temp === view.title || !view.edit) { return }
this.$set(view, 'edit', false)
if (this.viewsList.some((v, i) => i !== index && (v.alias || v.title) === view.title_temp)) { if (this.viewsList.some((v, i) => i !== index && (v.alias || v.title) === view.title_temp)) {
this.$toast.info('View name should be unique').goAway(3000) this.$toast.info('View name should be unique').goAway(3000)
this.$set(view, 'edit', false)
return return
} }
try { try {
@ -713,12 +713,12 @@ export default {
} }
await this.sqlOp({ dbAlias: this.nodes.dbAlias }, 'xcVirtualTableRename', { await this.sqlOp({ dbAlias: this.nodes.dbAlias }, 'xcVirtualTableRename', {
id: view.id, id: view.id,
old_title: view.title,
title: view.title_temp, title: view.title_temp,
alias: view.alias, alias: view.alias,
parent_model_title: this.meta._tn parent_model_title: this.meta._tn
}) })
this.$toast.success('View renamed successfully').goAway(3000) this.$toast.success('View renamed successfully').goAway(3000)
this.$set(view, 'edit', false)
} catch (e) { } catch (e) {
this.$toast.error(e.message).goAway(3000) this.$toast.error(e.message).goAway(3000)
} }
@ -738,6 +738,7 @@ export default {
await this.sqlOp({ dbAlias: this.nodes.dbAlias }, 'xcVirtualTableDelete', { await this.sqlOp({ dbAlias: this.nodes.dbAlias }, 'xcVirtualTableDelete', {
id: view.id, id: view.id,
title: view.alias || view.title, title: view.alias || view.title,
view_name: view.alias || view.title,
parent_model_title: this.table parent_model_title: this.table
}) })
this.$toast.success('View deleted successfully').goAway(3000) this.$toast.success('View deleted successfully').goAway(3000)

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

@ -754,7 +754,8 @@ export default {
await this.sqlOp({ dbAlias: this.nodes.dbAlias }, 'xcVirtualTableUpdate', { await this.sqlOp({ dbAlias: this.nodes.dbAlias }, 'xcVirtualTableUpdate', {
id: this.selectedViewId, id: this.selectedViewId,
query_params: queryParams, query_params: queryParams,
tn: this.meta.tn tn: this.meta.tn,
view_name: this.$route.query.view
}) })
} catch (e) { } catch (e) {
// this.$toast.error(e.message).goAway(3000); // this.$toast.error(e.message).goAway(3000);

12
packages/nc-gui/components/project/spreadsheet/views/formView.vue

@ -455,6 +455,9 @@ export default {
return obj return obj
}, },
computed: { computed: {
allColumnsLoc() {
return this.allColumns.filter(c => !hiddenCols.includes(c.cn) && !(c.pk && c.ai) && this.meta.belongsTo.every(bt => c.cn !== bt.cn))
},
isEditable() { isEditable() {
return this._isUIAllowed('editFormView') return this._isUIAllowed('editFormView')
}, },
@ -473,13 +476,13 @@ export default {
}, },
columns: { columns: {
get() { get() {
return this.allColumns.filter(c => this.showFields[c.alias] && !hiddenCols.includes(c.cn)).sort((a, b) => ((this.fieldsOrder.indexOf(a.alias) + 1) || Infinity) - ((this.fieldsOrder.indexOf(b.alias) + 1) || Infinity)) return this.allColumnsLoc.filter(c => this.showFields[c.alias] && !hiddenCols.includes(c.cn)).sort((a, b) => ((this.fieldsOrder.indexOf(a.alias) + 1) || Infinity) - ((this.fieldsOrder.indexOf(b.alias) + 1) || Infinity))
}, },
set(val) { set(val) {
const showFields = val.reduce((o, v) => { const showFields = val.reduce((o, v) => {
o[v.alias] = true o[v.alias] = true
return o return o
}, this.allColumns.reduce((o, v) => { }, this.allColumnsLoc.reduce((o, v) => {
o[v.alias] = this.isDbRequired(v) o[v.alias] = this.isDbRequired(v)
return o return o
}, {})) }, {}))
@ -524,9 +527,10 @@ export default {
}, },
methods: { methods: {
addAllColumns() { addAllColumns() {
this.columns = [...this.allColumns.filter(c => !hiddenCols.includes(c.cn))] this.columns = [...this.allColumnsLoc]
}, },
isDbRequired(column) { isDbRequired(column) {
if (hiddenCols.includes(column.cn)) { return true }
let isRequired = (!column.virtual && column.rqd && !column.default && this.meta.belongsTo.every(bt => column.cn !== bt.cn)) || let isRequired = (!column.virtual && column.rqd && !column.default && this.meta.belongsTo.every(bt => column.cn !== bt.cn)) ||
(column.pk && !(column.ai || column.default)) (column.pk && !(column.ai || column.default))
@ -587,7 +591,7 @@ export default {
// if (this.isNew) { // if (this.isNew) {
// todo: add params option in GraphQL // todo: add params option in GraphQL
let data = await this.api.insert(this.localState, { params: { form: this.id } }) let data = await this.api.insert(this.localState, { params: { form: this.$route.query.view } })
data = { ...this.localState, ...data } data = { ...this.localState, ...data }
// save hasmany and manytomany relations from local state // save hasmany and manytomany relations from local state

3
packages/nocodb/src/lib/noco/NcProjectBuilder.ts

@ -186,6 +186,9 @@ export default class NcProjectBuilder {
case 'xcVirtualTableUpdate': case 'xcVirtualTableUpdate':
await curBuilder.onVirtualTableUpdate(data.req.args); await curBuilder.onVirtualTableUpdate(data.req.args);
break; break;
case 'xcVirtualTableRename':
await curBuilder.onVirtualTableRename(data.req.args);
break;
case 'xcVirtualTableCreate': case 'xcVirtualTableCreate':
await curBuilder.loadFormViews(); await curBuilder.loadFormViews();
break; break;

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

@ -1529,7 +1529,8 @@ export default abstract class BaseApiBuilder<T extends Noco>
formView.query_params = formView.query_params =
formView.query_params && JSON.parse(formView.query_params); formView.query_params && JSON.parse(formView.query_params);
} catch (e) {} } catch (e) {}
this.formViews[formView.parent_model_title][formView.id] = formView; // this.formViews[formView.parent_model_title][formView.id] = formView;
this.formViews[formView.parent_model_title][formView.title] = formView;
} }
} }
@ -2435,9 +2436,16 @@ export default abstract class BaseApiBuilder<T extends Noco>
XcCache.del([this.projectId, this.dbAlias, 'table', args.tn].join('::')); XcCache.del([this.projectId, this.dbAlias, 'table', args.tn].join('::'));
// todo: update meta and model // todo: update meta and model
} }
if (args?.query_params?.extraViewParams?.formParams) { if (
this.formViews[args.tn][args.id].query_params = args.query_params; args?.query_params?.extraViewParams?.formParams &&
this.formViews[args.tn]?.[args.view_name]
) {
this.formViews[args.tn][args.view_name].query_params = args.query_params;
}
} }
public async onVirtualTableRename(_args: any) {
await this.loadFormViews();
} }
public getMeta(tableName: string): any { public getMeta(tableName: string): any {

32
packages/nocodb/src/lib/noco/meta/NcMetaMgr.ts

@ -3525,25 +3525,14 @@ export default class NcMetaMgr {
for (const [key, obj] of Object.entries(args.args.nested)) { for (const [key, obj] of Object.entries(args.args.nested)) {
if (fields.includes(key)) { if (fields.includes(key)) {
// const colMeta = meta.v.find(c => c._cn === key);
// if (colMeta.bt) {
// insertObject[colMeta.bt.cn] = obj[colMeta.bt._rcn || colMeta.bt.rcn];
// } else if (colMeta.hm) {
// // todo:
insertObject[key] = obj; insertObject[key] = obj;
// } else if (colMeta.mm) {
// // todo:
// insertObject[key] = obj;
// }
} }
} }
const model = apiBuilder?.xcModels?.[viewMeta.model_name]; const model = apiBuilder?.xcModels?.[viewMeta.model_name];
if (model) { if (model) {
req.query.form = queryParams?.selectedViewId; req.query.form = viewMeta.view_name;
await model.nestedInsert(insertObject, null, req); await model.nestedInsert(insertObject, null, req);
// todo: map nested data
} }
} }
@ -4305,6 +4294,19 @@ export default class NcMetaMgr {
args.args.id args.args.id
); );
await this.xcMeta.metaUpdate(
projectId,
dbAlias,
'nc_shared_views',
{
view_name: args.args.title
},
{
view_name: args.args.old_title,
model_name: args.args.parent_model_title
}
);
this.xcMeta.audit(projectId, dbAlias, 'nc_audit', { this.xcMeta.audit(projectId, dbAlias, 'nc_audit', {
op_type: 'TABLE_VIEW', op_type: 'TABLE_VIEW',
op_sub_type: 'RENAMED', op_sub_type: 'RENAMED',
@ -4396,6 +4398,12 @@ export default class NcMetaMgr {
parent_model_title: args.args.parent_model_title, parent_model_title: args.args.parent_model_title,
id: args.args.id id: args.args.id
}); });
await this.xcMeta.metaDelete(projectId, dbAlias, 'nc_shared_views', {
model_name: args.args.parent_model_title,
view_name: args.args.view_name
});
this.xcMeta.audit(projectId, dbAlias, 'nc_audit', { this.xcMeta.audit(projectId, dbAlias, 'nc_audit', {
op_type: 'TABLE_VIEW', op_type: 'TABLE_VIEW',
op_sub_type: 'DELETED', op_sub_type: 'DELETED',

Loading…
Cancel
Save