Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ui/src/api/mock/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,7 @@ export class MockTransport implements Transport {
return json(200, [
{ repo: `${root}\\shop`, id: 'shop-3f9a1c', name: 'shop', error: null, registered: true, added: false },
{ repo: `${root}\\billing`, id: 'b111', name: 'billing', error: null, registered: add, added: add },
{ repo: `${root}\\worker`, id: 'w333', name: 'worker', error: null, registered: add, added: add },
{ repo: `${root}\\legacy`, id: 'l222', name: null, error: 'devstack.toml: unknown field `biuld`', registered: false, added: false },
]);
}
Expand Down
113 changes: 51 additions & 62 deletions ui/src/components/AddStackDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ import { computed, ref, watch } from 'vue';
import { useRouter } from 'vue-router';
import { api, paths } from '@/api';
import { act } from '@/lib/actions';
import { useUi } from '@/stores/ui';
import AgentPrompt from './AgentPrompt.vue';
import FolderField from './FolderField.vue';
import Modal from './Modal.vue';
import Icon from './icons/Icon.vue';
import ScanStacks from './ScanStacks.vue';
import { stackPage } from '@/lib/stackRoutes';

const props = defineProps<{ open: boolean }>();
const emit = defineEmits<{ close: [] }>();
const ui = useUi();
const router = useRouter();

type Inspect = { repo: string; is_dir: boolean; has_stack_file: boolean; valid: { Ok?: null; Err?: string } | null; registered: string | null; id: string };
Expand All @@ -41,42 +40,31 @@ watch(
},
);

// The hub shows the operating system's folder dialog (a page cannot learn a
// folder's path). Where it cannot (no desktop), the text field stays.
const canPick = ref(true);
const picking = ref(false);
async function pick() {
picking.value = true;
problem.value = null;
try {
const res = await api().request<{ path: string | null } | { error: string }>('POST', paths.pickFolder);
const b = typeof res.body === 'object' ? res.body : null;
if (res.status === 501) {
canPick.value = false;
ui.toast('info', 'No folder dialog on this machine', 'Paste the folder path instead.');
} else if (res.ok && b && 'path' in b) {
if (b.path) {
path.value = b.path;
await check();
}
} else {
problem.value = b && 'error' in b ? b.error : `HTTP ${res.status}`;
}
} catch {
problem.value = 'The hub does not answer.';
} finally {
picking.value = false;
}
}
// A typed or pasted path is checked once typing pauses; a picked one, Enter
// or a click at once. An answer for a path the field no longer holds is
// dropped.
let timer: ReturnType<typeof setTimeout> | undefined;
watch(
path,
() => {
clearTimeout(timer);
info.value = null;
problem.value = null;
if (path.value.trim()) timer = setTimeout(check, 450);
},
{ flush: 'sync' },
);

async function check() {
clearTimeout(timer);
const p = path.value.trim();
if (!p) return;
checking.value = true;
problem.value = null;
info.value = null;
try {
const res = await api().request<Inspect | { error: string }>('GET', paths.inspect(p));
if (p !== path.value.trim()) return;
const b = typeof res.body === 'object' ? res.body : null;
if (res.ok && b && 'repo' in b) info.value = b;
else problem.value = b && 'error' in b ? b.error : `HTTP ${res.status}`;
Expand Down Expand Up @@ -112,11 +100,11 @@ async function add() {

<template>
<Modal :open="open" title="Add a stack" size="lg" testid="add-stack" @close="emit('close')">
<div class="modes" role="tablist" aria-label="How to add">
<button type="button" role="tab" class="btn btn-sm" :aria-selected="mode === 'one'" :class="{ active: mode === 'one' }" data-testid="add-mode-one" @click="mode = 'one'">
<div class="tabs" role="tablist" aria-label="How to add">
<button type="button" role="tab" class="tab" :aria-selected="mode === 'one'" :class="{ active: mode === 'one' }" data-testid="add-mode-one" @click="mode = 'one'">
<Icon name="folder" :size="14" /> One repository
</button>
<button type="button" role="tab" class="btn btn-sm" :aria-selected="mode === 'scan'" :class="{ active: mode === 'scan' }" data-testid="add-mode-scan" @click="mode = 'scan'">
<button type="button" role="tab" class="tab" :aria-selected="mode === 'scan'" :class="{ active: mode === 'scan' }" data-testid="add-mode-scan" @click="mode = 'scan'">
<Icon name="search" :size="14" /> Scan a folder of repositories
</button>
</div>
Expand All @@ -125,16 +113,8 @@ async function add() {
<ScanStacks @added="emit('close')" />
</template>
<template v-else>
<p class="muted">The folder of a repository. Choose it, or paste its path. devstack looks for its <code>devstack.toml</code>.</p>
<form class="pathrow" @submit.prevent="check">
<button v-if="canPick" type="button" class="btn" :disabled="picking" data-testid="add-stack-pick" @click="pick">
<span v-if="picking" class="spinner" /><Icon v-else name="folder" :size="14" /> Choose folder…
</button>
<input v-model="path" class="input grow" type="text" placeholder="C:\src\shop or /home/me/src/shop" spellcheck="false" autocomplete="off" data-testid="add-stack-path" />
<button type="submit" class="btn btn-primary" :disabled="!path.trim() || checking" data-testid="add-stack-check">
<span v-if="checking" class="spinner" /><Icon v-else name="search" :size="14" /> Check
</button>
</form>
<p class="muted">The folder of a repository: browse to it, or paste its path. devstack looks for its <code>devstack.toml</code>.</p>
<FolderField v-model="path" placeholder="C:\src\shop or /home/me/src/shop" :busy="checking" testid="add-stack" @submit="check" @picked="check" @problem="problem = $event" />

<p v-if="problem" class="note danger">{{ problem }}</p>

Expand Down Expand Up @@ -168,28 +148,37 @@ async function add() {
</template>

<style scoped>
.modes {
.tabs {
display: flex;
gap: 6px;
margin-bottom: 4px;
}
.modes .active {
border-color: var(--accent);
background: var(--accent-soft);
gap: 2px;
margin: 0 0 12px;
border-bottom: 1px solid var(--border);
}
.pathrow {
display: flex;
gap: 8px;
margin: 12px 0;
}
.input {
font: 13px/1.4 var(--font-mono, ui-monospace, Consolas, monospace);
padding: 7px 10px;
border: 1px solid var(--border);
border-radius: 8px;
background: var(--surface, transparent);
color: inherit;
min-width: 0;
.tab {
display: inline-flex;
align-items: center;
gap: 7px;
height: 38px;
padding: 0 12px;
margin-bottom: -1px;
border: 0;
border-bottom: 2px solid transparent;
background: none;
color: var(--text-muted);
font-weight: 550;
font-size: 13px;
cursor: pointer;
}
.tab:hover {
color: var(--text);
}
.tab.active {
color: var(--text);
border-bottom-color: var(--accent);
}
.tab:focus-visible {
outline: none;
box-shadow: inset var(--focus);
}
.note {
border: 1px solid var(--border);
Expand Down
125 changes: 125 additions & 0 deletions ui/src/components/FolderField.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<script setup lang="ts">
// A folder path as one control: the path field, the button that opens the
// operating system's folder dialog through the hub (a page never learns a
// picked folder's absolute path), and the action. The hub answers 501 where
// it has no desktop; then only the field stays.
import { ref } from 'vue';
import { api, paths } from '@/api';
import { useUi } from '@/stores/ui';
import Icon from './icons/Icon.vue';

const path = defineModel<string>({ required: true });
defineProps<{ placeholder: string; busy?: boolean; testid: string }>();
const emit = defineEmits<{ submit: []; picked: []; problem: [message: string] }>();
const ui = useUi();

const canPick = ref(true);
const picking = ref(false);

async function pick() {
picking.value = true;
try {
const res = await api().request<{ path: string | null } | { error: string }>('POST', paths.pickFolder);
const b = typeof res.body === 'object' ? res.body : null;
if (res.status === 501) {
canPick.value = false;
ui.toast('info', 'No folder dialog on this machine', 'Paste the folder path instead.');
} else if (res.ok && b && 'path' in b) {
if (b.path) {
path.value = b.path;
emit('picked');
}
} else {
emit('problem', b && 'error' in b ? b.error : `HTTP ${res.status}`);
}
} catch {
emit('problem', 'The hub does not answer.');
} finally {
picking.value = false;
}
}
</script>

<template>
<form class="field" @submit.prevent="emit('submit')">
<Icon name="folder" :size="15" class="lead" />
<input v-model="path" type="text" :placeholder="placeholder" spellcheck="false" autocomplete="off" aria-label="Folder path" :data-testid="`${testid}-path`" />
<span v-if="busy" class="spinner" />
<button v-if="canPick" type="button" class="browse" :disabled="picking" title="Choose the folder in a dialog" :data-testid="`${testid}-pick`" @click="pick">
<span v-if="picking" class="spinner" />
<template v-else>Browse…</template>
</button>
<slot />
</form>
</template>

<style scoped>
.field {
display: flex;
align-items: center;
height: 38px;
margin: 12px 0;
border: 1px solid var(--border-strong);
border-radius: var(--radius);
background: var(--surface);
overflow: hidden;
transition: border-color 0.12s var(--ease);
}
.field:focus-within {
border-color: var(--accent);
box-shadow: var(--focus);
}
.lead {
flex: none;
margin: 0 2px 0 11px;
color: var(--text-faint);
}
input {
flex: 1;
min-width: 0;
height: 100%;
padding: 0 8px;
border: 0;
background: transparent;
color: inherit;
font: 13px/1.4 var(--font-mono, ui-monospace, Consolas, monospace);
}
input:focus,
input:focus-visible {
outline: none;
box-shadow: none;
}
.field > .spinner {
flex: none;
margin-right: 10px;
}
.browse {
flex: none;
display: inline-flex;
align-items: center;
height: 100%;
padding: 0 14px;
border: 0;
border-left: 1px solid var(--border);
background: var(--surface-2);
color: var(--text-2);
font-weight: 500;
font-size: 13px;
cursor: pointer;
}
.browse:hover:not(:disabled) {
background: var(--surface-hover);
color: var(--text);
}
.browse:focus-visible,
.field :slotted(button:focus-visible) {
outline: none;
box-shadow: inset var(--focus);
}
.field :slotted(.btn) {
height: 100%;
border: 0;
border-left: 1px solid var(--border);
border-radius: 0;
}
</style>
Loading