|
1 | | -<script lang="ts" context="module"> |
| 1 | +<script lang="ts" module> |
2 | 2 | import { total } from '$lib/helpers/array'; |
3 | 3 | import { clampMin } from '$lib/helpers/numbers'; |
4 | 4 | import type { Metric } from '$lib/sdk/usage'; |
|
16 | 16 | import { addSubPanel, registerCommands, updateCommandGroupRanks } from '$lib/commandCenter'; |
17 | 17 | import { PlatformsPanel } from '$lib/commandCenter/panels'; |
18 | 18 | import { Tab, Tabs } from '$lib/components'; |
| 19 | + import { isTabSelected } from '$lib/helpers/load'; |
19 | 20 | import { humanFileSize } from '$lib/helpers/sizeConvertion'; |
20 | 21 | import { Container, type UsagePeriods } from '$lib/layout'; |
21 | 22 | import { onMount, setContext, type Component } from 'svelte'; |
|
30 | 31 | import { IconPlus } from '@appwrite.io/pink-icons-svelte'; |
31 | 32 | import { isSmallViewport } from '$lib/stores/viewport'; |
32 | 33 |
|
33 | | - let period: UsagePeriods = '30d'; |
34 | | - $: path = `${base}/project-${page.params.region}-${page.params.project}/overview`; |
| 34 | + let period: UsagePeriods = $state('30d'); |
| 35 | + const path = $derived(`${base}/project-${page.params.region}-${page.params.project}/overview`); |
35 | 36 |
|
36 | 37 | onMount(handle); |
37 | 38 | afterNavigate(handle); |
|
52 | 53 | return usage.load(dates.start, dates.end, dates.period); |
53 | 54 | } |
54 | 55 |
|
55 | | - function isTabSelected(key: string) { |
56 | | - return page.url.pathname.endsWith(`/${key}`); |
57 | | - } |
58 | | -
|
59 | | - $: $registerCommands([ |
| 56 | + const integrationTabs = $derived([ |
60 | 57 | { |
61 | | - label: 'Add platform', |
62 | | - keys: ['a', 'p'], |
63 | | - callback() { |
64 | | - addSubPanel(PlatformsPanel); |
65 | | - }, |
66 | | - icon: IconPlus, |
67 | | - group: 'integrations', |
68 | | - disabled: !$canWriteProjects |
| 58 | + href: `${path}/platforms`, |
| 59 | + title: 'Platforms', |
| 60 | + event: 'platforms', |
| 61 | + hasChildren: true |
69 | 62 | }, |
70 | 63 | { |
71 | | - label: 'Create API Key', |
72 | | - icon: IconPlus, |
73 | | - callback() { |
74 | | - goto(`${path}/api-keys/create`); |
75 | | - }, |
76 | | - keys: ['c', 'k'], |
77 | | - group: 'integrations', |
78 | | - disabled: !$canWriteProjects |
| 64 | + href: `${path}/api-keys`, |
| 65 | + title: 'API keys', |
| 66 | + event: 'api-keys', |
| 67 | + hasChildren: true |
79 | 68 | }, |
80 | 69 | { |
81 | | - label: 'Create Dev Key', |
82 | | - icon: IconPlus, |
83 | | - callback() { |
84 | | - goto(`${path}/dev-keys/create`); |
85 | | - }, |
86 | | - keys: ['c', 'd', 'k'], |
87 | | - group: 'integrations', |
88 | | - disabled: !$canWriteProjects |
| 70 | + href: `${path}/dev-keys`, |
| 71 | + title: 'Dev keys', |
| 72 | + event: 'dev-keys', |
| 73 | + hasChildren: true |
89 | 74 | } |
90 | 75 | ]); |
91 | 76 |
|
92 | | - $: $updateCommandGroupRanks({ |
93 | | - integrations: 10 |
| 77 | + $effect(() => { |
| 78 | + const unregister = $registerCommands([ |
| 79 | + { |
| 80 | + label: 'Add platform', |
| 81 | + keys: ['a', 'p'], |
| 82 | + callback() { |
| 83 | + addSubPanel(PlatformsPanel); |
| 84 | + }, |
| 85 | + icon: IconPlus, |
| 86 | + group: 'integrations', |
| 87 | + disabled: !$canWriteProjects |
| 88 | + }, |
| 89 | + { |
| 90 | + label: 'Create API Key', |
| 91 | + icon: IconPlus, |
| 92 | + callback() { |
| 93 | + goto(`${path}/api-keys/create`); |
| 94 | + }, |
| 95 | + keys: ['c', 'k'], |
| 96 | + group: 'integrations', |
| 97 | + disabled: !$canWriteProjects |
| 98 | + }, |
| 99 | + { |
| 100 | + label: 'Create Dev Key', |
| 101 | + icon: IconPlus, |
| 102 | + callback() { |
| 103 | + goto(`${path}/dev-keys/create`); |
| 104 | + }, |
| 105 | + keys: ['c', 'd', 'k'], |
| 106 | + group: 'integrations', |
| 107 | + disabled: !$canWriteProjects |
| 108 | + } |
| 109 | + ]); |
| 110 | + $updateCommandGroupRanks({ |
| 111 | + integrations: 10 |
| 112 | + }); |
| 113 | + return unregister; |
94 | 114 | }); |
95 | 115 | </script> |
96 | 116 |
|
|
223 | 243 | <Typography.Title>Integrations</Typography.Title> |
224 | 244 | <Layout.Stack gap="xl" direction="row" justifyContent="space-between"> |
225 | 245 | <Tabs> |
226 | | - <Tab |
227 | | - noscroll |
228 | | - event="platforms" |
229 | | - href={`${path}/platforms`} |
230 | | - selected={isTabSelected('platforms')}>Platforms</Tab> |
231 | | - <Tab |
232 | | - noscroll |
233 | | - event="api-keys" |
234 | | - href={`${path}/api-keys`} |
235 | | - selected={isTabSelected('api-keys')}>API keys</Tab> |
236 | | - <Tab |
237 | | - noscroll |
238 | | - event="dev-keys" |
239 | | - href={`${path}/dev-keys`} |
240 | | - selected={isTabSelected('dev-keys')}>Dev keys</Tab> |
| 246 | + {#each integrationTabs as tab} |
| 247 | + <Tab |
| 248 | + noscroll |
| 249 | + href={tab.href} |
| 250 | + event={tab.event} |
| 251 | + selected={isTabSelected(tab, page.url.pathname, path, integrationTabs)} |
| 252 | + >{tab.title}</Tab> |
| 253 | + {/each} |
241 | 254 | </Tabs> |
242 | 255 | {#if $action} |
243 | 256 | <svelte:component this={$action} /> |
|
0 commit comments