Skip to content

Commit

Permalink
[ML] Support legacy watcher URL (#86661)
Browse files Browse the repository at this point in the history
* [ML] update watcher URL, support legacy state

* [ML] fix comment
  • Loading branch information
darnautov authored Dec 21, 2020
1 parent 8760fa5 commit 58b4297
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,16 @@ import { ExplorerAppState } from '../../../../common/types/ml_url_generator';
import { ML_PAGES } from '../../../../common/constants/ml_url_generator';

export function useExplorerUrlState() {
return usePageUrlState<ExplorerAppState>(ML_PAGES.ANOMALY_EXPLORER);
/**
* Originally `mlExplorerSwimlane` resided directly in the app URL state (`_a` URL state key).
* With current URL structure it has been moved under the `explorer` key of the app state (_a).
*/
const [legacyExplorerState] = usePageUrlState<ExplorerAppState['mlExplorerSwimlane']>(
'mlExplorerSwimlane'
);

return usePageUrlState<ExplorerAppState>(ML_PAGES.ANOMALY_EXPLORER, {
mlExplorerSwimlane: legacyExplorerState,
mlExplorerFilter: {},
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<br />
<br />

<a href="<%= serverAddress %>#/explorer/?_g=(ml:(jobIds:!('{{ctx.payload.aggregations.bucket_results.top_bucket_hits.hits.hits.0._source.job_id}}')),time:(from:'{{ctx.payload.aggregations.bucket_results.top_bucket_hits.hits.hits.0.fields.start.0}}',mode:absolute,to:'{{ctx.payload.aggregations.bucket_results.top_bucket_hits.hits.hits.0.fields.end.0}}'))&_a=(filters:!(),mlAnomaliesTable:(intervalValue:auto,thresholdValue:0),mlExplorerSwimlane:(selectedLane:Overall,selectedTime:{{ctx.payload.aggregations.bucket_results.top_bucket_hits.hits.hits.0.fields.timestamp_epoch.0}},selectedType:overall),query:(query_string:(analyze_wildcard:!t,query:'*')))">
<a href="<%= serverAddress %>#/explorer/?_g=(ml:(jobIds:!('{{ctx.payload.aggregations.bucket_results.top_bucket_hits.hits.hits.0._source.job_id}}')),time:(from:'{{ctx.payload.aggregations.bucket_results.top_bucket_hits.hits.hits.0.fields.start.0}}',mode:absolute,to:'{{ctx.payload.aggregations.bucket_results.top_bucket_hits.hits.hits.0.fields.end.0}}'))&_a=(explorer:(mlExplorerSwimlane:(selectedLane:Overall,selectedTime:{{ctx.payload.aggregations.bucket_results.top_bucket_hits.hits.hits.0.fields.timestamp_epoch.0}},selectedType:overall)),query:(query_string:(analyze_wildcard:!t,query:'*')))">
<%= openInAnomalyExplorerLinkText %>
</a>
<br />
Expand Down
9 changes: 8 additions & 1 deletion x-pack/plugins/ml/public/application/util/url_state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,14 @@ export const useUrlState = (accessor: Accessor) => {
return [urlState, setUrlState];
};

type AppStateKey = 'mlSelectSeverity' | 'mlSelectInterval' | 'mlAnomaliesTable' | MlPages;
type LegacyUrlKeys = 'mlExplorerSwimlane';

type AppStateKey =
| 'mlSelectSeverity'
| 'mlSelectInterval'
| 'mlAnomaliesTable'
| MlPages
| LegacyUrlKeys;

/**
* Hook for managing the URL state of the page.
Expand Down

0 comments on commit 58b4297

Please sign in to comment.