@scalar/api-client
Version:
the open source API testing client
74 lines (73 loc) • 2.23 kB
JavaScript
import { defineComponent as C, createElementBlock as h, createCommentVNode as y, openBlock as r, Fragment as v, createBlock as u, unref as a, withCtx as m, createTextVNode as c } from "vue";
import { ScalarButton as l } from "@scalar/components";
import { useToasts as x } from "@scalar/use-toasts";
import { useRouter as b } from "vue-router";
import { useActiveEntities as g } from "../../store/active-entities.js";
import { importCollection as B } from "./utils/import-collection.js";
import { useWorkspace as I } from "../../store/store.js";
const R = /* @__PURE__ */ C({
__name: "ImportNowButton",
props: {
source: {},
variant: {},
watchMode: { type: Boolean, default: !0 }
},
emits: ["importFinished"],
setup(o, { emit: p }) {
const f = p, d = b(), k = I(), { activeWorkspace: n } = g(), { toast: s } = x();
function i() {
B({
store: k,
workspace: n.value,
source: o.source,
watchMode: o.watchMode,
onSuccess(t) {
t && (w(t), s("Import successful", "info"), f("importFinished"));
},
onError(t) {
console.error("[importCollection]", t);
const e = t?.message || "Unknown error";
s(`Import failed: ${e}`, "error");
}
});
}
function w(t) {
t && d.push({
name: "request",
params: {
workspace: n.value?.uid,
request: t?.requests[0]
}
});
}
return (t, e) => o.source ? (r(), h(v, { key: 0 }, [
o.variant === "button" ? (r(), u(a(l), {
key: 0,
class: "mt-3 h-fit w-full rounded-lg px-6 py-2.5 font-bold",
size: "md",
type: "button",
onClick: i
}, {
default: m(() => [...e[0] || (e[0] = [
c(" Import Collection ", -1)
])]),
_: 1
})) : (r(), u(a(l), {
key: 1,
class: "h-fit rounded-lg px-6 py-2.5 text-[21px] font-bold",
size: "md",
type: "button",
variant: "ghost",
onClick: i
}, {
default: m(() => [...e[1] || (e[1] = [
c(" Try it in the browser ", -1)
])]),
_: 1
}))
], 64)) : y("", !0);
}
});
export {
R as default
};