|
@@ -2,11 +2,13 @@ import * as React from 'react';
|
|
|
import ReactDOM from 'react-dom';
|
|
|
import styled from '@emotion/styled';
|
|
|
|
|
|
+import Feature from 'app/components/acl/feature';
|
|
|
import Button from 'app/components/button';
|
|
|
import {SectionHeading} from 'app/components/charts/styles';
|
|
|
import {IconAdd, IconDelete, IconGrabbable} from 'app/icons';
|
|
|
import {t} from 'app/locale';
|
|
|
import space from 'app/styles/space';
|
|
|
+import {LightWeightOrganization} from 'app/types';
|
|
|
import {Column} from 'app/utils/discover/fields';
|
|
|
import theme from 'app/utils/theme';
|
|
|
import {getPointerPosition} from 'app/utils/touch';
|
|
@@ -15,6 +17,7 @@ import {setBodyUserSelect, UserSelectValues} from 'app/utils/userselect';
|
|
|
import {generateFieldOptions} from '../utils';
|
|
|
|
|
|
import {QueryField} from './queryField';
|
|
|
+import {FieldValueKind} from './types';
|
|
|
|
|
|
type Props = {
|
|
|
// Input columns
|
|
@@ -22,6 +25,7 @@ type Props = {
|
|
|
fieldOptions: ReturnType<typeof generateFieldOptions>;
|
|
|
// Fired when columns are added/removed/modified
|
|
|
onChange: (columns: Column[]) => void;
|
|
|
+ organization: LightWeightOrganization;
|
|
|
className?: string;
|
|
|
};
|
|
|
|
|
@@ -101,6 +105,11 @@ class ColumnEditCollection extends React.Component<Props, State> {
|
|
|
this.props.onChange([...this.props.columns, newColumn]);
|
|
|
};
|
|
|
|
|
|
+ handleAddEquation = () => {
|
|
|
+ const newColumn: Column = {kind: FieldValueKind.EQUATION, field: ''};
|
|
|
+ this.props.onChange([...this.props.columns, newColumn]);
|
|
|
+ };
|
|
|
+
|
|
|
handleUpdateColumn = (index: number, column: Column) => {
|
|
|
const newColumns = [...this.props.columns];
|
|
|
newColumns.splice(index, 1, column);
|
|
@@ -339,7 +348,7 @@ class ColumnEditCollection extends React.Component<Props, State> {
|
|
|
}
|
|
|
|
|
|
render() {
|
|
|
- const {className, columns} = this.props;
|
|
|
+ const {className, columns, organization} = this.props;
|
|
|
const canDelete = columns.length > 1;
|
|
|
const canAdd = columns.length < MAX_COL_COUNT;
|
|
|
const title = canAdd
|
|
@@ -378,6 +387,18 @@ class ColumnEditCollection extends React.Component<Props, State> {
|
|
|
>
|
|
|
{t('Add a Column')}
|
|
|
</Button>
|
|
|
+ <Feature organization={organization} features={['discover-arithmetic']}>
|
|
|
+ <Button
|
|
|
+ size="small"
|
|
|
+ label={t('Add an Equation')}
|
|
|
+ onClick={this.handleAddEquation}
|
|
|
+ title={title}
|
|
|
+ disabled={!canAdd}
|
|
|
+ icon={<IconAdd isCircled size="xs" />}
|
|
|
+ >
|
|
|
+ {t('Add an Equation')}
|
|
|
+ </Button>
|
|
|
+ </Feature>
|
|
|
</Actions>
|
|
|
</RowContainer>
|
|
|
</div>
|
|
@@ -425,6 +446,10 @@ const DragPlaceholder = styled('div')`
|
|
|
|
|
|
const Actions = styled('div')`
|
|
|
grid-column: 2 / 3;
|
|
|
+
|
|
|
+ & button {
|
|
|
+ margin-right: ${space(1)};
|
|
|
+ }
|
|
|
`;
|
|
|
|
|
|
const Heading = styled('div')<{gridColumns: number}>`
|