Skip to content

Commit 865d64f

Browse files
committed
feat: update resource handling to exclude backend-only metadata and enhance frontend resource types
1 parent 95af0a2 commit 865d64f

12 files changed

Lines changed: 59 additions & 25 deletions

File tree

adminforth/modules/restApi.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { afLogger } from "./logger.js";
2323
import { ADMINFORTH_VERSION, listify, md5hash, getLoginPromptHTML, hookResponseError } from './utils.js';
2424

2525
import AdminForthAuth from "../auth.js";
26-
import { ActionCheckSource, AdminForthConfigMenuItem, AdminForthDataTypes, AdminForthFilterOperators, AdminForthResourceColumnInputCommon, AdminForthResourceCommon, AdminForthResourcePages,
26+
import { ActionCheckSource, AdminForthConfigMenuItem, AdminForthDataTypes, AdminForthFilterOperators, AdminForthResourceColumnInputCommon, AdminForthResourceFrontend, AdminForthResourcePages,
2727
AdminForthSortDirections,
2828
AdminUser, AllowedActionsEnum, AllowedActionsResolved,
2929
AnnouncementBadgeResponse,
@@ -78,6 +78,11 @@ async function isFilledOnCreate( col: AdminForthResource['columns'][number] ):
7878
return fillOnCreate;
7979
}
8080

81+
function stripResourceColumnFrontendMeta(column: Record<string, any>) {
82+
const { default: _default, _baseTypeDebug, ...sanitizedColumn } = column;
83+
return sanitizedColumn;
84+
}
85+
8186
const SIMPLE_FILTER_OPERATORS = Object.values(AdminForthFilterOperators).filter((operator) => {
8287
return operator !== AdminForthFilterOperators.AND && operator !== AdminForthFilterOperators.OR;
8388
});
@@ -1045,7 +1050,7 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
10451050
description: 'Returns the definition of a single resource. The response includes translated labels, column metadata, allowed actions, visible bulk actions, frontend action metadata, and resource options after permission checks and removal of backend-only internals.',
10461051
request_schema: getResourceRequestSchema,
10471052
response_schema: getResourceResponseSchema,
1048-
handler: async ({ body, adminUser, tr }): Promise<{ resource?: AdminForthResourceCommon, error?: string }> => {
1053+
handler: async ({ body, adminUser, tr }): Promise<{ resource?: AdminForthResourceFrontend, error?: string }> => {
10491054
const { resourceId } = body;
10501055
if (!this.adminforth.statuses.dbDiscover) {
10511056
return { error: 'Database discovery not started' };
@@ -1106,13 +1111,13 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
11061111

11071112

11081113
const toReturn = {
1109-
...resource,
1114+
resourceId: resource.resourceId,
11101115
label: translated.resLabel,
11111116
columns:
11121117
await Promise.all(
11131118
resource.columns.map(
11141119
async (inCol, i) => {
1115-
const col = JSON.parse(JSON.stringify(inCol));
1120+
const col = JSON.parse(JSON.stringify(stripResourceColumnFrontendMeta(inCol)));
11161121
let validation = null;
11171122
if (col.validation) {
11181123
validation = await Promise.all(
@@ -1188,14 +1193,13 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
11881193
),
11891194
actions: resource.options.actions?.map((action) => ({
11901195
...action,
1196+
id: action.id!,
11911197
hasBulkHandler: !!action.bulkHandler,
11921198
bulkHandler: undefined,
11931199
})),
11941200
allowedActions,
11951201
}
11961202
}
1197-
delete toReturn.hooks;
1198-
delete toReturn.plugins;
11991203

12001204
return {
12011205
resource: toReturn,

adminforth/spa/src/components/ResourceForm.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ import { useRouter, useRoute } from 'vue-router';
7676
import { useCoreStore } from "@/stores/core";
7777
import GroupsTable from '@/components/GroupsTable.vue';
7878
import { useI18n } from 'vue-i18n';
79-
import { type AdminForthResourceColumnCommon, type AdminForthResourceCommon } from '@/types/Common';
79+
import { type AdminForthResourceColumnCommon, type AdminForthResourceFrontend } from '@/types/Common';
8080
import { Mutex } from 'async-mutex';
8181
import debounce from 'lodash.debounce';
8282
@@ -88,7 +88,7 @@ const coreStore = useCoreStore();
8888
const router = useRouter();
8989
const route = useRoute();
9090
const props = defineProps<{
91-
resource: AdminForthResourceCommon,
91+
resource: AdminForthResourceFrontend,
9292
record: any,
9393
validatingMode: boolean,
9494
source: 'create' | 'edit',

adminforth/spa/src/components/ResourceListTable.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ import {
363363
} from '@iconify-prerendered/vue-flowbite';
364364
import router from '@/router';
365365
import { Tooltip, Spinner } from '@/afcl';
366-
import type { AdminForthResourceCommon, AdminForthResourceColumnCommon, AdminForthComponentDeclarationFull, AdminForthComponentDeclaration } from '@/types/Common';
366+
import type { AdminForthResourceFrontend, AdminForthResourceColumnCommon, AdminForthComponentDeclarationFull, AdminForthComponentDeclaration } from '@/types/Common';
367367
import { useAdminforth } from '@/adminforth';
368368
import Checkbox from '@/afcl/Checkbox.vue';
369369
import ListActionsThreeDots from '@/components/ListActionsThreeDots.vue';
@@ -374,7 +374,7 @@ const { t } = useI18n();
374374
const { alert, confirm } = useAdminforth();
375375
const props = defineProps<{
376376
page: number,
377-
resource: AdminForthResourceCommon | null,
377+
resource: AdminForthResourceFrontend | null,
378378
rows: any[] | null,
379379
totalRows: number,
380380
pageSize: number,

adminforth/spa/src/components/ShowTable.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
import { getCustomComponent, checkShowIf } from '@/utils';
6565
import { useCoreStore } from '@/stores/core';
6666
import { computed } from 'vue';
67-
import type { AdminForthResourceCommon, AdminForthResourceColumnInputCommon } from '@/types/Common';
67+
import type { AdminForthResourceFrontend, AdminForthResourceColumnInputCommon } from '@/types/Common';
6868
const props = withDefaults(defineProps<{
6969
columns: Array<{
7070
name: string;
@@ -83,7 +83,7 @@
8383
}>;
8484
groupName?: string | null;
8585
noTitle?: boolean;
86-
resource: AdminForthResourceCommon | null;
86+
resource: AdminForthResourceFrontend | null;
8787
record: Record<string, any>;
8888
isRounded?: boolean;
8989
}>(), {

adminforth/spa/src/controls/BoolToggle.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import Toggle from '@/afcl/Toggle.vue';
1313
import type {
1414
AdminForthResourceColumnCommon,
15-
AdminForthResourceCommon,
15+
AdminForthResourceFrontend,
1616
AdminUser,
1717
} from "@/types/Common";
1818
@@ -22,7 +22,7 @@ import type {
2222
column: AdminForthResourceColumnCommon,
2323
record: any,
2424
meta: any,
25-
resource: AdminForthResourceCommon,
25+
resource: AdminForthResourceFrontend,
2626
adminUser: AdminUser,
2727
readonly: boolean
2828
}>();

adminforth/spa/src/renderers/RichText.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
</template>
44

55
<script setup lang="ts">
6-
import type { AdminForthResourceColumnCommon, AdminForthResourceCommon, AdminUser } from '@/types/Common'
6+
import type { AdminForthResourceColumnCommon, AdminForthResourceFrontend, AdminUser } from '@/types/Common'
77
import { protectAgainstXSS } from '@/utils'
88
99
const props = defineProps<{
1010
column: AdminForthResourceColumnCommon
1111
record: any
1212
meta: any
13-
resource: AdminForthResourceCommon
13+
resource: AdminForthResourceFrontend
1414
adminUser: AdminUser
1515
}>()
1616
const htmlContent = protectAgainstXSS(props.record[props.column.name])

adminforth/spa/src/renderers/ZeroStylesRichText.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
<script setup lang="ts">
66
import { nextTick, onMounted, ref, watch } from 'vue'
7-
import type { AdminForthResourceColumnCommon, AdminForthResourceCommon, AdminUser } from '@/types/Common'
7+
import type { AdminForthResourceColumnCommon, AdminForthResourceFrontend, AdminUser } from '@/types/Common'
88
import { protectAgainstXSS } from '@/utils'
99
1010
const props = defineProps<{
1111
column: AdminForthResourceColumnCommon
1212
record: any
1313
meta: any
14-
resource: AdminForthResourceCommon
14+
resource: AdminForthResourceFrontend
1515
adminUser: AdminUser
1616
}>()
1717

adminforth/spa/src/stores/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const useCoreStore = defineStore('core', () => {
4242
return resource.value.columns.filter((col: AdminForthResourceColumnCommon) => col.showIn?.filter);
4343
})
4444

45-
const resourceOptions: Ref<AdminForthResourceCommon['options'] | null> = ref(null);
45+
const resourceOptions: Ref<AdminForthResourceFrontend['options'] | null> = ref(null);
4646
const resourceColumnsError: Ref<string> = ref('');
4747
const resourceColumnsId: Ref<string | null> = ref(null);
4848
const adminUser: Ref<null | AdminUser> = ref(null);

adminforth/spa/src/utils/listUtils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { nextTick, onMounted, ref, resolveComponent } from 'vue';
22
import { callAdminForthApi } from '@/utils';
3-
import { type AdminForthResourceCommon } from '../types/Common';
3+
import { type AdminForthResourceFrontend } from '../types/Common';
44
import { useAdminforth } from '@/adminforth';
55
import { showErrorTost } from '@/composables/useFrontendApi'
66

77
let getResourceDataLastAbortController: AbortController | null = null;
8-
export async function getList(resource: AdminForthResourceCommon, isPageLoaded: boolean, page: number | null , pageSize: number, sort: any, checkboxes:{ value: any[] }, filters: any = [] ) {
8+
export async function getList(resource: AdminForthResourceFrontend, isPageLoaded: boolean, page: number | null , pageSize: number, sort: any, checkboxes:{ value: any[] }, filters: any = [] ) {
99
let rows: any[] = [];
1010
let totalRows: number | null = null;
1111
if (!isPageLoaded) {
@@ -53,7 +53,7 @@ export async function getList(resource: AdminForthResourceCommon, isPageLoaded:
5353

5454

5555

56-
export async function startBulkAction(actionId: string, resource: AdminForthResourceCommon, checkboxes: { value: any[] },
56+
export async function startBulkAction(actionId: string, resource: AdminForthResourceFrontend, checkboxes: { value: any[] },
5757
bulkActionLoadingStates: {value: Record<string, boolean>}, getListInner: () => Promise<any>) {
5858
const action = resource?.options?.bulkActions?.find(a => a.id === actionId);
5959
const { confirm, alert } = useAdminforth();

adminforth/spa/src/utils/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Dropdown } from 'flowbite';
88
import adminforth, { useAdminforth } from '../adminforth';
99
import sanitizeHtml from 'sanitize-html'
1010
import debounce from 'debounce';
11-
import type { AdminForthActionFront, AdminForthResourceColumnInputCommon, AdminForthResourceCommon, Predicate } from '@/types/Common';
11+
import type { AdminForthActionFront, AdminForthResourceColumnInputCommon, AdminForthResourceFrontend, Predicate } from '@/types/Common';
1212
import { i18nInstance } from '../i18n'
1313
import { useI18n } from 'vue-i18n';
1414
import { onBeforeRouteLeave } from 'vue-router';
@@ -779,7 +779,7 @@ export async function executeCustomBulkAction({
779779
onError?: (error: string) => void,
780780
setLoadingState?: (loading: boolean) => void,
781781
confirmMessage?: string,
782-
resource?: AdminForthResourceCommon,
782+
resource?: AdminForthResourceFrontend,
783783
}): Promise<any> {
784784
if (!recordIds || recordIds.length === 0) {
785785
if (onError) {

0 commit comments

Comments
 (0)