@scalar/api-client
Version:
the open source API testing client
124 lines (123 loc) • 4.28 kB
JavaScript
import { defineComponent as T, ref as v, computed as h, useTemplateRef as B, createBlock as u, openBlock as m, withCtx as l, createVNode as d, createTextVNode as E, unref as s, createElementVNode as f, normalizeClass as M, toDisplayString as R } from "vue";
import { ScalarListbox as $, ScalarButton as b, ScalarIcon as j } from "@scalar/components";
import { useToasts as z } from "@scalar/use-toasts";
import { emitCustomEvent as I } from "@scalar/workspace-store/events";
import { useRouter as L } from "vue-router";
import { PathId as C } from "../../routes.js";
import { useActiveEntities as O } from "../../store/active-entities.js";
import W from "./CommandActionForm.vue.js";
import A from "./CommandActionInput.vue.js";
import { useWorkspace as q } from "../../store/store.js";
const te = /* @__PURE__ */ T({
__name: "CommandPaletteServer",
props: {
metaData: {}
},
emits: ["close", "back"],
setup(x, { emit: S }) {
const n = x, c = S, k = L(), { toast: p } = z(), { activeCollection: w, activeWorkspaceCollections: V } = O(), {
collectionMutators: g,
serverMutators: D,
events: U,
collections: y
} = q(), a = v(""), i = h(
() => V.value.flatMap(
(e) => e.info?.title === "Drafts" ? [] : {
id: e.uid,
label: e.info?.title ?? "Unititled Collection"
}
)
), o = v(
n.metaData ? i.value.find(
(e) => e.id === n.metaData?.itemUid || e.id === n.metaData?.parentUid
) : i.value.find(
(e) => e.id === w.value?.uid
)
), P = () => {
if (!a.value.trim()) {
p("Please enter a valid url before creating a server.", "error");
return;
}
const e = y[o.value?.id ?? ""];
if (!e) {
p("Please select a collection before creating a server.", "error");
return;
}
const t = D.add({ url: a.value }, e.uid);
g.edit(e.uid, "selectedServerUid", t.uid), I(N.value?.$el, "scalar-add-server", {
server: { url: a.value },
options: {
disableOldStoreUpdate: !0
}
}), k.push({
name: "collection.servers.edit",
params: {
[C.Collection]: e.uid,
[C.Servers]: t.uid
}
}), c("close");
}, _ = () => {
U.commandPalette.emit({ commandName: "Create Collection" });
}, N = B("wrapper-ref");
return (e, t) => (m(), u(W, {
ref: "wrapper-ref",
disabled: !a.value.trim() || !o.value,
onSubmit: P
}, {
options: l(() => [
d(s($), {
modelValue: o.value,
"onUpdate:modelValue": t[2] || (t[2] = (r) => o.value = r),
options: i.value
}, {
default: l(() => [
i.value.length > 0 ? (m(), u(s(b), {
key: 0,
class: "hover:bg-b-2 max-h-8 w-fit justify-between gap-1 p-2 text-xs",
variant: "outlined"
}, {
default: l(() => [
f("span", {
class: M(o.value ? "text-c-1" : "text-c-3")
}, R(o.value ? o.value.label : "Select Collection"), 3),
d(s(j), {
class: "text-c-3",
icon: "ChevronDown",
size: "md"
})
]),
_: 1
})) : (m(), u(s(b), {
key: 1,
class: "hover:bg-b-2 max-h-8 w-fit justify-between gap-1 p-2 text-xs",
variant: "outlined",
onClick: _
}, {
default: l(() => [...t[3] || (t[3] = [
f("span", { class: "text-c-1" }, "Create Collection", -1)
])]),
_: 1
}))
]),
_: 1
}, 8, ["modelValue", "options"])
]),
submit: l(() => [...t[4] || (t[4] = [
E(" Create Server ", -1)
])]),
default: l(() => [
d(A, {
modelValue: a.value,
"onUpdate:modelValue": t[0] || (t[0] = (r) => a.value = r),
label: "Server URL",
placeholder: "https://void.scalar.com",
onOnDelete: t[1] || (t[1] = (r) => c("back", r))
}, null, 8, ["modelValue"])
]),
_: 1
}, 8, ["disabled"]));
}
});
export {
te as default
};