-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ML] Improving model snapshot revert UI experience #88588
[ML] Improving model snapshot revert UI experience #88588
Conversation
Pinging @elastic/ml-ui (:ml) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and LGTM
@@ -50,15 +50,24 @@ export const ModelSnapshotTable: FC<Props> = ({ job, refreshJobList }) => { | |||
const [closeJobModalVisible, setCloseJobModalVisible] = useState<ModelSnapshot | null>(null); | |||
const [combinedJobState, setCombinedJobState] = useState<COMBINED_JOB_STATE | null>(null); | |||
|
|||
let unmounted = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid the let
and resetting the variable on every render we use this alternative pattern in some places: https://github.com/elastic/kibana/blob/master/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/outlier_exploration/use_outlier_data.ts#L81
We discussed making a reusable custom hook in the past but didn't get around to do it. Here's the PR that originally introduced it: #81123
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a look at other similar examples in our code, but could not find one where the guard variable is used in a separate function and so needed to in the outer scope.
I might missing something, but using a const
wrapper around the variable won't make any difference? Both will be redefined on render.
let unmounted = false;
vs
const options = { unmounted: false };
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right this is different because of the additional outside callback. In the other examples the difference was that everything could be kept within the useEffect
.
As an alternative you could use a refresh value to trigger the useEffect
instead of directly calling loadModelSnapshots()
.
Something like:
const [isRefreshed, setIsRefreshed] = useState(true);
useEffect(() => {
const options = { didCancel: false };
loadModelSnapshots(options);
return () => {
options.didCancel = true;
};
}, [isRefreshed]);
async function loadModelSnapshots(options) {
if (options.didCancel === true) {
// table refresh can be triggered a while after a snapshot revert has been triggered.
// ensure the table is still visible before attempted to refresh it.
return;
}
const { model_snapshots: ms } = await ml.getModelSnapshots(job.job_id);
setSnapshots(ms);
setSnapshotsLoaded(true);
}
const refresh = useCallback(
() => {
setIsRefreshed(state => !state);
// wait half a second before refreshing the jobs list
setTimeout(refreshJobList, 500);
}
[setIsRefreshed],
);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated this check so it now uses useRef
to keep track of the flag for whether the component is mounted.
in 6f1867d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Latest changes LGTM 🥳
@elasticmachine merge upstream |
💚 Build SucceededMetrics [docs]Async chunks
History
To update your PR or re-run it, just comment with: |
* [ML] Improving model snapshot revert UI experience * removing button disabling * updating component is mounted check Co-authored-by: Kibana Machine <[email protected]>
* [ML] Improving model snapshot revert UI experience * removing button disabling * updating component is mounted check Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Kibana Machine <[email protected]>
When applying a snapshot revert, the apply modal no longer stays open and disabled while the revert is happening. Instead the modal closes an a toast appears once the revert has been applied.
@lcawl is this text ok?
Fixes #74484
cc @pheyos
Checklist
Delete any items that are not applicable to this PR.