Skip to content

Commit

Permalink
Merge pull request elastic#17 from Elastic-AWP-Platform/refactor-use-…
Browse files Browse the repository at this point in the history
…style-hook

Refactor styles hook to use cssobject and remove unused styles
  • Loading branch information
Jack authored Nov 29, 2021
2 parents cc106b6 + c9324af commit d345568
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 71 deletions.
37 changes: 19 additions & 18 deletions x-pack/plugins/session_view/public/components/ProcessTree/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,33 @@

import { useMemo } from 'react';
import { useEuiTheme } from '@elastic/eui';
import { CSSObject } from '@emotion/react';

export const useStyles = () => {
const { euiTheme } = useEuiTheme();

const cached = useMemo(() => {
const defaultSelectionColor = euiTheme.colors.accent;

const scroller = `
font-family: ${euiTheme.font.familyCode};
overflow: auto;
height: 100%;
background-color: ${euiTheme.colors.lightestShade};
display: flex;
flex-direction: column;
`;
const scroller: CSSObject = {
fontFamily: euiTheme.font.familyCode,
overflow: 'auto',
height: '100%',
backgroundColor: euiTheme.colors.lightestShade,
display: 'flex',
flexDirection: 'column',
};

const selectionArea = `
position: absolute;
display: none;
margin-left: -50%;
width: 150%;
height: 100%;
background-color: ${defaultSelectionColor};
pointer-events:none;
opacity: .1;
`;
const selectionArea: CSSObject = {
position: 'absolute',
display: 'none',
marginLeft: '-50%',
width: '150%',
height: '100%',
backgroundColor: defaultSelectionColor,
pointerEvents: 'none',
opacity: 0.1,
};

return {
scroller,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useEffect, useState } from 'react';
import { useQuery } from 'react-query';
import { EuiSearchBarOnChangeArgs } from '@elastic/eui';
import { CoreStart } from 'kibana/public';
import { useKibana } from 'src/plugins/kibana_react/public';
import { useKibana } from '../../../../../../src/plugins/kibana_react/public';
import { ProcessEvent } from '../../hooks/use_process_tree';
import { PROCESS_EVENTS_ROUTE } from '../../../common/constants';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { useMemo } from 'react';
import { useEuiTheme } from '@elastic/eui';
import { keyframes, CSSObject } from '@emotion/react';
import { CSSObject } from '@emotion/react';

interface StylesDeps {
height: number | undefined;
Expand Down Expand Up @@ -35,52 +35,10 @@ export const useStyles = ({ height = 500 }: StylesDeps) => {
paddingLeft: padding,
};

const slideIn = keyframes({
to: {
right: '0',
},
});

const slideOut = keyframes({
from: {
right: '0',
},
to: {
right: '-100%',
},
});

const detailPanel: CSSObject = {
width: '424px',
height: `${height}px`,
overflowY: 'auto',
position: 'absolute',
top: '8px',
right: '-100%',
};

const detailPanelIn: Array<string | CSSObject> = [
slideIn.styles,
{
...detailPanel,
animation: `${slideIn.name} 200ms ease forwards`,
},
];

const detailPanelOut: Array<string | CSSObject> = [
slideOut.styles,
{
...detailPanel,
animation: `${slideOut.name} 150ms ease`,
},
];

return {
processTree,
outerPanel,
treePanel,
detailPanelIn,
detailPanelOut,
};
}, [height, euiTheme]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ export const SessionViewDetailPanel = ({
kind: processEvent?.event.kind,
}));

const [commandTabs, alertTabs] = partition(selectedProcessEvents, { kind: EventKind.event });
const [processCommandTabs, processAlertTabs] = partition(selectedProcessEvents, {
kind: EventKind.event,
});

setCommandTabs(commandTabs);
setSelectedCommandTab(commandTabs[0]?.id || '');
setAlertTabs(alertTabs);
setSelectedAlertTab(alertTabs[0]?.id || '');
setCommandTabs(processCommandTabs);
setSelectedCommandTab(processCommandTabs[0]?.id || '');
setAlertTabs(processAlertTabs);
setSelectedAlertTab(processAlertTabs[0]?.id || '');
}, [selectedProcess]);

const handleAnimationEnd = () => {
Expand Down Expand Up @@ -115,10 +117,7 @@ export const SessionViewDetailPanel = ({
<div>
<EuiTitle size="s">
<span>
<FormattedMessage
id="xpack.sessionView.alertDetail"
defaultMessage="Alert detail"
/>
<FormattedMessage id="xpack.sessionView.alertDetail" defaultMessage="Alert detail" />
</span>
</EuiTitle>
<EuiSpacer />
Expand Down

0 comments on commit d345568

Please sign in to comment.