connectedAutomationList.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import {useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import type {GridColumnOrder} from 'sentry/components/gridEditable';
  4. import GridEditable from 'sentry/components/gridEditable';
  5. import {Grid} from 'sentry/components/gridEditable/styles';
  6. import {ActionCell} from 'sentry/components/workflowEngine/gridCell/actionCell';
  7. import {TimeAgoCell} from 'sentry/components/workflowEngine/gridCell/timeAgoCell';
  8. import {TitleCell} from 'sentry/components/workflowEngine/gridCell/titleCell';
  9. import type {Automation} from 'sentry/views/automations/components/automationListRow';
  10. export function ConnectedAutomationsList() {
  11. const [activeRowKey, setActiveRowKey] = useState<number | undefined>(undefined);
  12. const columnOrder: Array<GridColumnOrder<keyof Automation>> = [
  13. {key: 'name', name: 'Name'},
  14. {key: 'lastTriggered', name: 'Last Triggered'},
  15. {key: 'actions', name: 'Action'},
  16. ];
  17. const renderHeadCell = (column: GridColumnOrder) => column.name;
  18. const renderBodyCell = (
  19. column: GridColumnOrder<keyof Automation>,
  20. dataRow: Automation
  21. ) => {
  22. switch (column.key) {
  23. case 'name':
  24. return (
  25. <TitleCell name={dataRow.name} project={dataRow.project} link={dataRow.link} />
  26. );
  27. case 'lastTriggered':
  28. return <TimeAgoCell date={dataRow.lastTriggered} />;
  29. case 'actions':
  30. return <ActionCell actions={dataRow.actions} />;
  31. default:
  32. return null;
  33. }
  34. };
  35. return (
  36. <Wrapper>
  37. <GridEditable
  38. data={[]}
  39. columnOrder={columnOrder}
  40. columnSortBy={[]}
  41. grid={{
  42. renderHeadCell,
  43. renderBodyCell,
  44. }}
  45. onRowMouseOver={(_dataRow, key) => {
  46. setActiveRowKey(key);
  47. }}
  48. onRowMouseOut={() => {
  49. setActiveRowKey(undefined);
  50. }}
  51. highlightedRowKey={activeRowKey}
  52. />
  53. </Wrapper>
  54. );
  55. }
  56. const Wrapper = styled('div')`
  57. ${Grid} {
  58. grid-template-columns: 3fr 1fr 1fr !important;
  59. }
  60. `;