Feat: Add shortcut to open flow share modal
This commit is contained in:
parent
2bbf01deaa
commit
d14e13d4e4
5 changed files with 28 additions and 21 deletions
|
|
@ -30,11 +30,11 @@ export default function FlowToolbar(): JSX.Element {
|
||||||
|
|
||||||
const openPlayground = useShortcutsStore((state) => state.open);
|
const openPlayground = useShortcutsStore((state) => state.open);
|
||||||
const api = useShortcutsStore((state) => state.api);
|
const api = useShortcutsStore((state) => state.api);
|
||||||
const share = useShortcutsStore((state) => state.share);
|
const flow = useShortcutsStore((state) => state.flow);
|
||||||
|
|
||||||
useHotkeys(openPlayground, handleChatWShortcut, { preventDefault });
|
useHotkeys(openPlayground, handleChatWShortcut, { preventDefault });
|
||||||
useHotkeys(api, handleAPIWShortcut, { preventDefault });
|
useHotkeys(api, handleAPIWShortcut, { preventDefault });
|
||||||
useHotkeys(share, handleShareWShortcut, { preventDefault });
|
useHotkeys(flow, handleShareWShortcut, { preventDefault });
|
||||||
|
|
||||||
const [open, setOpen] = useState<boolean>(false);
|
const [open, setOpen] = useState<boolean>(false);
|
||||||
const [openCodeModal, setOpenCodeModal] = useState<boolean>(false);
|
const [openCodeModal, setOpenCodeModal] = useState<boolean>(false);
|
||||||
|
|
@ -55,7 +55,7 @@ export default function FlowToolbar(): JSX.Element {
|
||||||
component={currentFlow!}
|
component={currentFlow!}
|
||||||
disabled={!hasApiKey || !validApiKey || !hasStore}
|
disabled={!hasApiKey || !validApiKey || !hasStore}
|
||||||
open={openShareModal}
|
open={openShareModal}
|
||||||
setOpen={setOpen}
|
setOpen={setOpenShareModal}
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
disabled={!hasApiKey || !validApiKey || !hasStore}
|
disabled={!hasApiKey || !validApiKey || !hasStore}
|
||||||
|
|
@ -79,7 +79,14 @@ export default function FlowToolbar(): JSX.Element {
|
||||||
</button>
|
</button>
|
||||||
</ShareModal>
|
</ShareModal>
|
||||||
),
|
),
|
||||||
[hasApiKey, validApiKey, currentFlow, hasStore, openShareModal, setOpen],
|
[
|
||||||
|
hasApiKey,
|
||||||
|
validApiKey,
|
||||||
|
currentFlow,
|
||||||
|
hasStore,
|
||||||
|
openShareModal,
|
||||||
|
setOpenShareModal,
|
||||||
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -813,6 +813,10 @@ export const defaultShortcuts = [
|
||||||
name: "Freeze",
|
name: "Freeze",
|
||||||
shortcut: `${IS_MAC ? "Cmd" : "Ctrl"} + F`,
|
shortcut: `${IS_MAC ? "Cmd" : "Ctrl"} + F`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Flow Share",
|
||||||
|
shortcut: `${IS_MAC ? "Cmd" : "Ctrl"} + B`,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export const DEFAULT_TABLE_ALERT_MSG = `Oops! It seems there's no data to display right now. Please check back later.`;
|
export const DEFAULT_TABLE_ALERT_MSG = `Oops! It seems there's no data to display right now. Please check back later.`;
|
||||||
|
|
|
||||||
|
|
@ -42,24 +42,19 @@ export default function ShareModal({
|
||||||
setOpen?: (open: boolean) => void;
|
setOpen?: (open: boolean) => void;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
}): JSX.Element {
|
}): JSX.Element {
|
||||||
function handleOpenWShortcut(e: KeyboardEvent) {
|
|
||||||
if (hasApiKey || hasStore) {
|
|
||||||
e.preventDefault();
|
|
||||||
internalSetOpen((state) => !state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const version = useDarkStore((state) => state.version);
|
const version = useDarkStore((state) => state.version);
|
||||||
const hasStore = useStoreStore((state) => state.hasStore);
|
const hasStore = useStoreStore((state) => state.hasStore);
|
||||||
const hasApiKey = useStoreStore((state) => state.hasApiKey);
|
const hasApiKey = useStoreStore((state) => state.hasApiKey);
|
||||||
|
|
||||||
const setSuccessData = useAlertStore((state) => state.setSuccessData);
|
const setSuccessData = useAlertStore((state) => state.setSuccessData);
|
||||||
const setErrorData = useAlertStore((state) => state.setErrorData);
|
const setErrorData = useAlertStore((state) => state.setErrorData);
|
||||||
const [internalOpen, internalSetOpen] = useState(children ? false : true);
|
const [internalOpen, internalSetOpen] =
|
||||||
|
setOpen !== undefined && open !== undefined
|
||||||
|
? [open, setOpen]
|
||||||
|
: useState(children ? false : true);
|
||||||
const [openConfirmationModal, setOpenConfirmationModal] = useState(false);
|
const [openConfirmationModal, setOpenConfirmationModal] = useState(false);
|
||||||
const nameComponent = is_component ? "component" : "workflow";
|
const nameComponent = is_component ? "component" : "workflow";
|
||||||
|
|
||||||
useHotkeys("mod+alt+s", handleOpenWShortcut);
|
|
||||||
|
|
||||||
const [tags, setTags] = useState<{ id: string; name: string }[]>([]);
|
const [tags, setTags] = useState<{ id: string; name: string }[]>([]);
|
||||||
const [loadingTags, setLoadingTags] = useState<boolean>(false);
|
const [loadingTags, setLoadingTags] = useState<boolean>(false);
|
||||||
const [sharePublic, setSharePublic] = useState(true);
|
const [sharePublic, setSharePublic] = useState(true);
|
||||||
|
|
@ -75,13 +70,13 @@ export default function ShareModal({
|
||||||
const description = component?.description ?? "";
|
const description = component?.description ?? "";
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (open || internalOpen) {
|
if (internalOpen) {
|
||||||
if (hasApiKey && hasStore) {
|
if (hasApiKey && hasStore) {
|
||||||
handleGetTags();
|
handleGetTags();
|
||||||
handleGetNames();
|
handleGetNames();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [open, internalOpen, hasApiKey, hasStore]);
|
}, [internalOpen, hasApiKey, hasStore]);
|
||||||
|
|
||||||
function handleGetTags() {
|
function handleGetTags() {
|
||||||
setLoadingTags(true);
|
setLoadingTags(true);
|
||||||
|
|
@ -155,8 +150,7 @@ export default function ShareModal({
|
||||||
|
|
||||||
const handleUpdateComponent = () => {
|
const handleUpdateComponent = () => {
|
||||||
handleShareComponent(true);
|
handleShareComponent(true);
|
||||||
if (setOpen) setOpen(false);
|
internalSetOpen(false);
|
||||||
else internalSetOpen(false);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleExportComponent = () => {
|
const handleExportComponent = () => {
|
||||||
|
|
@ -208,8 +202,8 @@ export default function ShareModal({
|
||||||
<>
|
<>
|
||||||
<BaseModal
|
<BaseModal
|
||||||
size="smaller-h-full"
|
size="smaller-h-full"
|
||||||
open={(!disabled && open) ?? internalOpen}
|
open={!disabled && internalOpen}
|
||||||
setOpen={setOpen ?? internalSetOpen}
|
setOpen={internalSetOpen}
|
||||||
onSubmit={() => {
|
onSubmit={() => {
|
||||||
const isNameAvailable = !unavaliableNames.some(
|
const isNameAvailable = !unavaliableNames.some(
|
||||||
(element) => element.name === name,
|
(element) => element.name === name,
|
||||||
|
|
@ -217,7 +211,7 @@ export default function ShareModal({
|
||||||
|
|
||||||
if (isNameAvailable) {
|
if (isNameAvailable) {
|
||||||
handleShareComponent();
|
handleShareComponent();
|
||||||
(setOpen || internalSetOpen)(false);
|
internalSetOpen(false);
|
||||||
} else {
|
} else {
|
||||||
setOpenConfirmationModal(true);
|
setOpenConfirmationModal(true);
|
||||||
}
|
}
|
||||||
|
|
@ -298,7 +292,7 @@ export default function ShareModal({
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className="gap-2"
|
className="gap-2"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
(setOpen || internalSetOpen)(false);
|
internalSetOpen(false);
|
||||||
handleExportComponent();
|
handleExportComponent();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ export const useShortcutsStore = create<shortcutsStoreType>((set, get) => ({
|
||||||
setShortcuts: (newShortcuts) => {
|
setShortcuts: (newShortcuts) => {
|
||||||
set({ shortcuts: newShortcuts });
|
set({ shortcuts: newShortcuts });
|
||||||
},
|
},
|
||||||
|
flow: "mod+b",
|
||||||
undo: "mod+z",
|
undo: "mod+z",
|
||||||
redo: "mod+y",
|
redo: "mod+y",
|
||||||
open: "mod+k",
|
open: "mod+k",
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ export type StoreComponentResponse = {
|
||||||
|
|
||||||
export type shortcutsStoreType = {
|
export type shortcutsStoreType = {
|
||||||
updateUniqueShortcut: (name: string, combination: string) => void;
|
updateUniqueShortcut: (name: string, combination: string) => void;
|
||||||
|
flow: string;
|
||||||
group: string;
|
group: string;
|
||||||
cut: string;
|
cut: string;
|
||||||
paste: string;
|
paste: string;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue