Workflows.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import * as React from "react";
  2. import { CommandBar, ContextualMenuItemType, ICommandBarItemProps, ScrollablePane, Sticky } from "@fluentui/react";
  3. import nlsHPCC from "src/nlsHPCC";
  4. import { useFluentGrid } from "../hooks/grid";
  5. import { useWorkunitWorkflows } from "../hooks/workunit";
  6. import { ShortVerticalDivider } from "./Common";
  7. interface WorkflowsProps {
  8. wuid: string;
  9. }
  10. export const Workflows: React.FunctionComponent<WorkflowsProps> = ({
  11. wuid
  12. }) => {
  13. const [workflows, , refreshWorkflow] = useWorkunitWorkflows(wuid);
  14. const [data, setData] = React.useState<any[]>([]);
  15. // Grid ---
  16. const [Grid, _selection, copyButtons] = useFluentGrid({
  17. data,
  18. primaryID: "__hpcc_id",
  19. alphaNumColumns: { Name: true, Value: true },
  20. sort: [{ attribute: "Wuid", "descending": true }],
  21. filename: "workflows",
  22. columns: {
  23. EventName: { label: nlsHPCC.Name, width: 180 },
  24. EventText: { label: nlsHPCC.Subtype },
  25. Count: {
  26. label: nlsHPCC.Count, width: 180,
  27. formatter: function (count) {
  28. if (count === -1) {
  29. return 0;
  30. }
  31. return count;
  32. }
  33. },
  34. CountRemaining: {
  35. label: nlsHPCC.Remaining, width: 180,
  36. formatter: function (countRemaining) {
  37. if (countRemaining === -1) {
  38. return 0;
  39. }
  40. return countRemaining;
  41. }
  42. }
  43. }
  44. });
  45. React.useEffect(() => {
  46. setData(workflows.map(row => {
  47. return {
  48. ...row,
  49. __hpcc_id: row.WFID
  50. };
  51. }));
  52. }, [workflows]);
  53. // Command Bar ---
  54. const buttons = React.useMemo((): ICommandBarItemProps[] => [
  55. {
  56. key: "refresh", text: nlsHPCC.Refresh, iconProps: { iconName: "Refresh" },
  57. onClick: () => {
  58. refreshWorkflow();
  59. }
  60. },
  61. { key: "divider_1", itemType: ContextualMenuItemType.Divider, onRender: () => <ShortVerticalDivider /> },
  62. ], [refreshWorkflow]);
  63. return <ScrollablePane>
  64. <Sticky>
  65. <CommandBar items={buttons} farItems={copyButtons} />
  66. </Sticky>
  67. <Grid />
  68. </ScrollablePane>;
  69. };