|
1 | 1 | <script lang="ts"> |
2 | | - import { fromNullable, nonNullish, isNullish, fromNullishNullable } from '@dfinity/utils'; |
3 | | - import { fade } from 'svelte/transition'; |
4 | 2 | import type { Satellite } from '$declarations/mission_control/mission_control.did'; |
5 | 3 | import type { AuthenticationConfig, Rule } from '$declarations/satellite/satellite.did'; |
6 | | - import Input from '$lib/components/ui/Input.svelte'; |
| 4 | + import AuthConfigForm from '$lib/components/auth/AuthConfigForm.svelte'; |
7 | 5 | import Modal from '$lib/components/ui/Modal.svelte'; |
8 | 6 | import SpinnerModal from '$lib/components/ui/SpinnerModal.svelte'; |
9 | | - import Value from '$lib/components/ui/Value.svelte'; |
10 | | - import Warning from '$lib/components/ui/Warning.svelte'; |
11 | | - import { sortedSatelliteCustomDomains } from '$lib/derived/satellite-custom-domains.derived'; |
12 | 7 | import { updateAuthConfig } from '$lib/services/auth.config.services'; |
13 | 8 | import { authStore } from '$lib/stores/auth.store'; |
14 | | - import { isBusy, wizardBusy } from '$lib/stores/busy.store'; |
| 9 | + import { wizardBusy } from '$lib/stores/busy.store'; |
15 | 10 | import { i18n } from '$lib/stores/i18n.store'; |
16 | 11 | import type { JunoModalDetail, JunoModalEditAuthConfigDetail } from '$lib/types/modal'; |
17 | 12 | import { emit } from '$lib/utils/events.utils'; |
18 | | - import { satelliteUrl as satelliteUrlUtils } from '$lib/utils/satellite.utils'; |
19 | 13 |
|
20 | 14 | interface Props { |
21 | 15 | detail: JunoModalDetail; |
|
26 | 20 |
|
27 | 21 | let satellite: Satellite = $state((detail as JunoModalEditAuthConfigDetail).satellite); |
28 | 22 |
|
29 | | - let satelliteUrl: URL | null = $derived( |
30 | | - URL.parse(satelliteUrlUtils(satellite.satellite_id.toText())) |
31 | | - ); |
32 | | -
|
33 | | - let customDomains: URL[] = $derived( |
34 | | - $sortedSatelliteCustomDomains |
35 | | - .map(([customDomain, _]) => URL.parse(`https://${customDomain}`)) |
36 | | - .filter(nonNullish) |
37 | | - ); |
38 | | -
|
39 | 23 | let rule: Rule | undefined = $state((detail as JunoModalEditAuthConfigDetail).rule); |
40 | 24 |
|
41 | 25 | let config: AuthenticationConfig | undefined = $state( |
42 | 26 | (detail as JunoModalEditAuthConfigDetail).config |
43 | 27 | ); |
44 | 28 |
|
45 | | - let currentDerivationOrigin: string | undefined = $state( |
46 | | - fromNullable( |
47 | | - fromNullishNullable((detail as JunoModalEditAuthConfigDetail).config?.internet_identity) |
48 | | - ?.derivation_origin ?? [] |
49 | | - ) |
50 | | - ); |
| 29 | + let maxTokens = $state<number | undefined>(undefined); |
51 | 30 |
|
52 | | - let derivationOrigin: string | undefined = $state( |
53 | | - fromNullable( |
54 | | - fromNullishNullable((detail as JunoModalEditAuthConfigDetail).config?.internet_identity) |
55 | | - ?.derivation_origin ?? [] |
56 | | - ) |
57 | | - ); |
58 | | -
|
59 | | - let warnDerivationOrigin = $derived( |
60 | | - (nonNullish(currentDerivationOrigin) && derivationOrigin !== currentDerivationOrigin) || |
61 | | - (isNullish(currentDerivationOrigin) && nonNullish(derivationOrigin) && nonNullish(config)) |
62 | | - ); |
63 | | -
|
64 | | - let maxTokens: number | undefined = $state( |
65 | | - nonNullish( |
66 | | - fromNullishNullable((detail as JunoModalEditAuthConfigDetail).rule?.rate_config)?.max_tokens |
67 | | - ) |
68 | | - ? Number( |
69 | | - fromNullishNullable((detail as JunoModalEditAuthConfigDetail).rule?.rate_config) |
70 | | - ?.max_tokens ?? 0 |
71 | | - ) |
72 | | - : undefined |
73 | | - ); |
| 31 | + let selectedDerivationOrigin = $state<URL | undefined>(undefined); |
74 | 32 |
|
75 | 33 | let step: 'init' | 'in_progress' | 'ready' | 'error' = $state('init'); |
76 | 34 |
|
|
80 | 38 | wizardBusy.start(); |
81 | 39 | step = 'in_progress'; |
82 | 40 |
|
83 | | - const selectedDerivationOrigin = nonNullish(derivationOrigin) |
84 | | - ? [...(nonNullish(satelliteUrl) ? [satelliteUrl] : []), ...customDomains].find( |
85 | | - ({ host }) => host === derivationOrigin |
86 | | - ) |
87 | | - : undefined; |
88 | | -
|
89 | 41 | const { success } = await updateAuthConfig({ |
90 | 42 | satellite, |
91 | 43 | identity: $authStore.identity, |
|
119 | 71 | <p>{$i18n.core.updating_configuration}</p> |
120 | 72 | </SpinnerModal> |
121 | 73 | {:else} |
122 | | - <h2>{$i18n.core.config}</h2> |
123 | | - |
124 | | - <p>{$i18n.authentication.edit_configuration}</p> |
125 | | - |
126 | | - <form class="content" onsubmit={handleSubmit}> |
127 | | - <div class="container"> |
128 | | - <div> |
129 | | - <div> |
130 | | - <Value> |
131 | | - {#snippet label()} |
132 | | - {$i18n.authentication.main_domain} |
133 | | - {/snippet} |
134 | | - |
135 | | - <select id="logVisibility" name="logVisibility" bind:value={derivationOrigin}> |
136 | | - <option value={undefined}>{$i18n.authentication.not_configured}</option> |
137 | | - |
138 | | - {#if nonNullish(satelliteUrl)} |
139 | | - <option value={satelliteUrl.host}>{satelliteUrl.host}</option> |
140 | | - {/if} |
141 | | - |
142 | | - {#each customDomains as customDomain} |
143 | | - <option value={customDomain.host}>{customDomain.host}</option> |
144 | | - {/each} |
145 | | - </select> |
146 | | - </Value> |
147 | | - </div> |
148 | | - </div> |
149 | | - |
150 | | - {#if nonNullish(rule)} |
151 | | - <div> |
152 | | - <Value> |
153 | | - {#snippet label()} |
154 | | - {$i18n.collections.rate_limit} |
155 | | - {/snippet} |
156 | | - |
157 | | - <Input |
158 | | - inputType="number" |
159 | | - placeholder={$i18n.collections.rate_limit_placeholder} |
160 | | - name="maxTokens" |
161 | | - required={false} |
162 | | - bind:value={maxTokens} |
163 | | - onblur={() => |
164 | | - (maxTokens = nonNullish(maxTokens) ? Math.trunc(maxTokens) : undefined)} |
165 | | - /> |
166 | | - </Value> |
167 | | - </div> |
168 | | - {/if} |
169 | | - |
170 | | - {#if warnDerivationOrigin} |
171 | | - <div class="warn" in:fade> |
172 | | - <Warning>{$i18n.authentication.main_domain_warn}</Warning> |
173 | | - </div> |
174 | | - {/if} |
175 | | - </div> |
176 | | - |
177 | | - <button type="submit" disabled={$isBusy}> |
178 | | - {$i18n.core.submit} |
179 | | - </button> |
180 | | - </form> |
| 74 | + <AuthConfigForm |
| 75 | + {satellite} |
| 76 | + {config} |
| 77 | + {rule} |
| 78 | + onsubmit={handleSubmit} |
| 79 | + bind:maxTokens |
| 80 | + bind:selectedDerivationOrigin |
| 81 | + /> |
181 | 82 | {/if} |
182 | 83 | </Modal> |
183 | 84 |
|
|
0 commit comments