QueryErrors.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 { useGrid } from "../hooks/grid";
  10. import { HolyGrail } from "../layouts/HolyGrail";
  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. // Grid ---
  22. const store = useConst(new Observable(new Memory("__hpcc_id")));
  23. const [Grid, _selection, refreshTable, copyButtons] = useGrid({
  24. store,
  25. sort: [{ attribute: "__hpcc_id" }],
  26. filename: "queryErrors",
  27. columns: {
  28. Cluster: { label: nlsHPCC.Cluster, width: 140 },
  29. Errors: { label: nlsHPCC.Errors },
  30. State: { label: nlsHPCC.State, width: 120 },
  31. }
  32. });
  33. // Command Bar ---
  34. const buttons = React.useMemo((): ICommandBarItemProps[] => [
  35. {
  36. key: "refresh", text: nlsHPCC.Refresh, iconProps: { iconName: "Refresh" },
  37. onClick: () => refreshTable()
  38. },
  39. ], [refreshTable]);
  40. React.useEffect(() => {
  41. setQuery(ESPQuery.Get(querySet, queryId));
  42. }, [setQuery, queryId, querySet]);
  43. React.useEffect(() => {
  44. query?.getDetails()
  45. .then(({ WUQueryDetailsResponse }) => {
  46. const clusterStates = query?.Clusters?.ClusterQueryState;
  47. if (clusterStates) {
  48. store.setData(clusterStates.map((item, idx) => {
  49. return {
  50. __hpcc_id: idx,
  51. Cluster: item.Cluster,
  52. Errors: item.Errors,
  53. State: item.State
  54. };
  55. }));
  56. refreshTable();
  57. }
  58. })
  59. .catch(logger.error)
  60. ;
  61. }, [store, query, refreshTable]);
  62. return <HolyGrail
  63. header={<CommandBar items={buttons} farItems={copyButtons} />}
  64. main={<Grid />}
  65. />;
  66. };