|
| 1 | +<script lang="ts"> |
| 2 | + import { getDrawerStore } from '@skeletonlabs/skeleton'; |
| 3 | + import { getDatasetDetails } from '$lib/services/dictionary'; |
| 4 | + import type { DashboardRow } from '$lib/stores/Dashboard'; |
| 5 | + import { ProgressRadial } from '@skeletonlabs/skeleton'; |
| 6 | + import ErrorAlert from '$lib/components/ErrorAlert.svelte'; |
| 7 | + const drawerStore = getDrawerStore(); |
| 8 | +
|
| 9 | + const datasetId = (($drawerStore.meta.row as DashboardRow)?.dataset_id as string) || ''; |
| 10 | + const title = (($drawerStore.meta.row as DashboardRow)?.name as string) || ''; |
| 11 | + const link = (($drawerStore.meta.row as DashboardRow)?.additional_info_link as string) || ''; |
| 12 | +
|
| 13 | + async function getDataset() { |
| 14 | + const details = await getDatasetDetails(datasetId); |
| 15 | + if (!details || Object.keys(details).length === 0) throw new Error('No details found'); |
| 16 | + if (details.datasetId) { |
| 17 | + delete details.datasetId; |
| 18 | + } |
| 19 | + if (details.studyFullname) { |
| 20 | + delete details.studyFullname; |
| 21 | + } |
| 22 | + return details; |
| 23 | + } |
| 24 | +</script> |
| 25 | + |
| 26 | +{#if title} |
| 27 | + <h2 data-testid="drawer-title" class="text-2xl font-bold ml-4">{title}</h2> |
| 28 | +{/if} |
| 29 | +<hr class="m-4 border-t-2 border-gray-200" /> |
| 30 | +{#await getDataset()} |
| 31 | + <div class="flex justify-center items-center h-full"> |
| 32 | + <ProgressRadial /> |
| 33 | + </div> |
| 34 | +{:then details} |
| 35 | + <ul data-testid="drawer-details" class="m-4 p-4"> |
| 36 | + {#each Object.entries(details) as [key, value]} |
| 37 | + {#if value} |
| 38 | + <li class="m-2"> |
| 39 | + <strong class="capitalize" |
| 40 | + >{key |
| 41 | + .replace(/([A-Z])/g, ' $1') |
| 42 | + .toLowerCase() |
| 43 | + .trim()}</strong |
| 44 | + >: |
| 45 | + {#if Array.isArray(value)} |
| 46 | + <ul class="list-disc"> |
| 47 | + {#each value as item} |
| 48 | + {#if item} |
| 49 | + <li class="ml-8">{item}</li> |
| 50 | + {/if} |
| 51 | + {/each} |
| 52 | + </ul> |
| 53 | + {:else} |
| 54 | + {value} |
| 55 | + {/if} |
| 56 | + </li> |
| 57 | + {/if} |
| 58 | + {/each} |
| 59 | + </ul> |
| 60 | + {#if link} |
| 61 | + <div class="flex justify-center items-center mb-4"> |
| 62 | + <a |
| 63 | + href={link || '#'} |
| 64 | + on:click|stopPropagation |
| 65 | + class="btn variant-ghost-primary hover:variant-filled-primary" |
| 66 | + target="_blank">More Info</a |
| 67 | + > |
| 68 | + </div> |
| 69 | + {/if} |
| 70 | +{:catch} |
| 71 | + <div class="flex justify-center items-center"> |
| 72 | + <ErrorAlert title="An Error Occured"> |
| 73 | + <p>We're having trouble fetching the dataset details right now. Please try again later.</p> |
| 74 | + </ErrorAlert> |
| 75 | + </div> |
| 76 | +{/await} |
0 commit comments