-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Resolver] model
location.search
in redux (#76140)
Read location.search from the redux store instead of a hook so that the entire view has a single (synchronized) source of truth. Also, no longer pass `pushToQueryParams` function to various components.
- Loading branch information
Robert Austin
authored
Aug 28, 2020
1 parent
712c4bd
commit 3fc3f58
Showing
18 changed files
with
271 additions
and
179 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
x-pack/plugins/security_solution/public/resolver/models/location_search.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,39 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* The legacy `crumbEvent` and `crumbId` parameters. | ||
* @deprecated | ||
*/ | ||
export function breadcrumbParameters( | ||
locationSearch: string, | ||
resolverComponentInstanceID: string | ||
): { crumbEvent: string; crumbId: string } { | ||
const urlSearchParams = new URLSearchParams(locationSearch); | ||
const { eventKey, idKey } = parameterNames(resolverComponentInstanceID); | ||
return { | ||
// Use `''` for backwards compatibility with deprecated code. | ||
crumbEvent: urlSearchParams.get(eventKey) ?? '', | ||
crumbId: urlSearchParams.get(idKey) ?? '', | ||
}; | ||
} | ||
|
||
/** | ||
* Parameter names based on the `resolverComponentInstanceID`. | ||
*/ | ||
function parameterNames( | ||
resolverComponentInstanceID: string | ||
): { | ||
idKey: string; | ||
eventKey: string; | ||
} { | ||
const idKey: string = `resolver-${resolverComponentInstanceID}-id`; | ||
const eventKey: string = `resolver-${resolverComponentInstanceID}-event`; | ||
return { | ||
idKey, | ||
eventKey, | ||
}; | ||
} |
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
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
80 changes: 50 additions & 30 deletions
80
x-pack/plugins/security_solution/public/resolver/store/ui/selectors.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 |
---|---|---|
@@ -1,30 +1,50 @@ | ||
/* | ||
* 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 { createSelector } from 'reselect'; | ||
import { ResolverUIState } from '../../types'; | ||
|
||
/** | ||
* id of the "current" tree node (fake-focused) | ||
*/ | ||
export const ariaActiveDescendant = createSelector( | ||
(uiState: ResolverUIState) => uiState, | ||
/* eslint-disable no-shadow */ | ||
({ ariaActiveDescendant }) => { | ||
return ariaActiveDescendant; | ||
} | ||
); | ||
|
||
/** | ||
* id of the currently "selected" tree node | ||
*/ | ||
export const selectedNode = createSelector( | ||
(uiState: ResolverUIState) => uiState, | ||
/* eslint-disable no-shadow */ | ||
({ selectedNode }: ResolverUIState) => { | ||
return selectedNode; | ||
} | ||
); | ||
/* | ||
* 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 { createSelector } from 'reselect'; | ||
import { ResolverUIState } from '../../types'; | ||
import * as locationSearchModel from '../../models/location_search'; | ||
|
||
/** | ||
* id of the "current" tree node (fake-focused) | ||
*/ | ||
export const ariaActiveDescendant = createSelector( | ||
(uiState: ResolverUIState) => uiState, | ||
/* eslint-disable no-shadow */ | ||
({ ariaActiveDescendant }) => { | ||
return ariaActiveDescendant; | ||
} | ||
); | ||
|
||
/** | ||
* id of the currently "selected" tree node | ||
*/ | ||
export const selectedNode = createSelector( | ||
(uiState: ResolverUIState) => uiState, | ||
/* eslint-disable no-shadow */ | ||
({ selectedNode }: ResolverUIState) => { | ||
return selectedNode; | ||
} | ||
); | ||
|
||
/** | ||
* The legacy `crumbEvent` and `crumbId` parameters. | ||
* @deprecated | ||
*/ | ||
export const breadcrumbParameters = createSelector( | ||
(state: ResolverUIState) => state.locationSearch, | ||
(state: ResolverUIState) => state.resolverComponentInstanceID, | ||
(locationSearch, resolverComponentInstanceID) => { | ||
if (locationSearch === undefined || resolverComponentInstanceID === undefined) { | ||
// Equivalent to `null` | ||
return { | ||
crumbId: '', | ||
crumbEvent: '', | ||
}; | ||
} | ||
return locationSearchModel.breadcrumbParameters(locationSearch, resolverComponentInstanceID); | ||
} | ||
); |
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
Oops, something went wrong.