Skip to content

Commit 99b22c2

Browse files
committed
feat: conditionally render table headers based on custom components
1 parent a5fbbfc commit 99b22c2

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

adminforth/modules/restApi.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { ActionCheckSource, AdminForthConfigMenuItem, AdminForthDataTypes, Admin
2020
AnnouncementBadgeResponse,
2121
GetBaseConfigResponse,
2222
ShowInResolved} from "../types/Common.js";
23-
import { fa } from "@faker-js/faker";
2423

2524
export async function interpretResource(
2625
adminUser: AdminUser,

adminforth/spa/src/components/GroupsTable.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{{ group.groupName }}
55
</div>
66
<table class="w-full text-sm text-left rtl:text-right text-gray-500 dark:text-gray-400">
7-
<thead class="text-xs text-gray-700 uppercase dark:text-gray-400 bg-lightFormHeading dark:bg-gray-700 block md:table-row-group ">
7+
<thead v-if="!allColumnsHaveCustomComponent" class="text-xs text-gray-700 uppercase dark:text-gray-400 bg-lightFormHeading dark:bg-gray-700 block md:table-row-group ">
88
<tr>
99
<th scope="col" :class="{'rounded-tl-lg': !group.groupName}" class="px-6 py-3 hidden md:w-52 md:table-cell">
1010
{{ $t('Field') }}
@@ -118,9 +118,15 @@
118118
}>();
119119
120120
const arrayItemRefs = ref([]);
121-
121+
122122
const customComponentsInValidity: Ref<Record<string, boolean>> = ref({});
123123
const customComponentsEmptiness: Ref<Record<string, boolean>> = ref({});
124+
const allColumnsHaveCustomComponent = computed(() => {
125+
return props.group.columns.every(column => {
126+
const componentKey = `${props.source}Row` as keyof typeof column.components;
127+
return column.components?.[componentKey];
128+
});
129+
});
124130
125131
const emit = defineEmits(['update:customComponentsInValidity', 'update:customComponentsEmptiness']);
126132

adminforth/spa/src/components/ShowTable.vue

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{{ groupName }}
55
</div>
66
<table class="w-full text-sm text-left rtl:text-right text-gray-500 dark:text-gray-400 table-fixed">
7-
<thead class="text-gray-700 dark:text-gray-400 bg-lightFormHeading dark:bg-gray-700 block md:table-row-group">
7+
<thead v-if="!allColumnsHaveCustomComponent" class="text-gray-700 dark:text-gray-400 bg-lightFormHeading dark:bg-gray-700 block md:table-row-group">
88
<tr>
99
<th scope="col" class="px-6 py-3 text-xs uppercase hidden md:w-52 md:table-cell">
1010
{{ $t('Field') }}
@@ -59,7 +59,8 @@
5959
import ValueRenderer from '@/components/ValueRenderer.vue';
6060
import { getCustomComponent } from '@/utils';
6161
import { useCoreStore } from '@/stores/core';
62-
defineProps<{
62+
import { computed } from 'vue';
63+
const props = defineProps<{
6364
columns: Array<{
6465
name: string;
6566
label: string;
@@ -74,11 +75,17 @@
7475
};
7576
};
7677
}>;
78+
source: string;
7779
groupName?: string | null;
7880
noTitle?: boolean;
7981
resource: Record<string, any>;
8082
record: Record<string, any>;
8183
}>();
8284
8385
const coreStore = useCoreStore();
86+
const allColumnsHaveCustomComponent = computed(() => {
87+
return props.columns.every(column => {
88+
return column.components?.showRow;
89+
});
90+
});
8491
</script>

0 commit comments

Comments
 (0)