MCPcopy Create free account
hub / github.com/outerbase/studio / SaveDocButton

Function SaveDocButton

src/components/gui/save-doc-button.tsx:25–114  ·  view source on GitHub ↗
({
  docId,
  onComplete,
  onPrepareContent,
}: Props)

Source from the content-addressed store, hash-verified

23}
24
25export default function SaveDocButton({
26 docId,
27 onComplete,
28 onPrepareContent,
29}: Props) {
30 const [open, setOpen] = useState(false);
31 const [loading, setLoading] = useState(false);
32 const { docDriver } = useStudioContext();
33 const [namespaceList, setNamespaceList] = useState<SavedDocNamespace[]>([]);
34
35 const onSaveQuery = useCallback(
36 (namespaceId?: string) => {
37 if (docDriver) {
38 if (docId) {
39 setLoading(true);
40 docDriver.updateDoc(docId, onPrepareContent()).finally(() => {
41 setLoading(false);
42 });
43 } else {
44 if (namespaceId) {
45 setLoading(true);
46 docDriver
47 .createDoc("sql", namespaceId, onPrepareContent())
48 .then(onComplete)
49 .finally(() => {
50 setLoading(false);
51 });
52 } else {
53 docDriver.getNamespaces().then((n) => {
54 if (n.length === 1) {
55 setLoading(true);
56 docDriver
57 .createDoc("sql", n[0].id, onPrepareContent())
58 .then(onComplete)
59 .finally(() => {
60 setLoading(false);
61 });
62 } else {
63 setNamespaceList(n);
64 setOpen(true);
65 }
66 });
67 }
68 }
69 }
70 },
71 [docDriver, onPrepareContent, docId, onComplete]
72 );
73
74 return (
75 <DropdownMenu
76 open={open}
77 onOpenChange={(openState) => {
78 if (!openState) setOpen(false);
79 }}
80 >
81 <DropdownMenuTrigger asChild>
82 <Button

Callers

nothing calls this directly

Calls 4

useStudioContextFunction · 0.90
updateDocMethod · 0.45
createDocMethod · 0.45
getNamespacesMethod · 0.45

Tested by

no test coverage detected