columnEditCollection.tsx 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. import * as React 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 React.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 = React.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. onDragEnd = (event: MouseEvent | TouchEvent) => {
  289. if (!this.state.isDragging || !['mouseup', 'touchend'].includes(event.type)) {
  290. return;
  291. }
  292. const sourceIndex = this.state.draggingIndex;
  293. const targetIndex = this.state.draggingTargetIndex;
  294. if (typeof sourceIndex !== 'number' || typeof targetIndex !== 'number') {
  295. return;
  296. }
  297. // remove listeners that were attached in startColumnDrag
  298. this.cleanUpListeners();
  299. // restore body user-select values
  300. if (this.previousUserSelect) {
  301. setBodyUserSelect(this.previousUserSelect);
  302. this.previousUserSelect = null;
  303. }
  304. // Reorder columns and trigger change.
  305. const newColumns = [...this.props.columns];
  306. const removed = newColumns.splice(sourceIndex, 1);
  307. newColumns.splice(targetIndex, 0, removed[0]);
  308. this.checkColumnErrors(newColumns);
  309. this.props.onChange(newColumns);
  310. this.setState({
  311. isDragging: false,
  312. left: undefined,
  313. top: undefined,
  314. draggingIndex: undefined,
  315. draggingTargetIndex: undefined,
  316. draggingGrabbedOffset: undefined,
  317. });
  318. };
  319. renderGhost({gridColumns, singleColumn}: {gridColumns: number; singleColumn: boolean}) {
  320. const {isDragging, draggingIndex, draggingGrabbedOffset} = this.state;
  321. const index = draggingIndex;
  322. if (typeof index !== 'number' || !isDragging || !this.portal) {
  323. return null;
  324. }
  325. const dragOffsetX = draggingGrabbedOffset?.x ?? 0;
  326. const dragOffsetY = draggingGrabbedOffset?.y ?? 0;
  327. const top = Number(this.state.top) - dragOffsetY;
  328. const left = Number(this.state.left) - dragOffsetX;
  329. const col = this.props.columns[index];
  330. const style = {
  331. top: `${top}px`,
  332. left: `${left}px`,
  333. };
  334. const ghost = (
  335. <Ghost ref={this.dragGhostRef} style={style}>
  336. {this.renderItem(col, index, {
  337. singleColumn,
  338. isGhost: true,
  339. gridColumns,
  340. })}
  341. </Ghost>
  342. );
  343. return createPortal(ghost, this.portal);
  344. }
  345. renderItem(
  346. col: Column,
  347. i: number,
  348. {
  349. singleColumn = false,
  350. canDelete = true,
  351. canDrag = true,
  352. isGhost = false,
  353. gridColumns = 2,
  354. disabled = false,
  355. }: {
  356. gridColumns: number;
  357. singleColumn: boolean;
  358. canDelete?: boolean;
  359. canDrag?: boolean;
  360. disabled?: boolean;
  361. isGhost?: boolean;
  362. }
  363. ) {
  364. const {
  365. columns,
  366. fieldOptions,
  367. filterAggregateParameters,
  368. filterPrimaryOptions,
  369. noFieldsMessage,
  370. showAliasField,
  371. } = this.props;
  372. const {isDragging, draggingTargetIndex, draggingIndex} = this.state;
  373. let placeholder: React.ReactNode = null;
  374. // Add a placeholder above the target row.
  375. if (isDragging && isGhost === false && draggingTargetIndex === i) {
  376. placeholder = (
  377. <DragPlaceholder
  378. key={`placeholder:${this.keyForColumn(col, isGhost)}`}
  379. className={DRAG_CLASS}
  380. />
  381. );
  382. }
  383. // If the current row is the row in the drag ghost return the placeholder
  384. // or a hole if the placeholder is elsewhere.
  385. if (isDragging && isGhost === false && draggingIndex === i) {
  386. return placeholder;
  387. }
  388. const position =
  389. Number(draggingTargetIndex) <= Number(draggingIndex)
  390. ? PlaceholderPosition.TOP
  391. : PlaceholderPosition.BOTTOM;
  392. return (
  393. <React.Fragment key={`${i}:${this.keyForColumn(col, isGhost)}`}>
  394. {position === PlaceholderPosition.TOP && placeholder}
  395. <RowContainer
  396. showAliasField={showAliasField}
  397. singleColumn={singleColumn}
  398. className={isGhost ? '' : DRAG_CLASS}
  399. >
  400. {canDrag ? (
  401. <DragAndReorderButton
  402. aria-label={t('Drag to reorder')}
  403. onMouseDown={event => this.startDrag(event, i)}
  404. onTouchStart={event => this.startDrag(event, i)}
  405. icon={<IconGrabbable size="xs" />}
  406. size="zero"
  407. borderless
  408. />
  409. ) : singleColumn && showAliasField ? null : (
  410. <span />
  411. )}
  412. <QueryField
  413. fieldOptions={fieldOptions}
  414. gridColumns={gridColumns}
  415. fieldValue={col}
  416. onChange={value => this.handleUpdateColumn(i, value)}
  417. error={this.state.error.get(i)}
  418. takeFocus={i === this.props.columns.length - 1}
  419. otherColumns={columns}
  420. shouldRenderTag
  421. disabled={disabled}
  422. filterPrimaryOptions={filterPrimaryOptions}
  423. filterAggregateParameters={filterAggregateParameters}
  424. noFieldsMessage={noFieldsMessage}
  425. skipParameterPlaceholder={showAliasField}
  426. />
  427. {showAliasField && (
  428. <AliasField singleColumn={singleColumn}>
  429. <AliasInput
  430. name="alias"
  431. placeholder={t('Alias')}
  432. value={col.alias ?? ''}
  433. onChange={value => {
  434. this.handleUpdateColumn(i, {
  435. ...col,
  436. alias: value.target.value,
  437. });
  438. }}
  439. />
  440. </AliasField>
  441. )}
  442. {canDelete || col.kind === 'equation' ? (
  443. showAliasField ? (
  444. <RemoveButton
  445. data-test-id={`remove-column-${i}`}
  446. aria-label={t('Remove column')}
  447. title={t('Remove column')}
  448. onClick={() => this.removeColumn(i)}
  449. icon={<IconDelete />}
  450. borderless
  451. />
  452. ) : (
  453. <RemoveButton
  454. data-test-id={`remove-column-${i}`}
  455. aria-label={t('Remove column')}
  456. onClick={() => this.removeColumn(i)}
  457. icon={<IconDelete />}
  458. borderless
  459. />
  460. )
  461. ) : singleColumn && showAliasField ? null : (
  462. <span />
  463. )}
  464. </RowContainer>
  465. {position === PlaceholderPosition.BOTTOM && placeholder}
  466. </React.Fragment>
  467. );
  468. }
  469. render() {
  470. const {className, columns, showAliasField, source} = this.props;
  471. const canDelete = columns.filter(field => field.kind !== 'equation').length > 1;
  472. const canDrag = columns.length > 1;
  473. const canAdd = columns.length < MAX_COL_COUNT;
  474. const title = canAdd
  475. ? undefined
  476. : t(
  477. `Sorry, you've reached the maximum number of columns (${MAX_COL_COUNT}). Delete columns to add more.`
  478. );
  479. const singleColumn = columns.length === 1;
  480. // Get the longest number of columns so we can layout the rows.
  481. // We always want at least 2 columns.
  482. const gridColumns =
  483. source === WidgetType.ISSUE
  484. ? 1
  485. : Math.max(
  486. ...columns.map(col => {
  487. if (col.kind !== 'function') {
  488. return 2;
  489. }
  490. const operation =
  491. AGGREGATIONS[col.function[0]] ?? SESSIONS_OPERATIONS[col.function[0]];
  492. return operation.parameters.length === 2 ? 3 : 2;
  493. })
  494. );
  495. return (
  496. <div className={className}>
  497. {this.renderGhost({gridColumns, singleColumn})}
  498. {!showAliasField && source !== WidgetType.ISSUE && (
  499. <RowContainer showAliasField={showAliasField} singleColumn={singleColumn}>
  500. <Heading gridColumns={gridColumns}>
  501. <StyledSectionHeading>{t('Tag / Field / Function')}</StyledSectionHeading>
  502. <StyledSectionHeading>{t('Field Parameter')}</StyledSectionHeading>
  503. </Heading>
  504. </RowContainer>
  505. )}
  506. {columns.map((col: Column, i: number) => {
  507. // Issue column in Issue widgets are fixed (cannot be changed or deleted)
  508. if (this.isFixedIssueColumn(i)) {
  509. return this.renderItem(col, i, {
  510. singleColumn,
  511. canDelete: false,
  512. canDrag,
  513. gridColumns,
  514. disabled: true,
  515. });
  516. }
  517. return this.renderItem(col, i, {
  518. singleColumn,
  519. canDelete,
  520. canDrag,
  521. gridColumns,
  522. });
  523. })}
  524. <RowContainer showAliasField={showAliasField} singleColumn={singleColumn}>
  525. <Actions gap={1} showAliasField={showAliasField}>
  526. <Button
  527. size="small"
  528. aria-label={t('Add a Column')}
  529. onClick={this.handleAddColumn}
  530. title={title}
  531. disabled={!canAdd}
  532. icon={<IconAdd isCircled size="xs" />}
  533. >
  534. {t('Add a Column')}
  535. </Button>
  536. {source !== WidgetType.ISSUE && source !== WidgetType.RELEASE && (
  537. <Button
  538. size="small"
  539. aria-label={t('Add an Equation')}
  540. onClick={this.handleAddEquation}
  541. title={title}
  542. disabled={!canAdd}
  543. icon={<IconAdd isCircled size="xs" />}
  544. >
  545. {t('Add an Equation')}
  546. </Button>
  547. )}
  548. </Actions>
  549. </RowContainer>
  550. </div>
  551. );
  552. }
  553. }
  554. const Actions = styled(ButtonBar)<{showAliasField?: boolean}>`
  555. grid-column: ${p => (p.showAliasField ? '1/-1' : ' 2/3')};
  556. justify-content: flex-start;
  557. `;
  558. const RowContainer = styled('div')<{
  559. singleColumn: boolean;
  560. showAliasField?: boolean;
  561. }>`
  562. display: grid;
  563. grid-template-columns: ${space(3)} 1fr 40px;
  564. justify-content: center;
  565. align-items: center;
  566. width: 100%;
  567. touch-action: none;
  568. padding-bottom: ${space(1)};
  569. ${p =>
  570. p.showAliasField &&
  571. css`
  572. align-items: flex-start;
  573. grid-template-columns: ${p.singleColumn ? `1fr` : `${space(3)} 1fr 40px`};
  574. @media (min-width: ${p.theme.breakpoints[0]}) {
  575. grid-template-columns: ${p.singleColumn
  576. ? `1fr calc(200px + ${space(1)})`
  577. : `${space(3)} 1fr calc(200px + ${space(1)}) 40px`};
  578. }
  579. `};
  580. `;
  581. const Ghost = styled('div')`
  582. background: ${p => p.theme.background};
  583. display: block;
  584. position: absolute;
  585. padding: ${GHOST_PADDING}px;
  586. border-radius: ${p => p.theme.borderRadius};
  587. box-shadow: 0 0 15px rgba(0, 0, 0, 0.15);
  588. width: 710px;
  589. opacity: 0.8;
  590. cursor: grabbing;
  591. padding-right: ${space(2)};
  592. & > ${RowContainer} {
  593. padding-bottom: 0;
  594. }
  595. & svg {
  596. cursor: grabbing;
  597. }
  598. `;
  599. const DragPlaceholder = styled('div')`
  600. margin: 0 ${space(3)} ${space(1)} ${space(3)};
  601. border: 2px dashed ${p => p.theme.border};
  602. border-radius: ${p => p.theme.borderRadius};
  603. height: 41px;
  604. `;
  605. const Heading = styled('div')<{gridColumns: number}>`
  606. grid-column: 2 / 3;
  607. /* Emulate the grid used in the column editor rows */
  608. display: grid;
  609. grid-template-columns: repeat(${p => p.gridColumns}, 1fr);
  610. grid-column-gap: ${space(1)};
  611. `;
  612. const StyledSectionHeading = styled(SectionHeading)`
  613. margin: 0;
  614. `;
  615. const AliasInput = styled(Input)`
  616. /* Match the height of the select boxes */
  617. height: 40px;
  618. min-width: 50px;
  619. `;
  620. const AliasField = styled('div')<{singleColumn: boolean}>`
  621. margin-top: ${space(1)};
  622. @media (min-width: ${p => p.theme.breakpoints[0]}) {
  623. margin-top: 0;
  624. margin-left: ${space(1)};
  625. }
  626. @media (max-width: ${p => p.theme.breakpoints[0]}) {
  627. grid-row: 2/2;
  628. grid-column: ${p => (p.singleColumn ? '1/-1' : '2/2')};
  629. }
  630. `;
  631. const RemoveButton = styled(Button)`
  632. margin-left: ${space(1)};
  633. height: 40px;
  634. `;
  635. const DragAndReorderButton = styled(Button)`
  636. height: 40px;
  637. `;
  638. export default ColumnEditCollection;