QueryErrors.tsx 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import * as React from "react";
  2. import { CommandBar, ICommandBarItemProps } from "@fluentui/react";
  3. import { useConst } from "@fluentui/react-hooks";
  4. import { scopedLogger } from "@hpcc-js/util";
  5. import * as ESPQuery from "src/ESPQuery";
  6. import * as Observable from "dojo/store/Observable";
  7. import { Memory } from "src/Memory";
  8. import nlsHPCC from "src/nlsHPCC";
  9. import { HolyGrail } from "../layouts/HolyGrail";
  10. import { DojoGrid } from "./DojoGrid";
  11. const logger = scopedLogger("../components/QueryErrors.tsx");
  12. interface QueryErrorsProps {
  13. querySet?: string;
  14. queryId?: string;
  15. }
  16. export const QueryErrors: React.FunctionComponent<QueryErrorsProps> = ({
  17. querySet,
  18. queryId
  19. }) => {
  20. const [query, setQuery] = React.useState<any>();
  21. const [grid, setGrid] = React.useState<any>(undefined);
  22. // Grid ---
  23. const gridStore = useConst(new Observable(new Memory("__hpcc_id")));
  24. const gridQuery = useConst({});
  25. const gridSort = useConst([{ attribute: "__hpcc_id" }]);
  26. const gridColumns = useConst({
  27. Cluster: { label: nlsHPCC.Cluster, width: 140 },
  28. Errors: { label: nlsHPCC.Errors },
  29. State: { label: nlsHPCC.State, width: 120 },
  30. });
  31. const refreshTable = React.useCallback((clearSelection = false) => {
  32. grid?.set("query", gridQuery);
  33. if (clearSelection) {
  34. grid?.clearSelection();
  35. }
  36. }, [grid, gridQuery]);
  37. // Command Bar ---
  38. const buttons = React.useMemo((): ICommandBarItemProps[] => [
  39. {
  40. key: "refresh", text: nlsHPCC.Refresh, iconProps: { iconName: "Refresh" },
  41. onClick: () => refreshTable()
  42. },
  43. ], [refreshTable]);
  44. React.useEffect(() => {
  45. setQuery(ESPQuery.Get(querySet, queryId));
  46. }, [setQuery, queryId, querySet]);
  47. React.useEffect(() => {
  48. query?.getDetails()
  49. .then(({ WUQueryDetailsResponse }) => {
  50. const clusterStates = query?.Clusters?.ClusterQueryState;
  51. if (clusterStates) {
  52. gridStore.setData(clusterStates.map((item, idx) => {
  53. return {
  54. __hpcc_id: idx,
  55. Cluster: item.Cluster,
  56. Errors: item.Errors,
  57. State: item.State
  58. };
  59. }));
  60. refreshTable();
  61. }
  62. })
  63. .catch(logger.error)
  64. ;
  65. }, [gridStore, query, refreshTable]);
  66. return <HolyGrail
  67. header={<CommandBar items={buttons} overflowButtonProps={{}} />}
  68. main={<DojoGrid store={gridStore} query={gridQuery} sort={gridSort} columns={gridColumns} setGrid={setGrid} setSelection={null} />}
  69. />;
  70. };