Skip to content

Commit e21f242

Browse files
committed
Revert "feat: add support for foreign resource array columns"
This reverts commit 3bd6064.
1 parent a12e267 commit e21f242

File tree

4 files changed

+8
-46
lines changed

4 files changed

+8
-46
lines changed

adminforth/modules/configValidator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,8 @@ export default class ConfigValidator implements IConfigValidator {
515515
if (col.masked) {
516516
errors.push(`Resource "${res.resourceId}" column "${col.name}" isArray cannot be used for a masked column`);
517517
}
518-
if (col.foreignResource && col.foreignResource.polymorphicResources) {
519-
errors.push(`Resource "${res.resourceId}" column "${col.name}" isArray cannot be used for a polymorphic foreignResource column`);
518+
if (col.foreignResource) {
519+
errors.push(`Resource "${res.resourceId}" column "${col.name}" isArray cannot be used for a foreignResource column`);
520520
}
521521

522522
if (!col.type || col.type !== AdminForthDataTypes.JSON) {

adminforth/modules/restApi.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -675,22 +675,13 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
675675
const targetResource = this.adminforth.config.resources.find((res) => res.resourceId == col.foreignResource.resourceId);
676676
const targetConnector = this.adminforth.connectors[targetResource.dataSource];
677677
const targetResourcePkField = targetResource.columns.find((col) => col.primaryKey).name;
678-
const pksUnique = [...new Set(data.data.reduce((pks, item) => {
679-
if (col.isArray?.enabled) {
680-
if (item[col.name]?.length) {
681-
pks = pks.concat(item[col.name]);
682-
}
683-
} else {
684-
pks.push(item[col.name]);
685-
}
686-
return pks;
687-
}, []))];
678+
const pksUnique = [...new Set(data.data.map((item) => item[col.name]))];
688679
if (pksUnique.length === 0) {
689680
return;
690681
}
691682
const targetData = await targetConnector.getData({
692683
resource: targetResource,
693-
limit: pksUnique.length,
684+
limit: limit,
694685
offset: 0,
695686
filters: [
696687
{
@@ -764,13 +755,7 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
764755
}
765756

766757
data.data.forEach((item) => {
767-
if (col.isArray?.enabled) {
768-
if (item[col.name]?.length) {
769-
item[col.name] = item[col.name].map((i) => targetDataMap[i]);
770-
}
771-
} else {
772-
item[col.name] = targetDataMap[item[col.name]];
773-
}
758+
item[col.name] = targetDataMap[item[col.name]];
774759

775760
if (!item[col.name]) {
776761
if (col.foreignResource && col.foreignResource.polymorphicResources) {

adminforth/spa/src/components/ValueRenderer.vue

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,7 @@
11
<template>
22
<div>
3-
<span
4-
v-if="column.foreignResource"
5-
:class="{'flex flex-wrap': column.isArray?.enabled}"
6-
@click="(e)=>{e.stopPropagation()}"
7-
>
8-
<span
9-
v-if="record[column.name] && column.isArray?.enabled"
10-
v-for="foreignResource in record[column.name]"
11-
class="rounded-md m-0.5 bg-lightAnnouncementBG dark:bg-darkAnnouncementBG text-lightAnnouncementText dark:text-darkAnnouncementText py-0.5 px-2.5 text-sm"
12-
>
13-
<RouterLink
14-
class="font-medium text-lightSidebarText dark:text-darkSidebarText hover:brightness-110 whitespace-nowrap"
15-
:to="{ name: 'resource-show', params: { primaryKey: foreignResource.pk, resourceId: column.foreignResource.resourceId || column.foreignResource.polymorphicResources.find((pr) => pr.whenValue === record[column.foreignResource.polymorphicOn]).resourceId } }"
16-
>
17-
{{ foreignResource.label }}
18-
</RouterLink>
19-
</span>
20-
<RouterLink v-else-if="record[column.name]" class="font-medium text-lightPrimary dark:text-darkPrimary hover:brightness-110 whitespace-nowrap"
3+
<span @click="(e)=>{e.stopPropagation()}" v-if="column.foreignResource">
4+
<RouterLink v-if="record[column.name]" class="font-medium text-lightPrimary dark:text-darkPrimary hover:brightness-110 whitespace-nowrap"
215
:to="{ name: 'resource-show', params: { primaryKey: record[column.name].pk, resourceId: column.foreignResource.resourceId || column.foreignResource.polymorphicResources.find((pr) => pr.whenValue === record[column.foreignResource.polymorphicOn]).resourceId } }">
226
{{ record[column.name].label }}
237
</RouterLink>

dev-demo/resources/apartments.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -223,16 +223,9 @@ export default {
223223
{
224224
name: "room_sizes",
225225
type: AdminForthDataTypes.JSON,
226-
// isArray: {
227-
// enabled: true,
228-
// itemType: AdminForthDataTypes.FLOAT,
229-
// },
230226
isArray: {
231227
enabled: true,
232-
itemType: AdminForthDataTypes.STRING,
233-
},
234-
foreignResource: {
235-
resourceId: "users",
228+
itemType: AdminForthDataTypes.FLOAT,
236229
},
237230
},
238231
{

0 commit comments

Comments
 (0)