Skip to content

Commit

Permalink
Adds SavedObjectsWarning to analytics results pages. (#144109) (#144401)
Browse files Browse the repository at this point in the history
- Fixes the saved object sync warning that should be shown on the analytics result pages.
- Adds a check if the jobs description is an empty string to avoid unnecessary whitespace rendering.

(cherry picked from commit a602fa8)
  • Loading branch information
walterra authored Nov 2, 2022
1 parent bf22fd4 commit 42f85ad
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export const ExplorationPageWrapper: FC<Props> = ({

return (
<>
{typeof jobConfig?.description !== 'undefined' && (
{typeof jobConfig?.description !== 'undefined' && jobConfig?.description !== '' && (
<>
<EuiText>{jobConfig?.description}</EuiText>
<EuiSpacer size="m" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export const OutlierExploration: FC<ExplorationProps> = React.memo(({ jobId }) =

return (
<>
{typeof jobConfig?.description !== 'undefined' && (
{typeof jobConfig?.description !== 'undefined' && jobConfig?.description !== '' && (
<>
<EuiText>{jobConfig?.description}</EuiText>
<EuiSpacer size="m" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
} from '../components/analytics_selector';
import { AnalyticsEmptyPrompt } from '../analytics_management/components/empty_prompt';
import { useUrlState } from '../../../util/url_state';
import { SavedObjectsWarning } from '../../../components/saved_objects_warning';

export const Page: FC<{
jobId: string;
Expand All @@ -41,7 +42,9 @@ export const Page: FC<{
} = useMlApiContext();
const helpLink = docLinks.links.ml.dataFrameAnalytics;
const jobIdToUse = jobId ?? analyticsId?.job_id;
const analysisTypeToUse = analysisType || analyticsId?.analysis_type;
const [analysisTypeToUse, setAnalysisTypeToUse] = useState<
DataFrameAnalysisConfigType | undefined
>(analysisType || analyticsId?.analysis_type);

const [, setGlobalState] = useUrlState('_g');

Expand All @@ -55,6 +58,25 @@ export const Page: FC<{
}
};

// The inner components of the results page don't have a concept of reloading the full page.
// Because we might want to refresh though if a user has to fix unsynced saved objects,
// we achieve this here by unmounting the inner pages first by setting `analysisTypeToUse`
// to `undefined`. The `useEffect()` below will then check if `analysisTypeToUse` doesn't
// match the passed in analyis type and will update it once again, the re-mounted
// page will then again fetch the most recent results.
const refresh = () => {
setAnalysisTypeToUse(undefined);
};

useEffect(
function checkRefresh() {
if (analysisTypeToUse !== analysisType || analyticsId?.analysis_type) {
setAnalysisTypeToUse(analysisType || analyticsId?.analysis_type);
}
},
[analyticsId, analysisType, analysisTypeToUse]
);

useEffect(function checkJobs() {
checkJobsExist();
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down Expand Up @@ -126,6 +148,9 @@ export const Page: FC<{
/>
</MlPageHeader>
)}

<SavedObjectsWarning onCloseFlyout={refresh} />

{jobIdToUse && analysisTypeToUse ? (
<div data-test-subj="mlPageDataFrameAnalyticsExploration">
{analysisTypeToUse === ANALYSIS_CONFIG_TYPE.OUTLIER_DETECTION && (
Expand Down

0 comments on commit 42f85ad

Please sign in to comment.