Skip to content

Commit ba7ec4f

Browse files
committed
Improve types (hopefully)
1 parent ddc8d2d commit ba7ec4f

2 files changed

Lines changed: 41 additions & 38 deletions

File tree

  • x-pack
    • platform/plugins/shared/lens/public/editor_frame_service/editor_frame/config_panel/layer_actions
    • solutions/observability/plugins/observability_ai_assistant_app/public/components/rca/rca_panel

x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/config_panel/layer_actions/layer_actions.tsx

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
EuiFlexGroup,
2121
EuiFlexItem,
2222
EuiToolTip,
23-
EuiButtonIconProps,
2423
} from '@elastic/eui';
2524
import type { CoreStart } from '@kbn/core/public';
2625
import { css } from '@emotion/react';
@@ -63,25 +62,25 @@ export const getSharedActions = ({
6362
core: Pick<CoreStart, 'overlays' | 'analytics' | 'i18n' | 'theme' | 'userProfile'>;
6463
customRemoveModalText?: { title?: string; description?: string };
6564
}) => [
66-
getOpenLayerSettingsAction({
67-
hasLayerSettings,
68-
openLayerSettings,
69-
}),
70-
getCloneLayerAction({
71-
execute: onCloneLayer,
72-
layerIndex,
73-
activeVisualization,
74-
isTextBasedLanguage,
75-
}),
76-
getRemoveLayerAction({
77-
execute: onRemoveLayer,
78-
layerIndex,
79-
layerType,
80-
isOnlyLayer,
81-
core,
82-
customModalText: customRemoveModalText,
83-
}),
84-
];
65+
getOpenLayerSettingsAction({
66+
hasLayerSettings,
67+
openLayerSettings,
68+
}),
69+
getCloneLayerAction({
70+
execute: onCloneLayer,
71+
layerIndex,
72+
activeVisualization,
73+
isTextBasedLanguage,
74+
}),
75+
getRemoveLayerAction({
76+
execute: onRemoveLayer,
77+
layerIndex,
78+
layerType,
79+
isOnlyLayer,
80+
core,
81+
customModalText: customRemoveModalText,
82+
}),
83+
];
8584

8685
/** @internal **/
8786
const InContextMenuActions = (props: LayerActionsProps) => {
@@ -102,6 +101,16 @@ const InContextMenuActions = (props: LayerActionsProps) => {
102101
}
103102
}, [isPopoverOpen]);
104103

104+
// `neutral` and `risk` variants belong to `severity` so they're not
105+
// available in `euiTheme.colors` directly
106+
const getColorFromTheme = useCallback(
107+
(color: LayerAction['color']) =>
108+
color === 'risk' || color === 'neutral'
109+
? euiTheme.colors.severity[color]
110+
: euiTheme.colors[color!],
111+
[euiTheme]
112+
);
113+
105114
return (
106115
<EuiOutsideClickDetector onOutsideClick={closePopover}>
107116
<EuiPopover
@@ -144,16 +153,14 @@ const InContextMenuActions = (props: LayerActionsProps) => {
144153
}}
145154
{...(i.color
146155
? {
147-
css: css`
148-
color: ${euiTheme.colors[i.color as keyof EuiButtonIconProps['color']]};
156+
css: css`
157+
color: ${getColorFromTheme(i.color)};
149158
&:hover {
150-
text-decoration-color: ${euiTheme.colors[
151-
i.color as keyof EuiButtonIconProps['color']
152-
]} !important;
159+
text-decoration-color: ${getColorFromTheme(i.color)} !important;
153160
}
154161
`,
155-
size: 's', // need to be explicit here as css prop will disable the default small size
156-
}
162+
size: 's', // need to be explicit here as css prop will disable the default small size
163+
}
157164
: {})}
158165
>
159166
<EuiText size={'s'} color={i.color}>

x-pack/solutions/observability/plugins/observability_ai_assistant_app/public/components/rca/rca_panel/index.tsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,12 @@
55
* 2.0.
66
*/
77

8-
import { EuiPanel, UseEuiTheme } from '@elastic/eui';
8+
import { EuiPanel } from '@elastic/eui';
99
import { css } from '@emotion/css';
1010
import { rgba } from 'polished';
1111
import React from 'react';
1212
import { useTheme } from '../../../hooks/use_theme';
1313

14-
type EuiBackgroundColor = Pick<
15-
UseEuiTheme['euiTheme']['colors'],
16-
'accent' | 'accentSecondary' | 'primary' | 'success' | 'warning' | 'danger'
17-
>;
18-
1914
export function RootCauseAnalysisPanel({
2015
children,
2116
color,
@@ -25,15 +20,16 @@ export function RootCauseAnalysisPanel({
2520
}) {
2621
const theme = useTheme();
2722

23+
const isSeverityColor = color === 'risk' || color === 'neutral';
2824
const panelClassName =
2925
color &&
30-
color !== 'transparent' &&
31-
color !== 'plain' &&
32-
color !== 'subdued' &&
33-
color !== 'highlighted'
26+
color !== 'transparent' &&
27+
color !== 'plain' &&
28+
color !== 'subdued' &&
29+
color !== 'highlighted'
3430
? css`
3531
border: 1px solid;
36-
border-color: ${rgba(theme.colors[color as keyof EuiBackgroundColor], 0.25)};
32+
border-color: ${rgba(isSeverityColor ? theme.colors.severity[color] : theme.colors[color], 0.25)};
3733
`
3834
: undefined;
3935

0 commit comments

Comments
 (0)