mirror of
https://github.com/open-webui/open-webui.git
synced 2026-12-03 18:17:56 -05:00
refac
This commit is contained in:
1 parent
3854a4d086
commit
ee38c0213c
4 files changed
+75
-12
No files matched your search
@@ -17,7 +17,9 @@ class ViewModel(BaseModel):
|
||||
|
||||
class PanelTab(ViewModel):
|
||||
id: str
|
||||
kind: Literal['chat', 'comments', 'files', 'file', 'terminal', 'browser', 'desktop', 'side', 'page', 'overview']
|
||||
kind: Literal[
|
||||
'chat', 'comments', 'files', 'file', 'git', 'terminal', 'browser', 'desktop', 'side', 'page', 'overview'
|
||||
]
|
||||
label: str
|
||||
href: str | None = None
|
||||
machineId: str | None = None
|
||||
|
||||
@@ -697,6 +697,7 @@
|
||||
chat: 'chat-lines',
|
||||
page: 'page',
|
||||
files: 'folder',
|
||||
git: 'git-branch',
|
||||
file: 'page',
|
||||
terminal: 'terminal',
|
||||
browser: 'browser',
|
||||
@@ -964,6 +965,21 @@
|
||||
});
|
||||
if (page != null) fileViews[id]?.revealPage?.(page);
|
||||
};
|
||||
const openGit = (machineId: string, root: string, sourceModelId = modelId) => {
|
||||
if (!isMachineReachable(machineId)) return;
|
||||
const target = resolveMachineTarget(machineId, $machines ?? [], localStorage.token, {
|
||||
chatId: panelChatId,
|
||||
modelId: sourceModelId ?? null
|
||||
});
|
||||
openPanel({
|
||||
id: JSON.stringify(['git', machineId, target?.context.modelId ?? null, root]),
|
||||
kind: 'git',
|
||||
label: root.split('/').filter(Boolean).pop() || $i18n.t('Git'),
|
||||
machineId,
|
||||
target: target ?? undefined,
|
||||
directory: root
|
||||
});
|
||||
};
|
||||
const openNewFileTab = () => {
|
||||
if (!selectedConnection) return askForMachine(openNewFileTab);
|
||||
let number = 1;
|
||||
@@ -2459,6 +2475,22 @@
|
||||
});
|
||||
}}
|
||||
/>
|
||||
{:else if tab.kind === 'git' && tab.machineId && target}
|
||||
<GitBar
|
||||
standalone
|
||||
bind:this={gitViews[tab.id]}
|
||||
initialView={chatView.transient[`git:${tab.id}`]}
|
||||
bind:diffMode={fileGitDiffModes[tab.machineId]}
|
||||
bind:hideWhitespace={fileGitHideWhitespace[tab.machineId]}
|
||||
{target}
|
||||
chatId={chatView.chatId}
|
||||
directory={tab.directory ?? '.'}
|
||||
active={panelVisible && visibleTabIds.has(tab.id)}
|
||||
onOpenFile={(path) => openFile(path, tab.machineId!, null, target.context.modelId)}
|
||||
onOpenDirectory={(path) =>
|
||||
openFiles(tab.machineId, path, false, target.context.modelId)}
|
||||
{onDraftPrompt}
|
||||
/>
|
||||
{:else if (tab.kind === 'files' || tab.kind === 'file') && tab.machineId}
|
||||
{@const fileTarget = isMounted ? resolveTabConnection(tab) : null}
|
||||
<div class="flex h-full min-h-0 flex-col">
|
||||
@@ -2541,6 +2573,7 @@
|
||||
openFile(path, tab.machineId!, null, fileTarget?.context.modelId)}
|
||||
onOpenDirectory={(path) =>
|
||||
openFiles(tab.machineId, path, false, fileTarget?.context.modelId)}
|
||||
onOpenTab={(root) => openGit(tab.machineId!, root, fileTarget?.context.modelId)}
|
||||
{onDraftPrompt}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
@@ -34,7 +34,10 @@
|
||||
const i18n = getContext<any>('i18n');
|
||||
export let status: GitStatus | null = null;
|
||||
export let initialView: any = null;
|
||||
let expanded = initialView?.expanded ?? false;
|
||||
/** Fills a tab of its own: always expanded, no collapse or resize. */
|
||||
export let standalone = false;
|
||||
export let onOpenTab: ((root: string) => void) | null = null;
|
||||
let expanded = standalone || (initialView?.expanded ?? false);
|
||||
export const captureView = () => ({ expanded, summary, description, height, listWidth, view });
|
||||
export let diffMode: 'unified' | 'split' = 'unified';
|
||||
export let hideWhitespace = false;
|
||||
@@ -266,7 +269,7 @@
|
||||
status = null;
|
||||
error = '';
|
||||
detectionError = '';
|
||||
expanded = restoring?.expanded ?? false;
|
||||
expanded = standalone || (restoring?.expanded ?? false);
|
||||
showBranches =
|
||||
showWorktrees =
|
||||
showRename =
|
||||
@@ -471,6 +474,7 @@
|
||||
)
|
||||
];
|
||||
const toggle = () => {
|
||||
if (standalone) return;
|
||||
expanded = !expanded;
|
||||
if (expanded) {
|
||||
void refresh(true);
|
||||
@@ -497,10 +501,12 @@
|
||||
|
||||
{#if status?.is_repo}
|
||||
<section
|
||||
class="@container relative shrink-0 border-t border-base-200/40 dark:border-base-850/20"
|
||||
class="@container relative {standalone
|
||||
? 'flex h-full min-h-0 flex-col'
|
||||
: 'shrink-0 border-t border-base-200/40 dark:border-base-850/20'}"
|
||||
aria-label={$i18n.t('Git')}
|
||||
>
|
||||
{#if expanded}
|
||||
{#if expanded && !standalone}
|
||||
<div
|
||||
role="separator"
|
||||
aria-label={$i18n.t('Resize Git panel')}
|
||||
@@ -769,11 +775,24 @@
|
||||
></button
|
||||
>
|
||||
</Tooltip>
|
||||
<button
|
||||
class="flex h-6 w-5 items-center justify-center text-base-500 dark:text-base-400 hover:text-base-700 dark:hover:text-base-200 ml-0.5 shrink-0"
|
||||
aria-label={expanded ? $i18n.t('Collapse Git panel') : $i18n.t('Expand Git panel')}
|
||||
on:click={toggle}><Icon name={expanded ? 'chevron-down' : 'chevron-up'} size={14} /></button
|
||||
>
|
||||
{#if onOpenTab && !standalone}
|
||||
<Tooltip content={$i18n.t('Open in tab')}>
|
||||
<button
|
||||
class="flex h-6 w-5 items-center justify-center text-base-400 hover:text-base-600 dark:hover:text-base-300 shrink-0 transition-colors duration-75"
|
||||
aria-label={$i18n.t('Open in tab')}
|
||||
on:click={() => onOpenTab?.(status?.root ?? directory)}
|
||||
><Icon name="expand" size={12} /></button
|
||||
>
|
||||
</Tooltip>
|
||||
{/if}
|
||||
{#if !standalone}
|
||||
<button
|
||||
class="flex h-6 w-5 items-center justify-center text-base-500 dark:text-base-400 hover:text-base-700 dark:hover:text-base-200 ml-0.5 shrink-0"
|
||||
aria-label={expanded ? $i18n.t('Collapse Git panel') : $i18n.t('Expand Git panel')}
|
||||
on:click={toggle}
|
||||
><Icon name={expanded ? 'chevron-down' : 'chevron-up'} size={14} /></button
|
||||
>
|
||||
{/if}
|
||||
</div>
|
||||
{#if error}<div
|
||||
role="alert"
|
||||
@@ -783,8 +802,10 @@
|
||||
</div>{/if}
|
||||
{#if expanded}
|
||||
<div
|
||||
class="flex flex-col min-h-0 max-h-[65dvh] border-t border-base-100/50 dark:border-base-0/2"
|
||||
style:height={`${height + 32}px`}
|
||||
class="flex flex-col min-h-0 {standalone
|
||||
? 'flex-1'
|
||||
: 'max-h-[65dvh]'} border-t border-base-100/50 dark:border-base-0/2"
|
||||
style:height={standalone ? null : `${height + 32}px`}
|
||||
>
|
||||
<div
|
||||
class="flex items-center gap-0.5 px-1 h-8 shrink-0 border-b border-base-100/50 dark:border-base-0/2"
|
||||
@@ -1260,6 +1281,12 @@
|
||||
on:click={() => refresh(true)}><Icon name="refresh" size={12} /></button
|
||||
>
|
||||
</div>
|
||||
{:else if standalone && status}
|
||||
<div
|
||||
class="flex h-full items-center justify-center p-3 text-center text-xs text-base-400 dark:text-base-500"
|
||||
>
|
||||
{$i18n.t('Not a Git repository')}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Retired warning: keep its translation.
|
||||
|
||||
@@ -6,6 +6,7 @@ export type TabKind =
|
||||
| 'chat'
|
||||
| 'page'
|
||||
| 'files'
|
||||
| 'git'
|
||||
| 'file'
|
||||
| 'terminal'
|
||||
| 'browser'
|
||||
|
||||
Reference in new issue
Block a user