Skip to content
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

base changes for active/current node styling #62007

Merged
merged 17 commits into from
Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
run style off of selected/current state
  • Loading branch information
Brent Kimmel committed Mar 31, 2020
commit 0055a47e135a764aa61e85b3ab74d630e7034db1
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,24 @@ interface UserFocusedOnResolverNode {
};
}

/**
* When the user "selects" a node in the Resolver
*/
interface UserSelectedResolverNode {
readonly type: 'userSelectedResolverNode';
readonly payload: {
/**
* Used to identify the process node that the user selected
*/
readonly nodeId: string;
};
}

export type ResolverAction =
| CameraAction
| DataAction
| UserBroughtProcessIntoView
| UserChangedSelectedEvent
| AppRequestedResolverData
| UserFocusedOnResolverNode;
| UserFocusedOnResolverNode
| UserSelectedResolverNode;
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@ import { dataReducer } from './data/reducer';
import { ResolverState, ResolverAction, ResolverUIState } from '../types';

const uiReducer: Reducer<ResolverUIState, ResolverAction> = (
uiState = { activeDescendentId: null },
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ Fun fact: "descendant" and "descendent" (at least in en-US) have slightly different meanings. "descendant" with a "a" is defined as a noun meaning a person, plant, or animal that is descended from a particular ancestor and "descendent" with an adjective "e" meaning descending from an ancestor. Given that many other ARIA attributes are also adjectives ("required","relevant") and a document element is difficult to classify as a "person, plant or animal" I would have suggested "descendent" as the better term, but 🤷‍♂

uiState = { activeDescendentId: null, selectedDescendantId: null },
action
) => {
if (action.type === 'userFocusedOnResolverNode') {
return {
...uiState,
activeDescendentId: action.payload.nodeId,
};
} else if (action.type === 'userSelectedResolverNode') {
return {
...uiState,
selectedDescendantId: action.payload.nodeId,
};
} else {
return uiState;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import * as cameraSelectors from './camera/selectors';
import * as dataSelectors from './data/selectors';
import * as uiSelectors from './ui/selectors';
import { ResolverState } from '../types';

/**
Expand Down Expand Up @@ -59,9 +60,21 @@ export const processAdjacencies = composeSelectors(
dataSelectors.processAdjacencies
);

export const uiActiveDescendantId = composeSelectors(uiStateSelector, uiState => {
return uiState.activeDescendentId;
});
/**
* Returns the id of the "current" tree node (fake-focused)
*/
export const uiActiveDescendantId = composeSelectors(
uiStateSelector,
uiSelectors.activeDescendantId
);

/**
* Returns the id of the "selected" tree node (fake-focused)
*/
export const uiSelectedDescendantId = composeSelectors(
uiStateSelector,
uiSelectors.selectedDescendantId
);

/**
* Returns the camera state from within ResolverState
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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 activeDescendantId = createSelector(
(uiState: ResolverUIState) => uiState,
({ activeDescendentId }) => {
return activeDescendentId;
}
);

/**
* id of the currently "selected" tree node
*/
export const selectedDescendantId = createSelector(
(uiState: ResolverUIState) => uiState,
/* eslint-disable no-shadow */
({ selectedDescendantId }) => {
return selectedDescendantId;
}
);
4 changes: 4 additions & 0 deletions x-pack/plugins/endpoint/public/embeddables/resolver/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export interface ResolverUIState {
* The ID attribute of the resolver's aria-activedescendent.
*/
readonly activeDescendentId: string | null;
/**
* The ID attribute of the resolver's currently selected descendant.
*/
readonly selectedDescendantId: string | null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export const ProcessEventDot = styled(
const selfId = adjacentNodeMap?.self;

const activeDescendantId = useSelector(selectors.uiActiveDescendantId);
const selectedDescendantId = useSelector(selectors.uiSelectedDescendantId);

const nodeViewportStyle = useMemo(
() => ({
Expand Down Expand Up @@ -147,6 +148,10 @@ export const ProcessEventDot = styled(
return nodeId === activeDescendantId;
}, [activeDescendantId, nodeId]);

const isSelectedDescendant = useMemo(() => {
return nodeId === selectedDescendantId;
}, [selectedDescendantId, nodeId]);

const dispatch = useResolverDispatch();

const handleFocus = useCallback(
Expand All @@ -157,7 +162,6 @@ export const ProcessEventDot = styled(
nodeId,
},
});
focusEvent.currentTarget.setAttribute('aria-current', 'true');
},
[dispatch, nodeId]
);
Expand All @@ -167,8 +171,14 @@ export const ProcessEventDot = styled(
if (clickTargetRef.current !== null) {
(clickTargetRef.current as any).beginElement();
}
dispatch({
type: 'userSelectedResolverNode',
payload: {
nodeId,
},
});
},
[clickTargetRef]
[clickTargetRef, dispatch, nodeId]
);

return (
Expand All @@ -184,7 +194,8 @@ export const ProcessEventDot = styled(
aria-labelledby={labelId}
aria-describedby={descriptionId}
aria-haspopup={'true'}
aria-selected={isActiveDescendant ? 'true' : undefined}
aria-current={isActiveDescendant ? 'true' : undefined}
aria-selected={isSelectedDescendant ? 'true' : undefined}
style={nodeViewportStyle}
id={nodeId}
onClick={handleClick}
Expand Down Expand Up @@ -271,6 +282,13 @@ export const ProcessEventDot = styled(
white-space: nowrap;
will-change: left, top, width, height;
contain: strict;

&[aria-current] {
outline: 1px solid red;
}
&[aria-selected] {
background: gray;
}
`;

const processTypeToCube: Record<ResolverProcessType, keyof typeof nodeAssets> = {
Expand Down