File size: 1,936 Bytes
1dd9186
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { memo } from 'react';
import NodeShell from '../components/NodeShell.jsx';
import { NodeDraftInput } from '../components/NodeDraftField.jsx';
import { useWorkflow } from '../context/WorkflowContext.jsx';
import { getNodeAccent } from '../lib/nodeRegistry.js';

function CounterFlowNode({ id, data, selected, type }) {
  const { getNodeHandles, patchNodeData } = useWorkflow();
  const handles = getNodeHandles(type, data);
  const runtime = data.runtime || {};

  return (
    <NodeShell
      nodeId={id}
      title={data.title}
      accent={getNodeAccent(type)}
      selected={selected}
      status={runtime.status}
      inputs={handles.inputs}
      outputs={handles.outputs}
    >
      <div className="field-stack">
        <label className="field-row">
          <span>Memory key</span>
          <NodeDraftInput
            className="nodrag node-input"
            type="text"
            value={data.key || ''}
            placeholder="counter"
            onCommit={(value) => patchNodeData(id, { key: value })}
          />
        </label>

        <label className="field-row">
          <span>Limit</span>
          <NodeDraftInput
            className="nodrag node-input"
            type="number"
            min="1"
            step="1"
            value={data.limit || 3}
            onCommit={(value) => patchNodeData(id, { limit: Number(value) || 1 })}
          />
        </label>

        <div className="node-note">
          {runtime.count
            ? `Сейчас: ${runtime.count}/${runtime.limit || data.limit}. Выход: ${runtime.matchId || 'continue'}.`
            : 'Увеличивает счетчик и пропускает поток через continue до лимита, затем через done.'}
        </div>

        {runtime.error ? <div className="node-error">{runtime.error}</div> : null}
      </div>
    </NodeShell>
  );
}

export default memo(CounterFlowNode);