fix(parameterComponent): add options prop to ParameterComponent to display global variables in dropdown
feat(codeTabsComponent): add support for global variables in InputComponent and DictComponent feat(inputComponent): remove dependency on globalVariablesStore and use options prop instead feat(editNodeModal): add support for global variables in InputComponent
This commit is contained in:
parent
45e24058bd
commit
a91668b5f2
4 changed files with 64 additions and 20 deletions
|
|
@ -413,6 +413,7 @@ export default function ParameterComponent({
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
password={data.node?.template[name].password ?? false}
|
password={data.node?.template[name].password ?? false}
|
||||||
value={data.node?.template[name].value ?? ""}
|
value={data.node?.template[name].value ?? ""}
|
||||||
|
options={globalVariablesEntries}
|
||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
handleOnNewValue(value);
|
handleOnNewValue(value);
|
||||||
if (globalVariablesEntries.includes(value)) {
|
if (globalVariablesEntries.includes(value)) {
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,10 @@ import {
|
||||||
TabsTrigger,
|
TabsTrigger,
|
||||||
} from "../../components/ui/tabs";
|
} from "../../components/ui/tabs";
|
||||||
import { LANGFLOW_SUPPORTED_TYPES } from "../../constants/constants";
|
import { LANGFLOW_SUPPORTED_TYPES } from "../../constants/constants";
|
||||||
|
import useAlertStore from "../../stores/alertStore";
|
||||||
import { useDarkStore } from "../../stores/darkStore";
|
import { useDarkStore } from "../../stores/darkStore";
|
||||||
import useFlowStore from "../../stores/flowStore";
|
import useFlowStore from "../../stores/flowStore";
|
||||||
|
import { useGlobalVariablesStore } from "../../stores/globalVariables";
|
||||||
import { codeTabsPropsType } from "../../types/components";
|
import { codeTabsPropsType } from "../../types/components";
|
||||||
import {
|
import {
|
||||||
convertObjToArray,
|
convertObjToArray,
|
||||||
|
|
@ -54,8 +56,12 @@ export default function CodeTabsComponent({
|
||||||
const [openAccordion, setOpenAccordion] = useState<string[]>([]);
|
const [openAccordion, setOpenAccordion] = useState<string[]>([]);
|
||||||
const dark = useDarkStore((state) => state.dark);
|
const dark = useDarkStore((state) => state.dark);
|
||||||
const unselectAll = useFlowStore((state) => state.unselectAll);
|
const unselectAll = useFlowStore((state) => state.unselectAll);
|
||||||
|
const globalVariablesEntries = useGlobalVariablesStore(
|
||||||
|
(state) => state.globalVariablesEntries
|
||||||
|
);
|
||||||
|
|
||||||
const setNodes = useFlowStore((state) => state.setNodes);
|
const setNodes = useFlowStore((state) => state.setNodes);
|
||||||
|
const setNoticeData = useAlertStore((state) => state.setNoticeData);
|
||||||
|
|
||||||
const [errorDuplicateKey, setErrorDuplicateKey] = useState(false);
|
const [errorDuplicateKey, setErrorDuplicateKey] = useState(false);
|
||||||
|
|
||||||
|
|
@ -347,6 +353,9 @@ export default function CodeTabsComponent({
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<InputComponent
|
<InputComponent
|
||||||
|
options={
|
||||||
|
globalVariablesEntries
|
||||||
|
}
|
||||||
editNode={true}
|
editNode={true}
|
||||||
disabled={false}
|
disabled={false}
|
||||||
password={
|
password={
|
||||||
|
|
@ -376,6 +385,16 @@ export default function CodeTabsComponent({
|
||||||
].data.node.template[
|
].data.node.template[
|
||||||
templateField
|
templateField
|
||||||
].value = target;
|
].value = target;
|
||||||
|
if (
|
||||||
|
globalVariablesEntries.includes(
|
||||||
|
target
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
setNoticeData({
|
||||||
|
title: `the value inserted in ${templateField} is a global variable, \n
|
||||||
|
the real value will be update on run`,
|
||||||
|
});
|
||||||
|
}
|
||||||
return newInputList;
|
return newInputList;
|
||||||
});
|
});
|
||||||
tweaks.buildTweakObject!(
|
tweaks.buildTweakObject!(
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { Listbox, Transition } from "@headlessui/react";
|
import { Listbox, Transition } from "@headlessui/react";
|
||||||
import * as Form from "@radix-ui/react-form";
|
import * as Form from "@radix-ui/react-form";
|
||||||
import { Fragment, useEffect, useRef, useState } from "react";
|
import { Fragment, useEffect, useRef, useState } from "react";
|
||||||
import { useGlobalVariablesStore } from "../../stores/globalVariables";
|
|
||||||
import { InputComponentType } from "../../types/components";
|
import { InputComponentType } from "../../types/components";
|
||||||
import { handleKeyDown } from "../../utils/reactflowUtils";
|
import { handleKeyDown } from "../../utils/reactflowUtils";
|
||||||
import { classNames } from "../../utils/utils";
|
import { classNames } from "../../utils/utils";
|
||||||
|
|
@ -27,12 +26,7 @@ export default function InputComponent({
|
||||||
const [pwdVisible, setPwdVisible] = useState(false);
|
const [pwdVisible, setPwdVisible] = useState(false);
|
||||||
const refInput = useRef<HTMLInputElement>(null);
|
const refInput = useRef<HTMLInputElement>(null);
|
||||||
const [showOptions, setShowOptions] = useState<boolean>(false);
|
const [showOptions, setShowOptions] = useState<boolean>(false);
|
||||||
const globalVariablesEntries = useGlobalVariablesStore(
|
const [filteredOpts, setFilteredValue] = useState<string[]>(options);
|
||||||
(state) => state.globalVariablesEntries
|
|
||||||
);
|
|
||||||
const [filteredOpts, setFilteredValue] = useState<string[]>(
|
|
||||||
globalVariablesEntries
|
|
||||||
);
|
|
||||||
|
|
||||||
// Clear component state
|
// Clear component state
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -197,19 +191,21 @@ export default function InputComponent({
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<span
|
{options.length > 0 && (
|
||||||
className={
|
<span
|
||||||
password
|
className={
|
||||||
? "dropdown-component-arrow right-8"
|
password
|
||||||
: "dropdown-component-arrow right-0"
|
? "dropdown-component-arrow right-8"
|
||||||
}
|
: "dropdown-component-arrow right-0"
|
||||||
>
|
}
|
||||||
<IconComponent
|
>
|
||||||
name="ChevronsUpDown"
|
<IconComponent
|
||||||
className="dropdown-component-arrow-color"
|
name="ChevronsUpDown"
|
||||||
aria-hidden="true"
|
className="dropdown-component-arrow-color"
|
||||||
/>
|
aria-hidden="true"
|
||||||
</span>
|
/>
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
|
||||||
{password && (
|
{password && (
|
||||||
<button
|
<button
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,9 @@ import {
|
||||||
LANGFLOW_SUPPORTED_TYPES,
|
LANGFLOW_SUPPORTED_TYPES,
|
||||||
limitScrollFieldsModal,
|
limitScrollFieldsModal,
|
||||||
} from "../../constants/constants";
|
} from "../../constants/constants";
|
||||||
|
import useAlertStore from "../../stores/alertStore";
|
||||||
import useFlowStore from "../../stores/flowStore";
|
import useFlowStore from "../../stores/flowStore";
|
||||||
|
import { useGlobalVariablesStore } from "../../stores/globalVariables";
|
||||||
import { NodeDataType } from "../../types/flow";
|
import { NodeDataType } from "../../types/flow";
|
||||||
import {
|
import {
|
||||||
convertObjToArray,
|
convertObjToArray,
|
||||||
|
|
@ -59,6 +61,10 @@ const EditNodeModal = forwardRef(
|
||||||
const setPending = useFlowStore((state) => state.setPending);
|
const setPending = useFlowStore((state) => state.setPending);
|
||||||
const edges = useFlowStore((state) => state.edges);
|
const edges = useFlowStore((state) => state.edges);
|
||||||
const setNode = useFlowStore((state) => state.setNode);
|
const setNode = useFlowStore((state) => state.setNode);
|
||||||
|
const setNoticeData = useAlertStore((state) => state.setNoticeData);
|
||||||
|
const globalVariablesEntries = useGlobalVariablesStore(
|
||||||
|
(state) => state.globalVariablesEntries
|
||||||
|
);
|
||||||
|
|
||||||
function changeAdvanced(n) {
|
function changeAdvanced(n) {
|
||||||
setMyData((old) => {
|
setMyData((old) => {
|
||||||
|
|
@ -245,6 +251,7 @@ const EditNodeModal = forwardRef(
|
||||||
<InputComponent
|
<InputComponent
|
||||||
id={"input-" + index}
|
id={"input-" + index}
|
||||||
editNode={true}
|
editNode={true}
|
||||||
|
options={globalVariablesEntries}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
password={
|
password={
|
||||||
myData.node.template[templateParam]
|
myData.node.template[templateParam]
|
||||||
|
|
@ -259,6 +266,27 @@ const EditNodeModal = forwardRef(
|
||||||
value,
|
value,
|
||||||
templateParam
|
templateParam
|
||||||
);
|
);
|
||||||
|
if (
|
||||||
|
globalVariablesEntries.includes(
|
||||||
|
value
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
setNoticeData({
|
||||||
|
title: `the value inserted in ${data.node?.display_name} is a global variable, \n
|
||||||
|
the real value will be update on run`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
//mark as global variable
|
||||||
|
setNode(data.id, (oldNode) => {
|
||||||
|
let newNode = cloneDeep(oldNode);
|
||||||
|
newNode.data = {
|
||||||
|
...newNode.data,
|
||||||
|
};
|
||||||
|
newNode.data.node.template[
|
||||||
|
templateParam
|
||||||
|
].load_from_db = true;
|
||||||
|
return newNode;
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue