Skip to content

Commit 6aeddde

Browse files
committed
chore: correct type location for the "baseActionsAsQuickIcons" and remove difference in types and classes for the resource list tables
1 parent 159c403 commit 6aeddde

File tree

4 files changed

+39
-36
lines changed

4 files changed

+39
-36
lines changed

adminforth/spa/src/components/ResourceListTable.vue

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<div class="h-2 bg-lightListSkeletLoader rounded-full dark:bg-darkListSkeletLoader max-w-[360px]"></div>
1111
</div>
1212
</div>
13-
<table v-else class=" w-full text-sm text-left rtl:text-right text-lightListTableText dark:text-darkListTableText rounded-default">
13+
<table v-else class="w-full text-sm text-left rtl:text-right text-lightListTableText dark:text-darkListTableText rounded-default">
1414

1515
<tbody>
1616
<!-- table header -->
@@ -64,7 +64,7 @@
6464
<!-- table header end -->
6565
<SkeleteLoader
6666
v-if="!rows"
67-
:columns="resource?.columns.filter((c: AdminForthResourceColumnInputCommon) => c.showIn?.list).length + 2"
67+
:columns="resource?.columns.filter((c: AdminForthResourceColumnCommon) => c.showIn?.list).length + 2"
6868
:rows="rowHeights.length || 3"
6969
:row-heights="rowHeights"
7070
:column-widths="columnWidths"
@@ -182,7 +182,7 @@
182182

183183
<template v-if="resource.options?.actions">
184184
<Tooltip
185-
v-for="action in resource.options.actions.filter(a => a.showIn?.list || a.showIn?.listQuickIcon)"
185+
v-for="action in resource.options.actions.filter(a => a.showIn?.list)"
186186
:key="action.id"
187187
>
188188
<component
@@ -339,7 +339,7 @@ import {
339339
} from '@iconify-prerendered/vue-flowbite';
340340
import router from '@/router';
341341
import { Tooltip } from '@/afcl';
342-
import type { AdminForthResourceCommon, AdminForthResourceColumnInputCommon, AdminForthResourceColumnCommon, AdminForthComponentDeclaration } from '@/types/Common';
342+
import type { AdminForthResourceCommon, AdminForthResourceColumnCommon, AdminForthComponentDeclarationFull } from '@/types/Common';
343343
import { useAdminforth } from '@/adminforth';
344344
import Checkbox from '@/afcl/Checkbox.vue';
345345
import ListActionsThreeDots from '@/components/ListActionsThreeDots.vue';
@@ -360,7 +360,7 @@ const props = defineProps<{
360360
customActionsInjection?: any[],
361361
tableBodyStartInjection?: any[],
362362
customActionIconsThreeDotsMenuItems?: any[]
363-
tableRowReplaceInjection?: AdminForthComponentDeclaration,
363+
tableRowReplaceInjection?: AdminForthComponentDeclarationFull,
364364
}>();
365365
366366
// emits, update page
@@ -436,7 +436,7 @@ watch(() => props.rows, (newRows) => {
436436
columnWidths.value = newRows || !headerRefs.value ? [] : [48, ...headerRefs.value.map((el: HTMLElement) => el.offsetWidth)];
437437
});
438438
439-
function addToCheckedValues(id: string) {
439+
function addToCheckedValues(id: string | number) {
440440
if (checkboxesInternal.value.includes(id)) {
441441
checkboxesInternal.value = checkboxesInternal.value.filter((item) => item !== id);
442442
} else {
@@ -468,7 +468,7 @@ const allFromThisPageChecked = computed(() => {
468468
if (!props.rows || !props.rows.length) return false;
469469
return props.rows.every((r) => checkboxesInternal.value.includes(r._primaryKeyValue));
470470
});
471-
const ascArr = computed(() => sort.value.filter((s:any) => s.direction === 'asc').map((s: any) => s.field));
471+
const ascArr = computed(() => sort.value.filter((s: any) => s.direction === 'asc').map((s: any) => s.field));
472472
const descArr = computed(() => sort.value.filter((s: any) => s.direction === 'desc').map((s: any) => s.field));
473473
474474
@@ -487,9 +487,9 @@ function onSortButtonClick(event: any, field: string) {
487487
} else {
488488
const sortField = sort.value[sortIndex];
489489
if (sortField.direction === 'asc') {
490-
sort.value = sort.value.map((s: any) => s.field === field ? {field, direction: 'desc'} : s);
490+
sort.value = sort.value.map((s) => s.field === field ? {field, direction: 'desc'} : s);
491491
} else {
492-
sort.value = sort.value.filter((s: any) => s.field !== field);
492+
sort.value = sort.value.filter((s) => s.field !== field);
493493
}
494494
}
495495
}
@@ -576,7 +576,7 @@ async function deleteRecord(row: any) {
576576
const actionLoadingStates = ref<Record<string | number, boolean>>({});
577577
578578
async function startCustomAction(actionId: string, row: any, extraData: Record<string, any> = {}) {
579-
console.log('Starting custom action', actionId, row);
579+
580580
actionLoadingStates.value[actionId] = true;
581581
582582
const data = await callAdminForthApi({
@@ -586,7 +586,7 @@ async function startCustomAction(actionId: string, row: any, extraData: Record<s
586586
resourceId: props.resource?.resourceId,
587587
actionId: actionId,
588588
recordId: row._primaryKeyValue,
589-
extra: extraData,
589+
extra: extraData
590590
}
591591
});
592592

adminforth/spa/src/components/ResourceListTableVirtual.vue

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
<tbody>
2020
<!-- table header -->
21-
<tr class="t-header sticky z-20 top-0 text-xs bg-lightListTableHeading dark:bg-darkListTableHeading dark:text-gray-400">
22-
<td scope="col" class="list-table-header-cell p-4 sticky-column bg-lightListTableHeading dark:bg-darkListTableHeading">
21+
<tr class="t-header sticky z-20 top-0 text-xs text-lightListTableHeadingText bg-lightListTableHeading dark:bg-darkListTableHeading dark:text-darkListTableHeadingText">
22+
<td scope="col" class="list-table-header-cell p-4 sticky-column bg-lightListTableHeading dark:bg-darkListTableHeading">
2323
<Checkbox
2424
:modelValue="allFromThisPageChecked"
2525
:disabled="!rows || !rows.length"
@@ -29,7 +29,7 @@
2929
</Checkbox>
3030
</td>
3131

32-
<td v-for="c in columnsListed" ref="headerRefs" scope="col" class="list-table-header-cell px-2 md:px-3 lg:px-6 py-3" :class="{'sticky-column bg-lightListTableHeading dark:bg-darkListTableHeading': c.listSticky}">
32+
<td v-for="c in columnsListed" ref="headerRefs" scope="col" class="list-table-header-cell px-2 md:px-3 lg:px-6 py-3" :class="{'sticky-column bg-lightListTableHeading dark:bg-darkListTableHeading': c.listSticky}">
3333

3434
<div @click="(evt) => c.sortable && onSortButtonClick(evt, c.name)"
3535
class="flex items-center " :class="{'cursor-pointer':c.sortable}">
@@ -69,7 +69,7 @@
6969
<SkeleteLoader
7070
v-if="!rows"
7171
:columns="resource?.columns.filter((c: AdminForthResourceColumnCommon) => c.showIn?.list).length + 2"
72-
:rows="rowHeights.length || 20"
72+
:rows="rowHeights.length || 3"
7373
:row-heights="rowHeights"
7474
:column-widths="columnWidths"
7575
/>
@@ -116,7 +116,7 @@
116116
>
117117
<span class="sr-only">{{ $t('checkbox') }}</span>
118118
</Checkbox>
119-
</td>
119+
</td>
120120
<td v-for="c in columnsListed" class="px-2 md:px-3 lg:px-6 py-4" :class="{'sticky-column bg-lightListTable dark:bg-darkListTable': c.listSticky}">
121121
<!-- if c.name in listComponentsPerColumn, render it. If not, render ValueRenderer -->
122122
<component
@@ -177,7 +177,7 @@
177177
<template v-slot:tooltip>
178178
{{ $t('Delete item') }}
179179
</template>
180-
</Tooltip>
180+
</Tooltip>
181181
<template v-if="customActionsInjection">
182182
<component
183183
v-for="c in customActionsInjection"
@@ -191,7 +191,7 @@
191191
</template>
192192
<template v-if="resource.options?.actions">
193193
<Tooltip
194-
v-for="action in resource.options.actions.filter(a => a.showIn?.list || a.showIn?.listQuickIcon)"
194+
v-for="action in resource.options.actions.filter(a => a.showIn?.list)"
195195
:key="action.id"
196196
>
197197
<CallActionWrapper
@@ -251,9 +251,9 @@
251251
<!-- pagination
252252
totalRows in v-if is used to not hide page input during loading when user puts cursor into it and edit directly (rows gets null there during edit)
253253
-->
254-
<div class="flex flex-row items-center mt-4 xs:flex-row xs:justify-between xs:items-center gap-3">
254+
<div class="af-pagination-container flex flex-row items-center mt-4 xs:flex-row xs:justify-between xs:items-center gap-3">
255255

256-
<div class="inline-flex "
256+
<div class="af-pagination-buttons-container inline-flex "
257257
v-if="(rows || totalRows) && totalRows >= pageSize && totalRows > 0"
258258
>
259259
<!-- Buttons -->
@@ -279,11 +279,10 @@
279279
type="text"
280280
v-model="pageInput"
281281
:style="{ width: `${Math.max(1, pageInput.length+4)}ch` }"
282-
class="af-pagination-input min-w-10 outline-none inline-block w-auto py-1.5 px-3 text-sm text-center text-lightListTablePaginationCurrentPageText border border-lightListTablePaginationBorder dark:border-darkListTablePaginationBorder dark:text-darkListTablePaginationCurrentPageText dark:bg-darkListTablePaginationBackgoround z-10"
282+
class="af-pagination-input min-w-10 outline-none inline-block py-1.5 px-3 text-sm text-center text-lightListTablePaginationCurrentPageText border border-lightListTablePaginationBorder dark:border-darkListTablePaginationBorder dark:text-darkListTablePaginationCurrentPageText dark:bg-darkListTablePaginationBackgoround z-10"
283283
@keydown="onPageKeydown($event)"
284284
@blur="validatePageInput()"
285-
>
286-
</input>
285+
/>
287286

288287
<button
289288
class="af-pagination-last-page-button flex items-center py-1 px-3 text-sm font-medium text-lightListTablePaginationText focus:outline-none bg-lightListTablePaginationBackgoround border-l-0 border border-lightListTablePaginationBorder hover:bg-lightListTablePaginationBackgoroundHover hover:text-lightListTablePaginationTextHover focus:z-10 focus:ring-4 focus:ring-lightListTablePaginationFocusRing dark:focus:ring-darkListTablePaginationFocusRing dark:bg-darkListTablePaginationBackgoround dark:text-darkListTablePaginationText dark:border-darkListTablePaginationBorder dark:hover:text-white dark:hover:bg-darkListTablePaginationBackgoroundHover disabled:opacity-50"
@@ -309,7 +308,7 @@
309308
<span v-if="((((page || 1) - 1) * pageSize + 1 > totalRows) && totalRows > 0)">{{ $t('Wrong Page') }} </span>
310309
<template v-else-if="resource && totalRows > 0">
311310

312-
<span class="hidden sm:inline">
311+
<span class="af-pagination-info hidden sm:inline">
313312
<i18n-t keypath="Showing {from} to {to} of {total} Entries" tag="p" >
314313
<template v-slot:from>
315314
<strong>{{ from }}</strong>
@@ -343,7 +342,7 @@
343342
<script setup lang="ts">
344343
345344
346-
import { computed, onMounted, ref, watch, useTemplateRef, nextTick, type Ref, onUnmounted } from 'vue';
345+
import { computed, onMounted, ref, watch, useTemplateRef, nextTick, type Ref } from 'vue';
347346
import { callAdminForthApi } from '@/utils';
348347
import { useI18n } from 'vue-i18n';
349348
import ValueRenderer from '@/components/ValueRenderer.vue';
@@ -352,18 +351,15 @@ import { useCoreStore } from '@/stores/core';
352351
import { showSuccesTost, showErrorTost } from '@/composables/useFrontendApi';
353352
import SkeleteLoader from '@/components/SkeleteLoader.vue';
354353
import { getIcon } from '@/utils';
355-
import {
356-
IconInboxOutline,
357-
} from '@iconify-prerendered/vue-flowbite';
358-
359354
import {
360355
IconEyeSolid,
361356
IconPenSolid,
362-
IconTrashBinSolid
357+
IconTrashBinSolid,
358+
IconInboxOutline
363359
} from '@iconify-prerendered/vue-flowbite';
364360
import router from '@/router';
365361
import { Tooltip } from '@/afcl';
366-
import type { AdminForthResourceCommon, AdminForthResourceColumnCommon, AdminForthComponentDeclaration } from '@/types/Common';
362+
import type { AdminForthResourceCommon, AdminForthResourceColumnCommon, AdminForthComponentDeclarationFull } from '@/types/Common';
367363
import { useAdminforth } from '@/adminforth';
368364
import Checkbox from '@/afcl/Checkbox.vue';
369365
import ListActionsThreeDots from '@/components/ListActionsThreeDots.vue';
@@ -387,7 +383,7 @@ const props = defineProps<{
387383
itemHeight?: number,
388384
bufferSize?: number,
389385
customActionIconsThreeDotsMenuItems?: any[]
390-
tableRowReplaceInjection?: AdminForthComponentDeclaration
386+
tableRowReplaceInjection?: AdminForthComponentDeclarationFull
391387
}>();
392388
393389
// emits, update page
@@ -463,7 +459,7 @@ watch(() => props.rows, (newRows) => {
463459
columnWidths.value = newRows || !headerRefs.value ? [] : [48, ...headerRefs.value.map((el: HTMLElement) => el.offsetWidth)];
464460
});
465461
466-
function addToCheckedValues(id: any) {
462+
function addToCheckedValues(id: string | number) {
467463
if (checkboxesInternal.value.includes(id)) {
468464
checkboxesInternal.value = checkboxesInternal.value.filter((item) => item !== id);
469465
} else {
@@ -499,7 +495,7 @@ const ascArr = computed(() => sort.value.filter((s: any) => s.direction === 'asc
499495
const descArr = computed(() => sort.value.filter((s: any) => s.direction === 'desc').map((s: any) => s.field));
500496
501497
502-
function onSortButtonClick(event: any, field: any) {
498+
function onSortButtonClick(event: any, field: string) {
503499
// if ctrl key is pressed, add to sort otherwise sort by this field
504500
// in any case if field is already in sort, toggle direction
505501
@@ -524,7 +520,7 @@ function onSortButtonClick(event: any, field: any) {
524520
525521
const clickTarget = ref(null);
526522
527-
async function onClick(e: any,row: any) {
523+
async function onClick(e: any, row: any) {
528524
if(clickTarget.value === e.target) return;
529525
clickTarget.value = e.target;
530526
await new Promise((resolve) => setTimeout(resolve, 100));

adminforth/types/Back.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1813,7 +1813,6 @@ export type AllowedActions = {
18131813
*/
18141814
export interface ResourceOptionsInput extends Omit<NonNullable<AdminForthResourceInputCommon['options']>, 'allowedActions' | 'bulkActions'> {
18151815

1816-
baseActionsAsQuickIcons?: ('show' | 'edit' | 'delete')[],
18171816
/**
18181817
* Custom bulk actions list. Bulk actions available in list view when user selects multiple records by
18191818
* using checkboxes.

adminforth/types/Common.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,14 @@ export interface AdminForthResourceInputCommon {
371371
* General options for resource.
372372
*/
373373
options?: {
374+
375+
376+
/**
377+
* Show quick action icons for base actions (show, edit, delete) in list view.
378+
* By default, they are inside three dots dropdown menu.
379+
*/
380+
baseActionsAsQuickIcons?: ('show' | 'edit' | 'delete')[],
381+
374382

375383
/**
376384
* Default sort for list view.

0 commit comments

Comments
 (0)