Browse Source

chore(nocodb): rename primary value to display value

pull/5117/head
Wing-Kam Wong 2 years ago
parent
commit
99e45839bb
  1. 12
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/conditionV2.ts
  2. 12
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/formulav2/formulaQueryBuilderv2.ts
  3. 2
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/helpers/getAst.ts
  4. 4
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/sortV2.ts
  5. 8
      packages/nocodb/src/lib/db/sql-mgr/code/models/xc/BaseModelXcMeta.ts
  6. 2
      packages/nocodb/src/lib/db/sql-mgr/code/models/xc/ModelXcMetaMssql.ts
  7. 2
      packages/nocodb/src/lib/db/sql-mgr/code/models/xc/ModelXcMetaMysql.ts
  8. 2
      packages/nocodb/src/lib/db/sql-mgr/code/models/xc/ModelXcMetaOracle.ts
  9. 2
      packages/nocodb/src/lib/db/sql-mgr/code/models/xc/ModelXcMetaPg.ts
  10. 2
      packages/nocodb/src/lib/db/sql-mgr/code/models/xc/ModelXcMetaSnowflake.ts
  11. 2
      packages/nocodb/src/lib/db/sql-mgr/code/models/xc/ModelXcMetaSqlite.ts
  12. 10
      packages/nocodb/src/lib/meta/api/columnApis.ts
  13. 2
      packages/nocodb/src/lib/meta/api/dataApis/helpers.ts
  14. 4
      packages/nocodb/src/lib/meta/api/helpers/populateMeta.ts
  15. 10
      packages/nocodb/src/lib/meta/api/metaDiffApis.ts
  16. 2
      packages/nocodb/src/lib/meta/api/publicApis/publicDataExportApis.ts
  17. 4
      packages/nocodb/src/lib/meta/api/tableApis.ts
  18. 2
      packages/nocodb/src/lib/meta/helpers/mapDefaultDisplayValue.ts
  19. 4
      packages/nocodb/src/lib/models/Model.ts
  20. 2
      packages/nocodb/src/lib/utils/common/BaseApiBuilder.ts

12
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/conditionV2.ts

@ -119,7 +119,7 @@ const parseConditionV2 = async (
? negatedMapping[filter.comparison_op]
: {}),
fk_model_id: childModel.id,
fk_column_id: childModel?.primaryValue?.id,
fk_column_id: childModel?.displayValue?.id,
}),
knex,
aliasCount
@ -154,7 +154,7 @@ const parseConditionV2 = async (
? negatedMapping[filter.comparison_op]
: {}),
fk_model_id: parentModel.id,
fk_column_id: parentModel?.primaryValue?.id,
fk_column_id: parentModel?.displayValue?.id,
}),
knex,
aliasCount
@ -209,7 +209,7 @@ const parseConditionV2 = async (
? negatedMapping[filter.comparison_op]
: {}),
fk_model_id: parentModel.id,
fk_column_id: parentModel?.primaryValue?.id,
fk_column_id: parentModel?.displayValue?.id,
}),
knex,
aliasCount
@ -650,7 +650,7 @@ async function nestedConditionJoin(
new Filter({
...filter,
fk_model_id: childModel.id,
fk_column_id: childModel.primaryValue?.id,
fk_column_id: childModel.displayValue?.id,
}),
knex,
aliasCount,
@ -666,7 +666,7 @@ async function nestedConditionJoin(
new Filter({
...filter,
fk_model_id: parentModel.id,
fk_column_id: parentModel?.primaryValue?.id,
fk_column_id: parentModel?.displayValue?.id,
}),
knex,
aliasCount,
@ -682,7 +682,7 @@ async function nestedConditionJoin(
new Filter({
...filter,
fk_model_id: parentModel.id,
fk_column_id: parentModel.primaryValue?.id,
fk_column_id: parentModel.displayValue?.id,
}),
knex,
aliasCount,

12
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/formulav2/formulaQueryBuilderv2.ts

@ -269,7 +269,7 @@ async function _formulaQueryBuilder(
);
cn = knex.raw('??.??', [
nestedAlias,
parentModel?.primaryValue?.column_name,
parentModel?.displayValue?.column_name,
]);
}
break;
@ -283,7 +283,7 @@ async function _formulaQueryBuilder(
);
cn = knex.raw('??.??', [
nestedAlias,
childModel?.primaryValue?.column_name,
childModel?.displayValue?.column_name,
]);
}
break;
@ -311,7 +311,7 @@ async function _formulaQueryBuilder(
}
cn = knex.raw('??.??', [
nestedAlias,
parentModel?.primaryValue?.column_name,
parentModel?.displayValue?.column_name,
]);
}
@ -424,7 +424,7 @@ async function _formulaQueryBuilder(
let selectQb;
if (relation.type === 'bt') {
selectQb = knex(parentModel.table_name)
.select(parentModel?.primaryValue?.column_name)
.select(parentModel?.displayValue?.column_name)
.where(
`${parentModel.table_name}.${parentColumn.column_name}`,
knex.raw(`??`, [
@ -447,7 +447,7 @@ async function _formulaQueryBuilder(
getAggregateFn(fn)({
qb,
knex,
cn: childModel?.primaryValue?.column_name,
cn: childModel?.displayValue?.column_name,
})
)
.wrap('(', ')');
@ -499,7 +499,7 @@ async function _formulaQueryBuilder(
getAggregateFn(fn)({
qb,
knex,
cn: parentModel?.primaryValue?.column_name,
cn: parentModel?.displayValue?.column_name,
})
)
.wrap('(', ')');

2
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/helpers/getAst.ts

@ -24,7 +24,7 @@ const getAst = async ({
...(model.primaryKeys
? model.primaryKeys.reduce((o, pk) => ({ ...o, [pk.title]: 1 }), {})
: {}),
...(model.primaryValue ? { [model.primaryValue.title]: 1 } : {}),
...(model.displayValue ? { [model.displayValue.title]: 1 } : {}),
};
}

4
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/sortV2.ts

@ -153,7 +153,7 @@ export default async function sortV2(
`${nestedAlias}.${parentColumn.column_name}`,
`${prevAlias}.${childColumn.column_name}`
)
.select(parentModel?.primaryValue?.column_name);
.select(parentModel?.displayValue?.column_name);
}
break;
case UITypes.Formula:
@ -201,7 +201,7 @@ export default async function sortV2(
await parentModel.getColumns();
const selectQb = knex(parentModel.table_name)
.select(parentModel?.primaryValue?.column_name)
.select(parentModel?.displayValue?.column_name)
.where(
`${parentModel.table_name}.${parentColumn.column_name}`,
knex.raw(`??`, [

8
packages/nocodb/src/lib/db/sql-mgr/code/models/xc/BaseModelXcMeta.ts

@ -1,5 +1,5 @@
import BaseRender from '../../BaseRender';
import mapDefaultPrimaryValue from '../../../../../meta/helpers/mapDefaultPrimaryValue';
import mapDefaultDisplayValue from '../../../../../meta/helpers/mapDefaultDisplayValue';
import { UITypes } from 'nocodb-sdk';
abstract class BaseModelXcMeta extends BaseRender {
@ -79,7 +79,7 @@ abstract class BaseModelXcMeta extends BaseRender {
columnsArr.push(columnObj);
}
this.mapDefaultPrimaryValue(columnsArr);
this.mapDefaultDisplayValue(columnsArr);
return columnsArr;
}
@ -127,8 +127,8 @@ abstract class BaseModelXcMeta extends BaseRender {
return virtualColumns;
}
public mapDefaultPrimaryValue(columnsArr: any[]): void {
mapDefaultPrimaryValue(columnsArr);
public mapDefaultDisplayValue(columnsArr: any[]): void {
mapDefaultDisplayValue(columnsArr);
}
}

2
packages/nocodb/src/lib/db/sql-mgr/code/models/xc/ModelXcMetaMssql.ts

@ -544,7 +544,7 @@ class ModelXcMetaMssql extends BaseModelXcMeta {
columnsArr.push(columnObj);
}
this.mapDefaultPrimaryValue(columnsArr);
this.mapDefaultDisplayValue(columnsArr);
return columnsArr;
}*/

2
packages/nocodb/src/lib/db/sql-mgr/code/models/xc/ModelXcMetaMysql.ts

@ -163,7 +163,7 @@ class ModelXcMetaMysql extends BaseModelXcMeta {
columnsArr.push(columnObj);
}
this.mapDefaultPrimaryValue(columnsArr);
this.mapDefaultDisplayValue(columnsArr);
return columnsArr;
}
*/

2
packages/nocodb/src/lib/db/sql-mgr/code/models/xc/ModelXcMetaOracle.ts

@ -163,7 +163,7 @@ class ModelXcMetaOracle extends BaseModelXcMeta {
columnsArr.push(columnObj);
}
this.mapDefaultPrimaryValue(columnsArr);
this.mapDefaultDisplayValue(columnsArr);
return columnsArr;
}
*/

2
packages/nocodb/src/lib/db/sql-mgr/code/models/xc/ModelXcMetaPg.ts

@ -953,7 +953,7 @@ class ModelXcMetaPg extends BaseModelXcMeta {
columnsArr.push(columnObj);
}
this.mapDefaultPrimaryValue(columnsArr);
this.mapDefaultDisplayValue(columnsArr);
return columnsArr;
}*/

2
packages/nocodb/src/lib/db/sql-mgr/code/models/xc/ModelXcMetaSnowflake.ts

@ -953,7 +953,7 @@ class ModelXcMetaSnowflake extends BaseModelXcMeta {
columnsArr.push(columnObj);
}
this.mapDefaultPrimaryValue(columnsArr);
this.mapDefaultDisplayValue(columnsArr);
return columnsArr;
}*/

2
packages/nocodb/src/lib/db/sql-mgr/code/models/xc/ModelXcMetaSqlite.ts

@ -504,7 +504,7 @@ class ModelXcMetaSqlite extends BaseModelXcMeta {
columnsArr.push(columnObj);
}
this.mapDefaultPrimaryValue(columnsArr);
this.mapDefaultDisplayValue(columnsArr);
return columnsArr;
}
*/

10
packages/nocodb/src/lib/meta/api/columnApis.ts

@ -31,7 +31,7 @@ import NcMetaIO from '../NcMetaIO';
import ncMetaAclMw from '../helpers/ncMetaAclMw';
import { NcError } from '../helpers/catchError';
import getColumnPropsFromUIDT from '../helpers/getColumnPropsFromUIDT';
import mapDefaultPrimaryValue from '../helpers/mapDefaultPrimaryValue';
import mapDefaultDisplayValue from '../helpers/mapDefaultDisplayValue';
import NcConnectionMgrv2 from '../../utils/common/NcConnectionMgrv2';
import { metaApiMetrics } from '../helpers/apiMetrics';
import FormulaColumn from '../../models/FormulaColumn';
@ -1592,11 +1592,11 @@ export async function columnDelete(req: Request, res: Response<TableType>) {
await table.getColumns();
const primaryValueColumn = mapDefaultPrimaryValue(table.columns);
if (primaryValueColumn) {
const displayValueColumn = mapDefaultDisplayValue(table.columns);
if (displayValueColumn) {
await Model.updatePrimaryColumn(
primaryValueColumn.fk_model_id,
primaryValueColumn.id
displayValueColumn.fk_model_id,
displayValueColumn.id
);
}

2
packages/nocodb/src/lib/meta/api/dataApis/helpers.ts

@ -225,7 +225,7 @@ export async function serializeCellValue({
await relatedModel.getColumns();
return [...(Array.isArray(value) ? value : [value])]
.map((v) => {
return v[relatedModel.primaryValue?.title];
return v[relatedModel.displayValue?.title];
})
.join(', ');
}

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

@ -10,7 +10,7 @@ import getTableNameAlias, {
} from '../../helpers/getTableName';
import LinkToAnotherRecordColumn from '../../../models/LinkToAnotherRecordColumn';
import getColumnUiType from '../../helpers/getColumnUiType';
import mapDefaultPrimaryValue from '../../helpers/mapDefaultPrimaryValue';
import mapDefaultDisplayValue from '../../helpers/mapDefaultDisplayValue';
import { extractAndGenerateManyToManyRelations } from '../metaDiffApis';
import { ModelTypes, UITypes, ViewTypes } from 'nocodb-sdk';
import { IGNORE_TABLES } from '../../../utils/common/BaseApiBuilder';
@ -90,7 +90,7 @@ export async function populateMeta(base: Base, project: Project): Promise<any> {
? []
: tableRelations.filter((r) => r.tn === table.tn);
mapDefaultPrimaryValue(columns);
mapDefaultDisplayValue(columns);
// add vitual columns
const virtualColumns = [

10
packages/nocodb/src/lib/meta/api/metaDiffApis.ts

@ -14,7 +14,7 @@ import LinkToAnotherRecordColumn from '../../models/LinkToAnotherRecordColumn';
import { getUniqueColumnAliasName } from '../helpers/getUniqueName';
import NcHelp from '../../utils/NcHelp';
import getTableNameAlias, { getColumnNameAlias } from '../helpers/getTableName';
import mapDefaultPrimaryValue from '../helpers/mapDefaultPrimaryValue';
import mapDefaultDisplayValue from '../helpers/mapDefaultDisplayValue';
import getColumnUiType from '../helpers/getColumnUiType';
import { metaApiMetrics } from '../helpers/apiMetrics';
@ -602,7 +602,7 @@ export async function metaDiffSync(req, res) {
await sqlClient.columnList({ tn: table_name })
)?.data?.list?.map((c) => ({ ...c, column_name: c.cn }));
mapDefaultPrimaryValue(columns);
mapDefaultDisplayValue(columns);
const model = await Model.insert(project.id, base.id, {
table_name: table_name,
@ -630,7 +630,7 @@ export async function metaDiffSync(req, res) {
await sqlClient.columnList({ tn: table_name })
)?.data?.list?.map((c) => ({ ...c, column_name: c.cn }));
mapDefaultPrimaryValue(columns);
mapDefaultDisplayValue(columns);
const model = await Model.insert(project.id, base.id, {
table_name: table_name,
@ -798,7 +798,7 @@ export async function baseMetaDiffSync(req, res) {
await sqlClient.columnList({ tn: table_name })
)?.data?.list?.map((c) => ({ ...c, column_name: c.cn }));
mapDefaultPrimaryValue(columns);
mapDefaultDisplayValue(columns);
const model = await Model.insert(project.id, base.id, {
table_name: table_name,
@ -826,7 +826,7 @@ export async function baseMetaDiffSync(req, res) {
await sqlClient.columnList({ tn: table_name })
)?.data?.list?.map((c) => ({ ...c, column_name: c.cn }));
mapDefaultPrimaryValue(columns);
mapDefaultDisplayValue(columns);
const model = await Model.insert(project.id, base.id, {
table_name: table_name,

2
packages/nocodb/src/lib/meta/api/publicApis/publicDataExportApis.ts

@ -237,7 +237,7 @@ async function serializeCellValue({
await relatedModel.getColumns();
return [...(Array.isArray(value) ? value : [value])]
.map((v) => {
return v[relatedModel.primaryValue?.title];
return v[relatedModel.displayValue?.title];
})
.join(', ');
}

4
packages/nocodb/src/lib/meta/api/tableApis.ts

@ -20,7 +20,7 @@ import ncMetaAclMw from '../helpers/ncMetaAclMw';
import { xcVisibilityMetaGet } from './modelVisibilityApis';
import View from '../../models/View';
import getColumnPropsFromUIDT from '../helpers/getColumnPropsFromUIDT';
import mapDefaultPrimaryValue from '../helpers/mapDefaultPrimaryValue';
import mapDefaultDisplayValue from '../helpers/mapDefaultDisplayValue';
import { NcError } from '../helpers/catchError';
import getTableNameAlias, { getColumnNameAlias } from '../helpers/getTableName';
import Column from '../../models/Column';
@ -195,7 +195,7 @@ export async function tableCreate(req: Request<any, any, TableReqType>, res) {
ip: (req as any).clientIp,
}).then(() => {});
mapDefaultPrimaryValue(req.body.columns);
mapDefaultDisplayValue(req.body.columns);
Tele.emit('evt', { evt_type: 'table:created' });

2
packages/nocodb/src/lib/meta/helpers/mapDefaultPrimaryValue.ts → packages/nocodb/src/lib/meta/helpers/mapDefaultDisplayValue.ts

@ -1,6 +1,6 @@
import { ColumnType } from 'nocodb-sdk';
export default function mapDefaultPrimaryValue<T extends ColumnType>(
export default function mapDefaultDisplayValue<T extends ColumnType>(
columnsArr: Array<T>
): void | T {
if (!columnsArr.some((column) => column.pv)) {

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

@ -84,7 +84,7 @@ export default class Model implements TableType {
return this.columns?.filter((c) => c.pk);
}
public get primaryValue(): Column {
public get displayValue(): Column {
if (!this.columns) return null;
const pCol = this.columns?.find((c) => c.pv);
if (pCol) return pCol;
@ -561,7 +561,7 @@ export default class Model implements TableType {
ncMeta = Noco.ncMeta
) {
const model = await this.getWithInfo({ id: tableId });
const currentPvCol = model.primaryValue;
const currentPvCol = model.displayValue;
const newPvCol = model.columns.find((c) => c.id === columnId);
if (!newPvCol) NcError.badRequest('Column not found');

2
packages/nocodb/src/lib/utils/common/BaseApiBuilder.ts

@ -2515,7 +2515,7 @@ export default abstract class BaseApiBuilder<T extends Noco>
ModelXcMetaFactory.create(
this.connectionConfig,
{}
).mapDefaultPrimaryValue(meta.columns);
).mapDefaultDisplayValue(meta.columns);
// update meta
await this.xcMeta.metaUpdate(
this.projectId,

Loading…
Cancel
Save