columnEditCollection.tsx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. import {Component, createRef, Fragment} from 'react';
  2. import {createPortal} from 'react-dom';
  3. import {css} from '@emotion/react';
  4. import styled from '@emotion/styled';
  5. import {parseArithmetic} from 'sentry/components/arithmeticInput/parser';
  6. import Button from 'sentry/components/button';
  7. import ButtonBar from 'sentry/components/buttonBar';
  8. import {SectionHeading} from 'sentry/components/charts/styles';
  9. import Input from 'sentry/components/forms/controls/input';
  10. import {getOffsetOfElement} from 'sentry/components/performance/waterfall/utils';
  11. import {IconAdd, IconDelete, IconGrabbable} from 'sentry/icons';
  12. import {t} from 'sentry/locale';
  13. import space from 'sentry/styles/space';
  14. import {Organization} from 'sentry/types';
  15. import {trackAnalyticsEvent} from 'sentry/utils/analytics';
  16. import {
  17. AGGREGATIONS,
  18. Column,
  19. generateFieldAsString,
  20. hasDuplicate,
  21. isLegalEquationColumn,
  22. } from 'sentry/utils/discover/fields';
  23. import theme from 'sentry/utils/theme';
  24. import {getPointerPosition} from 'sentry/utils/touch';
  25. import {setBodyUserSelect, UserSelectValues} from 'sentry/utils/userselect';
  26. import {WidgetType} from 'sentry/views/dashboardsV2/types';
  27. import {FieldKey} from 'sentry/views/dashboardsV2/widgetBuilder/issueWidget/fields';
  28. import {SESSIONS_OPERATIONS} from 'sentry/views/dashboardsV2/widgetBuilder/releaseWidget/fields';
  29. import {generateFieldOptions} from '../utils';
  30. import {FieldValueOption, QueryField} from './queryField';
  31. import {FieldValueKind} from './types';
  32. type Sources = WidgetType;
  33. type Props = {
  34. // Input columns
  35. columns: Column[];
  36. fieldOptions: ReturnType<typeof generateFieldOptions>;
  37. // Fired when columns are added/removed/modified
  38. onChange: (columns: Column[]) => void;
  39. organization: Organization;
  40. className?: string;
  41. filterAggregateParameters?: (option: FieldValueOption) => boolean;
  42. filterPrimaryOptions?: (option: FieldValueOption) => boolean;
  43. noFieldsMessage?: string;
  44. showAliasField?: boolean;
  45. source?: Sources;
  46. };
  47. type State = {
  48. draggingGrabbedOffset: undefined | {x: number; y: number};
  49. draggingIndex: undefined | number;
  50. draggingTargetIndex: undefined | number;
  51. error: Map<number, string | undefined>;
  52. isDragging: boolean;
  53. left: undefined | number;
  54. top: undefined | number;
  55. };
  56. const DRAG_CLASS = 'draggable-item';
  57. const GHOST_PADDING = 4;
  58. const MAX_COL_COUNT = 20;
  59. enum PlaceholderPosition {
  60. TOP,
  61. BOTTOM,
  62. }
  63. class ColumnEditCollection extends Component<Props, State> {
  64. state: State = {
  65. isDragging: false,
  66. draggingIndex: void 0,
  67. draggingTargetIndex: void 0,
  68. draggingGrabbedOffset: void 0,
  69. error: new Map(),
  70. left: void 0,
  71. top: void 0,
  72. };
  73. componentDidMount() {
  74. if (!this.portal) {
  75. const portal = document.createElement('div');
  76. portal.style.position = 'absolute';
  77. portal.style.top = '0';
  78. portal.style.left = '0';
  79. portal.style.zIndex = String(theme.zIndex.modal);
  80. this.portal = portal;
  81. document.body.appendChild(this.portal);
  82. }
  83. this.checkColumnErrors(this.props.columns);
  84. }
  85. componentWillUnmount() {
  86. if (this.portal) {
  87. document.body.removeChild(this.portal);
  88. }
  89. this.cleanUpListeners();
  90. }
  91. checkColumnErrors(columns: Column[]) {
  92. const error = new Map();
  93. for (let i = 0; i < columns.length; i += 1) {
  94. const column = columns[i];
  95. if (column.kind === 'equation') {
  96. const result = parseArithmetic(column.field);
  97. if (result.error) {
  98. error.set(i, result.error);
  99. }
  100. }
  101. }
  102. this.setState({error});
  103. }
  104. previousUserSelect: UserSelectValues | null = null;
  105. portal: HTMLElement | null = null;
  106. dragGhostRef = createRef<HTMLDivElement>();
  107. keyForColumn(column: Column, isGhost: boolean): string {
  108. if (column.kind === 'function') {
  109. return [...column.function, isGhost].join(':');
  110. }
  111. return [...column.field, isGhost].join(':');
  112. }
  113. cleanUpListeners() {
  114. if (this.state.isDragging) {
  115. window.removeEventListener('mousemove', this.onDragMove);
  116. window.removeEventListener('touchmove', this.onDragMove);
  117. window.removeEventListener('mouseup', this.onDragEnd);
  118. window.removeEventListener('touchend', this.onDragEnd);
  119. }
  120. }
  121. // Signal to the parent that a new column has been added.
  122. handleAddColumn = () => {
  123. const newColumn: Column = {kind: 'field', field: ''};
  124. this.props.onChange([...this.props.columns, newColumn]);
  125. };
  126. handleAddEquation = () => {
  127. const {organization} = this.props;
  128. const newColumn: Column = {kind: FieldValueKind.EQUATION, field: ''};
  129. trackAnalyticsEvent({
  130. eventKey: 'discover_v2.add_equation',
  131. eventName: 'Discoverv2: Equation added',
  132. organization_id: parseInt(organization.id, 10),
  133. });
  134. this.props.onChange([...this.props.columns, newColumn]);
  135. };
  136. handleUpdateColumn = (index: number, updatedColumn: Column) => {
  137. const newColumns = [...this.props.columns];
  138. if (updatedColumn.kind === 'equation') {
  139. this.setState(prevState => {
  140. const error = new Map(prevState.error);
  141. error.set(index, parseArithmetic(updatedColumn.field).error);
  142. return {
  143. ...prevState,
  144. error,
  145. };
  146. });
  147. } else {
  148. // Update any equations that contain the existing column
  149. this.updateEquationFields(newColumns, index, updatedColumn);
  150. }
  151. newColumns.splice(index, 1, updatedColumn);
  152. this.props.onChange(newColumns);
  153. };
  154. updateEquationFields = (newColumns: Column[], index: number, updatedColumn: Column) => {
  155. const oldColumn = newColumns[index];
  156. const existingColumn = generateFieldAsString(newColumns[index]);
  157. const updatedColumnString = generateFieldAsString(updatedColumn);
  158. if (!isLegalEquationColumn(updatedColumn) || hasDuplicate(newColumns, oldColumn)) {
  159. return;
  160. }
  161. // Find the equations in the list of columns
  162. for (let i = 0; i < newColumns.length; i++) {
  163. const newColumn = newColumns[i];
  164. if (newColumn.kind === 'equation') {
  165. const result = parseArithmetic(newColumn.field);
  166. let newEquation = '';
  167. // Track where to continue from, not reconstructing from result so we don't have to worry
  168. // about spacing
  169. let lastIndex = 0;
  170. // the parser separates fields & functions, so we only need to check one
  171. const fields =
  172. oldColumn.kind === 'function' ? result.tc.functions : result.tc.fields;
  173. // for each field, add the text before it, then the new function and update index
  174. // to be where we want to start again
  175. for (const field of fields) {
  176. if (field.term === existingColumn && lastIndex !== field.location.end.offset) {
  177. newEquation +=
  178. newColumn.field.substring(lastIndex, field.location.start.offset) +
  179. updatedColumnString;
  180. lastIndex = field.location.end.offset;
  181. }
  182. }
  183. // Add whatever remains to be added from the equation, if existing field wasn't found
  184. // add the entire equation
  185. newEquation += newColumn.field.substring(lastIndex);
  186. newColumns[i] = {
  187. kind: 'equation',
  188. field: newEquation,
  189. alias: newColumns[i].alias,
  190. };
  191. }
  192. }
  193. };
  194. removeColumn(index: number) {
  195. const newColumns = [...this.props.columns];
  196. newColumns.splice(index, 1);
  197. this.checkColumnErrors(newColumns);
  198. this.props.onChange(newColumns);
  199. }
  200. startDrag(
  201. event: React.MouseEvent<HTMLButtonElement> | React.TouchEvent<HTMLButtonElement>,
  202. index: number
  203. ) {
  204. const isDragging = this.state.isDragging;
  205. if (isDragging || !['mousedown', 'touchstart'].includes(event.type)) {
  206. return;
  207. }
  208. event.preventDefault();
  209. event.stopPropagation();
  210. const top = getPointerPosition(event, 'pageY');
  211. const left = getPointerPosition(event, 'pageX');
  212. // Compute where the user clicked on the drag handle. Avoids the element
  213. // jumping from the cursor on mousedown.
  214. const draggingElement = Array.from(document.querySelectorAll(`.${DRAG_CLASS}`)).find(
  215. n => n.contains(event.currentTarget)
  216. )!;
  217. const {x, y} = getOffsetOfElement(draggingElement);
  218. const draggingGrabbedOffset = {
  219. x: left - x + GHOST_PADDING,
  220. y: top - y + GHOST_PADDING,
  221. };
  222. // prevent the user from selecting things when dragging a column.
  223. this.previousUserSelect = setBodyUserSelect({
  224. userSelect: 'none',
  225. MozUserSelect: 'none',
  226. msUserSelect: 'none',
  227. webkitUserSelect: 'none',
  228. });
  229. // attach event listeners so that the mouse cursor can drag anywhere
  230. window.addEventListener('mousemove', this.onDragMove);
  231. window.addEventListener('touchmove', this.onDragMove);
  232. window.addEventListener('mouseup', this.onDragEnd);
  233. window.addEventListener('touchend', this.onDragEnd);
  234. this.setState({
  235. isDragging: true,
  236. draggingIndex: index,
  237. draggingTargetIndex: index,
  238. draggingGrabbedOffset,
  239. top,
  240. left,
  241. });
  242. }
  243. onDragMove = (event: MouseEvent | TouchEvent) => {
  244. const {isDragging, draggingTargetIndex, draggingGrabbedOffset} = this.state;
  245. if (!isDragging || !['mousemove', 'touchmove'].includes(event.type)) {
  246. return;
  247. }
  248. event.preventDefault();
  249. event.stopPropagation();
  250. const pointerX = getPointerPosition(event, 'pageX');
  251. const pointerY = getPointerPosition(event, 'pageY');
  252. const dragOffsetX = draggingGrabbedOffset?.x ?? 0;
  253. const dragOffsetY = draggingGrabbedOffset?.y ?? 0;
  254. if (this.dragGhostRef.current) {
  255. // move the ghost box
  256. const ghostDOM = this.dragGhostRef.current;
  257. // Adjust so cursor is over the grab handle.
  258. ghostDOM.style.left = `${pointerX - dragOffsetX}px`;
  259. ghostDOM.style.top = `${pointerY - dragOffsetY}px`;
  260. }
  261. const dragItems = document.querySelectorAll(`.${DRAG_CLASS}`);
  262. // Find the item that the ghost is currently over.
  263. const targetIndex = Array.from(dragItems).findIndex(dragItem => {
  264. const rects = dragItem.getBoundingClientRect();
  265. const top = pointerY;
  266. const thresholdStart = window.scrollY + rects.top;
  267. const thresholdEnd = window.scrollY + rects.top + rects.height;
  268. return top >= thresholdStart && top <= thresholdEnd;
  269. });
  270. // Issue column in Issue widgets are fixed (cannot be moved or deleted)
  271. if (targetIndex >= 0 && targetIndex !== draggingTargetIndex) {
  272. this.setState({draggingTargetIndex: targetIndex});
  273. }
  274. };
  275. isFixedIssueColumn = (columnIndex: number) => {
  276. const {source, columns} = this.props;
  277. const column = columns[columnIndex];
  278. const issueFieldColumnCount = columns.filter(
  279. col => col.kind === 'field' && col.field === FieldKey.ISSUE
  280. ).length;
  281. return (
  282. issueFieldColumnCount <= 1 &&
  283. source === WidgetType.ISSUE &&
  284. column.kind === 'field' &&
  285. column.field === FieldKey.ISSUE
  286. );
  287. };
  288. isRemainingReleaseHealthAggregate = (columnIndex: number) => {
  289. const {source, columns} = this.props;
  290. const column = columns[columnIndex];
  291. const aggregateCount = columns.filter(
  292. col => col.kind === FieldValueKind.FUNCTION
  293. ).length;
  294. return (
  295. aggregateCount <= 1 &&
  296. source === WidgetType.RELEASE &&
  297. column.kind === FieldValueKind.FUNCTION
  298. );
  299. };
  300. onDragEnd = (event: MouseEvent | TouchEvent) => {
  301. if (!this.state.isDragging || !['mouseup', 'touchend'].includes(event.type)) {
  302. return;
  303. }
  304. const sourceIndex = this.state.draggingIndex;
  305. const targetIndex = this.state.draggingTargetIndex;
  306. if (typeof sourceIndex !== 'number' || typeof targetIndex !== 'number') {
  307. return;
  308. }
  309. // remove listeners that were attached in startColumnDrag
  310. this.cleanUpListeners();
  311. // restore body user-select values
  312. if (this.previousUserSelect) {
  313. setBodyUserSelect(this.previousUserSelect);
  314. this.previousUserSelect = null;
  315. }
  316. // Reorder columns and trigger change.
  317. const newColumns = [...this.props.columns];
  318. const removed = newColumns.splice(sourceIndex, 1);
  319. newColumns.splice(targetIndex, 0, removed[0]);
  320. this.checkColumnErrors(newColumns);
  321. this.props.onChange(newColumns);
  322. this.setState({
  323. isDragging: false,
  324. left: undefined,
  325. top: undefined,
  326. draggingIndex: undefined,
  327. draggingTargetIndex: undefined,
  328. draggingGrabbedOffset: undefined,
  329. });
  330. };
  331. renderGhost({gridColumns, singleColumn}: {gridColumns: number; singleColumn: boolean}) {
  332. const {isDragging, draggingIndex, draggingGrabbedOffset} = this.state;
  333. const index = draggingIndex;
  334. if (typeof index !== 'number' || !isDragging || !this.portal) {
  335. return null;
  336. }
  337. const dragOffsetX = draggingGrabbedOffset?.x ?? 0;
  338. const dragOffsetY = draggingGrabbedOffset?.y ?? 0;
  339. const top = Number(this.state.top) - dragOffsetY;
  340. const left = Number(this.state.left) - dragOffsetX;
  341. const col = this.props.columns[index];
  342. const style = {
  343. top: `${top}px`,
  344. left: `${left}px`,
  345. };
  346. const ghost = (
  347. <Ghost ref={this.dragGhostRef} style={style}>
  348. {this.renderItem(col, index, {
  349. singleColumn,
  350. isGhost: true,
  351. gridColumns,
  352. })}
  353. </Ghost>
  354. );
  355. return createPortal(ghost, this.portal);
  356. }
  357. renderItem(
  358. col: Column,
  359. i: number,
  360. {
  361. singleColumn = false,
  362. canDelete = true,
  363. canDrag = true,
  364. isGhost = false,
  365. gridColumns = 2,
  366. disabled = false,
  367. }: {
  368. gridColumns: number;
  369. singleColumn: boolean;
  370. canDelete?: boolean;
  371. canDrag?: boolean;
  372. disabled?: boolean;
  373. isGhost?: boolean;
  374. }
  375. ) {
  376. const {
  377. columns,
  378. fieldOptions,
  379. filterAggregateParameters,
  380. filterPrimaryOptions,
  381. noFieldsMessage,
  382. showAliasField,
  383. } = this.props;
  384. const {isDragging, draggingTargetIndex, draggingIndex} = this.state;
  385. let placeholder: React.ReactNode = null;
  386. // Add a placeholder above the target row.
  387. if (isDragging && isGhost === false && draggingTargetIndex === i) {
  388. placeholder = (
  389. <DragPlaceholder
  390. key={`placeholder:${this.keyForColumn(col, isGhost)}`}
  391. className={DRAG_CLASS}
  392. />
  393. );
  394. }
  395. // If the current row is the row in the drag ghost return the placeholder
  396. // or a hole if the placeholder is elsewhere.
  397. if (isDragging && isGhost === false && draggingIndex === i) {
  398. return placeholder;
  399. }
  400. const position =
  401. Number(draggingTargetIndex) <= Number(draggingIndex)
  402. ? PlaceholderPosition.TOP
  403. : PlaceholderPosition.BOTTOM;
  404. return (
  405. <Fragment key={`${i}:${this.keyForColumn(col, isGhost)}`}>
  406. {position === PlaceholderPosition.TOP && placeholder}
  407. <RowContainer
  408. showAliasField={showAliasField}
  409. singleColumn={singleColumn}
  410. className={isGhost ? '' : DRAG_CLASS}
  411. >
  412. {canDrag ? (
  413. <DragAndReorderButton
  414. aria-label={t('Drag to reorder')}
  415. onMouseDown={event => this.startDrag(event, i)}
  416. onTouchStart={event => this.startDrag(event, i)}
  417. icon={<IconGrabbable size="xs" />}
  418. size="zero"
  419. borderless
  420. />
  421. ) : singleColumn && showAliasField ? null : (
  422. <span />
  423. )}
  424. <QueryField
  425. fieldOptions={fieldOptions}
  426. gridColumns={gridColumns}
  427. fieldValue={col}
  428. onChange={value => this.handleUpdateColumn(i, value)}
  429. error={this.state.error.get(i)}
  430. takeFocus={i === this.props.columns.length - 1}
  431. otherColumns={columns}
  432. shouldRenderTag
  433. disabled={disabled}
  434. filterPrimaryOptions={filterPrimaryOptions}
  435. filterAggregateParameters={filterAggregateParameters}
  436. noFieldsMessage={noFieldsMessage}
  437. skipParameterPlaceholder={showAliasField}
  438. />
  439. {showAliasField && (
  440. <AliasField singleColumn={singleColumn}>
  441. <AliasInput
  442. name="alias"
  443. placeholder={t('Alias')}
  444. value={col.alias ?? ''}
  445. onChange={value => {
  446. this.handleUpdateColumn(i, {
  447. ...col,
  448. alias: value.target.value,
  449. });
  450. }}
  451. />
  452. </AliasField>
  453. )}
  454. {canDelete || col.kind === 'equation' ? (
  455. showAliasField ? (
  456. <RemoveButton
  457. data-test-id={`remove-column-${i}`}
  458. aria-label={t('Remove column')}
  459. title={t('Remove column')}
  460. onClick={() => this.removeColumn(i)}
  461. icon={<IconDelete />}
  462. borderless
  463. />
  464. ) : (
  465. <RemoveButton
  466. data-test-id={`remove-column-${i}`}
  467. aria-label={t('Remove column')}
  468. onClick={() => this.removeColumn(i)}
  469. icon={<IconDelete />}
  470. borderless
  471. />
  472. )
  473. ) : singleColumn && showAliasField ? null : (
  474. <span />
  475. )}
  476. </RowContainer>
  477. {position === PlaceholderPosition.BOTTOM && placeholder}
  478. </Fragment>
  479. );
  480. }
  481. render() {
  482. const {className, columns, showAliasField, source} = this.props;
  483. const canDelete = columns.filter(field => field.kind !== 'equation').length > 1;
  484. const canDrag = columns.length > 1;
  485. const canAdd = columns.length < MAX_COL_COUNT;
  486. const title = canAdd
  487. ? undefined
  488. : t(
  489. `Sorry, you've reached the maximum number of columns (${MAX_COL_COUNT}). Delete columns to add more.`
  490. );
  491. const singleColumn = columns.length === 1;
  492. // Get the longest number of columns so we can layout the rows.
  493. // We always want at least 2 columns.
  494. const gridColumns =
  495. source === WidgetType.ISSUE
  496. ? 1
  497. : Math.max(
  498. ...columns.map(col => {
  499. if (col.kind !== 'function') {
  500. return 2;
  501. }
  502. const operation =
  503. AGGREGATIONS[col.function[0]] ?? SESSIONS_OPERATIONS[col.function[0]];
  504. return operation.parameters.length === 2 ? 3 : 2;
  505. })
  506. );
  507. return (
  508. <div className={className}>
  509. {this.renderGhost({gridColumns, singleColumn})}
  510. {!showAliasField && source !== WidgetType.ISSUE && (
  511. <RowContainer showAliasField={showAliasField} singleColumn={singleColumn}>
  512. <Heading gridColumns={gridColumns}>
  513. <StyledSectionHeading>{t('Tag / Field / Function')}</StyledSectionHeading>
  514. <StyledSectionHeading>{t('Field Parameter')}</StyledSectionHeading>
  515. </Heading>
  516. </RowContainer>
  517. )}
  518. {columns.map((col: Column, i: number) => {
  519. // Issue column in Issue widgets are fixed (cannot be changed or deleted)
  520. if (this.isFixedIssueColumn(i)) {
  521. return this.renderItem(col, i, {
  522. singleColumn,
  523. canDelete: false,
  524. canDrag,
  525. gridColumns,
  526. disabled: true,
  527. });
  528. }
  529. if (this.isRemainingReleaseHealthAggregate(i)) {
  530. return this.renderItem(col, i, {
  531. singleColumn,
  532. canDelete: false,
  533. canDrag,
  534. gridColumns,
  535. });
  536. }
  537. return this.renderItem(col, i, {
  538. singleColumn,
  539. canDelete,
  540. canDrag,
  541. gridColumns,
  542. });
  543. })}
  544. <RowContainer showAliasField={showAliasField} singleColumn={singleColumn}>
  545. <Actions gap={1} showAliasField={showAliasField}>
  546. <Button
  547. size="sm"
  548. aria-label={t('Add a Column')}
  549. onClick={this.handleAddColumn}
  550. title={title}
  551. disabled={!canAdd}
  552. icon={<IconAdd isCircled size="xs" />}
  553. >
  554. {t('Add a Column')}
  555. </Button>
  556. {source !== WidgetType.ISSUE && source !== WidgetType.RELEASE && (
  557. <Button
  558. size="sm"
  559. aria-label={t('Add an Equation')}
  560. onClick={this.handleAddEquation}
  561. title={title}
  562. disabled={!canAdd}
  563. icon={<IconAdd isCircled size="xs" />}
  564. >
  565. {t('Add an Equation')}
  566. </Button>
  567. )}
  568. </Actions>
  569. </RowContainer>
  570. </div>
  571. );
  572. }
  573. }
  574. const Actions = styled(ButtonBar)<{showAliasField?: boolean}>`
  575. grid-column: ${p => (p.showAliasField ? '1/-1' : ' 2/3')};
  576. justify-content: flex-start;
  577. `;
  578. const RowContainer = styled('div')<{
  579. singleColumn: boolean;
  580. showAliasField?: boolean;
  581. }>`
  582. display: grid;
  583. grid-template-columns: ${space(3)} 1fr 40px;
  584. justify-content: center;
  585. align-items: center;
  586. width: 100%;
  587. touch-action: none;
  588. padding-bottom: ${space(1)};
  589. ${p =>
  590. p.showAliasField &&
  591. css`
  592. align-items: flex-start;
  593. grid-template-columns: ${p.singleColumn ? `1fr` : `${space(3)} 1fr 40px`};
  594. @media (min-width: ${p.theme.breakpoints.small}) {
  595. grid-template-columns: ${p.singleColumn
  596. ? `1fr calc(200px + ${space(1)})`
  597. : `${space(3)} 1fr calc(200px + ${space(1)}) 40px`};
  598. }
  599. `};
  600. `;
  601. const Ghost = styled('div')`
  602. background: ${p => p.theme.background};
  603. display: block;
  604. position: absolute;
  605. padding: ${GHOST_PADDING}px;
  606. border-radius: ${p => p.theme.borderRadius};
  607. box-shadow: 0 0 15px rgba(0, 0, 0, 0.15);
  608. width: 710px;
  609. opacity: 0.8;
  610. cursor: grabbing;
  611. padding-right: ${space(2)};
  612. & > ${RowContainer} {
  613. padding-bottom: 0;
  614. }
  615. & svg {
  616. cursor: grabbing;
  617. }
  618. `;
  619. const DragPlaceholder = styled('div')`
  620. margin: 0 ${space(3)} ${space(1)} ${space(3)};
  621. border: 2px dashed ${p => p.theme.border};
  622. border-radius: ${p => p.theme.borderRadius};
  623. height: 41px;
  624. `;
  625. const Heading = styled('div')<{gridColumns: number}>`
  626. grid-column: 2 / 3;
  627. /* Emulate the grid used in the column editor rows */
  628. display: grid;
  629. grid-template-columns: repeat(${p => p.gridColumns}, 1fr);
  630. grid-column-gap: ${space(1)};
  631. `;
  632. const StyledSectionHeading = styled(SectionHeading)`
  633. margin: 0;
  634. `;
  635. const AliasInput = styled(Input)`
  636. /* Match the height of the select boxes */
  637. height: 40px;
  638. min-width: 50px;
  639. `;
  640. const AliasField = styled('div')<{singleColumn: boolean}>`
  641. margin-top: ${space(1)};
  642. @media (min-width: ${p => p.theme.breakpoints.small}) {
  643. margin-top: 0;
  644. margin-left: ${space(1)};
  645. }
  646. @media (max-width: ${p => p.theme.breakpoints.small}) {
  647. grid-row: 2/2;
  648. grid-column: ${p => (p.singleColumn ? '1/-1' : '2/2')};
  649. }
  650. `;
  651. const RemoveButton = styled(Button)`
  652. margin-left: ${space(1)};
  653. height: 40px;
  654. `;
  655. const DragAndReorderButton = styled(Button)`
  656. height: 40px;
  657. `;
  658. export default ColumnEditCollection;