@scalar/api-client
Version:
the open source API testing client
76 lines (75 loc) • 2.25 kB
JavaScript
import { defineComponent as y, createElementBlock as C, createCommentVNode as h, 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 z = /* @__PURE__ */ y({
__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();
async 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(), C(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,
__: [0]
})) : (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)) : h("", !0);
}
});
export {
z as default
};