-
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] Adding job sychronization warning to job list pages #85794
Merged
jgowdyelastic
merged 9 commits into
elastic:master
from
jgowdyelastic:adding-job-synchronization-callout-to-job-list-pages
Dec 16, 2020
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
134ace0
[ML] Adding job sychronization warning to job list pages
jgowdyelastic 288beeb
fixing overview page callout
jgowdyelastic c8fc513
improving check logic
jgowdyelastic 4eedc54
adding render lock
jgowdyelastic b1e9287
Merge branch 'master' into adding-job-synchronization-callout-to-job-…
kibanamachine 8e9bd86
Merge branch 'master' into adding-job-synchronization-callout-to-job-…
kibanamachine b1cb6a6
Merge branch 'master' into adding-job-synchronization-callout-to-job-…
kibanamachine 6053e39
Merge branch 'master' into adding-job-synchronization-callout-to-job-…
jgowdyelastic 2848418
Merge branch 'master' into adding-job-synchronization-callout-to-job-…
kibanamachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
x-pack/plugins/ml/public/application/components/saved_objects_warning/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export { SavedObjectsWarning } from './saved_objects_warning'; |
82 changes: 82 additions & 0 deletions
82
.../plugins/ml/public/application/components/saved_objects_warning/saved_objects_warning.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React, { FC, useEffect, useState } from 'react'; | ||
|
||
import { EuiCallOut, EuiLink, EuiSpacer } from '@elastic/eui'; | ||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
import { JobType } from '../../../../common/types/saved_objects'; | ||
import { useMlApiContext, useMlKibana } from '../../contexts/kibana'; | ||
|
||
interface Props { | ||
jobType?: JobType; | ||
} | ||
|
||
export const SavedObjectsWarning: FC<Props> = ({ jobType }) => { | ||
const { | ||
savedObjects: { initSavedObjects }, | ||
} = useMlApiContext(); | ||
const { | ||
services: { | ||
http: { basePath }, | ||
}, | ||
} = useMlKibana(); | ||
|
||
const [showWarning, setShowWarning] = useState(false); | ||
|
||
useEffect(() => { | ||
let unmounted = false; | ||
initSavedObjects(true) | ||
.then(({ jobs }) => { | ||
if (unmounted === true) { | ||
return; | ||
} | ||
|
||
const missingJobs = | ||
jobs.length > 0 && (jobType === undefined || jobs.some(({ type }) => type === jobType)); | ||
setShowWarning(missingJobs); | ||
}) | ||
.catch(() => { | ||
console.log('Saved object synchronization check could not be performed.'); // eslint-disable-line no-console | ||
darnautov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
return () => { | ||
unmounted = true; | ||
}; | ||
}, []); | ||
|
||
return showWarning === false ? null : ( | ||
<> | ||
<EuiCallOut | ||
title={ | ||
<FormattedMessage | ||
id="xpack.ml.jobsList.missingSavedObjectWarning.title" | ||
defaultMessage="ML job synchronization needed" | ||
/> | ||
} | ||
color="warning" | ||
iconType="alert" | ||
> | ||
<div> | ||
<FormattedMessage | ||
id="xpack.ml.jobsList.missingSavedObjectWarning.description" | ||
defaultMessage="All jobs require an accompanying saved object. Some jobs are missing their saved object and require synchronization in the {link}." | ||
values={{ | ||
link: ( | ||
<EuiLink href={`${basePath.get()}/app/management/insightsAndAlerting/jobsListLink`}> | ||
<FormattedMessage | ||
id="xpack.ml.jobsList.missingSavedObjectWarning.linkToManagement.link" | ||
defaultMessage="stack management page" | ||
/> | ||
</EuiLink> | ||
), | ||
}} | ||
/> | ||
</div> | ||
</EuiCallOut> | ||
<EuiSpacer size="m" /> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
this effect potentially can update the state of an unmounted component
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.
Isn't this the case for all async calls that are made from a
useEffect
?Normally we call an async function but do not await on it as you can't pass an async function to
useEffect
, here I decided to use athen
rather than create a second function.This is a pattern i've seen in plenty of places, is there a better alternative?
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.
Check out this example
kibana/x-pack/plugins/ml/public/application/timeseriesexplorer/components/timeseries_chart/timeseries_chart_with_tooltip.tsx
Line 112 in 7a7057e
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.
ok yeah, a lock like this is a good solution.
We have a lot of components which have this potential problem.
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.
updated in 4eedc54
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.
yes, you're right, I see a warning message from React on this issue quite often.