Skip to content

Commit

Permalink
Rename documentLocation to resolverComponentInstanceID
Browse files Browse the repository at this point in the history
  • Loading branch information
kqualters-elastic committed Jul 13, 2020
1 parent 6532698 commit b4c9faf
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ interface AppReceivedNewExternalProperties {
* the `_id` of an ES document. This defines the origin of the Resolver graph.
*/
databaseDocumentID?: string;
documentLocation: string;
resolverComponentInstanceID: string;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import { ResolverAction } from '../actions';
const initialState: DataState = {
relatedEvents: new Map(),
relatedEventsReady: new Map(),
documentLocation: '',
resolverComponentInstanceID: '',
};

export const dataReducer: Reducer<DataState, ResolverAction> = (state = initialState, action) => {
if (action.type === 'appReceivedNewExternalProperties') {
const nextState: DataState = {
...state,
databaseDocumentID: action.payload.databaseDocumentID,
documentLocation: action.payload.documentLocation,
resolverComponentInstanceID: action.payload.resolverComponentInstanceID,
};
return nextState;
} else if (action.type === 'appRequestedResolverData') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ describe('data state', () => {

describe('when there is a databaseDocumentID but no pending request', () => {
const databaseDocumentID = 'databaseDocumentID';
const documentLocation = 'location';
const resolverComponentInstanceID = 'resolverComponentInstanceID';
beforeEach(() => {
actions = [
{
type: 'appReceivedNewExternalProperties',
payload: { databaseDocumentID, documentLocation },
payload: { databaseDocumentID, resolverComponentInstanceID },
},
];
});
Expand Down Expand Up @@ -105,12 +105,12 @@ describe('data state', () => {
});
describe('when there is a pending request for the current databaseDocumentID', () => {
const databaseDocumentID = 'databaseDocumentID';
const documentLocation = 'location';
const resolverComponentInstanceID = 'resolverComponentInstanceID';
beforeEach(() => {
actions = [
{
type: 'appReceivedNewExternalProperties',
payload: { databaseDocumentID, documentLocation },
payload: { databaseDocumentID, resolverComponentInstanceID },
},
{
type: 'appRequestedResolverData',
Expand Down Expand Up @@ -162,14 +162,17 @@ describe('data state', () => {
describe('when there is a pending request for a different databaseDocumentID than the current one', () => {
const firstDatabaseDocumentID = 'first databaseDocumentID';
const secondDatabaseDocumentID = 'second databaseDocumentID';
const firstLocation = 'firstLocation';
const secondLocation = 'secondLocation';
const resolverComponentInstanceID1 = 'resolverComponentInstanceID1';
const resolverComponentInstanceID2 = 'resolverComponentInstanceID2';
beforeEach(() => {
actions = [
// receive the document ID, this would cause the middleware to starts the request
{
type: 'appReceivedNewExternalProperties',
payload: { databaseDocumentID: firstDatabaseDocumentID, documentLocation: firstLocation },
payload: {
databaseDocumentID: firstDatabaseDocumentID,
resolverComponentInstanceID: resolverComponentInstanceID1,
},
},
// this happens when the middleware starts the request
{
Expand All @@ -181,7 +184,7 @@ describe('data state', () => {
type: 'appReceivedNewExternalProperties',
payload: {
databaseDocumentID: secondDatabaseDocumentID,
documentLocation: secondLocation,
resolverComponentInstanceID: resolverComponentInstanceID2,
},
},
];
Expand All @@ -196,10 +199,10 @@ describe('data state', () => {
expect(selectors.databaseDocumentIDToFetch(state())).toBe(secondDatabaseDocumentID);
});
it('should use the correct location for the first resolver', () => {
expect(selectors.documentLocation(state())).toBe(firstLocation);
expect(selectors.resolverComponentInstanceID(state())).toBe(resolverComponentInstanceID1);
});
it('should use the correct location for the second resolver', () => {
expect(selectors.documentLocation(state())).toBe(secondLocation);
expect(selectors.resolverComponentInstanceID(state())).toBe(resolverComponentInstanceID2);
});
it('should not have an error, more children, or more ancestors.', () => {
expect(viewAsAString(state())).toMatchInlineSnapshot(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ export function isLoading(state: DataState): boolean {
return state.pendingRequestDatabaseDocumentID !== undefined;
}

export function documentLocation(state: DataState): string {
return state.documentLocation;
/**
* A string for uniquely identifying the instance of resolver within the app.
*/
export function resolverComponentInstanceID(state: DataState): string {
return state.resolverComponentInstanceID;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ export const databaseDocumentIDToAbort = composeSelectors(
dataSelectors.databaseDocumentIDToAbort
);

export const documentLocation = composeSelectors(dataStateSelector, dataSelectors.documentLocation);
export const resolverComponentInstanceID = composeSelectors(
dataStateSelector,
dataSelectors.resolverComponentInstanceID
);

export const processAdjacencies = composeSelectors(
dataStateSelector,
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/security_solution/public/resolver/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export interface DataState {
* The id used for the pending request, if there is one.
*/
readonly pendingRequestDatabaseDocumentID?: string;
readonly documentLocation: string;
readonly resolverComponentInstanceID: string;

/**
* The parameters and response from the last successful request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { useKibana } from '../../../../../../src/plugins/kibana_react/public';
export const Resolver = React.memo(function ({
className,
databaseDocumentID,
documentLocation,
resolverComponentInstanceID,
}: {
/**
* Used by `styled-components`.
Expand All @@ -33,7 +33,7 @@ export const Resolver = React.memo(function ({
* A string literal describing where in the app resolver is located,
* used to prevent collisions in things like query params
*/
documentLocation: string;
resolverComponentInstanceID: string;
}) {
const context = useKibana<StartServices>();
const store = useMemo(() => {
Expand All @@ -49,7 +49,7 @@ export const Resolver = React.memo(function ({
<ResolverMap
className={className}
databaseDocumentID={databaseDocumentID}
documentLocation={documentLocation}
resolverComponentInstanceID={resolverComponentInstanceID}
/>
</Provider>
);
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/security_solution/public/resolver/view/map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { SideEffectContext } from './side_effect_context';
export const ResolverMap = React.memo(function ({
className,
databaseDocumentID,
documentLocation,
resolverComponentInstanceID,
}: {
/**
* Used by `styled-components`.
Expand All @@ -44,13 +44,13 @@ export const ResolverMap = React.memo(function ({
* A string literal describing where in the app resolver is located,
* used to prevent collisions in things like query params
*/
documentLocation: string;
resolverComponentInstanceID: string;
}) {
/**
* This is responsible for dispatching actions that include any external data.
* `databaseDocumentID`
*/
useStateSyncingActions({ databaseDocumentID, documentLocation });
useStateSyncingActions({ databaseDocumentID, resolverComponentInstanceID });

const { timestamp } = useContext(SideEffectContext);
const { processNodePositions, connectingEdgeLineSegments } = useSelector(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export function useResolverQueryParams() {
*/
const history = useHistory();
const urlSearch = useLocation().search;
const documentLocation = useSelector(selectors.documentLocation);
const uniqueCrumbIdKey: string = `${documentLocation}CrumbId`;
const uniqueCrumbEventKey: string = `${documentLocation}CrumbEvent`;
const resolverComponentInstanceID = useSelector(selectors.resolverComponentInstanceID);
const uniqueCrumbIdKey: string = `${resolverComponentInstanceID}CrumbId`;
const uniqueCrumbEventKey: string = `${resolverComponentInstanceID}CrumbEvent`;
const pushToQueryParams = useCallback(
(newCrumbs: CrumbInfo) => {
// Construct a new set of params from the current set (minus empty params)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ import { useResolverDispatch } from './use_resolver_dispatch';
*/
export function useStateSyncingActions({
databaseDocumentID,
documentLocation,
resolverComponentInstanceID,
}: {
/**
* The `_id` of an event in ES. Used to determine the origin of the Resolver graph.
*/
databaseDocumentID?: string;
documentLocation: string;
resolverComponentInstanceID: string;
}) {
const dispatch = useResolverDispatch();
useLayoutEffect(() => {
dispatch({
type: 'appReceivedNewExternalProperties',
payload: { databaseDocumentID, documentLocation },
payload: { databaseDocumentID, resolverComponentInstanceID },
});
}, [dispatch, databaseDocumentID, documentLocation]);
}, [dispatch, databaseDocumentID, resolverComponentInstanceID]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ const GraphOverlayComponent = ({
</EuiFlexGroup>

<EuiHorizontalRule margin="none" />
<StyledResolver databaseDocumentID={graphEventId} documentLocation={currentTimeline.id} />
<StyledResolver
databaseDocumentID={graphEventId}
resolverComponentInstanceID={currentTimeline.id}
/>
<AllCasesModal
onCloseCaseModal={onCloseCaseModal}
showCaseModal={showCaseModal}
Expand Down

0 comments on commit b4c9faf

Please sign in to comment.