Feat: Add shortcut for output inspection and play component
This commit is contained in:
parent
1aca27e5f3
commit
33b1ee8365
6 changed files with 60 additions and 13 deletions
|
|
@ -39,7 +39,11 @@ import {
|
||||||
scapedJSONStringfy,
|
scapedJSONStringfy,
|
||||||
} from "../../../../utils/reactflowUtils";
|
} from "../../../../utils/reactflowUtils";
|
||||||
import { nodeColors } from "../../../../utils/styleUtils";
|
import { nodeColors } from "../../../../utils/styleUtils";
|
||||||
import { classNames, groupByFamily } from "../../../../utils/utils";
|
import {
|
||||||
|
classNames,
|
||||||
|
groupByFamily,
|
||||||
|
isThereModal,
|
||||||
|
} from "../../../../utils/utils";
|
||||||
import useFetchDataOnMount from "../../../hooks/use-fetch-data-on-mount";
|
import useFetchDataOnMount from "../../../hooks/use-fetch-data-on-mount";
|
||||||
import useHandleOnNewValue from "../../../hooks/use-handle-new-value";
|
import useHandleOnNewValue from "../../../hooks/use-handle-new-value";
|
||||||
import useHandleNodeClass from "../../../hooks/use-handle-node-class";
|
import useHandleNodeClass from "../../../hooks/use-handle-node-class";
|
||||||
|
|
@ -47,6 +51,8 @@ import useHandleRefreshButtonPress from "../../../hooks/use-handle-refresh-butto
|
||||||
import OutputModal from "../outputModal";
|
import OutputModal from "../outputModal";
|
||||||
import TooltipRenderComponent from "../tooltipRenderComponent";
|
import TooltipRenderComponent from "../tooltipRenderComponent";
|
||||||
import { TEXT_FIELD_TYPES } from "./constants";
|
import { TEXT_FIELD_TYPES } from "./constants";
|
||||||
|
import { useShortcutsStore } from "../../../../stores/shortcuts";
|
||||||
|
import { useHotkeys } from "react-hotkeys-hook";
|
||||||
|
|
||||||
export default function ParameterComponent({
|
export default function ParameterComponent({
|
||||||
left,
|
left,
|
||||||
|
|
@ -63,6 +69,7 @@ export default function ParameterComponent({
|
||||||
proxy,
|
proxy,
|
||||||
showNode,
|
showNode,
|
||||||
index = "",
|
index = "",
|
||||||
|
selected,
|
||||||
}: ParameterComponentType): JSX.Element {
|
}: ParameterComponentType): JSX.Element {
|
||||||
const ref = useRef<HTMLDivElement>(null);
|
const ref = useRef<HTMLDivElement>(null);
|
||||||
const refHtml = useRef<HTMLDivElement & ReactNode>(null);
|
const refHtml = useRef<HTMLDivElement & ReactNode>(null);
|
||||||
|
|
@ -90,6 +97,19 @@ export default function ParameterComponent({
|
||||||
"unknown"
|
"unknown"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const preventDefault = true;
|
||||||
|
|
||||||
|
function handleOutputWShortcut() {
|
||||||
|
if (!displayOutputPreview || unknownOutput) return;
|
||||||
|
if (isThereModal() && !openOutputModal) return;
|
||||||
|
if (selected && !left) {
|
||||||
|
setOpenOutputModal((state) => !state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const output = useShortcutsStore((state) => state.output);
|
||||||
|
useHotkeys(output, handleOutputWShortcut, { preventDefault });
|
||||||
|
|
||||||
const { handleOnNewValue: handleOnNewValueHook } = useHandleOnNewValue(
|
const { handleOnNewValue: handleOnNewValueHook } = useHandleOnNewValue(
|
||||||
data,
|
data,
|
||||||
name,
|
name,
|
||||||
|
|
@ -98,7 +118,7 @@ export default function ParameterComponent({
|
||||||
debouncedHandleUpdateValues,
|
debouncedHandleUpdateValues,
|
||||||
setNode,
|
setNode,
|
||||||
renderTooltips,
|
renderTooltips,
|
||||||
setIsLoading
|
setIsLoading,
|
||||||
);
|
);
|
||||||
|
|
||||||
const { handleNodeClass: handleNodeClassHook } = useHandleNodeClass(
|
const { handleNodeClass: handleNodeClassHook } = useHandleNodeClass(
|
||||||
|
|
@ -107,7 +127,7 @@ export default function ParameterComponent({
|
||||||
takeSnapshot,
|
takeSnapshot,
|
||||||
setNode,
|
setNode,
|
||||||
updateNodeInternals,
|
updateNodeInternals,
|
||||||
renderTooltips
|
renderTooltips,
|
||||||
);
|
);
|
||||||
|
|
||||||
const { handleRefreshButtonPress: handleRefreshButtonPressHook } =
|
const { handleRefreshButtonPress: handleRefreshButtonPressHook } =
|
||||||
|
|
@ -116,7 +136,7 @@ export default function ParameterComponent({
|
||||||
let disabled =
|
let disabled =
|
||||||
edges.some(
|
edges.some(
|
||||||
(edge) =>
|
(edge) =>
|
||||||
edge.targetHandle === scapedJSONStringfy(proxy ? { ...id, proxy } : id)
|
edge.targetHandle === scapedJSONStringfy(proxy ? { ...id, proxy } : id),
|
||||||
) ?? false;
|
) ?? false;
|
||||||
|
|
||||||
const handleRefreshButtonPress = async (name, data) => {
|
const handleRefreshButtonPress = async (name, data) => {
|
||||||
|
|
@ -129,12 +149,12 @@ export default function ParameterComponent({
|
||||||
handleUpdateValues,
|
handleUpdateValues,
|
||||||
setNode,
|
setNode,
|
||||||
renderTooltips,
|
renderTooltips,
|
||||||
setIsLoading
|
setIsLoading,
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleOnNewValue = async (
|
const handleOnNewValue = async (
|
||||||
newValue: string | string[] | boolean | Object[],
|
newValue: string | string[] | boolean | Object[],
|
||||||
skipSnapshot: boolean | undefined = false
|
skipSnapshot: boolean | undefined = false,
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
handleOnNewValueHook(newValue, skipSnapshot);
|
handleOnNewValueHook(newValue, skipSnapshot);
|
||||||
};
|
};
|
||||||
|
|
@ -216,7 +236,7 @@ export default function ParameterComponent({
|
||||||
className={classNames(
|
className={classNames(
|
||||||
left ? "my-12 -ml-0.5 " : " my-12 -mr-0.5 ",
|
left ? "my-12 -ml-0.5 " : " my-12 -mr-0.5 ",
|
||||||
"h-3 w-3 rounded-full border-2 bg-background",
|
"h-3 w-3 rounded-full border-2 bg-background",
|
||||||
!showNode ? "mt-0" : ""
|
!showNode ? "mt-0" : "",
|
||||||
)}
|
)}
|
||||||
style={{
|
style={{
|
||||||
borderColor: color ?? nodeColors.unknown,
|
borderColor: color ?? nodeColors.unknown,
|
||||||
|
|
@ -286,7 +306,7 @@ export default function ParameterComponent({
|
||||||
"h-5 w-5 rounded-md",
|
"h-5 w-5 rounded-md",
|
||||||
displayOutputPreview && !unknownOutput
|
displayOutputPreview && !unknownOutput
|
||||||
? " hover:bg-secondary-foreground/5 hover:text-medium-indigo"
|
? " hover:bg-secondary-foreground/5 hover:text-medium-indigo"
|
||||||
: " cursor-not-allowed text-muted-foreground"
|
: " cursor-not-allowed text-muted-foreground",
|
||||||
)}
|
)}
|
||||||
name={"ScanEye"}
|
name={"ScanEye"}
|
||||||
/>
|
/>
|
||||||
|
|
@ -336,7 +356,7 @@ export default function ParameterComponent({
|
||||||
}
|
}
|
||||||
className={classNames(
|
className={classNames(
|
||||||
left ? "-ml-0.5" : "-mr-0.5",
|
left ? "-ml-0.5" : "-mr-0.5",
|
||||||
"h-3 w-3 rounded-full border-2 bg-background"
|
"h-3 w-3 rounded-full border-2 bg-background",
|
||||||
)}
|
)}
|
||||||
style={{ borderColor: color ?? nodeColors.unknown }}
|
style={{ borderColor: color ?? nodeColors.unknown }}
|
||||||
onClick={() => setFilterEdge(groupedEdge.current)}
|
onClick={() => setFilterEdge(groupedEdge.current)}
|
||||||
|
|
|
||||||
|
|
@ -241,8 +241,18 @@ export default function GenericNode({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handlePlayWShortcut() {
|
||||||
|
if (buildStatus === BuildStatus.BUILDING || isBuilding || !selected) return;
|
||||||
|
setValidationStatus(null);
|
||||||
|
console.log(data.node?.display_name);
|
||||||
|
buildFlow({ stopNodeId: data.id });
|
||||||
|
}
|
||||||
|
|
||||||
const update = useShortcutsStore((state) => state.update);
|
const update = useShortcutsStore((state) => state.update);
|
||||||
|
const play = useShortcutsStore((state) => state.play);
|
||||||
|
|
||||||
useHotkeys(update, handleUpdateCodeWShortcut, { preventDefault });
|
useHotkeys(update, handleUpdateCodeWShortcut, { preventDefault });
|
||||||
|
useHotkeys(play, handlePlayWShortcut, { preventDefault });
|
||||||
|
|
||||||
const shortcuts = useShortcutsStore((state) => state.shortcuts);
|
const shortcuts = useShortcutsStore((state) => state.shortcuts);
|
||||||
|
|
||||||
|
|
@ -388,6 +398,7 @@ export default function GenericNode({
|
||||||
data.node!.template[templateField].show &&
|
data.node!.template[templateField].show &&
|
||||||
!data.node!.template[templateField].advanced && (
|
!data.node!.template[templateField].advanced && (
|
||||||
<ParameterComponent
|
<ParameterComponent
|
||||||
|
selected={selected}
|
||||||
index={idx.toString()}
|
index={idx.toString()}
|
||||||
key={scapedJSONStringfy({
|
key={scapedJSONStringfy({
|
||||||
inputTypes:
|
inputTypes:
|
||||||
|
|
@ -461,6 +472,7 @@ export default function GenericNode({
|
||||||
),
|
),
|
||||||
)}
|
)}
|
||||||
<ParameterComponent
|
<ParameterComponent
|
||||||
|
selected={selected}
|
||||||
key={scapedJSONStringfy({
|
key={scapedJSONStringfy({
|
||||||
baseClasses: data.node!.base_classes,
|
baseClasses: data.node!.base_classes,
|
||||||
id: data.id,
|
id: data.id,
|
||||||
|
|
@ -644,6 +656,7 @@ export default function GenericNode({
|
||||||
{data.node!.template[templateField].show &&
|
{data.node!.template[templateField].show &&
|
||||||
!data.node!.template[templateField].advanced ? (
|
!data.node!.template[templateField].advanced ? (
|
||||||
<ParameterComponent
|
<ParameterComponent
|
||||||
|
selected={selected}
|
||||||
index={idx.toString()}
|
index={idx.toString()}
|
||||||
key={scapedJSONStringfy({
|
key={scapedJSONStringfy({
|
||||||
inputTypes:
|
inputTypes:
|
||||||
|
|
@ -723,6 +736,7 @@ export default function GenericNode({
|
||||||
</div>
|
</div>
|
||||||
{data.node!.base_classes.length > 0 && (
|
{data.node!.base_classes.length > 0 && (
|
||||||
<ParameterComponent
|
<ParameterComponent
|
||||||
|
selected={selected}
|
||||||
key={scapedJSONStringfy({
|
key={scapedJSONStringfy({
|
||||||
baseClasses: data.node!.base_classes,
|
baseClasses: data.node!.base_classes,
|
||||||
id: data.id,
|
id: data.id,
|
||||||
|
|
|
||||||
|
|
@ -817,6 +817,14 @@ export const defaultShortcuts = [
|
||||||
name: "Flow Share",
|
name: "Flow Share",
|
||||||
shortcut: `${IS_MAC ? "Cmd" : "Ctrl"} + B`,
|
shortcut: `${IS_MAC ? "Cmd" : "Ctrl"} + B`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Play",
|
||||||
|
shortcut: `P`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Output Inspection",
|
||||||
|
shortcut: `O`,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
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.`;
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ export const useShortcutsStore = create<shortcutsStoreType>((set, get) => ({
|
||||||
setShortcuts: (newShortcuts) => {
|
setShortcuts: (newShortcuts) => {
|
||||||
set({ shortcuts: newShortcuts });
|
set({ shortcuts: newShortcuts });
|
||||||
},
|
},
|
||||||
|
output: "o",
|
||||||
|
play: "p",
|
||||||
flow: "mod+b",
|
flow: "mod+b",
|
||||||
undo: "mod+z",
|
undo: "mod+z",
|
||||||
redo: "mod+y",
|
redo: "mod+y",
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ export type DropDownComponentType = {
|
||||||
children?: ReactNode;
|
children?: ReactNode;
|
||||||
};
|
};
|
||||||
export type ParameterComponentType = {
|
export type ParameterComponentType = {
|
||||||
|
selected: boolean;
|
||||||
data: NodeDataType;
|
data: NodeDataType;
|
||||||
title: string;
|
title: string;
|
||||||
id: sourceHandleType | targetHandleType;
|
id: sourceHandleType | targetHandleType;
|
||||||
|
|
@ -491,7 +492,7 @@ export type ChatInputType = {
|
||||||
isDragging: boolean;
|
isDragging: boolean;
|
||||||
files: FilePreviewType[];
|
files: FilePreviewType[];
|
||||||
setFiles: (
|
setFiles: (
|
||||||
files: FilePreviewType[] | ((prev: FilePreviewType[]) => FilePreviewType[])
|
files: FilePreviewType[] | ((prev: FilePreviewType[]) => FilePreviewType[]),
|
||||||
) => void;
|
) => void;
|
||||||
chatValue: string;
|
chatValue: string;
|
||||||
inputRef: {
|
inputRef: {
|
||||||
|
|
@ -593,7 +594,7 @@ export type chatMessagePropsType = {
|
||||||
updateChat: (
|
updateChat: (
|
||||||
chat: ChatMessageType,
|
chat: ChatMessageType,
|
||||||
message: string,
|
message: string,
|
||||||
stream_url?: string
|
stream_url?: string,
|
||||||
) => void;
|
) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -685,12 +686,12 @@ export type codeTabsPropsType = {
|
||||||
value: string,
|
value: string,
|
||||||
node: NodeType,
|
node: NodeType,
|
||||||
template: TemplateVariableType,
|
template: TemplateVariableType,
|
||||||
tweak: tweakType
|
tweak: tweakType,
|
||||||
) => string;
|
) => string;
|
||||||
buildTweakObject?: (
|
buildTweakObject?: (
|
||||||
tw: string,
|
tw: string,
|
||||||
changes: string | string[] | boolean | number | Object[] | Object,
|
changes: string | string[] | boolean | number | Object[] | Object,
|
||||||
template: TemplateVariableType
|
template: TemplateVariableType,
|
||||||
) => Promise<string | void>;
|
) => Promise<string | void>;
|
||||||
};
|
};
|
||||||
activeTweaks?: boolean;
|
activeTweaks?: boolean;
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@ export type StoreComponentResponse = {
|
||||||
|
|
||||||
export type shortcutsStoreType = {
|
export type shortcutsStoreType = {
|
||||||
updateUniqueShortcut: (name: string, combination: string) => void;
|
updateUniqueShortcut: (name: string, combination: string) => void;
|
||||||
|
output: string;
|
||||||
|
play: string;
|
||||||
flow: string;
|
flow: string;
|
||||||
group: string;
|
group: string;
|
||||||
cut: string;
|
cut: string;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue