Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: update keyboard shortcuts display #3316

Merged
merged 44 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
56a5b13
remove repeated code
anovazzi1 Aug 7, 2024
bce2e6a
refactor: remove useless code
anovazzi1 Aug 7, 2024
19abddb
feat: sort input parameters in GenericNode renderInputParameter
anovazzi1 Aug 7, 2024
a7bd5f9
refactor: remove unused code in GenericNode component
anovazzi1 Aug 8, 2024
ae9c37f
refactor: add NodeName component for displaying and editing node names
anovazzi1 Aug 8, 2024
4b27c6b
refactor: add NodeDescription component for displaying and editing no…
anovazzi1 Aug 8, 2024
f6c1041
fix import and add autofocus on nodeName
anovazzi1 Aug 8, 2024
55247d0
feat: add NodeStatus component for displaying and managing node status
anovazzi1 Aug 8, 2024
9bbeaa4
[autofix.ci] apply automated fixes
autofix-ci[bot] Aug 8, 2024
693fe70
refactor: remove unused code in GenericNode component
anovazzi1 Aug 8, 2024
8a067a9
fix bugs on minimize
anovazzi1 Aug 8, 2024
52689fa
[autofix.ci] apply automated fixes
autofix-ci[bot] Aug 8, 2024
a33f8fc
Merge remote-tracking branch 'origin/main' into refactorNode
anovazzi1 Aug 13, 2024
bc3448b
refactor: remove unused code and handle count in GenericNodeToolbar c…
anovazzi1 Aug 8, 2024
4aaef1f
refactor: Add useShortcuts hook for handling keyboard shortcuts in no…
anovazzi1 Aug 8, 2024
e288013
refactor: Add keyboard shortcuts handling to nodeToolbarComponent nee…
anovazzi1 Aug 8, 2024
c887f09
refactor: Update FreezeAllVertices function in NodeToolbarComponent
anovazzi1 Aug 13, 2024
4eb6137
feat: Add getNodeLength function to calculate the length of a node's …
anovazzi1 Aug 13, 2024
946d391
refactor: Update RenderIcons component to use navigator.platform for …
anovazzi1 Aug 13, 2024
f3bfe0d
refactor: Add ShortcutDisplay component to nodeToolbarComponent
anovazzi1 Aug 13, 2024
bed43ae
refactor: Update nodeToolbarComponent to remove RenderIcons and add S…
anovazzi1 Aug 13, 2024
a4d7756
refactor: Improve keyboard shortcuts handling in nodeToolbarComponent
anovazzi1 Aug 13, 2024
1d4aa71
Merge remote-tracking branch 'origin/main' into refactorNodeToolbar
anovazzi1 Aug 13, 2024
84563b0
[autofix.ci] apply automated fixes
autofix-ci[bot] Aug 13, 2024
4949dd6
Merge branch 'main' into refactorNodeToolbar
anovazzi1 Aug 13, 2024
d15b08f
refactor: Add OptionIcon to nodeIconsLucide
anovazzi1 Aug 13, 2024
5776fd5
feat: Add SHORTCUT_KEYS constant
anovazzi1 Aug 13, 2024
43d480b
feat: Add SHORTCUT_KEYS constant
anovazzi1 Aug 13, 2024
dab8a74
refactor: Add RenderKey component for rendering keyboard shortcuts
anovazzi1 Aug 13, 2024
56efc15
refactor: Update RenderIcons component to use RenderKey for rendering…
anovazzi1 Aug 13, 2024
eb5ba1c
update shortcut page to use shortcut icons
anovazzi1 Aug 13, 2024
00b90f9
[autofix.ci] apply automated fixes
autofix-ci[bot] Aug 13, 2024
fef6bb9
Update Astra link in README.md (#3314)
alexleventer Aug 13, 2024
292cd82
Merge branch 'main' into fixShortcutRender
anovazzi1 Aug 14, 2024
4af2631
refactor: Simplify NodeToolbarComponent's save flow logic
anovazzi1 Aug 14, 2024
24612ec
[autofix.ci] apply automated fixes
autofix-ci[bot] Aug 14, 2024
e40ac91
feat: Google Drive Search Component (#3319)
edwinjosechittilappilly Aug 14, 2024
0815ad7
feat: Add support for metadata filtering and namespaces for the Upsta…
ytkimirti Aug 14, 2024
a977890
ci: Update pytest configuration and add pytest-flakefinder. (#3330)
ogabrielluiz Aug 14, 2024
221296a
chore: Refactor NodeToolbarComponent to simplify code structure
anovazzi1 Aug 14, 2024
d253342
[autofix.ci] apply automated fixes
autofix-ci[bot] Aug 14, 2024
ba17168
refactor: Simplify NodeToolbarComponent's save flow logic
anovazzi1 Aug 14, 2024
a4fae9a
[autofix.ci] apply automated fixes
autofix-ci[bot] Aug 14, 2024
7abf5e3
chore: Fix formatting issue in get-curl-code.tsx
anovazzi1 Aug 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import ForwardedIconComponent from "@/components/genericIconComponent";
import { IS_MAC } from "@/constants/constants";
import { cn } from "@/utils/utils";

export default function RenderKey({
value,
tableRender,
}: {
value: string;
tableRender?: boolean;
}): JSX.Element {
const check = value.toLowerCase().trim();
return (
<div>
{check === "shift" ? (
<ForwardedIconComponent
name="ArrowBigUp"
className={cn(tableRender ? "h-5 w-5" : "h-4 w-4")}
/>
) : check === "ctrl" && IS_MAC ? (
<span>⌃</span>
) : check === "alt" && IS_MAC ? (
<ForwardedIconComponent
name="OptionIcon"
className={cn(tableRender ? "h-4 w-4" : "h-3 w-3")}
/>
) : check === "cmd" ? (
<ForwardedIconComponent
name="Command"
className={cn(tableRender ? "h-4 w-4" : "h-3 w-3")}
/>
) : (
<span>{value}</span>
)}
</div>
);
}
59 changes: 17 additions & 42 deletions src/frontend/src/components/renderIconComponent/index.tsx
Original file line number Diff line number Diff line change
@@ -1,52 +1,27 @@
import ForwardedIconComponent from "../genericIconComponent";
import { IS_MAC } from "@/constants/constants";
import { addPlusSignes, cn, sortShortcuts } from "@/utils/utils";
import RenderKey from "./components/renderKey";

export default function RenderIcons({
isMac = navigator.platform.toUpperCase().includes("MAC"),
hasShift,
filteredShortcut,
shortcutWPlus,
tableRender = false,
}: {
isMac?: boolean;
hasShift: boolean;
filteredShortcut: string[];
shortcutWPlus: string[];
tableRender?: boolean;
}): JSX.Element {
return hasShift ? (
<span className="flex items-center justify-center gap-0.5 text-xs">
{isMac ? (
<ForwardedIconComponent name="Command" className="h-3 w-3" />
) : (
filteredShortcut[0]
const shortcutList = addPlusSignes([...filteredShortcut].sort(sortShortcuts));
return (
<span
className={cn(
"flex items-center gap-0.5",
tableRender ? "justify-start" : "justify-center text-xs",
)}
<ForwardedIconComponent name="ArrowBigUp" className="h-4 w-4" />
{filteredShortcut.map((key, idx) => {
if (idx > 0) {
return key.toUpperCase();
}
return null;
})}
</span>
) : (
<span className="flex items-center justify-center gap-0.5 text-xs">
{shortcutWPlus[0].toLowerCase() === "space" ? (
"Space"
) : shortcutWPlus[0].length <= 1 ? (
shortcutWPlus[0]
) : isMac ? (
<ForwardedIconComponent name="Command" className="h-3 w-3" />
) : (
<span className="flex items-center">{shortcutWPlus[0]}</span>
)}
{shortcutWPlus.map((key, idx) => {
if (idx > 0) {
return (
<span key={idx} className="flex items-center">
{key.toUpperCase()}
</span>
);
}
return null;
})}
>
{shortcutList.map((key, index) => (
<span key={index}>
<RenderKey value={key} tableRender={tableRender} />
</span>
))}
</span>
);
}
2 changes: 2 additions & 0 deletions src/frontend/src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -886,3 +886,5 @@ export const LANGFLOW_ACCESS_TOKEN_EXPIRE_SECONDS_ENV =
export const TEXT_FIELD_TYPES: string[] = ["str", "SecretStr"];
export const NODE_WIDTH = 400;
export const NODE_HEIGHT = NODE_WIDTH * 3;

export const SHORTCUT_KEYS = ["cmd", "ctrl", "alt", "shift"];
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,14 @@ export default function ShortcutDisplay({
name: string;
shortcut: string;
}): JSX.Element {
let hasShift: boolean = false;
const fixedShortcut = shortcut?.split("+");
fixedShortcut.forEach((key) => {
if (key.toLowerCase().includes("shift")) {
hasShift = true;
}
});
const filteredShortcut = fixedShortcut.filter(
(key) => !key.toLowerCase().includes("shift"),
);
let shortcutWPlus: string[] = [];
if (!hasShift) shortcutWPlus = filteredShortcut.join("+").split(" ");
return (
<div className="flex justify-center">
<span> {name} </span>
<span
className={`ml-3 flex items-center rounded-sm bg-muted px-1.5 py-[0.1em] text-lg text-muted-foreground`}
>
<RenderIcons
hasShift={hasShift}
filteredShortcut={filteredShortcut}
shortcutWPlus={shortcutWPlus}
/>
<RenderIcons filteredShortcut={fixedShortcut} />
</span>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,7 @@ export default function ToolbarSelectItem({
ping,
shortcut,
}: toolbarSelectItemProps) {
let hasShift = false;
const fixedShortcut = shortcut?.split("+");
fixedShortcut.forEach((key) => {
if (key.toLowerCase().includes("shift")) {
hasShift = true;
}
});
const filteredShortcut = fixedShortcut.filter(
(key) => !key.toLowerCase().includes("shift"),
);
let shortcutWPlus: string[] = [];
if (!hasShift) shortcutWPlus = filteredShortcut.join("+").split(" ");

return (
<div className={`flex ${style}`} data-testid={dataTestId}>
<ForwardedIconComponent
Expand All @@ -40,12 +28,7 @@ export default function ToolbarSelectItem({
<span
className={`absolute right-2 top-[0.43em] flex items-center rounded-sm bg-muted px-1.5 py-[0.1em] text-muted-foreground`}
>
<RenderIcons
isMac={IS_MAC}
hasShift={hasShift}
filteredShortcut={filteredShortcut}
shortcutWPlus={shortcutWPlus}
/>
<RenderIcons filteredShortcut={fixedShortcut} />
</span>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import RenderIcons from "@/components/renderIconComponent";
import { CustomCellRendererProps } from "ag-grid-react";

export default function CellRenderShortcuts(params: CustomCellRendererProps) {
const shortcut = params.value;
const splitShortcut = shortcut?.split("+");
return <RenderIcons filteredShortcut={splitShortcut} tableRender />;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect, useState } from "react";
import useAlertStore from "../../../../../stores/alertStore";

import RenderKey from "@/components/renderIconComponent/components/renderKey";
import ForwardedIconComponent from "../../../../../components/genericIconComponent";
import { Button } from "../../../../../components/ui/button";
import BaseModal from "../../../../../modals/baseModal";
Expand All @@ -11,7 +12,6 @@ export default function EditShortcutButton({
children,
shortcut,
defaultShortcuts,
defaultCombination,
open,
setOpen,
disable,
Expand All @@ -20,7 +20,6 @@ export default function EditShortcutButton({
children: JSX.Element;
shortcut: string[];
defaultShortcuts: Array<{ name: string; shortcut: string }>;
defaultCombination: string;
open: boolean;
setOpen: (bool: boolean) => void;
disable?: boolean;
Expand Down Expand Up @@ -161,10 +160,10 @@ export default function EditShortcutButton({
<BaseModal.Trigger>{children}</BaseModal.Trigger>
<BaseModal.Content>
<div className="align-center flex h-full w-full justify-center gap-4 rounded-md border border-border py-2">
<div className="flex items-center justify-center text-center text-lg font-bold">
{key === null
? shortcutInitialValue?.toUpperCase()
: key.toUpperCase()}
<div className="flex items-center justify-center gap-0.5 text-center text-lg font-bold">
{(key ?? shortcutInitialValue ?? "").split("+").map((k, i) => (
<RenderKey key={i} value={k} tableRender />
))}
</div>
</div>
</BaseModal.Content>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { ColDef } from "ag-grid-community";
import { useEffect, useState } from "react";
import ForwardedIconComponent from "../../../../components/genericIconComponent";
import TableComponent from "../../../../components/tableComponent";
import { Button } from "../../../../components/ui/button";
import { defaultShortcuts } from "../../../../constants/constants";
import { useShortcutsStore } from "../../../../stores/shortcuts";
import CellRenderShortcuts from "./CellRenderWrapper";
import EditShortcutButton from "./EditShortcutButton";

export default function ShortcutsPage() {
Expand All @@ -12,7 +14,7 @@ export default function ShortcutsPage() {
const setShortcuts = useShortcutsStore((state) => state.setShortcuts);

// Column Definitions: Defines the columns to be displayed.
const colDefs = [
const colDefs: ColDef[] = [
{
headerName: "Functionality",
field: "name",
Expand All @@ -26,6 +28,7 @@ export default function ShortcutsPage() {
flex: 2,
editable: false,
resizable: false,
cellRenderer: CellRenderShortcuts,
},
];

Expand Down Expand Up @@ -73,7 +76,6 @@ export default function ShortcutsPage() {
{open && (
<EditShortcutButton
disable={selectedRows.length === 0}
defaultCombination={combinationToEdit[0]?.shortcut}
shortcut={selectedRows}
defaultShortcuts={shortcuts}
open={open}
Expand Down
3 changes: 3 additions & 0 deletions src/frontend/src/utils/styleUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ import {
MoonIcon,
MoreHorizontal,
Network,
OptionIcon,
Package2,
Palette,
Paperclip,
Expand Down Expand Up @@ -596,4 +597,6 @@ export const nodeIconsLucide: iconsType = {
"AI/ML": AIMLIcon,
GitLoader: GitLoaderIcon,
athenaIcon: AthenaIcon,
OptionIcon: OptionIcon,
Option: OptionIcon,
};
38 changes: 37 additions & 1 deletion src/frontend/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { ColDef, ColGroupDef } from "ag-grid-community";
import clsx, { ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
import TableAutoCellRender from "../components/tableComponent/components/tableAutoCellRender";
import { MESSAGES_TABLE_ORDER, MODAL_CLASSES } from "../constants/constants";
import {
MESSAGES_TABLE_ORDER,
MODAL_CLASSES,
SHORTCUT_KEYS,
} from "../constants/constants";
import { APIDataType, InputFieldType, VertexDataTypeAPI } from "../types/api";
import {
groupedObjType,
Expand Down Expand Up @@ -584,3 +588,35 @@ export function getNodeLength(data: NodeDataType) {
data.node.template[templateField]?.type === "NestedDict"),
).length;
}

export function sortShortcuts(a: string, b: string) {
const order = SHORTCUT_KEYS;
const aTrimmed = a.trim().toLowerCase();
const bTrimmed = b.trim().toLowerCase();
const aIndex = order.indexOf(aTrimmed);
const bIndex = order.indexOf(bTrimmed);
if (aIndex === -1 && bIndex === -1) {
return aTrimmed.localeCompare(bTrimmed);
}
if (aIndex === -1) {
return 1;
}
if (bIndex === -1) {
return -1;
}
return aIndex - bIndex;
}
export function addPlusSignes(array: string[]): string[] {
const exceptions = SHORTCUT_KEYS;
// add + sign to the shortcuts beetwen characters that are not in the exceptions
return array.map((key, index) => {
if (index === 0) return key;
if (
exceptions.includes(key.trim().toLocaleLowerCase()) ||
exceptions.includes(array[index - 1].trim().toLocaleLowerCase())
)
return key;

return "+" + key;
});
}
Loading