Skip to content

Commit

Permalink
fix payload user
Browse files Browse the repository at this point in the history
  • Loading branch information
wl-zhao committed Jan 22, 2025
2 parents 5bb9140 + f0c16ca commit 7496bef
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { useReactFlowStore, NodeTypeEnum } from '@shellagent/flow-engine';
import { Select } from '@shellagent/ui';
import { useMemo } from 'react';

import { useAppState } from '@/stores/app/use-app-state';

interface StateSelectorProps {
value: string;
Expand All @@ -16,20 +19,42 @@ export const StateSelector = ({
excludeTargets = [],
disabled = false,
}: StateSelectorProps) => {
const { nodes } = useReactFlowStore(state => ({
const { nodes, edges } = useReactFlowStore(state => ({
nodes: state.nodes,
edges: state.edges,
}));

const { currentEdgeId } = useAppState(state => ({
currentEdgeId: state.currentEdgeId,
}));

const options = nodes
.filter(
node =>
node.data.type !== NodeTypeEnum.start &&
!excludeTargets.includes(node.id),
)
.map(node => ({
label: node.data.display_name || 'Untitled State',
value: node.id,
}));
const options = useMemo(() => {
const currentEdgeSource = edges.find(e => e.id === currentEdgeId)?.source;

return nodes
.filter(node => {
const baseConditions =
node.data.type !== NodeTypeEnum.start &&
node.data.type !== NodeTypeEnum.intro &&
!excludeTargets.includes(node.id);

if (node.id === value) {
return baseConditions;
}

return (
baseConditions &&
!edges.some(
edge =>
edge.source === currentEdgeSource && edge.target === node.id,
)
);
})
.map(node => ({
label: node.data.display_name || 'Untitled State',
value: node.id,
}));
}, [nodes, edges, value, excludeTargets]);

return (
<div className={className}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
Cog8ToothIcon,
ArrowRightIcon,
} from '@heroicons/react/24/outline';
import { useReactFlowStore } from '@shellagent/flow-engine';
import { Button, Input, IconButton, Drawer } from '@shellagent/ui';
import { produce } from 'immer';
import { useInjection } from 'inversify-react';
Expand Down Expand Up @@ -49,7 +48,7 @@ const ConditionItem = ({
};

const excludeTargets = conditions
.slice(0, index)
.filter((_, i) => i !== index)
.map(condition => condition.target);

return (
Expand Down Expand Up @@ -142,15 +141,12 @@ const TransitionConditionEditor = ({
);
};

const { nodes } = useReactFlowStore(state => ({
nodes: state.nodes,
}));

return (
<div className="flex gap-3 flex-col justify-center">
{value?.map?.((condition, index) => (
<ConditionItem
key={condition.target}
// eslint-disable-next-line react/no-array-index-key
key={`condition-${index}`}
value={condition}
onChange={v => handleChange(index, v)}
onDelete={handleDelete}
Expand Down
2 changes: 1 addition & 1 deletion web/apps/web/src/components/home/detail-form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default function DetailForm({
default: 'chat_bot',
'x-component-props': {
options: [
{ label: 'ChatBot', value: 'chat_bot' },
{ label: 'Chatbot', value: 'chat_bot' },
{ label: 'X Bot', value: 'x_bot' },
],
},
Expand Down
2 changes: 1 addition & 1 deletion web/apps/web/src/components/home/filter-tabs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { cn } from '@/utils/cn';

const FILTER_OPTIONS: { value: AppType; label: string }[] = [
{ value: 'all', label: 'All' },
{ value: 'chat_bot', label: 'ChatBot' },
{ value: 'chat_bot', label: 'Chatbot' },
{ value: 'x_bot', label: 'X Bot' },
];

Expand Down

0 comments on commit 7496bef

Please sign in to comment.