Skip to content

Commit 3cf47a5

Browse files
authored
Merge pull request #526 from devforth/feature/AdminForth/765/fix-typescript-errors
Feature/admin forth/765/fix typescript errors
2 parents 25a2fbb + 770fa7f commit 3cf47a5

23 files changed

+223
-122
lines changed

adminforth/spa/package-lock.json

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

adminforth/spa/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"@tailwindcss/typography": "^0.5.19",
4040
"@tsconfig/node20": "^20.1.4",
4141
"@types/node": "^20.12.5",
42+
"@types/sanitize-html": "^2.16.1",
4243
"@vitejs/plugin-vue": "^5.0.4",
4344
"@vue/eslint-config-typescript": "^13.0.0",
4445
"@vue/tsconfig": "^0.5.1",

adminforth/spa/pnpm-lock.yaml

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

adminforth/spa/src/adminforth.ts

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,13 @@ class FrontendAPI implements FrontendAPIInterface {
1919
public modalStore:any
2020
public filtersStore:any
2121
public coreStore:any
22-
private saveInterceptors: Record<string, Array<(ctx: { action: 'create'|'edit'; values: any; resource: any; resourceId: string; }) => Promise<{ ok: boolean; error?: string | null; extra?: object; }>>> = {};
23-
24-
public list: {
25-
refresh(): Promise<{ error? : string }>;
26-
silentRefresh(): Promise<{ error? : string }>;
27-
silentRefreshRow(pk: any): Promise<{ error? : string }>;
28-
closeThreeDotsDropdown(): Promise<{ error? : string }>;
29-
closeUserMenuDropdown: () => void;
30-
setFilter: (filter: FilterParams) => void;
31-
updateFilter: (filter: FilterParams) => void;
32-
clearFilters: () => void;
33-
}
22+
private saveInterceptors: Record<string, Array<Parameters<FrontendAPIInterface['registerSaveInterceptor']>[0]>> = {};
3423

35-
public menu: {
36-
refreshMenuBadges: () => void;
37-
}
24+
public list: FrontendAPIInterface['list'];
3825

39-
public show: {
40-
refresh(): void;
41-
}
26+
public menu: FrontendAPIInterface['menu'];
27+
28+
public show: FrontendAPIInterface['show'];
4229

4330
closeUserMenuDropdown(): void {
4431
console.log('closeUserMenuDropdown')
@@ -70,9 +57,6 @@ class FrontendAPI implements FrontendAPIInterface {
7057
console.log('closeThreeDotsDropdown')
7158
return { error: 'Not implemented' }
7259
},
73-
closeUserMenuDropdown: () => {
74-
console.log('closeUserMenuDropdown')
75-
},
7660
setFilter: this.setListFilter.bind(this),
7761
updateFilter: this.updateListFilter.bind(this),
7862
clearFilters: this.clearListFilters.bind(this),
@@ -83,11 +67,15 @@ class FrontendAPI implements FrontendAPIInterface {
8367
console.log('show.refresh')
8468
}
8569
}
70+
71+
this.closeUserMenuDropdown = () => {
72+
console.log('closeUserMenuDropdown')
73+
};
8674
}
8775

8876
registerSaveInterceptor(
89-
handler: (ctx: { action: 'create'|'edit'; values: any; resource: any; }) => Promise<{ ok: boolean; error?: string | null; extra?: object; }>,
90-
): void {
77+
handler: Parameters<FrontendAPIInterface['registerSaveInterceptor']>[0]
78+
): ReturnType<FrontendAPIInterface['registerSaveInterceptor']> {
9179
const rid = router.currentRoute.value?.params?.resourceId as string;
9280
if (!rid) {
9381
return;
@@ -98,7 +86,7 @@ class FrontendAPI implements FrontendAPIInterface {
9886
this.saveInterceptors[rid].push(handler);
9987
}
10088

101-
async runSaveInterceptors(params: { action: 'create'|'edit'; values: any; resource: any; resourceId: string; }): Promise<{ ok: boolean; error?: string | null; extra?: object; }> {
89+
async runSaveInterceptors(params: Parameters<FrontendAPIInterface['runSaveInterceptors']>[0]): ReturnType<FrontendAPIInterface['runSaveInterceptors']> {
10290
const list = this.saveInterceptors[params.resourceId] || [];
10391
const aggregatedExtra: Record<string, any> = {};
10492
for (const fn of list) {
@@ -120,15 +108,15 @@ class FrontendAPI implements FrontendAPIInterface {
120108
return { ok: true, extra: aggregatedExtra };
121109
}
122110

123-
clearSaveInterceptors(resourceId?: string): void {
111+
clearSaveInterceptors(resourceId?: Parameters<FrontendAPIInterface['clearSaveInterceptors']>[0]): ReturnType<FrontendAPIInterface['clearSaveInterceptors']> {
124112
if (resourceId) {
125113
delete this.saveInterceptors[resourceId];
126114
} else {
127115
this.saveInterceptors = {};
128116
}
129117
}
130118

131-
confirm(params: ConfirmParams): Promise<boolean> {
119+
confirm(params: Parameters<FrontendAPIInterface['confirm']>[0]): ReturnType<FrontendAPIInterface['confirm']> {
132120
return new Promise((resolve, reject) => {
133121
this.modalStore.setModalContent({
134122
content: params.message,
@@ -142,7 +130,7 @@ class FrontendAPI implements FrontendAPIInterface {
142130
})
143131
}
144132

145-
alert(params: AlertParams): void | Promise<string> | string {
133+
alert(params: Parameters<FrontendAPIInterface['alert']>[0]): ReturnType<FrontendAPIInterface['alert']> {
146134
const toats = {
147135
message: params.message,
148136
messageHtml: params.messageHtml,
@@ -162,14 +150,14 @@ class FrontendAPI implements FrontendAPIInterface {
162150
}
163151
}
164152

165-
listFilterValidation(filter: FilterParams): boolean {
153+
listFilterValidation(filter: Parameters<FrontendAPIInterface['list']['setFilter']>[0]): boolean {
166154
if(router.currentRoute.value.meta.type !== 'list'){
167155
throw new Error(`Cannot use ${this.setListFilter.name} filter on a list page`)
168156
}
169157
return true
170158
}
171159

172-
setListFilter(filter: FilterParams): void {
160+
setListFilter(filter: Parameters<FrontendAPIInterface['list']['setFilter']>[0]): ReturnType<FrontendAPIInterface['list']['setFilter']> {
173161
if(this.listFilterValidation(filter)){
174162
const existingFilterIndex = this.filtersStore.filters.findIndex((f: any) => {
175163
return f.field === filter.field && f.operator === filter.operator

adminforth/spa/src/afcl/Input.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const isIos = coreStore.isIos;
4343
4444
const props = defineProps<{
4545
type: string,
46-
fullWidth: boolean,
46+
fullWidth?: boolean,
4747
modelValue: string,
4848
suffix?: string,
4949
prefix?: string,

adminforth/spa/src/afcl/Select.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,12 @@ import { ref, computed, onMounted, onUnmounted, watch, nextTick,type PropType, t
119119
import { IconCaretDownSolid } from '@iconify-prerendered/vue-flowbite';
120120
import { useElementSize } from '@vueuse/core'
121121
122+
type ISingleSelectModelValue = string | number;
123+
122124
const props = defineProps({
123125
options: Array,
124126
modelValue: {
125-
type: Array as PropType<(string | number)[] | (string | number)>,
127+
type: Array as PropType<(ISingleSelectModelValue)[] | ISingleSelectModelValue>,
126128
default: () => [],
127129
},
128130
multiple: {
@@ -201,7 +203,7 @@ function updateFromProps() {
201203
selectedItems.value = [];
202204
}
203205
} else {
204-
selectedItems.value = props.options?.filter((item: any) => props.modelValue?.includes(item.value)) || [];
206+
selectedItems.value = props.options?.filter((item: any) => (props.modelValue as (ISingleSelectModelValue)[])?.includes(item.value)) || [];
205207
}
206208
}
207209
}

adminforth/spa/src/afcl/Table.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ function sortArrayData(data:any[], sortField?:string, dir:'asc'|'desc'='asc') {
364364
});
365365
}
366366
367-
function tableRowClick(row) {
367+
function tableRowClick(row: any) {
368368
emit("clickTableRow", row)
369369
}
370370
</script>

adminforth/spa/src/components/ColumnValueInputWrapper.vue

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
:unmasked="unmasked"
1717
:deletable="!column.editReadonly"
1818
@update:modelValue="setCurrentValue(column.name, $event, arrayItemIndex)"
19-
@update:recordFieldValue="({ fieldName, fieldValue }: { fieldName: string; fieldValue: any }) => setCurrentValue(fieldName, fieldValue)"
19+
@update:recordFieldValue="recordFieldValueUpdate"
2020
@update:unmasked="$emit('update:unmasked', column.name)"
2121
@update:inValidity="$emit('update:inValidity', { name: column.name, value: $event })"
2222
@update:emptiness="$emit('update:emptiness', { name: column.name, value: $event })"
23-
@delete="setCurrentValue(column.name, currentValues[column.name].filter((_: any, index: any) => index !== arrayItemIndex))"
23+
@delete="deleteHandler(arrayItemIndex)"
2424
/>
2525
</div>
2626
<div class="flex items-center">
@@ -48,7 +48,7 @@
4848
:columnOptions="columnOptions"
4949
:unmasked="unmasked"
5050
@update:modelValue="setCurrentValue(column.name, $event)"
51-
@update:recordFieldValue="({ fieldName, fieldValue }: { fieldName: string; fieldValue: any }) => setCurrentValue(fieldName, fieldValue)"
51+
@update:recordFieldValue="recordFieldValueUpdate"
5252
@update:unmasked="$emit('update:unmasked', column.name)"
5353
@update:inValidity="$emit('update:inValidity', { name: column.name, value: $event })"
5454
@update:emptiness="$emit('update:emptiness', { name: column.name, value: $event })"
@@ -80,4 +80,12 @@
8080
await nextTick();
8181
arrayItemRefs.value[arrayItemRefs.value.length - 1].focus();
8282
}
83+
84+
function recordFieldValueUpdate({ fieldName, fieldValue }: { fieldName: string; fieldValue: any }) {
85+
props.setCurrentValue(fieldName, fieldValue);
86+
}
87+
88+
function deleteHandler(arrayItemIndex: number | string) {
89+
props.setCurrentValue(props.column.name, props.currentValues[props.column.name].filter((_: any, index: any) => index !== arrayItemIndex));
90+
}
8391
</script>

adminforth/spa/src/components/ListActionsThreeDots.vue

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@
5757
{{ $t('Delete item') }}
5858
</button>
5959
</template>
60-
<div v-for="action in (resourceOptions.actions ?? []).filter(a => a.showIn?.listThreeDotsMenu)" :key="action.id" >
60+
<div v-for="action in (resourceOptions.actions ?? []).filter((a: AdminForthActionInput) => a.showIn?.listThreeDotsMenu)" :key="action.id" >
6161
<button class="flex text-nowrap p-1 hover:bg-gray-100 dark:hover:bg-gray-800 w-full text-left px-4 py-2 text-sm text-gray-700 dark:text-gray-300" @click="() => { startCustomAction(action.id, record); showMenu = false; }">
6262
<component
6363
:is="action.customComponent ? getCustomComponent(action.customComponent) : CallActionWrapper"
6464
:meta="action.customComponent?.meta"
6565
:row="record"
66-
:resource="resource"
67-
:adminUser="adminUser"
66+
:resource="coreStore.resource"
67+
:adminUser="coreStore.adminUser"
6868
@callAction="(payload? : Object) => startCustomAction(action.id, record, payload)"
6969
>
7070
<component
@@ -79,8 +79,8 @@
7979
<template v-if="customActionIconsThreeDotsMenuItems">
8080
<component
8181
v-for="c in customActionIconsThreeDotsMenuItems"
82-
:is="getCustomComponent(c)"
83-
:meta="c.meta"
82+
:is="getCustomComponent(formatComponent(c))"
83+
:meta="formatComponent(c).meta"
8484
:resource="coreStore.resource"
8585
:adminUser="coreStore.adminUser"
8686
:record="record"
@@ -100,9 +100,10 @@ import {
100100
IconDotsHorizontalOutline
101101
} from '@iconify-prerendered/vue-flowbite';
102102
import { onMounted, onBeforeUnmount, ref, nextTick, watch } from 'vue';
103-
import { getIcon, getCustomComponent } from '@/utils';
103+
import { getIcon, getCustomComponent, formatComponent } from '@/utils';
104104
import { useCoreStore } from '@/stores/core';
105105
import CallActionWrapper from '@/components/CallActionWrapper.vue'
106+
import { type AdminForthActionInput, type AdminForthComponentDeclaration, type AdminForthComponentDeclarationFull } from '@/types/Common';
106107
107108
const coreStore = useCoreStore();
108109
const showMenu = ref(false);
@@ -113,11 +114,11 @@ const menuStyles = ref<Record<string, string>>({});
113114
const props = defineProps<{
114115
resourceOptions: any;
115116
record: any;
116-
customActionIconsThreeDotsMenuItems: any[];
117+
customActionIconsThreeDotsMenuItems: AdminForthComponentDeclaration[];
117118
resourceId: string;
118119
deleteRecord: (record: any) => void;
119120
updateRecords: () => void;
120-
startCustomAction: (actionId: string, record: any) => void;
121+
startCustomAction: (actionId: string, row: any, extraData?: Record<string, any>) => void;
121122
}>();
122123
123124
onMounted(() => {

0 commit comments

Comments
 (0)