Browse Source

chore: lint

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5030/head
Pranav C 2 years ago
parent
commit
14a2843927
  1. 4
      packages/nocodb/src/lib/meta/api/helpers/index.ts
  2. 2
      packages/nocodb/src/lib/models/GridViewColumn.ts
  3. 13
      packages/nocodb/src/lib/models/Model.ts
  4. 109
      packages/nocodb/src/lib/models/View.ts
  5. 50
      packages/nocodb/src/lib/version-upgrader/ncStickyColumnUpgrader.ts

4
packages/nocodb/src/lib/meta/api/helpers/index.ts

@ -1,3 +1,3 @@
import { populateMeta } from "./populateMeta";
import { populateMeta } from './populateMeta';
export { populateMeta }
export { populateMeta };

2
packages/nocodb/src/lib/models/GridViewColumn.ts

@ -108,7 +108,7 @@ export default class GridViewColumn implements GridColumnType {
[column.fk_view_id],
`${CacheScope.GRID_VIEW_COLUMN}:${id}`
);
await View.fixPVColumnForView(column.fk_view_id, ncMeta);
return this.get(id, ncMeta);

13
packages/nocodb/src/lib/models/Model.ts

@ -606,11 +606,16 @@ export default class Model implements TableType {
newPvCol.id
);
const grid_views_with_column = await ncMeta.metaList2(null, null, MetaTable.GRID_VIEW_COLUMNS, {
condition: {
fk_column_id: newPvCol.id,
const grid_views_with_column = await ncMeta.metaList2(
null,
null,
MetaTable.GRID_VIEW_COLUMNS,
{
condition: {
fk_column_id: newPvCol.id,
},
}
})
);
if (grid_views_with_column.length) {
for (const gv of grid_views_with_column) {

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

@ -633,16 +633,26 @@ export default class View implements ViewType {
// keep primary_value_column always visible and first in grid view
if (view.type === ViewTypes.GRID) {
const primary_value_column_meta = await ncMeta.metaGet2(null, null, MetaTable.COLUMNS, {
fk_model_id: view.fk_model_id,
pv: true,
});
const primary_value_column_meta = await ncMeta.metaGet2(
null,
null,
MetaTable.COLUMNS,
{
fk_model_id: view.fk_model_id,
pv: true,
}
);
const primary_value_column = await ncMeta.metaGet2(
null,
null,
MetaTable.GRID_VIEW_COLUMNS,
{
fk_view_id: view.id,
fk_column_id: primary_value_column_meta.id,
}
);
const primary_value_column = await ncMeta.metaGet2(null, null, MetaTable.GRID_VIEW_COLUMNS, {
fk_view_id: view.id,
fk_column_id: primary_value_column_meta.id,
});
if (primary_value_column && primary_value_column.id === colId) {
updateObj.order = 1;
updateObj.show = true;
@ -1108,14 +1118,19 @@ export default class View implements ViewType {
const scope = this.extractViewColumnsTableNameScope(view);
if (view.type === ViewTypes.GRID) {
const primary_value_column = await ncMeta.metaGet2(null, null, MetaTable.COLUMNS, {
fk_model_id: view.fk_model_id,
pv: true,
})
const primary_value_column = await ncMeta.metaGet2(
null,
null,
MetaTable.COLUMNS,
{
fk_model_id: view.fk_model_id,
pv: true,
}
);
// keep primary_value_column always visible
if (primary_value_column) {
ignoreColdIds.push(primary_value_column.id)
ignoreColdIds.push(primary_value_column.id);
}
}
@ -1179,27 +1194,41 @@ export default class View implements ViewType {
static async fixPVColumnForView(viewId, ncMeta = Noco.ncMeta) {
// get a list of view columns sorted by order
const view_columns = await ncMeta.metaList2(null, null, MetaTable.GRID_VIEW_COLUMNS, {
condition: {
fk_view_id: viewId,
},
orderBy: {
order: 'asc',
},
});
const view_columns_meta = []
const view_columns = await ncMeta.metaList2(
null,
null,
MetaTable.GRID_VIEW_COLUMNS,
{
condition: {
fk_view_id: viewId,
},
orderBy: {
order: 'asc',
},
}
);
const view_columns_meta = [];
// get column meta for each view column
for (const col of view_columns) {
const col_meta = await ncMeta.metaGet2(null, null, MetaTable.COLUMNS, col.fk_column_id);
const col_meta = await ncMeta.metaGet2(
null,
null,
MetaTable.COLUMNS,
col.fk_column_id
);
view_columns_meta.push(col_meta);
}
const primary_value_column_meta = view_columns_meta.find((col) => col.pv);
if (primary_value_column_meta) {
const primary_value_column = view_columns.find((col) => col.fk_column_id === primary_value_column_meta.id);
const primary_value_column_index = view_columns.findIndex((col) => col.fk_column_id === primary_value_column_meta.id);
const primary_value_column = view_columns.find(
(col) => col.fk_column_id === primary_value_column_meta.id
);
const primary_value_column_index = view_columns.findIndex(
(col) => col.fk_column_id === primary_value_column_meta.id
);
const view_orders = view_columns.map((col) => col.order);
const view_min_order = Math.min(...view_orders);
@ -1210,7 +1239,7 @@ export default class View implements ViewType {
null,
MetaTable.GRID_VIEW_COLUMNS,
{ show: true },
primary_value_column.id,
primary_value_column.id
);
await NocoCache.set(
`${CacheScope.GRID_VIEW_COLUMN}:${primary_value_column.id}`,
@ -1218,7 +1247,10 @@ export default class View implements ViewType {
);
}
if (primary_value_column.order === view_min_order && view_orders.filter((o) => o === view_min_order).length === 1) {
if (
primary_value_column.order === view_min_order &&
view_orders.filter((o) => o === view_min_order).length === 1
) {
// if primary_value_column is in first order do nothing
return;
} else {
@ -1245,14 +1277,19 @@ export default class View implements ViewType {
}
}
const views = await ncMeta.metaList2(null, null, MetaTable.GRID_VIEW_COLUMNS, {
condition: {
fk_view_id: viewId,
},
orderBy: {
order: 'asc',
},
});
const views = await ncMeta.metaList2(
null,
null,
MetaTable.GRID_VIEW_COLUMNS,
{
condition: {
fk_view_id: viewId,
},
orderBy: {
order: 'asc',
},
}
);
await NocoCache.setList(CacheScope.GRID_VIEW_COLUMN, [viewId], views);
}
}

50
packages/nocodb/src/lib/version-upgrader/ncStickyColumnUpgrader.ts

@ -6,32 +6,47 @@ import { MetaTable } from '../utils/globals';
// this upgrader will make primary value column first column in grid views
export default async function ({ ncMeta }: NcUpgraderCtx) {
const grid_columns = await ncMeta.metaList2(null, null, MetaTable.GRID_VIEW_COLUMNS);
const grid_views = [...new Set(grid_columns.map((col) => col.fk_view_id))]
const grid_columns = await ncMeta.metaList2(
null,
null,
MetaTable.GRID_VIEW_COLUMNS
);
const grid_views = [...new Set(grid_columns.map((col) => col.fk_view_id))];
for (const view_id of grid_views) {
// get a list of view columns sorted by order
const view_columns = await ncMeta.metaList2(null, null, MetaTable.GRID_VIEW_COLUMNS, {
condition: {
fk_view_id: view_id,
},
orderBy: {
order: 'asc',
},
});
const view_columns_meta = []
const view_columns = await ncMeta.metaList2(
null,
null,
MetaTable.GRID_VIEW_COLUMNS,
{
condition: {
fk_view_id: view_id,
},
orderBy: {
order: 'asc',
},
}
);
const view_columns_meta = [];
// get column meta for each view column
for (const col of view_columns) {
const col_meta = await ncMeta.metaGet(null, null, MetaTable.COLUMNS, { id: col.fk_column_id });
const col_meta = await ncMeta.metaGet(null, null, MetaTable.COLUMNS, {
id: col.fk_column_id,
});
view_columns_meta.push(col_meta);
}
const primary_value_column_meta = view_columns_meta.find((col) => col.pv);
if (primary_value_column_meta) {
const primary_value_column = view_columns.find((col) => col.fk_column_id === primary_value_column_meta.id);
const primary_value_column_index = view_columns.findIndex((col) => col.fk_column_id === primary_value_column_meta.id);
const primary_value_column = view_columns.find(
(col) => col.fk_column_id === primary_value_column_meta.id
);
const primary_value_column_index = view_columns.findIndex(
(col) => col.fk_column_id === primary_value_column_meta.id
);
const view_orders = view_columns.map((col) => col.order);
const view_min_order = Math.min(...view_orders);
@ -42,11 +57,14 @@ export default async function ({ ncMeta }: NcUpgraderCtx) {
null,
MetaTable.GRID_VIEW_COLUMNS,
{ show: true },
primary_value_column.id,
primary_value_column.id
);
}
if (primary_value_column.order === view_min_order && view_orders.filter((o) => o === view_min_order).length === 1) {
if (
primary_value_column.order === view_min_order &&
view_orders.filter((o) => o === view_min_order).length === 1
) {
// if primary_value_column is in first order do nothing
continue;
} else {

Loading…
Cancel
Save