Workflows.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import * as React from "react";
  2. import { CommandBar, ContextualMenuItemType, ICommandBarItemProps } from "@fluentui/react";
  3. import { useConst } from "@fluentui/react-hooks";
  4. import { AlphaNumSortMemory } from "src/Memory";
  5. import * as Observable from "dojo/store/Observable";
  6. import nlsHPCC from "src/nlsHPCC";
  7. import { useWorkunitWorkflows } from "../hooks/Workunit";
  8. import { HolyGrail } from "../layouts/HolyGrail";
  9. import { ShortVerticalDivider } from "./Common";
  10. import { DojoGrid } from "./DojoGrid";
  11. interface WorkflowsProps {
  12. wuid: string;
  13. }
  14. export const Workflows: React.FunctionComponent<WorkflowsProps> = ({
  15. wuid
  16. }) => {
  17. const [grid, setGrid] = React.useState<any>(undefined);
  18. const [, setSelection] = React.useState([]);
  19. const [workflows, , refreshWorkflow] = useWorkunitWorkflows(wuid);
  20. // Command Bar ---
  21. const buttons: ICommandBarItemProps[] = [
  22. {
  23. key: "refresh", text: nlsHPCC.Refresh, iconProps: { iconName: "Refresh" },
  24. onClick: () => {
  25. refreshWorkflow();
  26. }
  27. },
  28. { key: "divider_1", itemType: ContextualMenuItemType.Divider, onRender: () => <ShortVerticalDivider /> },
  29. ];
  30. const rightButtons: ICommandBarItemProps[] = [
  31. {
  32. key: "copy", text: nlsHPCC.Copy, disabled: true, iconOnly: true, iconProps: { iconName: "Copy" },
  33. onClick: () => {
  34. // TODO: See HPCC-25473
  35. }
  36. },
  37. {
  38. key: "download", text: nlsHPCC.DownloadToCSV, disabled: true, iconOnly: true, iconProps: { iconName: "Download" },
  39. onClick: () => {
  40. // TODO: See HPCC-25473
  41. }
  42. }
  43. ];
  44. // Grid ---
  45. const gridStore = useConst(new Observable(new AlphaNumSortMemory("__hpcc_id", { Name: true, Value: true })));
  46. const gridQuery = useConst({});
  47. const gridSort = useConst([{ attribute: "Wuid", "descending": true }]);
  48. const gridColumns = useConst({
  49. EventName: { label: nlsHPCC.Name, width: 180 },
  50. EventText: { label: nlsHPCC.Subtype },
  51. Count: {
  52. label: nlsHPCC.Count, width: 180,
  53. formatter: function (count) {
  54. if (count === -1) {
  55. return 0;
  56. }
  57. return count;
  58. }
  59. },
  60. CountRemaining: {
  61. label: nlsHPCC.Remaining, width: 180,
  62. formatter: function (countRemaining) {
  63. if (countRemaining === -1) {
  64. return 0;
  65. }
  66. return countRemaining;
  67. }
  68. }
  69. });
  70. const refreshTable = (clearSelection = false) => {
  71. grid?.set("query", gridQuery);
  72. if (clearSelection) {
  73. grid?.clearSelection();
  74. }
  75. };
  76. React.useEffect(() => {
  77. gridStore.setData(workflows.map(row => {
  78. return {
  79. ...row,
  80. __hpcc_id: row.WFID
  81. };
  82. }));
  83. refreshTable();
  84. // eslint-disable-next-line react-hooks/exhaustive-deps
  85. }, [gridStore, workflows]);
  86. return <HolyGrail
  87. header={<CommandBar items={buttons} overflowButtonProps={{}} farItems={rightButtons} />}
  88. main={
  89. <DojoGrid type="SimpleGrid" store={gridStore} query={gridQuery} sort={gridSort} columns={gridColumns} setGrid={setGrid} setSelection={setSelection} />
  90. }
  91. />;
  92. };