Fixed: Clearing logs not updating UI once complete

pull/4637/head
Mark McDowall 3 years ago
parent b24bea415b
commit 56b3acddc9

@ -17,6 +17,7 @@ export const section = 'commands';
let lastCommand = null; let lastCommand = null;
let lastCommandTimeout = null; let lastCommandTimeout = null;
const removeCommandTimeoutIds = {}; const removeCommandTimeoutIds = {};
const commandFinishedCallbacks = {};
// //
// State // State
@ -119,7 +120,7 @@ function scheduleRemoveCommand(command, dispatch) {
}, 60000 * 5); }, 60000 * 5);
} }
export function executeCommandHelper( payload, dispatch) { export function executeCommandHelper(payload, dispatch) {
// TODO: show a message for the user // TODO: show a message for the user
if (lastCommand && isSameCommand(lastCommand, payload)) { if (lastCommand && isSameCommand(lastCommand, payload)) {
console.warn('Please wait at least 5 seconds before running this command again'); console.warn('Please wait at least 5 seconds before running this command again');
@ -136,13 +137,22 @@ export function executeCommandHelper( payload, dispatch) {
lastCommand = null; lastCommand = null;
}, 5000); }, 5000);
const {
commandFinished,
...requestPayload
} = payload;
const promise = createAjaxRequest({ const promise = createAjaxRequest({
url: '/command', url: '/command',
method: 'POST', method: 'POST',
data: JSON.stringify(payload) data: JSON.stringify(requestPayload)
}).request; }).request;
return promise.then((data) => { return promise.then((data) => {
if (commandFinished) {
commandFinishedCallbacks[data.id] = commandFinished;
}
dispatch(addCommand(data)); dispatch(addCommand(data));
}); });
} }
@ -182,12 +192,20 @@ export const actionHandlers = handleThunks({
} }
}); });
const commandFinished = commandFinishedCallbacks[payload.id];
if (commandFinished) {
commandFinished(payload);
}
delete commandFinishedCallbacks[payload.id];
dispatch(updateItem({ section: 'commands', ...payload })); dispatch(updateItem({ section: 'commands', ...payload }));
scheduleRemoveCommand(payload, dispatch); scheduleRemoveCommand(payload, dispatch);
showCommandMessage(payload, dispatch); showCommandMessage(payload, dispatch);
}, },
[ADD_COMMAND]: function(getState, payload, dispatch) { [REMOVE_COMMAND]: function(getState, payload, dispatch) {
dispatch(removeItem({ section: 'commands', ...payload })); dispatch(removeItem({ section: 'commands', ...payload }));
} }

@ -96,7 +96,14 @@ class LogsTableConnector extends Component {
} }
onClearLogsPress = () => { onClearLogsPress = () => {
this.props.executeCommand({ name: commandNames.CLEAR_LOGS }); this.props.executeCommand({
name: commandNames.CLEAR_LOGS,
commandFinished: this.onCommandFinished
});
}
onCommandFinished = () => {
this.props.gotoLogsFirstPage();
} }
// //

@ -50,12 +50,6 @@ class LogFilesConnector extends Component {
this.props.fetchLogFiles(); this.props.fetchLogFiles();
} }
componentDidUpdate(prevProps) {
if (prevProps.deleteFilesExecuting && !this.props.deleteFilesExecuting) {
this.props.fetchLogFiles();
}
}
// //
// Listeners // Listeners
@ -64,7 +58,14 @@ class LogFilesConnector extends Component {
} }
onDeleteFilesPress = () => { onDeleteFilesPress = () => {
this.props.executeCommand({ name: commandNames.DELETE_LOG_FILES }); this.props.executeCommand({
name: commandNames.DELETE_LOG_FILES,
commandFinished: this.onCommandFinished
});
}
onCommandFinished = () => {
this.props.fetchLogFiles();
} }
// //

Loading…
Cancel
Save