Skip to content
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

Conversation

jgowdyelastic
Copy link
Member

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.

2021-01-18 11-51-47 2021-01-18 11_56_23

@lcawl is this text ok?
image

Fixes #74484
cc @pheyos

Checklist

Delete any items that are not applicable to this PR.

@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui (:ml)

@jgowdyelastic jgowdyelastic requested a review from lcawl January 18, 2021 12:04
Copy link
Contributor

@peteharverson peteharverson left a 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;
Copy link
Contributor

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

Copy link
Member Author

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 };

Copy link
Contributor

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],
);

Copy link
Member Author

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

Copy link
Contributor

@walterra walterra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Latest changes LGTM 🥳

@jgowdyelastic
Copy link
Member Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
ml 7.0MB 7.0MB +348.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@jgowdyelastic jgowdyelastic merged commit 1709c70 into elastic:master Jan 21, 2021
@jgowdyelastic jgowdyelastic deleted the improve-model-snapshot-revert-UI-experience branch January 21, 2021 10:54
jgowdyelastic added a commit to jgowdyelastic/kibana that referenced this pull request Jan 21, 2021
* [ML] Improving model snapshot revert UI experience

* removing button disabling

* updating component is mounted check

Co-authored-by: Kibana Machine <[email protected]>
jgowdyelastic added a commit that referenced this pull request Jan 21, 2021
* [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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ML] Improve usability for AD model snapshot revert
5 participants