Browse Source

fix(api): add view column if missing in view columns table

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/3310/head
Pranav C 2 years ago
parent
commit
879267cd4d
  1. 4
      packages/nocodb/src/lib/meta/api/swagger/helpers/getSwaggerJSON.ts
  2. 82
      packages/nocodb/src/lib/models/View.ts

4
packages/nocodb/src/lib/meta/api/swagger/helpers/getSwaggerJSON.ts

@ -1,3 +1,5 @@
import FormViewColumn from '../../../../models/FormViewColumn';
import GalleryViewColumn from '../../../../models/GalleryViewColumn';
import Noco from '../../../../Noco'; import Noco from '../../../../Noco';
import Model from '../../../../models/Model'; import Model from '../../../../models/Model';
import swaggerBase from './swagger-base.json'; import swaggerBase from './swagger-base.json';
@ -62,5 +64,5 @@ export default async function getSwaggerJSON(
export interface SwaggerView { export interface SwaggerView {
view: View; view: View;
columns: Array<GridViewColumn>; columns: Array<GridViewColumn | GalleryViewColumn | FormViewColumn>;
} }

82
packages/nocodb/src/lib/models/View.ts

@ -468,7 +468,7 @@ export default class View implements ViewType {
static async getColumns( static async getColumns(
viewId: string, viewId: string,
ncMeta = Noco.ncMeta ncMeta = Noco.ncMeta
): Promise<Array<GridViewColumn | any>> { ): Promise<Array<GridViewColumn | FormViewColumn | GalleryViewColumn>> {
let columns: Array<GridViewColumn | any> = []; let columns: Array<GridViewColumn | any> = [];
const view = await this.get(viewId, ncMeta); const view = await this.get(viewId, ncMeta);
@ -497,8 +497,8 @@ export default class View implements ViewType {
viewId: string, viewId: string,
colId: string, colId: string,
colData: { colData: {
order: number; order?: number;
show: boolean; show?: boolean;
}, },
ncMeta = Noco.ncMeta ncMeta = Noco.ncMeta
): Promise<Array<GridViewColumn | any>> { ): Promise<Array<GridViewColumn | any>> {
@ -524,10 +524,7 @@ export default class View implements ViewType {
cacheScope = CacheScope.FORM_VIEW_COLUMN; cacheScope = CacheScope.FORM_VIEW_COLUMN;
break; break;
} }
const updateObj = { const updateObj = extractProps(colData, ['order', 'show']);
order: colData.order,
show: colData.show,
};
// get existing cache // get existing cache
const key = `${cacheScope}:${colId}`; const key = `${cacheScope}:${colId}`;
let o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT); let o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
@ -886,6 +883,15 @@ export default class View implements ViewType {
const view = await this.get(viewId); const view = await this.get(viewId);
const table = this.extractViewColumnsTableName(view); const table = this.extractViewColumnsTableName(view);
const scope = this.extractViewColumnsTableNameScope(view); const scope = this.extractViewColumnsTableNameScope(view);
const columns = await view
.getModel(ncMeta)
.then((meta) => meta.getColumns());
const viewColumns = await this.getColumns(viewId, ncMeta);
const availableColumnsInView = viewColumns.map(
(column) => column.fk_column_id
);
// get existing cache // get existing cache
const dataList = await NocoCache.getList(scope, [viewId]); const dataList = await NocoCache.getList(scope, [viewId]);
if (dataList?.length) { if (dataList?.length) {
@ -898,24 +904,50 @@ export default class View implements ViewType {
} }
} }
} }
return await ncMeta.metaUpdate(
null, // insert or update view column
null, for (const col of columns) {
table, const colIndex = availableColumnsInView.indexOf(col.id);
{ show: true }, if (colIndex > -1) {
{ await this.updateColumn(
fk_view_id: viewId, viewId,
}, viewColumns[colIndex].id,
ignoreColdIds?.length { show: true },
? { ncMeta
_not: { );
fk_column_id: { } else {
in: ignoreColdIds, await this.insertColumn(
}, {
}, view_id: viewId,
} order: await ncMeta.metaGetNextOrder(table, {
: null fk_view_id: viewId,
); }),
show: true,
fk_column_id: col.id,
},
ncMeta
);
}
// return await ncMeta.metaUpdate(
// null,
// null,
// table,
// { show: true },
// {
// fk_view_id: viewId,
// },
// ignoreColdIds?.length
// ? {
// _not: {
// fk_column_id: {
// in: ignoreColdIds,
// },
// },
// }
// : null
// );
}
} }
static async hideAllColumns( static async hideAllColumns(

Loading…
Cancel
Save