Browse Source

fix(gui): show cusstom icon in meta diff

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/4630/head
Pranav C 2 years ago
parent
commit
ee2a1e6adb
  1. 12
      packages/nc-gui/components/dashboard/settings/Metadata.vue
  2. 57
      packages/nocodb/src/lib/meta/api/metaDiffApis.ts

12
packages/nc-gui/components/dashboard/settings/Metadata.vue

@ -97,7 +97,6 @@ const columns = [
</div> </div>
</a-button> </a-button>
</div> </div>
<div class="max-h-600px overflow-y-auto"> <div class="max-h-600px overflow-y-auto">
<a-table <a-table
class="w-full" class="w-full"
@ -116,6 +115,17 @@ const columns = [
<template #emptyText> <template #emptyText>
<a-empty :image="Empty.PRESENTED_IMAGE_SIMPLE" :description="$t('labels.noData')" /> <a-empty :image="Empty.PRESENTED_IMAGE_SIMPLE" :description="$t('labels.noData')" />
</template> </template>
<template #bodyCell="{ record, column }">
<div v-if="column.key === 'table_name'">
<div class="flex items-center gap-1">
<div class="min-w-5 flex items-center justify-center">
<GeneralTableIcon :meta="record" class="text-gray-500"></GeneralTableIcon>
</div>
<span class="overflow-ellipsis min-w-0 shrink-1">{{ record.table_name }}</span>
</div>
</div>
</template>
</a-table> </a-table>
</div> </div>
</div> </div>

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

@ -44,6 +44,7 @@ type MetaDiff = {
table_name: string; table_name: string;
base_id: string; base_id: string;
type: ModelTypes; type: ModelTypes;
meta?: any;
detectedChanges: Array<MetaDiffChange>; detectedChanges: Array<MetaDiffChange>;
}; };
@ -176,6 +177,7 @@ async function getMetaDiff(
const tableProp: MetaDiff = { const tableProp: MetaDiff = {
title: oldMeta.title, title: oldMeta.title,
meta: oldMeta.meta,
table_name: table.tn, table_name: table.tn,
base_id: base.id, base_id: base.id,
type: ModelTypes.TABLE, type: ModelTypes.TABLE,
@ -248,6 +250,7 @@ async function getMetaDiff(
for (const model of oldTableMetas) { for (const model of oldTableMetas) {
changes.push({ changes.push({
table_name: model.table_name, table_name: model.table_name,
meta: model.meta,
base_id: base.id, base_id: base.id,
type: ModelTypes.TABLE, type: ModelTypes.TABLE,
detectedChanges: [ detectedChanges: [
@ -452,6 +455,7 @@ async function getMetaDiff(
const tableProp: MetaDiff = { const tableProp: MetaDiff = {
title: oldMeta.title, title: oldMeta.title,
meta: oldMeta.meta,
table_name: view.tn, table_name: view.tn,
base_id: base.id, base_id: base.id,
type: ModelTypes.VIEW, type: ModelTypes.VIEW,
@ -520,6 +524,7 @@ async function getMetaDiff(
for (const model of oldViewMetas) { for (const model of oldViewMetas) {
changes.push({ changes.push({
table_name: model.table_name, table_name: model.table_name,
meta: model.meta,
base_id: base.id, base_id: base.id,
type: ModelTypes.TABLE, type: ModelTypes.TABLE,
detectedChanges: [ detectedChanges: [
@ -539,7 +544,7 @@ async function getMetaDiff(
export async function metaDiff(req, res) { export async function metaDiff(req, res) {
const project = await Project.getWithInfo(req.params.projectId); const project = await Project.getWithInfo(req.params.projectId);
let changes = [] let changes = [];
for (const base of project.bases) { for (const base of project.bases) {
try { try {
// @ts-ignore // @ts-ignore
@ -556,7 +561,7 @@ export async function metaDiff(req, res) {
export async function baseMetaDiff(req, res) { export async function baseMetaDiff(req, res) {
const project = await Project.getWithInfo(req.params.projectId); const project = await Project.getWithInfo(req.params.projectId);
const base = await Base.get(req.params.baseId); const base = await Base.get(req.params.baseId);
let changes = [] let changes = [];
const sqlClient = NcConnectionMgrv2.getSqlClient(base); const sqlClient = NcConnectionMgrv2.getSqlClient(base);
changes = await getMetaDiff(sqlClient, project, base); changes = await getMetaDiff(sqlClient, project, base);
@ -572,10 +577,10 @@ export async function metaDiffSync(req, res) {
// @ts-ignore // @ts-ignore
const sqlClient = NcConnectionMgrv2.getSqlClient(base); const sqlClient = NcConnectionMgrv2.getSqlClient(base);
const changes = await getMetaDiff(sqlClient, project, base); const changes = await getMetaDiff(sqlClient, project, base);
/* Get all relations */ /* Get all relations */
// const relations = (await sqlClient.relationListAll())?.data?.list; // const relations = (await sqlClient.relationListAll())?.data?.list;
for (const { table_name, detectedChanges } of changes) { for (const { table_name, detectedChanges } of changes) {
// reorder changes to apply relation remove changes // reorder changes to apply relation remove changes
// before column remove to avoid foreign key constraint error // before column remove to avoid foreign key constraint error
@ -585,7 +590,7 @@ export async function metaDiffSync(req, res) {
applyChangesPriorityOrder.indexOf(a.type) applyChangesPriorityOrder.indexOf(a.type)
); );
}); });
for (const change of detectedChanges) { for (const change of detectedChanges) {
switch (change.type) { switch (change.type) {
case MetaDiffType.TABLE_NEW: case MetaDiffType.TABLE_NEW:
@ -593,15 +598,19 @@ export async function metaDiffSync(req, res) {
const columns = ( const columns = (
await sqlClient.columnList({ tn: table_name }) await sqlClient.columnList({ tn: table_name })
)?.data?.list?.map((c) => ({ ...c, column_name: c.cn })); )?.data?.list?.map((c) => ({ ...c, column_name: c.cn }));
mapDefaultPrimaryValue(columns); mapDefaultPrimaryValue(columns);
const model = await Model.insert(project.id, base.id, { const model = await Model.insert(project.id, base.id, {
table_name: table_name, table_name: table_name,
title: getTableNameAlias(table_name, base.is_meta ? project.prefix : '', base), title: getTableNameAlias(
table_name,
base.is_meta ? project.prefix : '',
base
),
type: ModelTypes.TABLE, type: ModelTypes.TABLE,
}); });
for (const column of columns) { for (const column of columns) {
await Column.insert({ await Column.insert({
uidt: getColumnUiType(base, column), uidt: getColumnUiType(base, column),
@ -617,15 +626,15 @@ export async function metaDiffSync(req, res) {
const columns = ( const columns = (
await sqlClient.columnList({ tn: table_name }) await sqlClient.columnList({ tn: table_name })
)?.data?.list?.map((c) => ({ ...c, column_name: c.cn })); )?.data?.list?.map((c) => ({ ...c, column_name: c.cn }));
mapDefaultPrimaryValue(columns); mapDefaultPrimaryValue(columns);
const model = await Model.insert(project.id, base.id, { const model = await Model.insert(project.id, base.id, {
table_name: table_name, table_name: table_name,
title: getTableNameAlias(table_name, project.prefix, base), title: getTableNameAlias(table_name, project.prefix, base),
type: ModelTypes.VIEW, type: ModelTypes.VIEW,
}); });
for (const column of columns) { for (const column of columns) {
await Column.insert({ await Column.insert({
uidt: getColumnUiType(base, column), uidt: getColumnUiType(base, column),
@ -657,7 +666,7 @@ export async function metaDiffSync(req, res) {
// update old // update old
// populateParams.tableNames.push({ tn }); // populateParams.tableNames.push({ tn });
// populateParams.oldMetas[tn] = oldMetas.find(m => m.tn === tn); // populateParams.oldMetas[tn] = oldMetas.find(m => m.tn === tn);
break; break;
case MetaDiffType.TABLE_COLUMN_TYPE_CHANGE: case MetaDiffType.TABLE_COLUMN_TYPE_CHANGE:
case MetaDiffType.VIEW_COLUMN_TYPE_CHANGE: case MetaDiffType.VIEW_COLUMN_TYPE_CHANGE:
@ -698,17 +707,21 @@ export async function metaDiffSync(req, res) {
}); });
const parentCol = await parentModel const parentCol = await parentModel
.getColumns() .getColumns()
.then((cols) => cols.find((c) => c.column_name === change.rcn)); .then((cols) =>
cols.find((c) => c.column_name === change.rcn)
);
const childCol = await childModel const childCol = await childModel
.getColumns() .getColumns()
.then((cols) => cols.find((c) => c.column_name === change.cn)); .then((cols) =>
cols.find((c) => c.column_name === change.cn)
);
await Column.update(childCol.id, { await Column.update(childCol.id, {
...childCol, ...childCol,
uidt: UITypes.ForeignKey, uidt: UITypes.ForeignKey,
system: true, system: true,
}); });
if (change.relationType === RelationTypes.BELONGS_TO) { if (change.relationType === RelationTypes.BELONGS_TO) {
const title = getUniqueColumnAliasName( const title = getUniqueColumnAliasName(
childModel.columns, childModel.columns,
@ -746,9 +759,9 @@ export async function metaDiffSync(req, res) {
} }
} }
} }
await NcHelp.executeOperations(virtualColumnInsert, base.type); await NcHelp.executeOperations(virtualColumnInsert, base.type);
// populate m2m relations // populate m2m relations
await extractAndGenerateManyToManyRelations(await base.getModels()); await extractAndGenerateManyToManyRelations(await base.getModels());
} }
@ -784,7 +797,11 @@ export async function baseMetaDiffSync(req, res) {
const model = await Model.insert(project.id, base.id, { const model = await Model.insert(project.id, base.id, {
table_name: table_name, table_name: table_name,
title: getTableNameAlias(table_name, base.is_meta ? project.prefix : '', base), title: getTableNameAlias(
table_name,
base.is_meta ? project.prefix : '',
base
),
type: ModelTypes.TABLE, type: ModelTypes.TABLE,
}); });

Loading…
Cancel
Save