🐛 fix(formModal/index.tsx): handle case when tabsState or formKeysData is undefined to prevent errors
✨ feat(formModal/index.tsx): add support for displaying input keys and handling input changes in the form modal
This commit is contained in:
parent
f61d265e77
commit
2abc0d2fb4
1 changed files with 72 additions and 67 deletions
|
|
@ -67,14 +67,17 @@ export default function FormModal({
|
||||||
const id = useRef(flow.id);
|
const id = useRef(flow.id);
|
||||||
const tabsStateFlowId = tabsState[flow.id];
|
const tabsStateFlowId = tabsState[flow.id];
|
||||||
const tabsStateFlowIdFormKeysData = tabsStateFlowId.formKeysData;
|
const tabsStateFlowIdFormKeysData = tabsStateFlowId.formKeysData;
|
||||||
const [chatKey, setChatKey] = useState(
|
const [chatKey, setChatKey] = useState(() => {
|
||||||
Object.keys(tabsState[flow.id].formKeysData.input_keys).find(
|
if (tabsState[flow.id]?.formKeysData?.input_keys) {
|
||||||
|
return Object.keys(tabsState[flow.id].formKeysData.input_keys).find(
|
||||||
(k) =>
|
(k) =>
|
||||||
!tabsState[flow.id].formKeysData.handle_keys.some((j) => j === k) &&
|
!tabsState[flow.id].formKeysData.handle_keys.some((j) => j === k) &&
|
||||||
tabsState[flow.id].formKeysData.input_keys[k] === ""
|
tabsState[flow.id].formKeysData.input_keys[k] === ""
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
// TODO: return a sensible default
|
||||||
|
return "";
|
||||||
|
});
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (messagesRef.current) {
|
if (messagesRef.current) {
|
||||||
messagesRef.current.scrollTop = messagesRef.current.scrollHeight;
|
messagesRef.current.scrollTop = messagesRef.current.scrollHeight;
|
||||||
|
|
@ -419,8 +422,10 @@ export default function FormModal({
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{Object.keys(tabsState[id.current].formKeysData.input_keys).map(
|
{tabsState[id.current]?.formKeysData?.input_keys
|
||||||
(i, k) => (
|
? Object.keys(
|
||||||
|
tabsState[id.current].formKeysData.input_keys
|
||||||
|
).map((i, k) => (
|
||||||
<div className="file-component-accordion-div" key={k}>
|
<div className="file-component-accordion-div" key={k}>
|
||||||
<AccordionComponent
|
<AccordionComponent
|
||||||
trigger={
|
trigger={
|
||||||
|
|
@ -467,9 +472,9 @@ export default function FormModal({
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
setTabsState((old) => {
|
setTabsState((old) => {
|
||||||
let newTabsState = _.cloneDeep(old);
|
let newTabsState = _.cloneDeep(old);
|
||||||
newTabsState[id.current].formKeysData.input_keys[
|
newTabsState[
|
||||||
i
|
id.current
|
||||||
] = e.target.value;
|
].formKeysData.input_keys[i] = e.target.value;
|
||||||
return newTabsState;
|
return newTabsState;
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
|
|
@ -479,8 +484,8 @@ export default function FormModal({
|
||||||
</div>
|
</div>
|
||||||
</AccordionComponent>
|
</AccordionComponent>
|
||||||
</div>
|
</div>
|
||||||
)
|
))
|
||||||
)}
|
: null}
|
||||||
{tabsState[id.current].formKeysData.memory_keys.map((i, k) => (
|
{tabsState[id.current].formKeysData.memory_keys.map((i, k) => (
|
||||||
<div className="file-component-accordion-div" key={k}>
|
<div className="file-component-accordion-div" key={k}>
|
||||||
<AccordionComponent
|
<AccordionComponent
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue