@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 o, Fragment as v, createBlock as u, unref as a, withCtx as m, createTextVNode as c } from "vue";
import { ScalarButton as p } from "@scalar/components";
import { useToasts as b } from "@scalar/use-toasts";
import { useRouter as g } from "vue-router";
import { useActiveEntities as x } 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(r, { emit: l }) {
const f = l, d = g(), k = I(), { activeWorkspace: n } = x(), { toast: s } = b();
function i() {
B({
store: k,
workspace: n.value,
source: r.source,
watchMode: r.watchMode,
onSuccess(e) {
e && (w(e), s("Import successful", "info"), f("importFinished"));
},
onError(e) {
console.error("[importCollection]", e);
const t = e?.message || "Unknown error";
s(`Import failed: ${t}`, "error");
}
});
}
function w(e) {
e && d.push({
name: "request",
params: {
workspace: n.value?.uid,
request: e?.requests[0]
}
});
}
return (e, t) => e.source ? (o(), h(v, { key: 0 }, [
e.variant === "button" ? (o(), u(a(p), {
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(() => [...t[0] || (t[0] = [
c(" Import Collection ", -1)
])]),
_: 1
})) : (o(), u(a(p), {
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(() => [...t[1] || (t[1] = [
c(" Try it in the browser ", -1)
])]),
_: 1
}))
], 64)) : y("", !0);
}
});
export {
R as default
};