Skip to content

Commit

Permalink
♻️ Refactor to let trigger have its own test id
Browse files Browse the repository at this point in the history
  • Loading branch information
dej611 committed Apr 13, 2023
1 parent 0db73aa commit 6b04133
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 48 deletions.
22 changes: 13 additions & 9 deletions x-pack/plugins/lens/public/datasources/form_based/layerpanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,19 @@ export function LayerPanel({
const extraIconLabelProps =
samplingValue !== 1
? {
icon: <RandomSamplingIcon color={euiTheme.colors.disabledText} fill="currentColor" />,
iconValue: `${samplingValue * 100}%`,
iconTooltipValue: i18n.translate('xpack.lens.indexPattern.randomSamplingInfo', {
defaultMessage: '{value}% sampling',
values: {
value: samplingValue * 100,
},
}),
'data-test-subj': 'lnsChangeIndexPatternSamplingInfo',
icon: {
component: (
<RandomSamplingIcon color={euiTheme.colors.disabledText} fill="currentColor" />
),
value: `${samplingValue * 100}%`,
tooltipValue: i18n.translate('xpack.lens.indexPattern.randomSamplingInfo', {
defaultMessage: '{value}% sampling',
values: {
value: samplingValue * 100,
},
}),
'data-test-subj': 'lnsChangeIndexPatternSamplingInfo',
},
}
: {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import { ToolbarButton, ToolbarButtonProps } from './toolbar_button';

interface TriggerLabelProps {
label: string;
icon?: React.ReactElement;
iconValue?: string;
iconTooltipValue?: string;
'data-test-subj'?: string;
icon?: {
component: React.ReactElement;
value?: string;
tooltipValue?: string;
'data-test-subj': string;
};
}

export type ChangeIndexPatternTriggerProps = ToolbarButtonProps &
Expand All @@ -25,13 +27,7 @@ export type ChangeIndexPatternTriggerProps = ToolbarButtonProps &
isDisabled?: boolean;
};

function TriggerLabel({
label,
icon,
iconValue,
iconTooltipValue,
'data-test-subj': dataTestSubj,
}: TriggerLabelProps) {
function TriggerLabel({ label, icon }: TriggerLabelProps) {
const { euiTheme } = useEuiTheme();
if (!icon) {
return <>{label}</>;
Expand All @@ -49,7 +45,7 @@ function TriggerLabel({
</EuiFlexItem>
<EuiFlexItem
grow={false}
data-test-subj={dataTestSubj}
data-test-subj={icon['data-test-subj']}
css={css`
display: block;
*:hover &,
Expand All @@ -58,12 +54,12 @@ function TriggerLabel({
}
`}
>
<EuiToolTip content={iconTooltipValue} position="top">
<EuiToolTip content={icon.tooltipValue} position="top">
<EuiFlexGroup alignItems="center" gutterSize="xs" responsive={false}>
<EuiFlexItem grow={false}>{icon}</EuiFlexItem>
{iconValue ? (
<EuiFlexItem grow={false}>{icon.component}</EuiFlexItem>
{icon.value ? (
<EuiFlexItem grow={false}>
<EuiTextColor color={euiTheme.colors.disabledText}>{iconValue}</EuiTextColor>
<EuiTextColor color={euiTheme.colors.disabledText}>{icon.value}</EuiTextColor>
</EuiFlexItem>
) : null}
</EuiFlexGroup>
Expand All @@ -79,9 +75,6 @@ export function TriggerButton({
togglePopover,
isMissingCurrent,
icon,
iconValue,
iconTooltipValue,
'data-test-subj': dataTestSubj,
...rest
}: ChangeIndexPatternTriggerProps & {
togglePopover: () => void;
Expand All @@ -102,13 +95,7 @@ export function TriggerButton({
{...rest}
textProps={{ style: { width: '100%' } }}
>
<TriggerLabel
label={label}
icon={icon}
iconValue={iconValue}
iconTooltipValue={iconTooltipValue}
data-test-subj={dataTestSubj}
/>
<TriggerLabel label={label} icon={icon} />
</ToolbarButton>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,21 @@ function AnnotationLayerHeaderContent({
const extraIconLabelProps = !layer.ignoreGlobalFilters
? {}
: {
icon: (
<EuiIcon
type={'filterIgnore'}
color={euiTheme.colors.disabledText}
css={css`
margin-top: 15px;
`}
/>
),
iconTooltipValue: i18n.translate('xpack.lens.layerPanel.ignoreGlobalFilters', {
defaultMessage: 'Ignore global filters',
}),
'data-test-subj': 'lnsChangeIndexPatternIgnoringFilters',
icon: {
component: (
<EuiIcon
type={'filterIgnore'}
color={euiTheme.colors.disabledText}
css={css`
margin-top: 15px;
`}
/>
),
tooltipValue: i18n.translate('xpack.lens.layerPanel.ignoreGlobalFilters', {
defaultMessage: 'Ignore global filters',
}),
'data-test-subj': 'lnsChangeIndexPatternIgnoringFilters',
},
};
return (
<ChangeIndexPattern
Expand Down

0 comments on commit 6b04133

Please sign in to comment.