2021-07-12 16:42:04 +02:00
|
|
|
import { css, cx } from '@emotion/css';
|
2022-04-22 14:33:13 +01:00
|
|
|
import React from 'react';
|
|
|
|
|
|
2021-07-12 16:42:04 +02:00
|
|
|
import { GrafanaTheme2 } from '@grafana/data';
|
2020-04-30 09:26:59 +02:00
|
|
|
import { selectors } from '@grafana/e2e-selectors';
|
2022-04-22 14:33:13 +01:00
|
|
|
import { IconButton, IconName, useStyles2 } from '@grafana/ui';
|
2020-04-09 21:23:22 +02:00
|
|
|
|
2023-05-10 11:57:08 +01:00
|
|
|
interface BaseQueryOperationActionProps {
|
2020-04-09 21:23:22 +02:00
|
|
|
icon: IconName;
|
Chore: Fix all Typescript strict null errors (#26204)
* Chore: Fix typescript strict null errors
* Added new limit
* Fixed ts issue
* fixed tests
* trying to fix type inference
* Fixing more ts errors
* Revert tsconfig option
* Fix
* Fixed code
* More fixes
* fix tests
* Updated snapshot
* Chore: More ts strict null fixes
* More fixes in some really messed up azure config components
* More fixes, current count: 441
* 419
* More fixes
* Fixed invalid initial state in explore
* Fixing tests
* Fixed tests
* Explore fix
* More fixes
* Progress
* Sub 300
* Now at 218
* Progress
* Update
* Progress
* Updated tests
* at 159
* fixed tests
* Progress
* YAy blow 100! at 94
* 10,9,8,7,6,5,4,3,2,1... lift off
* Fixed tests
* Fixed more type errors
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2020-07-10 12:46:59 +02:00
|
|
|
title: string;
|
2020-04-09 21:23:22 +02:00
|
|
|
onClick: (e: React.MouseEvent) => void;
|
|
|
|
|
disabled?: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-10 11:57:08 +01:00
|
|
|
function BaseQueryOperationAction(props: QueryOperationActionProps | QueryOperationToggleActionProps) {
|
2021-07-12 16:42:04 +02:00
|
|
|
const styles = useStyles2(getStyles);
|
2020-04-11 16:07:18 +02:00
|
|
|
|
2020-04-09 21:23:22 +02:00
|
|
|
return (
|
2023-05-10 11:57:08 +01:00
|
|
|
<div className={cx(styles.icon, 'active' in props && props.active && styles.active)}>
|
2021-07-12 16:42:04 +02:00
|
|
|
<IconButton
|
2023-05-10 11:57:08 +01:00
|
|
|
name={props.icon}
|
|
|
|
|
tooltip={props.title}
|
2021-07-12 16:42:04 +02:00
|
|
|
className={styles.icon}
|
2023-05-10 11:57:08 +01:00
|
|
|
disabled={!!props.disabled}
|
|
|
|
|
onClick={props.onClick}
|
2021-07-12 16:42:04 +02:00
|
|
|
type="button"
|
2023-05-10 11:57:08 +01:00
|
|
|
aria-label={selectors.components.QueryEditorRow.actionButton(props.title)}
|
|
|
|
|
{...('active' in props && { 'aria-pressed': props.active })}
|
2021-07-12 16:42:04 +02:00
|
|
|
/>
|
|
|
|
|
</div>
|
2020-04-09 21:23:22 +02:00
|
|
|
);
|
2023-05-10 11:57:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface QueryOperationActionProps extends BaseQueryOperationActionProps {}
|
|
|
|
|
export function QueryOperationAction(props: QueryOperationActionProps) {
|
|
|
|
|
return <BaseQueryOperationAction {...props} />;
|
|
|
|
|
}
|
2020-04-09 21:23:22 +02:00
|
|
|
|
2023-05-10 11:57:08 +01:00
|
|
|
interface QueryOperationToggleActionProps extends BaseQueryOperationActionProps {
|
|
|
|
|
active: boolean;
|
|
|
|
|
}
|
|
|
|
|
export const QueryOperationToggleAction = (props: QueryOperationToggleActionProps) => {
|
|
|
|
|
return <BaseQueryOperationAction {...props} />;
|
|
|
|
|
};
|
2020-04-11 16:07:18 +02:00
|
|
|
|
2021-07-12 16:42:04 +02:00
|
|
|
const getStyles = (theme: GrafanaTheme2) => {
|
2020-04-09 21:23:22 +02:00
|
|
|
return {
|
2020-04-11 16:07:18 +02:00
|
|
|
icon: css`
|
2021-07-12 16:42:04 +02:00
|
|
|
display: flex;
|
|
|
|
|
position: relative;
|
|
|
|
|
color: ${theme.colors.text.secondary};
|
|
|
|
|
`,
|
|
|
|
|
active: css`
|
|
|
|
|
&::before {
|
|
|
|
|
display: block;
|
|
|
|
|
content: ' ';
|
|
|
|
|
position: absolute;
|
|
|
|
|
left: -1px;
|
|
|
|
|
right: 2px;
|
|
|
|
|
height: 3px;
|
2023-03-21 12:24:50 +01:00
|
|
|
border-radius: ${theme.shape.radius.default};
|
2021-07-12 16:42:04 +02:00
|
|
|
bottom: -8px;
|
|
|
|
|
background-image: ${theme.colors.gradients.brandHorizontal} !important;
|
|
|
|
|
}
|
2020-04-11 16:07:18 +02:00
|
|
|
`,
|
2020-04-09 21:23:22 +02:00
|
|
|
};
|
2021-07-12 16:42:04 +02:00
|
|
|
};
|