Refactor: Use a single array of shortcuts to prevent bugs on MACOS
This commit is contained in:
parent
9d73489ea9
commit
3541101047
6 changed files with 14 additions and 65 deletions
|
|
@ -815,27 +815,6 @@ export const defaultShortcuts = [
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export const unavailableShortcutss = [
|
|
||||||
"CTRL + R",
|
|
||||||
"CTRL + V",
|
|
||||||
"CTRL + X",
|
|
||||||
"CTRL + G",
|
|
||||||
"CTRL + SHIFT + A",
|
|
||||||
"CTRL + Q",
|
|
||||||
"CTRL + SHIFT + U",
|
|
||||||
"CTRL + C",
|
|
||||||
"CTRL + D",
|
|
||||||
"CTRL + SHIFT + S",
|
|
||||||
"CTRL + SHIFT + D",
|
|
||||||
"CTRL + S",
|
|
||||||
"BACKSPACE",
|
|
||||||
"CTRL + K",
|
|
||||||
"CTRL + Z",
|
|
||||||
"CTRL + Y",
|
|
||||||
"CTRL + J",
|
|
||||||
"CTRL + U",
|
|
||||||
"CTRL + F",
|
|
||||||
];
|
|
||||||
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.`;
|
||||||
|
|
||||||
export const DEFAULT_TABLE_ALERT_TITLE = "No Data Available";
|
export const DEFAULT_TABLE_ALERT_TITLE = "No Data Available";
|
||||||
|
|
|
||||||
|
|
@ -37,15 +37,12 @@ export default function EditShortcutButton({
|
||||||
const [key, setKey] = useState<string | null>(null);
|
const [key, setKey] = useState<string | null>(null);
|
||||||
const setSuccessData = useAlertStore((state) => state.setSuccessData);
|
const setSuccessData = useAlertStore((state) => state.setSuccessData);
|
||||||
const setShortcuts = useShortcutsStore((state) => state.setShortcuts);
|
const setShortcuts = useShortcutsStore((state) => state.setShortcuts);
|
||||||
const unavaliableShortcuts = useShortcutsStore(
|
|
||||||
(state) => state.unavailableShortcuts,
|
|
||||||
);
|
|
||||||
const setErrorData = useAlertStore((state) => state.setErrorData);
|
const setErrorData = useAlertStore((state) => state.setErrorData);
|
||||||
|
|
||||||
function canEditCombination(newCombination: string): boolean {
|
function canEditCombination(newCombination: string): boolean {
|
||||||
let canSave = true;
|
let canSave = true;
|
||||||
unavaliableShortcuts.forEach((s) => {
|
defaultShortcuts.forEach(({ shortcut }) => {
|
||||||
if (s.toLowerCase() === newCombination.toLowerCase()) {
|
if (shortcut.toLowerCase() === newCombination.toLowerCase()) {
|
||||||
canSave = false;
|
canSave = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -65,11 +62,6 @@ export default function EditShortcutButton({
|
||||||
}
|
}
|
||||||
return { name: s.name, shortcut: s.shortcut };
|
return { name: s.name, shortcut: s.shortcut };
|
||||||
});
|
});
|
||||||
const unavailable = unavaliableShortcuts.map((s) => {
|
|
||||||
if (s.toLowerCase() === defaultCombination.toLowerCase())
|
|
||||||
return (s = key.toUpperCase());
|
|
||||||
return s;
|
|
||||||
});
|
|
||||||
const fixCombination = key.split(" ");
|
const fixCombination = key.split(" ");
|
||||||
if (
|
if (
|
||||||
fixCombination[0].toLowerCase().includes("ctrl") ||
|
fixCombination[0].toLowerCase().includes("ctrl") ||
|
||||||
|
|
@ -79,23 +71,16 @@ export default function EditShortcutButton({
|
||||||
}
|
}
|
||||||
const shortcutName = shortcut[0].split(" ")[0].toLowerCase();
|
const shortcutName = shortcut[0].split(" ")[0].toLowerCase();
|
||||||
setUniqueShortcut(shortcutName, fixCombination.join("").toLowerCase());
|
setUniqueShortcut(shortcutName, fixCombination.join("").toLowerCase());
|
||||||
console.log(newCombination);
|
setShortcuts(newCombination);
|
||||||
setShortcuts(newCombination, unavailable);
|
|
||||||
setOpen(false);
|
|
||||||
setSuccessData({
|
|
||||||
title: `${shortcut[0]} shortcut successfully changed`,
|
|
||||||
});
|
|
||||||
setKey(null);
|
|
||||||
localStorage.removeItem("langflow-shortcuts");
|
|
||||||
localStorage.removeItem("langflow-UShortcuts");
|
|
||||||
localStorage.setItem(
|
localStorage.setItem(
|
||||||
"langflow-shortcuts",
|
"langflow-shortcuts",
|
||||||
JSON.stringify(newCombination),
|
JSON.stringify(newCombination),
|
||||||
);
|
);
|
||||||
localStorage.setItem(
|
setKey(null);
|
||||||
"langflow-UShortcuts",
|
setOpen(false);
|
||||||
JSON.stringify(unavailable),
|
setSuccessData({
|
||||||
);
|
title: `${shortcut[0]} shortcut successfully changed`,
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,7 @@ import { useEffect, useState } from "react";
|
||||||
import ForwardedIconComponent from "../../../../components/genericIconComponent";
|
import ForwardedIconComponent from "../../../../components/genericIconComponent";
|
||||||
import TableComponent from "../../../../components/tableComponent";
|
import TableComponent from "../../../../components/tableComponent";
|
||||||
import { Button } from "../../../../components/ui/button";
|
import { Button } from "../../../../components/ui/button";
|
||||||
import {
|
import { defaultShortcuts } from "../../../../constants/constants";
|
||||||
defaultShortcuts,
|
|
||||||
unavailableShortcutss,
|
|
||||||
} from "../../../../constants/constants";
|
|
||||||
import { useShortcutsStore } from "../../../../stores/shortcuts";
|
import { useShortcutsStore } from "../../../../stores/shortcuts";
|
||||||
import EditShortcutButton from "./EditShortcutButton";
|
import EditShortcutButton from "./EditShortcutButton";
|
||||||
|
|
||||||
|
|
@ -45,9 +42,8 @@ export default function ShortcutsPage() {
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
|
|
||||||
function handleRestore() {
|
function handleRestore() {
|
||||||
setShortcuts(defaultShortcuts, unavailableShortcutss);
|
setShortcuts(defaultShortcuts);
|
||||||
localStorage.removeItem("langflow-shortcuts");
|
localStorage.removeItem("langflow-shortcuts");
|
||||||
localStorage.removeItem("langflow-UShortcuts");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,11 @@
|
||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
import {
|
import { defaultShortcuts } from "../constants/constants";
|
||||||
defaultShortcuts,
|
|
||||||
unavailableShortcutss,
|
|
||||||
} from "../constants/constants";
|
|
||||||
import { shortcutsStoreType } from "../types/store";
|
import { shortcutsStoreType } from "../types/store";
|
||||||
|
|
||||||
export const useShortcutsStore = create<shortcutsStoreType>((set, get) => ({
|
export const useShortcutsStore = create<shortcutsStoreType>((set, get) => ({
|
||||||
unavailableShortcuts: unavailableShortcutss,
|
|
||||||
shortcuts: defaultShortcuts,
|
shortcuts: defaultShortcuts,
|
||||||
setShortcuts: (newShortcuts, unavailable) => {
|
setShortcuts: (newShortcuts) => {
|
||||||
set({ shortcuts: newShortcuts, unavailableShortcuts: unavailable });
|
set({ shortcuts: newShortcuts });
|
||||||
},
|
},
|
||||||
undo: "mod+z",
|
undo: "mod+z",
|
||||||
redo: "mod+y",
|
redo: "mod+y",
|
||||||
|
|
@ -38,7 +34,6 @@ export const useShortcutsStore = create<shortcutsStoreType>((set, get) => ({
|
||||||
getShortcutsFromStorage: () => {
|
getShortcutsFromStorage: () => {
|
||||||
if (localStorage.getItem("langflow-shortcuts")) {
|
if (localStorage.getItem("langflow-shortcuts")) {
|
||||||
const savedShortcuts = localStorage.getItem("langflow-shortcuts");
|
const savedShortcuts = localStorage.getItem("langflow-shortcuts");
|
||||||
const savedUShortcuts = localStorage.getItem("langflow-UShortcuts");
|
|
||||||
const savedArr = JSON.parse(savedShortcuts!);
|
const savedArr = JSON.parse(savedShortcuts!);
|
||||||
savedArr.forEach(({ name, shortcut }) => {
|
savedArr.forEach(({ name, shortcut }) => {
|
||||||
let shortcutName = name.split(" ")[0].toLowerCase();
|
let shortcutName = name.split(" ")[0].toLowerCase();
|
||||||
|
|
@ -46,10 +41,7 @@ export const useShortcutsStore = create<shortcutsStoreType>((set, get) => ({
|
||||||
[shortcutName]: shortcut,
|
[shortcutName]: shortcut,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
get().setShortcuts(
|
get().setShortcuts(JSON.parse(savedShortcuts!));
|
||||||
JSON.parse(savedShortcuts!),
|
|
||||||
JSON.parse(savedUShortcuts!),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
|
||||||
|
|
@ -44,10 +44,8 @@ export type shortcutsStoreType = {
|
||||||
name: string;
|
name: string;
|
||||||
shortcut: string;
|
shortcut: string;
|
||||||
}>;
|
}>;
|
||||||
unavailableShortcuts: string[];
|
|
||||||
setShortcuts: (
|
setShortcuts: (
|
||||||
newShortcuts: Array<{ name: string; shortcut: string }>,
|
newShortcuts: Array<{ name: string; shortcut: string }>,
|
||||||
unavailable: string[],
|
|
||||||
) => void;
|
) => void;
|
||||||
getShortcutsFromStorage: () => void;
|
getShortcutsFromStorage: () => void;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -541,7 +541,6 @@ export const nodeIconsLucide: iconsType = {
|
||||||
FolderIcon,
|
FolderIcon,
|
||||||
Discord: FaDiscord,
|
Discord: FaDiscord,
|
||||||
PaperclipIcon,
|
PaperclipIcon,
|
||||||
RotateCcw,
|
|
||||||
Settings,
|
Settings,
|
||||||
Streamlit,
|
Streamlit,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue