|
| 1 | +<script setup lang="ts"> |
| 2 | +import { useTask } from '@vue-kakuyaku/core' |
| 3 | +import { computed } from 'vue' |
| 4 | +import CompatibilityMatrixTableIcon, { type Status } from './CompatibilityMatrixTableIcon.vue' |
| 5 | +
|
| 6 | +interface Matrix { |
| 7 | + included_sdks: MatrixSdkDeclaration[] |
| 8 | + stories: MatrixStory[] |
| 9 | +} |
| 10 | +
|
| 11 | +interface MatrixSdkDeclaration { |
| 12 | + name: string |
| 13 | +} |
| 14 | +
|
| 15 | +interface MatrixStory { |
| 16 | + name: string |
| 17 | + results: MatrixStoryResult[] |
| 18 | +} |
| 19 | +
|
| 20 | +interface MatrixStoryResult { |
| 21 | + status: Status |
| 22 | +} |
| 23 | +
|
| 24 | +const COMPAT_MATRIX_URL: string = import.meta.env.VITE_COMPAT_MATRIX_URL |
| 25 | +
|
| 26 | +const task = useTask<Matrix>( |
| 27 | + () => { |
| 28 | + return fetch(COMPAT_MATRIX_URL, {}).then((x) => x.json()) |
| 29 | + }, |
| 30 | + { immediate: true }, |
| 31 | +) |
| 32 | +
|
| 33 | +const table = computed(() => { |
| 34 | + if (!task.state.fulfilled) return null |
| 35 | + const data = task.state.fulfilled.value |
| 36 | +
|
| 37 | + const headers = ['Story', ...data.included_sdks.map((x) => x.name)] |
| 38 | + const rows = data.stories.map((story) => { |
| 39 | + return { story: story.name, results: story.results.map((x) => x.status) } |
| 40 | + }) |
| 41 | +
|
| 42 | + return { headers, rows } |
| 43 | +}) |
| 44 | +</script> |
| 45 | + |
| 46 | +<template> |
| 47 | + <table v-if="table"> |
| 48 | + <thead> |
| 49 | + <th |
| 50 | + v-for="name in table.headers" |
| 51 | + :key="name" |
| 52 | + > |
| 53 | + {{ name }} |
| 54 | + </th> |
| 55 | + </thead> |
| 56 | + <tbody> |
| 57 | + <tr |
| 58 | + v-for="(row, i) in table.rows" |
| 59 | + :key="i" |
| 60 | + > |
| 61 | + <td>{{ row.story }}</td> |
| 62 | + <td |
| 63 | + v-for="(status, j) in row.results" |
| 64 | + :key="j" |
| 65 | + class="status-cell" |
| 66 | + :title="`Status: ${status}`" |
| 67 | + > |
| 68 | + <CompatibilityMatrixTableIcon :status="status" /> |
| 69 | + </td> |
| 70 | + </tr> |
| 71 | + </tbody> |
| 72 | + </table> |
| 73 | + |
| 74 | + <div |
| 75 | + v-else |
| 76 | + class="border rounded p-2 my-4" |
| 77 | + > |
| 78 | + <div |
| 79 | + v-if="task.state.pending" |
| 80 | + class="flex space-x-2 items-center" |
| 81 | + > |
| 82 | + <span>Loading data...</span> |
| 83 | + </div> |
| 84 | + <div v-else-if="task.state.rejected"> |
| 85 | + Failed to load compatibility matrix data: {{ task.state.rejected.reason }} |
| 86 | + </div> |
| 87 | + </div> |
| 88 | +</template> |
| 89 | + |
| 90 | +<style lang="scss" scoped> |
| 91 | +.border { |
| 92 | + border-color: var(--vp-c-border); |
| 93 | +} |
| 94 | +
|
| 95 | +td.status-cell { |
| 96 | + font-size: 1.3em; |
| 97 | + padding: 0; |
| 98 | +
|
| 99 | + svg { |
| 100 | + margin-left: auto; |
| 101 | + margin-right: auto; |
| 102 | + } |
| 103 | +} |
| 104 | +</style> |
0 commit comments