flowstudio 0.0.18 → 0.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app_analytics.js +2 -1
- package/dist/app_analytics.js.map +1 -1
- package/dist/app_details.js +3 -2
- package/dist/app_details.js.map +1 -1
- package/dist/app_layout.js +1 -0
- package/dist/app_layout.js.map +1 -1
- package/dist/app_settings.js +2 -2
- package/dist/app_settings.js.map +1 -1
- package/dist/code.d.ts +1 -0
- package/dist/code.js +8 -0
- package/dist/code.js.map +1 -0
- package/dist/components/combo_box/style.css +10 -0
- package/dist/components/sheet/index.d.ts +1 -0
- package/dist/components/sheet/index.js +1 -1
- package/dist/components/sheet/index.js.map +1 -1
- package/dist/constants.d.ts +6 -0
- package/dist/constants.js +7 -0
- package/dist/constants.js.map +1 -0
- package/dist/envs.js +26 -10
- package/dist/envs.js.map +1 -1
- package/dist/functions.js +39 -32
- package/dist/functions.js.map +1 -1
- package/dist/home.d.ts +1 -1
- package/dist/home.js +5 -3
- package/dist/home.js.map +1 -1
- package/dist/index.d.ts +11 -2
- package/dist/index.js +19 -17
- package/dist/index.js.map +1 -1
- package/dist/new_project.js +3 -2
- package/dist/new_project.js.map +1 -1
- package/dist/node.js +4 -3
- package/dist/node.js.map +1 -1
- package/dist/project_widget.js +1 -1
- package/dist/project_widget.js.map +1 -1
- package/dist/simulator.js +16 -14
- package/dist/simulator.js.map +1 -1
- package/dist/studio_pane.d.ts +2 -1
- package/dist/studio_pane.js +285 -120
- package/dist/studio_pane.js.map +1 -1
- package/dist/studio_pane_old.d.ts +1 -0
- package/dist/studio_pane_old.js +309 -0
- package/dist/studio_pane_old.js.map +1 -0
- package/dist/studio_pane_old_new.d.ts +1 -0
- package/dist/studio_pane_old_new.js +349 -0
- package/dist/studio_pane_old_new.js.map +1 -0
- package/dist/top_left_panel.js +2 -1
- package/dist/top_left_panel.js.map +1 -1
- package/dist/top_right_panel.js +4 -3
- package/dist/top_right_panel.js.map +1 -1
- package/dist/triggers.js +8 -7
- package/dist/triggers.js.map +1 -1
- package/dist/zustand/store.d.ts +4 -1
- package/package.json +5 -4
- package/dist/getcode.d.ts +0 -1
- package/dist/getcode.js +0 -8
- package/dist/getcode.js.map +0 -1
- /package/{src/styes/date_picker.css → dist/components/date_picker/style.css} +0 -0
- /package/{src/styes/sheet.css → dist/components/sheet/style.css} +0 -0
- /package/{src/styes → dist}/studio.css +0 -0
package/dist/project_widget.js
CHANGED
|
@@ -18,6 +18,6 @@ export default function ProjectWidget({ api_key, identifier, name, logo, ...rest
|
|
|
18
18
|
setOpenedProjects([...openedProjects, { identifier, name }]);
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
|
-
return (_jsx(_Fragment, { children: _jsx(Card, { onClick: handleClick, style: { cursor: 'pointer' }, children: _jsx(Inset, { children: _jsxs(Flex, { direction: 'column', justify: 'center', align: 'center', children: [_jsx(Flex, { height: '100%', width: '100%', direction: 'column', align: 'center', justify: 'center', p: '5', children: _jsx("img", { fetchPriority: 'high', src: logo || '/onenote.png', alt: 'icon', width: 70, height: 70 }) }), _jsx(Separator, { size: '4' }), _jsx(Flex, { p: '2', children: _jsx(Text, { size: '1', color: 'gray', children: name }) })] }) }) }) }));
|
|
21
|
+
return (_jsx(_Fragment, { children: _jsx(Card, { onClick: handleClick, style: { cursor: 'pointer' }, children: _jsx(Inset, { children: _jsxs(Flex, { direction: 'column', justify: 'center', align: 'center', children: [_jsx(Flex, { height: '100%', width: '100%', direction: 'column', align: 'center', justify: 'center', p: '5', children: _jsx("img", { fetchPriority: 'high', src: logo || '/onenote.png', alt: 'icon', width: 70, height: 70 }) }), _jsx(Separator, { size: '4' }), _jsx(Flex, { p: '2', justify: 'center', align: 'center', children: _jsx(Text, { size: '1', color: 'gray', align: 'center', truncate: true, children: name }) })] }) }) }) }));
|
|
22
22
|
}
|
|
23
23
|
//# sourceMappingURL=project_widget.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":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C1B,CAAC;aAAM,CAAC;YACJ,iBAAiB,CAAC,CAAC,GAAG,cAAc,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QAEjE,CAAC;IAEL,CAAC,CAAA;IAED,OAAO,CACH,4BACI,KAAC,IAAI,IAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,EAAC,MAAM,EAAC,SAAS,EAAC,YACjD,KAAC,KAAK,cACN,MAAC,IAAI,IAAC,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,aACzD,KAAC,IAAI,IAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,EAAE,GAAG,YAChG,cAAK,aAAa,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,IAAI,cAAc,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,GAAI,GAC5F,EACP,KAAC,SAAS,IAAC,IAAI,EAAE,GAAG,GAAI,EACxB,KAAC,IAAI,IAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,YAC5C,KAAC,IAAI,IAAC,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,kBAAE,IAAI,GAAQ,GACpE,IACJ,GACC,GACL,GACR,CACN,CAAA;AACL,CAAC"}
|
package/dist/simulator.js
CHANGED
|
@@ -20,12 +20,12 @@ export default function Simulator({ api_key, projectId }) {
|
|
|
20
20
|
setRefreshing(true);
|
|
21
21
|
await handleSubmit({
|
|
22
22
|
production_type: deploymentType || "live",
|
|
23
|
-
user_input: "
|
|
24
|
-
|
|
23
|
+
user_input: "800",
|
|
24
|
+
sessionId: '1234567',
|
|
25
25
|
msisdn: "024",
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
requestType: "INITIATION",
|
|
27
|
+
trafficId: "123456789",
|
|
28
|
+
trafficSource: "ussd"
|
|
29
29
|
});
|
|
30
30
|
setRefreshing(false);
|
|
31
31
|
};
|
|
@@ -46,26 +46,28 @@ export default function Simulator({ api_key, projectId }) {
|
|
|
46
46
|
const post_data = JSON.stringify({
|
|
47
47
|
project_id: projectId,
|
|
48
48
|
production_type: deploymentType,
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
userInput: data.user_input,
|
|
50
|
+
sessionId: '1234567',
|
|
51
51
|
msisdn: "024",
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
requestType: (data === null || data === void 0 ? void 0 : data.requestType) || "EXISTING",
|
|
53
|
+
trafficId: "123456789",
|
|
54
|
+
trafficSource: "ussd"
|
|
55
55
|
});
|
|
56
56
|
const response = await fetch(`${simulatorEndpoint}`, { method: 'POST', body: post_data, headers: { "X-API-KEY": `${api_key}`, "Content-Type": "application/json" } });
|
|
57
|
+
const response_data = await response.json();
|
|
57
58
|
if (await response.ok) {
|
|
58
|
-
const response_data = await response.text();
|
|
59
59
|
resetForm({});
|
|
60
60
|
setFocus('user_input');
|
|
61
|
-
|
|
61
|
+
const new_message = response_data.menuContent.replace(/\\n/g, "<br>");
|
|
62
|
+
// console.log(new_message)
|
|
63
|
+
setFlowMessage(new_message);
|
|
62
64
|
}
|
|
63
65
|
else {
|
|
64
|
-
console.log(
|
|
66
|
+
console.log(`simulator POST not successful: ${response_data}`);
|
|
65
67
|
}
|
|
66
68
|
}
|
|
67
69
|
catch (e) {
|
|
68
|
-
console.log(
|
|
70
|
+
console.log(`Form Submit Error: ${e}`);
|
|
69
71
|
}
|
|
70
72
|
};
|
|
71
73
|
return (_jsxs(Popover.Root, { children: [_jsx(Tooltip, { content: 'Simulator', side: 'right', align: 'center', children: _jsx(Popover.Trigger, { children: _jsx(Button, { size: '1', variant: 'soft', children: _jsx(MdOutlinePhoneAndroid, {}) }) }) }), _jsx(Popover.Content, { side: 'right', sideOffset: 10, children: _jsxs(Flex, { direction: 'column', gap: '3', children: [_jsxs(Flex, { justify: 'between', children: [_jsxs(SegmentedControl.Root, { size: "1", defaultValue: "draft", radius: "large", children: [_jsx(SegmentedControl.Item, { onClick: () => setDeploymentType('draft'), value: "draft", children: "Draft" }), _jsx(SegmentedControl.Item, { onClick: () => setDeploymentType('live'), value: "live", children: "Live" })] }), _jsxs(Button, { size: '1', variant: 'outline', onClick: initialFormSubmit, children: [!refreshing && _jsx(IoReload, { size: '13' }), refreshing && _jsx(Spinner, {})] })] }), _jsx(Card, { style: { height: 'auto', minHeight: '150px', maxWidth: '230px' }, children: _jsx(Text, { wrap: 'wrap', color: 'gray', size: '1', children: parse(flowMessage) || 'No message' }) }), _jsx(Form.Root, { onSubmit: handleFormSubmit(handleSubmit), noValidate: true, children: _jsxs(Form.Field, { name: 'user_input', serverInvalid: errors.user_input != null, children: [_jsx(TextField.Root, { type: "text", ...registerInput('user_input'), id: "user_input", autoComplete: "off", placeholder: 'User Input', autoFocus: true, children: _jsx(TextField.Slot, { side: 'right', pr: '1', children: _jsxs(Button, { size: '1', highContrast: true, disabled: isSubmitting, type: "submit", children: [_jsx(Spinner, { loading: isSubmitting }), !isSubmitting && _jsx(SendHorizonalIcon, { size: '15' })] }) }) }), ((_a = errors.user_input) === null || _a === void 0 ? void 0 : _a.message) && _jsx(Form.Message, { children: (_b = errors.user_input) === null || _b === void 0 ? void 0 : _b.message })] }) })] }) })] }));
|
package/dist/simulator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simulator.js","sourceRoot":"","sources":["../src/simulator.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACrD,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,gBAAgB,EAAE,SAAS,EAAE,IAAI,EAA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,IAAI,IAAC,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,YACpC,MAAC,MAAM,IAAC,IAAI,EAAE,GAAG,EAAE,YAAY,QAAC,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAC,QAAQ,aAAE,KAAC,OAAO,IAAC,OAAO,EAAE,YAAY,GAAI,EAAC,CAAC,YAAY,IAAE,KAAC,iBAAiB,IAAC,IAAI,EAAE,IAAI,GAAI,IAAU,GACrJ,GACF,EAChB,CAAA,MAAA,MAAM,CAAC,UAAU,0CAAE,OAAO,KAAI,KAAC,IAAI,CAAC,OAAO,cAAE,MAAA,MAAM,CAAC,UAAU,0CAAE,OAAO,GAAgB,IAC7E,GACH,IACP,GACiB,IACP,CAEtB,CAAA;AACD,CAAC"}
|
package/dist/studio_pane.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import './studio.css';
|
|
2
|
+
export default function StudioPane({ api_key, projectsRefetch, identifier, providers, provider, theme }: any): import("react/jsx-runtime").JSX.Element;
|
package/dist/studio_pane.js
CHANGED
|
@@ -12,70 +12,279 @@ import { v4 as uuidv4 } from 'uuid';
|
|
|
12
12
|
import TopRightPanel from './top_right_panel';
|
|
13
13
|
import TopCenterPanel from './top_center_panel';
|
|
14
14
|
import TopLeftPanel from './top_left_panel';
|
|
15
|
-
|
|
15
|
+
import './studio.css';
|
|
16
16
|
import AppAnalytics from './app_analytics';
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
import flow_constants from './constants';
|
|
18
|
+
// Constants
|
|
19
|
+
const MAX_HISTORY_SIZE = 50;
|
|
20
|
+
const AUTO_SAVE_DELAY = 1000;
|
|
21
|
+
const QUERY_STALE_TIME = 5 * 60 * 1000; // 5 minutes
|
|
22
|
+
const QUERY_CACHE_TIME = 10 * 60 * 1000; // 10 minutes
|
|
23
|
+
// Node templates for performance
|
|
24
|
+
const NODE_TEMPLATES = {
|
|
25
|
+
function: {
|
|
26
|
+
type: 'fNode',
|
|
27
|
+
data: { label: '', function: '' }
|
|
28
|
+
},
|
|
29
|
+
default: {
|
|
30
|
+
type: 'gNode',
|
|
31
|
+
data: {
|
|
32
|
+
label: '',
|
|
33
|
+
message: '',
|
|
34
|
+
type: 'end',
|
|
35
|
+
response: {
|
|
36
|
+
validation: 'alpha-numeric',
|
|
37
|
+
source: 'manual',
|
|
38
|
+
inputs: [{ id: 1 }]
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
// Debounce utility
|
|
44
|
+
function useDebounce(callback, delay) {
|
|
45
|
+
const timeoutRef = useRef(null);
|
|
46
|
+
return useCallback((...args) => {
|
|
47
|
+
if (timeoutRef.current) {
|
|
48
|
+
clearTimeout(timeoutRef.current);
|
|
49
|
+
}
|
|
50
|
+
timeoutRef.current = setTimeout(() => callback(...args), delay);
|
|
51
|
+
}, [callback, delay]);
|
|
52
|
+
}
|
|
53
|
+
// Custom hook for history management
|
|
54
|
+
function useFlowHistory() {
|
|
55
|
+
const [history, setHistory] = useState([]);
|
|
56
|
+
const [historyIndex, setHistoryIndex] = useState(0);
|
|
57
|
+
const addToHistory = useCallback((newState) => {
|
|
58
|
+
setHistory(prevHistory => {
|
|
59
|
+
let updatedHistory = prevHistory;
|
|
60
|
+
// If we're not at the end, truncate future history
|
|
61
|
+
if (historyIndex < prevHistory.length - 1) {
|
|
62
|
+
updatedHistory = prevHistory.slice(0, historyIndex + 1);
|
|
63
|
+
}
|
|
64
|
+
// Add new state and maintain max size
|
|
65
|
+
const newHistory = [...updatedHistory, newState];
|
|
66
|
+
return newHistory.length > MAX_HISTORY_SIZE
|
|
67
|
+
? newHistory.slice(-MAX_HISTORY_SIZE)
|
|
68
|
+
: newHistory;
|
|
69
|
+
});
|
|
70
|
+
setHistoryIndex(prev => {
|
|
71
|
+
const newIndex = Math.min(prev + 1, MAX_HISTORY_SIZE - 1);
|
|
72
|
+
return newIndex;
|
|
73
|
+
});
|
|
74
|
+
}, [historyIndex]);
|
|
75
|
+
const undo = useCallback(() => {
|
|
76
|
+
if (historyIndex > 0) {
|
|
77
|
+
setHistoryIndex(prev => prev - 1);
|
|
78
|
+
return history[historyIndex - 1];
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
}, [history, historyIndex]);
|
|
82
|
+
const redo = useCallback(() => {
|
|
83
|
+
if (historyIndex < history.length - 1) {
|
|
84
|
+
setHistoryIndex(prev => prev + 1);
|
|
85
|
+
return history[historyIndex + 1];
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}, [history, historyIndex]);
|
|
89
|
+
return { addToHistory, undo, redo, historyIndex, historySize: history.length };
|
|
90
|
+
}
|
|
91
|
+
// Custom hook for auto-save functionality
|
|
92
|
+
function useAutoSave(rfInstance, identifier, api_key, nodes, edges, addToHistory) {
|
|
93
|
+
const [saving, setSaving] = useState(false);
|
|
94
|
+
const lastSavedStateRef = useRef('');
|
|
95
|
+
const performSave = useCallback(async () => {
|
|
96
|
+
if (!rfInstance || !identifier)
|
|
97
|
+
return;
|
|
98
|
+
setSaving(true);
|
|
99
|
+
try {
|
|
100
|
+
const flow = rfInstance.toObject();
|
|
101
|
+
const response = await fetch(`${flow_constants.BACKEND_ENDPOINT}/projects/${identifier}`, {
|
|
102
|
+
method: 'PATCH',
|
|
103
|
+
headers: {
|
|
104
|
+
"X-API-KEY": `${api_key}`,
|
|
105
|
+
'Content-Type': 'application/json'
|
|
106
|
+
},
|
|
107
|
+
body: JSON.stringify({ flow_draft: flow })
|
|
108
|
+
});
|
|
109
|
+
if (!response.ok) {
|
|
110
|
+
console.error('Failed to save flow draft');
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
console.error('Error saving nodes and edges:', error);
|
|
115
|
+
}
|
|
116
|
+
finally {
|
|
117
|
+
setSaving(false);
|
|
118
|
+
}
|
|
119
|
+
}, [rfInstance, identifier, api_key]);
|
|
120
|
+
const debouncedSave = useDebounce(performSave, AUTO_SAVE_DELAY);
|
|
121
|
+
const saveWithHistory = useCallback(() => {
|
|
122
|
+
if (!rfInstance)
|
|
123
|
+
return;
|
|
124
|
+
const currentState = {
|
|
125
|
+
nodes: nodes === null || nodes === void 0 ? void 0 : nodes.map(n => ({ ...n })),
|
|
126
|
+
edges: edges === null || edges === void 0 ? void 0 : edges.map(e => ({ ...e })),
|
|
127
|
+
viewport: rfInstance.getViewport()
|
|
128
|
+
};
|
|
129
|
+
// Check if state actually changed to avoid unnecessary saves
|
|
130
|
+
const currentStateString = JSON.stringify(currentState);
|
|
131
|
+
if (currentStateString === lastSavedStateRef.current)
|
|
132
|
+
return;
|
|
133
|
+
lastSavedStateRef.current = currentStateString;
|
|
134
|
+
addToHistory(currentState);
|
|
135
|
+
debouncedSave();
|
|
136
|
+
}, [rfInstance, nodes, edges, addToHistory, debouncedSave]);
|
|
137
|
+
return { performSave, saveWithHistory, saving };
|
|
138
|
+
}
|
|
139
|
+
// Custom hook for context menu
|
|
140
|
+
function useContextMenu() {
|
|
141
|
+
const [contextMenu, setContextMenu] = useState({
|
|
142
|
+
show: false,
|
|
143
|
+
position: { x: 0, y: 0 }
|
|
144
|
+
});
|
|
145
|
+
const handleContextMenu = useCallback((event) => {
|
|
146
|
+
event.preventDefault();
|
|
147
|
+
setContextMenu({
|
|
148
|
+
show: true,
|
|
149
|
+
position: { x: event.clientX, y: event.clientY }
|
|
150
|
+
});
|
|
151
|
+
}, []);
|
|
152
|
+
const hideContextMenu = useCallback(() => {
|
|
153
|
+
setContextMenu(prev => ({ ...prev, show: false }));
|
|
154
|
+
}, []);
|
|
155
|
+
return {
|
|
156
|
+
showContextMenu: contextMenu.show,
|
|
157
|
+
contextMenuPosition: contextMenu.position,
|
|
158
|
+
handleContextMenu,
|
|
159
|
+
setShowContextMenu: hideContextMenu
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
export default function StudioPane({ api_key, projectsRefetch, identifier, providers, provider, theme }) {
|
|
163
|
+
const { stateType } = useConfigStore();
|
|
164
|
+
// Optimized queries with better caching
|
|
165
|
+
const { data: project, status: projectStatus, refetch: projectRefetch } = useQuery({
|
|
166
|
+
queryKey: [`project_${identifier}`],
|
|
167
|
+
queryFn: async () => {
|
|
168
|
+
const res = await fetch(`${flow_constants.BACKEND_ENDPOINT}/projects/${identifier}`, {
|
|
169
|
+
headers: { "X-API-KEY": `${api_key}` }
|
|
170
|
+
});
|
|
21
171
|
return res === null || res === void 0 ? void 0 : res.json();
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
|
|
172
|
+
},
|
|
173
|
+
enabled: !!identifier,
|
|
174
|
+
staleTime: QUERY_STALE_TIME,
|
|
175
|
+
gcTime: QUERY_CACHE_TIME
|
|
176
|
+
});
|
|
177
|
+
const { data: functions, refetch: functionsRefetch } = useQuery({
|
|
178
|
+
queryKey: [`project_${identifier}_functions`],
|
|
179
|
+
queryFn: async () => {
|
|
180
|
+
const res = await fetch(`${flow_constants.BACKEND_ENDPOINT}/functions?project=${identifier}`, {
|
|
181
|
+
headers: { "X-API-KEY": `${api_key}` }
|
|
182
|
+
});
|
|
25
183
|
return res === null || res === void 0 ? void 0 : res.json();
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
|
|
184
|
+
},
|
|
185
|
+
enabled: !!identifier,
|
|
186
|
+
staleTime: QUERY_STALE_TIME,
|
|
187
|
+
gcTime: QUERY_CACHE_TIME
|
|
188
|
+
});
|
|
189
|
+
const { data: triggers, refetch: triggersRefetch } = useQuery({
|
|
190
|
+
queryKey: [`project_${identifier}_triggers`],
|
|
191
|
+
queryFn: async () => {
|
|
192
|
+
const res = await fetch(`${flow_constants.BACKEND_ENDPOINT}/triggers?project=${identifier}`, {
|
|
193
|
+
headers: { "X-API-KEY": `${api_key}` }
|
|
194
|
+
});
|
|
29
195
|
return res === null || res === void 0 ? void 0 : res.json();
|
|
30
|
-
},
|
|
31
|
-
|
|
32
|
-
|
|
196
|
+
},
|
|
197
|
+
enabled: !!identifier,
|
|
198
|
+
staleTime: QUERY_STALE_TIME,
|
|
199
|
+
gcTime: QUERY_CACHE_TIME
|
|
200
|
+
});
|
|
201
|
+
const { data: envs, refetch: envsRefetch } = useQuery({
|
|
202
|
+
queryKey: [`project_${identifier}_envs`],
|
|
203
|
+
queryFn: async () => {
|
|
204
|
+
const res = await fetch(`${flow_constants.BACKEND_ENDPOINT}/envs?project=${identifier}`, {
|
|
205
|
+
headers: { "X-API-KEY": `${api_key}` }
|
|
206
|
+
});
|
|
33
207
|
return res === null || res === void 0 ? void 0 : res.json();
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
|
|
208
|
+
},
|
|
209
|
+
enabled: !!identifier,
|
|
210
|
+
staleTime: QUERY_STALE_TIME,
|
|
211
|
+
gcTime: QUERY_CACHE_TIME
|
|
212
|
+
});
|
|
213
|
+
const { data: sessions, status: sessionsStatus, refetch: sessionsRefetch } = useQuery({
|
|
214
|
+
queryKey: [`project_${identifier}_sessions`],
|
|
215
|
+
queryFn: async () => {
|
|
216
|
+
const res = await fetch(`${flow_constants.BACKEND_ENDPOINT}/sessions?project=${identifier}`, {
|
|
217
|
+
headers: { "X-API-KEY": `${api_key}` }
|
|
218
|
+
});
|
|
37
219
|
return res === null || res === void 0 ? void 0 : res.json();
|
|
38
|
-
},
|
|
220
|
+
},
|
|
221
|
+
enabled: !!identifier,
|
|
222
|
+
staleTime: QUERY_STALE_TIME,
|
|
223
|
+
gcTime: QUERY_CACHE_TIME
|
|
224
|
+
});
|
|
225
|
+
// Optimized session lookup - compute once, use many times
|
|
226
|
+
const sessionsByNodeId = useMemo(() => {
|
|
227
|
+
if (!(sessions === null || sessions === void 0 ? void 0 : sessions.results))
|
|
228
|
+
return {};
|
|
229
|
+
return sessions.results.reduce((acc, session) => {
|
|
230
|
+
if (!acc[session.node_id]) {
|
|
231
|
+
acc[session.node_id] = [];
|
|
232
|
+
}
|
|
233
|
+
acc[session.node_id].push(session);
|
|
234
|
+
return acc;
|
|
235
|
+
}, {});
|
|
236
|
+
}, [sessions === null || sessions === void 0 ? void 0 : sessions.results]);
|
|
39
237
|
////////////////// Nodes Management (React Flow) /////////////////////////////
|
|
40
|
-
const CustomSmoothstepEdge = ({ data, ...props }) => {
|
|
238
|
+
const CustomSmoothstepEdge = memo(({ data, ...props }) => {
|
|
41
239
|
return _jsx(SmoothStepEdge, { ...props, data: data, style: { strokeWidth: 2 } });
|
|
42
|
-
};
|
|
240
|
+
});
|
|
241
|
+
// Optimized node types with memoized session lookup
|
|
43
242
|
const nodeTypes = useMemo(() => ({
|
|
44
|
-
gNode: (props) =>
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
243
|
+
gNode: (props) => (_jsx(GNode, { ...props, data: {
|
|
244
|
+
...props.data,
|
|
245
|
+
functions: functions === null || functions === void 0 ? void 0 : functions.results,
|
|
246
|
+
sessions: sessionsByNodeId[props.id] || []
|
|
247
|
+
} })),
|
|
248
|
+
fNode: (props) => (_jsx(FNode, { ...props, data: {
|
|
249
|
+
...props.data,
|
|
250
|
+
functions: functions === null || functions === void 0 ? void 0 : functions.results,
|
|
251
|
+
sessions: sessionsByNodeId[props.id] || []
|
|
252
|
+
} }))
|
|
253
|
+
}), [functions === null || functions === void 0 ? void 0 : functions.results, sessionsByNodeId]);
|
|
254
|
+
const edgeTypes = useMemo(() => ({
|
|
255
|
+
default: memo((props) => (_jsx(CustomSmoothstepEdge, { ...props, deletable: true })))
|
|
256
|
+
}), []);
|
|
48
257
|
const [nodes, setNodes, onNodesChange] = useNodesState((project === null || project === void 0 ? void 0 : project.nodes) || []);
|
|
49
258
|
const [edges, setEdges, onEdgesChange] = useEdgesState((project === null || project === void 0 ? void 0 : project.edges) || []);
|
|
50
259
|
const [rfInstance, setRfInstance] = useState(null);
|
|
51
|
-
const [saving, setSaving] = useState(false);
|
|
52
260
|
const { setViewport, screenToFlowPosition, getNodes, getEdges } = useReactFlow();
|
|
53
261
|
const isReconnectingRef = useRef(false);
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
const
|
|
262
|
+
// Custom hooks
|
|
263
|
+
const { addToHistory, undo, redo, historyIndex, historySize } = useFlowHistory();
|
|
264
|
+
const { performSave, saveWithHistory, saving } = useAutoSave(rfInstance, identifier, api_key, nodes, edges, addToHistory);
|
|
265
|
+
const { showContextMenu, contextMenuPosition, handleContextMenu, setShowContextMenu } = useContextMenu();
|
|
57
266
|
// Key Presses
|
|
58
267
|
const cmdAndSPressed = useKeyPress(['Meta+s', 'Strg+s']);
|
|
59
268
|
const cmdAndZPressed = useKeyPress(['Meta+z', 'Strg+z']);
|
|
60
269
|
const cmdAndYPressed = useKeyPress(['Meta+y', 'Strg+y']);
|
|
61
270
|
////////////// onMount and Initial Load //////////////
|
|
62
271
|
useEffect(() => {
|
|
272
|
+
// Component initialization logic can go here
|
|
63
273
|
}, []);
|
|
64
274
|
useEffect(() => {
|
|
65
275
|
var _a, _b, _c;
|
|
66
276
|
if (project === null || project === void 0 ? void 0 : project.flow_draft) {
|
|
67
277
|
const { x = 0, y = 0, zoom = 1 } = ((_a = project === null || project === void 0 ? void 0 : project.flow_draft) === null || _a === void 0 ? void 0 : _a.viewport) || {};
|
|
68
|
-
// const updatedNodes = project?.flow_draft?.nodes?.map((val: any) => {
|
|
69
|
-
// return { ...val, data: { ...val.data,
|
|
70
|
-
// },};
|
|
71
|
-
// }) || [];
|
|
72
278
|
setNodes(((_b = project === null || project === void 0 ? void 0 : project.flow_draft) === null || _b === void 0 ? void 0 : _b.nodes) || []);
|
|
73
279
|
setEdges(((_c = project === null || project === void 0 ? void 0 : project.flow_draft) === null || _c === void 0 ? void 0 : _c.edges) || []);
|
|
74
280
|
setViewport({ x, y, zoom });
|
|
75
281
|
}
|
|
76
|
-
}, [project]);
|
|
282
|
+
}, [project, setNodes, setEdges, setViewport]);
|
|
77
283
|
useEffect(() => {
|
|
78
|
-
setEdges((eds) => eds.map((edge) => ({
|
|
284
|
+
setEdges((eds) => eds.map((edge) => ({
|
|
285
|
+
...edge,
|
|
286
|
+
animated: stateType === 'sessions'
|
|
287
|
+
})));
|
|
79
288
|
}, [stateType, setEdges]);
|
|
80
289
|
//////////////////////////// Connections /////////////////////////////////
|
|
81
290
|
const onConnect = useCallback((connection) => {
|
|
@@ -86,7 +295,6 @@ export default function StudioPane({ api_key, projectsRefetch, identifier, provi
|
|
|
86
295
|
// Generate a unique ID for the new edge
|
|
87
296
|
const newEdgeId = `e${connection.source}-${connection.sourceHandle}-${connection.target}-${connection.targetHandle}`;
|
|
88
297
|
// Add the new connection with the unique ID
|
|
89
|
-
// console.log(`on connect edge: ${connection}`)
|
|
90
298
|
return addEdge({ ...connection, id: newEdgeId }, filteredEdges);
|
|
91
299
|
});
|
|
92
300
|
}, [setEdges]);
|
|
@@ -94,7 +302,6 @@ export default function StudioPane({ api_key, projectsRefetch, identifier, provi
|
|
|
94
302
|
// isReconnectingRef.current = false;
|
|
95
303
|
}, []);
|
|
96
304
|
const onConnectEnd = useCallback((event, connectionState) => {
|
|
97
|
-
// const reactFlowWrapper = document.querySelector('.react-flow'); // or your actual wrapper class
|
|
98
305
|
if (!connectionState.isValid && !connectionState.toNode) {
|
|
99
306
|
if (!connectionState.toNode && !isReconnectingRef.current) {
|
|
100
307
|
const { clientX, clientY } = 'changedTouches' in event ? event.changedTouches[0] : event;
|
|
@@ -151,7 +358,7 @@ export default function StudioPane({ api_key, projectsRefetch, identifier, provi
|
|
|
151
358
|
}, []);
|
|
152
359
|
const onEdgesDelete = useCallback((edgesToDelete) => {
|
|
153
360
|
setEdges((eds) => eds.filter((e) => !edgesToDelete.some((d) => d.id === e.id)));
|
|
154
|
-
}, []);
|
|
361
|
+
}, [setEdges]);
|
|
155
362
|
const onReconnect = useCallback((oldEdge, newConnection) => {
|
|
156
363
|
if (!newConnection.target) {
|
|
157
364
|
// If no target, remove the edge
|
|
@@ -171,86 +378,41 @@ export default function StudioPane({ api_key, projectsRefetch, identifier, provi
|
|
|
171
378
|
isReconnectingRef.current = false;
|
|
172
379
|
}, [setEdges]);
|
|
173
380
|
///////////////////////////////Save//////////////////////////////////////////
|
|
174
|
-
const onSave = useCallback(
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
const flow = rfInstance.toObject();
|
|
178
|
-
// alert(JSON.stringify(flow))
|
|
179
|
-
if (!identifier)
|
|
180
|
-
return;
|
|
181
|
-
try {
|
|
182
|
-
const response = await fetch(`${process.env.BACKEND_ENDPOINT}/projects/${identifier}`, { method: 'PATCH', headers: { "X-API-KEY": `${api_key}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ flow_draft: flow }) });
|
|
183
|
-
if (!response.ok) {
|
|
184
|
-
setSaving(false);
|
|
185
|
-
// throw new Error('Failed to save flow draft');
|
|
186
|
-
}
|
|
187
|
-
setSaving(false);
|
|
188
|
-
// const result = await response.json();
|
|
189
|
-
// console.log('Save successful:', result);
|
|
190
|
-
}
|
|
191
|
-
catch (error) {
|
|
192
|
-
setSaving(false);
|
|
193
|
-
console.error('Error saving nodes and edges:', error);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}, [rfInstance]);
|
|
381
|
+
const onSave = useCallback(() => {
|
|
382
|
+
performSave();
|
|
383
|
+
}, [performSave]);
|
|
197
384
|
useEffect(() => {
|
|
198
385
|
if (cmdAndSPressed) {
|
|
199
386
|
onSave();
|
|
200
387
|
}
|
|
201
388
|
}, [cmdAndSPressed, onSave]);
|
|
202
389
|
///////////////// Undo and Redo ///////////////////////
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
if (
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
setHistory((prevHistory) => [...prevHistory, newState]);
|
|
210
|
-
setHistoryIndex((prevIndex) => prevIndex + 1);
|
|
211
|
-
setCurrentState(newState);
|
|
212
|
-
};
|
|
213
|
-
// Undo function
|
|
214
|
-
const undo = () => {
|
|
215
|
-
if (historyIndex > 0) {
|
|
216
|
-
const prevIndex = historyIndex - 1;
|
|
217
|
-
setHistoryIndex(prevIndex);
|
|
218
|
-
setCurrentState(history[prevIndex]);
|
|
219
|
-
setNodes(history[prevIndex].nodes);
|
|
220
|
-
setEdges(history[prevIndex].edges);
|
|
221
|
-
setViewport(history[prevIndex].viewport);
|
|
390
|
+
const handleUndo = useCallback(() => {
|
|
391
|
+
const prevState = undo();
|
|
392
|
+
if (prevState) {
|
|
393
|
+
setNodes(prevState.nodes);
|
|
394
|
+
setEdges(prevState.edges);
|
|
395
|
+
setViewport(prevState.viewport);
|
|
222
396
|
}
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
if (
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
setNodes(history[nextIndex].nodes);
|
|
231
|
-
setEdges(history[nextIndex].edges);
|
|
232
|
-
setViewport(history[nextIndex].viewport);
|
|
397
|
+
}, [undo, setNodes, setEdges, setViewport]);
|
|
398
|
+
const handleRedo = useCallback(() => {
|
|
399
|
+
const nextState = redo();
|
|
400
|
+
if (nextState) {
|
|
401
|
+
setNodes(nextState.nodes);
|
|
402
|
+
setEdges(nextState.edges);
|
|
403
|
+
setViewport(nextState.viewport);
|
|
233
404
|
}
|
|
234
|
-
};
|
|
405
|
+
}, [redo, setNodes, setEdges, setViewport]);
|
|
235
406
|
useEffect(() => {
|
|
236
407
|
if (cmdAndZPressed) {
|
|
237
|
-
|
|
408
|
+
handleUndo();
|
|
238
409
|
}
|
|
239
410
|
if (cmdAndYPressed) {
|
|
240
|
-
|
|
411
|
+
handleRedo();
|
|
241
412
|
}
|
|
242
|
-
}, [cmdAndZPressed, cmdAndYPressed]);
|
|
413
|
+
}, [cmdAndZPressed, cmdAndYPressed, handleUndo, handleRedo]);
|
|
243
414
|
////////////////// For Context Menu /////////////////////////////
|
|
244
|
-
const
|
|
245
|
-
const [contextMenuPosition, setContextMenuPosition] = useState({ x: 0, y: 0 });
|
|
246
|
-
const handleContextMenu = (event) => {
|
|
247
|
-
event.preventDefault();
|
|
248
|
-
const clickX = event.clientX;
|
|
249
|
-
const clickY = event.clientY;
|
|
250
|
-
setContextMenuPosition({ x: clickX, y: clickY });
|
|
251
|
-
setShowContextMenu(true);
|
|
252
|
-
};
|
|
253
|
-
const createNode = (type) => {
|
|
415
|
+
const createNode = useCallback((type) => {
|
|
254
416
|
if ((contextMenuPosition === null || contextMenuPosition === void 0 ? void 0 : contextMenuPosition.x) != null && (contextMenuPosition === null || contextMenuPosition === void 0 ? void 0 : contextMenuPosition.y) != null) {
|
|
255
417
|
setNodes((prevNodes) => {
|
|
256
418
|
const newId = `node-${uuidv4()}`;
|
|
@@ -261,32 +423,37 @@ export default function StudioPane({ api_key, projectsRefetch, identifier, provi
|
|
|
261
423
|
while (existingLabels.has(newLabel)) {
|
|
262
424
|
newLabel = `${type}_label_${counter++}`;
|
|
263
425
|
}
|
|
426
|
+
const template = type === 'function' ? NODE_TEMPLATES.function : NODE_TEMPLATES.default;
|
|
264
427
|
return [
|
|
265
428
|
...prevNodes,
|
|
266
429
|
{
|
|
267
430
|
id: newId,
|
|
268
|
-
type: type
|
|
431
|
+
type: template.type,
|
|
269
432
|
position: { x: contextMenuPosition.x, y: contextMenuPosition.y },
|
|
270
|
-
data:
|
|
271
|
-
|
|
272
|
-
|
|
433
|
+
data: {
|
|
434
|
+
...template.data,
|
|
435
|
+
label: newLabel,
|
|
436
|
+
...(type === 'function' ? { function: '' } : {
|
|
437
|
+
message: '',
|
|
438
|
+
type,
|
|
439
|
+
response: {
|
|
440
|
+
validation: 'alpha-numeric',
|
|
441
|
+
source: 'manual',
|
|
442
|
+
inputs: [{ id: 1 }]
|
|
443
|
+
}
|
|
444
|
+
})
|
|
445
|
+
}
|
|
273
446
|
}
|
|
274
447
|
];
|
|
275
448
|
});
|
|
276
|
-
// Reset context menu position to avoid reusing the same position
|
|
277
|
-
setContextMenuPosition({ x: 0, y: 0 });
|
|
278
449
|
}
|
|
279
|
-
};
|
|
450
|
+
}, [contextMenuPosition, setNodes]);
|
|
280
451
|
//////////////////// Auto Save //////////////////
|
|
281
452
|
useEffect(() => {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
// Add a small debounce to prevent too frequent saves
|
|
285
|
-
const timer = setTimeout(() => { onSave(); }, 1000); // 1 second debounce
|
|
286
|
-
handleChange({ nodes, edges, viewport: rfInstance.getViewport() });
|
|
287
|
-
return () => clearTimeout(timer);
|
|
453
|
+
if (rfInstance && identifier && (nodes.length > 0 || edges.length > 0)) {
|
|
454
|
+
saveWithHistory();
|
|
288
455
|
}
|
|
289
|
-
}, [nodes, edges]);
|
|
456
|
+
}, [nodes, edges, rfInstance, identifier, saveWithHistory]);
|
|
290
457
|
///////////////// Delete Key Code ////////////////
|
|
291
458
|
const onSelectionChange = useCallback(({ nodes, edges }) => {
|
|
292
459
|
// console.log('Selected nodes:', nodes)
|
|
@@ -302,8 +469,6 @@ export default function StudioPane({ api_key, projectsRefetch, identifier, provi
|
|
|
302
469
|
window.addEventListener('keydown', handleKeyDown);
|
|
303
470
|
return () => window.removeEventListener('keydown', handleKeyDown);
|
|
304
471
|
}, [setNodes, setEdges]);
|
|
305
|
-
return (_jsxs(Box, { position: 'absolute', top: '0', right: '0', bottom: '0px', left: '0', style: {}, children: [_jsxs(ReactFlow, { nodes: nodes, edges: edges, onNodesChange: onNodesChange, onEdgesChange: onEdgesChange, onConnect: onConnect, nodeTypes: nodeTypes, edgeTypes: edgeTypes, onNodesDelete: onNodesDelete, onEdgesDelete: onEdgesDelete, onSelectionChange: onSelectionChange, onConnectEnd: onConnectEnd, onConnectStart: onConnectStart, onReconnect: onReconnect, onReconnectStart: onReconnectStart, onReconnectEnd: onReconnectEnd, onInit: setRfInstance, snapToGrid: true, fitView: true, minZoom: 0.1, maxZoom: 3, colorMode:
|
|
306
|
-
// viewport={project?.flow_draft?.viewport}
|
|
307
|
-
attributionPosition: "bottom-right", children: [_jsx(Controls, {}), _jsx(Background, { gap: 12, size: 1 }), _jsxs(Panel, { position: "top-center", children: [" ", _jsx(TopCenterPanel, { projectId: identifier })] }), _jsxs(Panel, { position: "top-left", children: [" ", _jsx(TopLeftPanel, { api_key: api_key, projectId: identifier, createNode: createNode, onSave: onSave, saving: saving, rfInstance: rfInstance, redo: redo, undo: undo, historyIndex: historyIndex })] }), _jsxs(Panel, { position: "top-right", children: [" ", _jsx(TopRightPanel, { api_key: api_key, projectId: identifier, createNode: createNode, onSave: onSave, saving: saving, rfInstance: rfInstance })] })] }), _jsx(AppAnalytics, { api_key: api_key, project: project, sessions: sessions, sessionsStatus: sessionsStatus, refetch: sessionsRefetch }), _jsx(AppSettings, { api_key: api_key, project: project, projectsRefetch: projectsRefetch, providers: providers, provider: provider, triggers: triggers, triggersRefetch: triggersRefetch, functions: functions, functionsRefetch: functionsRefetch, envs: envs, envsRefetch: envsRefetch }), _jsx(ContextMenu, { api_key: api_key, open: showContextMenu, setOpen: setShowContextMenu, createNode: createNode, menuPosition: contextMenuPosition })] }));
|
|
472
|
+
return (_jsxs(Box, { position: 'absolute', top: '0', right: '0', bottom: '0px', left: '0', style: {}, children: [_jsxs(ReactFlow, { nodes: nodes, edges: edges, onNodesChange: onNodesChange, onEdgesChange: onEdgesChange, onConnect: onConnect, nodeTypes: nodeTypes, edgeTypes: edgeTypes, onNodesDelete: onNodesDelete, onEdgesDelete: onEdgesDelete, onSelectionChange: onSelectionChange, onConnectEnd: onConnectEnd, onConnectStart: onConnectStart, onReconnect: onReconnect, onReconnectStart: onReconnectStart, onReconnectEnd: onReconnectEnd, onInit: setRfInstance, snapToGrid: true, fitView: true, minZoom: 0.1, maxZoom: 3, colorMode: theme, onPaneContextMenu: handleContextMenu, deleteKeyCode: null, attributionPosition: "bottom-right", children: [_jsx(Controls, {}), _jsx(Background, { gap: 12, size: 1 }), _jsx(Panel, { position: "top-center", children: _jsx(TopCenterPanel, { projectId: identifier }) }), _jsx(Panel, { position: "top-left", children: _jsx(TopLeftPanel, { api_key: api_key, projectId: identifier, createNode: createNode, onSave: onSave, saving: saving, rfInstance: rfInstance, redo: handleRedo, undo: handleUndo, historyIndex: historyIndex }) }), _jsx(Panel, { position: "top-right", children: _jsx(TopRightPanel, { api_key: api_key, projectId: identifier, createNode: createNode, onSave: onSave, saving: saving, rfInstance: rfInstance }) })] }), _jsx(AppAnalytics, { api_key: api_key, project: project, sessions: sessions, sessionsStatus: sessionsStatus, refetch: sessionsRefetch }), _jsx(AppSettings, { api_key: api_key, project: project, projectsRefetch: projectsRefetch, providers: providers, provider: provider, triggers: triggers, triggersRefetch: triggersRefetch, functions: functions, functionsRefetch: functionsRefetch, envs: envs, envsRefetch: envsRefetch }), _jsx(ContextMenu, { api_key: api_key, open: showContextMenu, setOpen: setShowContextMenu, createNode: createNode, menuPosition: contextMenuPosition })] }));
|
|
308
473
|
}
|
|
309
474
|
//# sourceMappingURL=studio_pane.js.map
|