mirror of
https://github.com/open-webui/open-webui.git
synced 2026-12-03 18:17:56 -05:00
116 lines
3.4 KiB
Svelte
116 lines
3.4 KiB
Svelte
<script lang="ts">
|
|
import { getContext } from 'svelte';
|
|
import { getChangedKeys } from '$lib/utils';
|
|
|
|
import ConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
|
|
import SensitiveInput from '$lib/components/common/SensitiveInput.svelte';
|
|
import Spinner from '$lib/components/common/Spinner.svelte';
|
|
import ArrowRight from '$lib/components/icons/ArrowRight.svelte';
|
|
|
|
const i18n: any = getContext('i18n');
|
|
|
|
export let settings: Record<string, any> | null = null;
|
|
export let savedConfig: Record<string, any> | null = null;
|
|
export let labels: Record<string, string> = {};
|
|
export let sensitiveKeys: string[] = [];
|
|
export let disabled: boolean = false;
|
|
export let loading: boolean = false;
|
|
|
|
let saveButton: HTMLButtonElement;
|
|
let showConfirm: boolean = false;
|
|
|
|
$: changedKeys = getChangedKeys(savedConfig, settings);
|
|
|
|
const formatValue = (value: any) => {
|
|
if (value === null || value === undefined || value === '') {
|
|
return $i18n.t('Empty');
|
|
}
|
|
if (typeof value === 'boolean') {
|
|
return value ? $i18n.t('On') : $i18n.t('Off');
|
|
}
|
|
if (typeof value === 'object') {
|
|
return JSON.stringify(value, null, 2);
|
|
}
|
|
return String(value);
|
|
};
|
|
</script>
|
|
|
|
<div class="flex items-center gap-2">
|
|
{#if changedKeys.length > 0}
|
|
<button
|
|
class="h-7 shrink-0 rounded-lg px-2 text-xs text-base-500 transition hover:text-base-900 dark:text-base-400 dark:hover:text-base-0"
|
|
type="button"
|
|
{disabled}
|
|
on:click={() => {
|
|
showConfirm = true;
|
|
}}
|
|
>
|
|
{$i18n.t('{{count}} Changes', { count: changedKeys.length })}
|
|
</button>
|
|
{/if}
|
|
|
|
<button
|
|
bind:this={saveButton}
|
|
class="flex h-7 shrink-0 items-center justify-center gap-1.5 rounded-lg bg-base-900 px-2.5 text-xs font-normal text-base-0 transition hover:bg-base-1000 disabled:cursor-not-allowed disabled:opacity-60 dark:bg-base-100 dark:text-base-900 dark:hover:bg-base-0"
|
|
type="submit"
|
|
{disabled}
|
|
on:click={(event) => {
|
|
if (changedKeys.length > 0 && saveButton.form!.checkValidity()) {
|
|
event.preventDefault();
|
|
showConfirm = true;
|
|
}
|
|
}}
|
|
>
|
|
{$i18n.t('Save')}
|
|
|
|
{#if loading}
|
|
<span class="shrink-0">
|
|
<Spinner className="size-3" />
|
|
</span>
|
|
{/if}
|
|
</button>
|
|
</div>
|
|
|
|
{#snippet settingValue(key: string, value: any)}
|
|
{#if sensitiveKeys.includes(key) && value}
|
|
<SensitiveInput value={String(value)} readOnly />
|
|
{:else}
|
|
<div class="break-words whitespace-pre-wrap">{formatValue(value)}</div>
|
|
{/if}
|
|
{/snippet}
|
|
|
|
<ConfirmDialog
|
|
bind:show={showConfirm}
|
|
title={$i18n.t('Unsaved changes')}
|
|
confirmLabel={$i18n.t('Save')}
|
|
onConfirm={() => {
|
|
saveButton.form!.requestSubmit();
|
|
}}
|
|
>
|
|
<div class="flex max-h-[60vh] flex-col gap-3 overflow-y-auto">
|
|
{#each changedKeys as key (key)}
|
|
<div class="flex flex-col gap-1">
|
|
<div class="flex items-baseline gap-1.5 text-xs text-base-800 dark:text-base-200">
|
|
{labels[key] ?? key}
|
|
{#if labels[key]}
|
|
<span class="truncate font-mono text-[0.625rem] text-base-500 dark:text-base-400">
|
|
{key}
|
|
</span>
|
|
{/if}
|
|
</div>
|
|
<div class="flex items-start gap-2 text-xs">
|
|
<div
|
|
class="min-w-0 flex-1 rounded-lg bg-base-50 px-2 py-1 text-base-500 dark:bg-base-850 dark:text-base-400"
|
|
>
|
|
{@render settingValue(key, savedConfig?.[key])}
|
|
</div>
|
|
<ArrowRight className="mt-1.5 size-3 shrink-0 text-base-400" />
|
|
<div class="min-w-0 flex-1 rounded-lg bg-base-50 px-2 py-1 dark:bg-base-850">
|
|
{@render settingValue(key, settings?.[key])}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{/each}
|
|
</div>
|
|
</ConfirmDialog>
|