improve parameter fetch feedback
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState, useRef } from 'react';
|
||||||
import {
|
import {
|
||||||
Box, Button, Table, TableBody, TableCell, TableContainer,
|
Box, Button, Table, TableBody, TableCell, TableContainer,
|
||||||
TableHead, TableRow, Typography, Paper, Tooltip, Chip
|
TableHead, TableRow, Typography, Paper, Tooltip, Chip
|
||||||
@@ -18,6 +18,9 @@ const OPCODE_ERASE = 1;
|
|||||||
const NodeParam = ({ nodeId, nodes }) => {
|
const NodeParam = ({ nodeId, nodes }) => {
|
||||||
const [modalOpen, setModalOpen] = useState(false);
|
const [modalOpen, setModalOpen] = useState(false);
|
||||||
const [editParamIndex, setEditParamIndex] = useState(null);
|
const [editParamIndex, setEditParamIndex] = useState(null);
|
||||||
|
const [paramsUpdateTimestamp, setParamsUpdateTimestamp] = useState(0);
|
||||||
|
const [fetchingParams, setFetchingParams] = useState(false);
|
||||||
|
const fetchTimeoutRef = useRef(null);
|
||||||
|
|
||||||
if (!nodeId) return null;
|
if (!nodeId) return null;
|
||||||
const node = nodes[nodeId];
|
const node = nodes[nodeId];
|
||||||
@@ -26,17 +29,38 @@ const NodeParam = ({ nodeId, nodes }) => {
|
|||||||
const handleFetchParams = () => {
|
const handleFetchParams = () => {
|
||||||
const localNode = window.localNode;
|
const localNode = window.localNode;
|
||||||
let currentParamIndex = 0;
|
let currentParamIndex = 0;
|
||||||
|
setFetchingParams(true);
|
||||||
|
setParamsUpdateTimestamp(Date.now());
|
||||||
|
if (fetchTimeoutRef.current) clearTimeout(fetchTimeoutRef.current);
|
||||||
|
|
||||||
|
const resetFetchTimeout = () => {
|
||||||
|
if (fetchTimeoutRef.current) clearTimeout(fetchTimeoutRef.current);
|
||||||
|
fetchTimeoutRef.current = setTimeout(() => {
|
||||||
|
setFetchingParams(false);
|
||||||
|
console.warn(`Fetch params timed out for node ${nodeId} at index ${currentParamIndex}`);
|
||||||
|
}, 3000);
|
||||||
|
};
|
||||||
|
|
||||||
const callback = (transfer) => {
|
const callback = (transfer) => {
|
||||||
const msg = transfer.payload;
|
const msg = transfer.payload;
|
||||||
|
console.log('Param response:', { nodeId: transfer.sourceNodeId, index: currentParamIndex, name: msg?.fields?.name?.toString?.() });
|
||||||
if (msg && msg.fields.name.items.length > 0) {
|
if (msg && msg.fields.name.items.length > 0) {
|
||||||
if (msg && transfer.destNodeId === localNode.nodeId) {
|
if (msg && transfer.destNodeId === localNode.nodeId) {
|
||||||
localNode.updateNodeParamsFromResponse(transfer, currentParamIndex);
|
localNode.updateNodeParamsFromResponse(transfer, currentParamIndex);
|
||||||
|
setParamsUpdateTimestamp(Date.now());
|
||||||
currentParamIndex += 1;
|
currentParamIndex += 1;
|
||||||
|
resetFetchTimeout();
|
||||||
localNode.fetchNodeParam(nodeId, currentParamIndex, '', callback);
|
localNode.fetchNodeParam(nodeId, currentParamIndex, '', callback);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
setFetchingParams(false);
|
||||||
|
setParamsUpdateTimestamp(Date.now());
|
||||||
|
if (fetchTimeoutRef.current) clearTimeout(fetchTimeoutRef.current);
|
||||||
|
console.log(`Finished fetching params for node ${nodeId}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
resetFetchTimeout();
|
||||||
localNode.fetchNodeParam(nodeId, 0, '', callback);
|
localNode.fetchNodeParam(nodeId, 0, '', callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -341,8 +365,9 @@ const NodeParam = ({ nodeId, nodes }) => {
|
|||||||
variant="contained"
|
variant="contained"
|
||||||
sx={{ mr: 1 }}
|
sx={{ mr: 1 }}
|
||||||
startIcon={<SyncIcon />}
|
startIcon={<SyncIcon />}
|
||||||
|
disabled={fetchingParams}
|
||||||
>
|
>
|
||||||
Fetch All
|
{fetchingParams ? 'Fetching...' : 'Fetch All'}
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
onClick={handleSaveParams}
|
onClick={handleSaveParams}
|
||||||
@@ -386,6 +411,7 @@ const NodeParam = ({ nodeId, nodes }) => {
|
|||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
{renderNodeParams()}
|
{renderNodeParams()}
|
||||||
|
<span style={{ display: 'none' }}>{paramsUpdateTimestamp}</span>
|
||||||
<ParamEditorSelector
|
<ParamEditorSelector
|
||||||
open={modalOpen}
|
open={modalOpen}
|
||||||
onClose={() => setModalOpen(false)}
|
onClose={() => setModalOpen(false)}
|
||||||
|
|||||||
Reference in New Issue
Block a user