Skip to content

Commit 86c2b37

Browse files
committed
ui: datatable columns only recognize width instead of max-width
introduce pinia to get viewportHeight
1 parent 22cf9ac commit 86c2b37

File tree

6 files changed

+183
-16
lines changed

6 files changed

+183
-16
lines changed

ui/app/components/Kani.vue

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,76 @@
11
<script setup lang="ts">
22
import { ofetch } from "ofetch";
3-
import { URL_MERGE_DIFF, MergeKaniColumns, multiSort, type VecMergeHashKaniList } from "~/shared/utils/merged_list";
3+
import { URL_MERGE_DIFF, MergeKaniColumns, multiSort, type VecMergeHashKaniList, FILTERS, ProofKind } from "~/shared/utils/kani";
4+
import { useStyleStore } from "~/stores/style";
45
5-
const vec = ref<VecMergeHashKaniList>([]);
6+
const { viewportHeight } = storeToRefs(useStyleStore());
7+
const colStyle = (ratio: number) => {
8+
const style = {
9+
"width": `${Math.round(viewportHeight.value * ratio)}px`,
10+
"white-space": "normal", "word-break": "break-word",
11+
};
12+
console.log(style);
13+
return style;
14+
};
15+
16+
const raw = ref<VecMergeHashKaniList>([]);
617
// Download JSON
718
ofetch<VecMergeHashKaniList>(
819
URL_MERGE_DIFF,
920
{ parseResponse: JSON.parse }
10-
).then(val => vec.value = val);
21+
).then(val => raw.value = val);
22+
23+
// fitler rows
24+
const filters = ref(FILTERS.filters);
25+
// stats
26+
const counts = computed<{ total: number, standard: number, contract: number }>(() => ({
27+
total: raw.value.length,
28+
standard: raw.value.filter(ele => ele.proof_kind === ProofKind.Standard).length,
29+
contract:
30+
raw.value.filter(ele => ele.proof_kind === ProofKind.Contract).length,
31+
}));
32+
1133
1234
// Set title
1335
useHead({ title: "Verify Rust Std - Kani" });
1436
</script>
1537

1638
<template>
17-
<div>len = {{ vec.length }}</div>
39+
<DataTable :value="raw" paginator :rows="5" :rowsPerPageOptions="[5, 10, 20, 50]" sortMode="multiple" removableSort
40+
v-model:multi-sort-meta="multiSort" stripedRows tableStyle="min-width: 20rem" v-model:filters="filters"
41+
:globalFilterFields="FILTERS.fields" currentPageReportTemplate="{first} to {last} of {totalRecords}">
1842

19-
<DataTable :value="vec" paginator :rows="5" :rowsPerPageOptions="[5, 10, 20, 50]" sortMode="multiple" removableSort
20-
v-model:multi-sort-meta="multiSort" stripedRows tableStyle="min-width: 50rem">
21-
<!-- :virtual-scroller-options="{ itemSize: 5, lazy: true, }"> It's slow to render the table, so partial render. -->
2243
<template #header>
23-
<div class="flex flex-wrap items-center justify-between gap-2">
24-
<span class="text-xl font-bold">Products</span>
25-
<Button icon="pi pi-refresh" rounded raised />
44+
<div class="flex justify-between items-center">
45+
<div>
46+
</div>
47+
<div>
48+
<IconField>
49+
<InputIcon>
50+
<i class="pi pi-search" />
51+
</InputIcon>
52+
<InputText v-model="filters.global.value" placeholder="filepath or function" />
53+
</IconField>
54+
</div>
2655
</div>
2756
</template>
2857

58+
<!-- Passing ratio to maxWidth seems not working. Pass bodyStyle to wrap long paths while bodyClass not working. -->
2959
<Column v-for="col of MergeKaniColumns" :key="col.key" :field="col.col.field" :header="col.col.header"
30-
:style="{ width: col.col.width }" :sortable="col.col.sortable"></Column>
60+
:style="{ width: col.col.width }" bodyStyle="white-space: normal; word-break: break-word"
61+
:sortable="col.col.sortable">
62+
</Column>
63+
64+
<template #paginatorstart>
65+
<span>Total: {{ counts.total }}</span>
66+
</template>
67+
<template #paginatorend>
68+
<div class="grid grid-cols-2 grid-rows-2 place-items-center">
69+
<span>Standard:</span>
70+
<span>{{ counts.standard }}</span>
71+
<span>Contract:</span>
72+
<span>{{ counts.contract }}</span>
73+
</div>
74+
</template>
3175
</DataTable>
3276
</template>

ui/app/shared/utils/merged_list.ts renamed to ui/app/shared/utils/kani.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { DataTableSortMeta } from "primevue";
2+
import { FilterMatchMode } from '@primevue/core/api';
23

34
export const URL_MERGE_DIFF = "https://raw.githubusercontent.com/os-checker/verify-rust-std_data/refs/heads/main/merge_diff-proofs-only.json";
45

@@ -31,23 +32,30 @@ export interface MergeKaniColumn {
3132
export const MergeKaniColumns: MergeKaniColumn[] = [
3233
{
3334
key: "file",
34-
col: { field: "file", header: "File Path", width: "25%", sortable: true },
35+
col: { field: "file", header: "File Path", width: "18%", sortable: true },
3536
},
3637
{
3738
key: "func",
3839
col: { field: "func", header: "Function", width: "25%", sortable: true },
3940
},
4041
{
4142
key: "hash",
42-
col: { field: "hash", header: "Hash", width: "25%" },
43+
col: { field: "hash", header: "Hash", width: "25%", },
4344
},
4445
{
4546
key: "proof_kind",
46-
col: { field: "proof_kind", header: "Proof Kind", width: "10%", sortable: true },
47+
col: { field: "proof_kind", header: "Proof Kind", width: "12%", sortable: true },
4748
},
4849
];
4950

5051
export const multiSort: DataTableSortMeta[] = [
5152
// { field: "proof_kind", order: 1 },
5253
// { field: "func", order: 1 },
5354
];
55+
56+
export const FILTERS = {
57+
filters: {
58+
global: { value: null, matchMode: FilterMatchMode.CONTAINS },
59+
},
60+
fields: ["file", "func"]
61+
};

ui/app/stores/style.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
export const useStyleStore = defineStore('style', () => {
2+
const color = reactive({
3+
green: "green", red: "red", grey: "grey",
4+
topButton: "white", orange: "orange", orange_light: "orange",
5+
});
6+
const viewportHeight = ref(800);
7+
8+
onMounted(() => {
9+
// 获取元素的计算后的样式
10+
const styles = window.getComputedStyle(document.documentElement);
11+
12+
// 获取CSS变量的值
13+
color.green = styles.getPropertyValue('--p-emerald-500').trim();
14+
color.red = styles.getPropertyValue('--p-red-500').trim();
15+
color.grey = styles.getPropertyValue('--p-gray-400').trim();
16+
color.topButton = styles.getPropertyValue('--p-button-primary-background').trim();
17+
color.orange_light = styles.getPropertyValue('--p-orange-400').trim();
18+
color.orange = styles.getPropertyValue('--p-orange-500').trim();
19+
20+
// 视窗高度
21+
viewportHeight.value = window.innerHeight;
22+
window.addEventListener('resize', () => {
23+
viewportHeight.value = window.innerHeight;
24+
});
25+
});
26+
27+
return { color, viewportHeight }
28+
});
29+

ui/nuxt.config.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ export default defineNuxtConfig({
77
ssr: false, // Client-side Only Rendering (SPA)
88
css: ["primeicons/primeicons.css"],
99
typescript: { typeCheck: true },
10-
modules: ['@primevue/nuxt-module', '@nuxtjs/tailwindcss'],
10+
modules: [
11+
'@primevue/nuxt-module',
12+
'@nuxtjs/tailwindcss',
13+
'@pinia/nuxt'
14+
],
1115
primevue: {
1216
options: {
1317
theme: {
@@ -16,4 +20,4 @@ export default defineNuxtConfig({
1620
}
1721
}
1822
}
19-
})
23+
})

ui/package-lock.json

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

ui/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
},
1212
"dependencies": {
1313
"@nuxtjs/tailwindcss": "^6.14.0",
14+
"@pinia/nuxt": "^0.11.2",
1415
"@primeuix/themes": "^1.2.3",
1516
"nuxt": "^4.0.1",
1617
"ofetch": "^1.4.1",
18+
"pinia": "^3.0.3",
1719
"primeicons": "^7.0.0",
1820
"primevue": "^4.3.7",
1921
"tailwindcss-primeui": "^0.6.1",

0 commit comments

Comments
 (0)