FileBlooms.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import * as React from "react";
  2. import { CommandBar, ICommandBarItemProps } from "@fluentui/react";
  3. import { useConst } from "@fluentui/react-hooks";
  4. import * as Observable from "dojo/store/Observable";
  5. import { Memory } from "src/Memory";
  6. import nlsHPCC from "src/nlsHPCC";
  7. import { useGrid } from "../hooks/grid";
  8. import { useFile } from "../hooks/file";
  9. import { HolyGrail } from "../layouts/HolyGrail";
  10. interface FileBloomsProps {
  11. cluster?: string;
  12. logicalFile: string;
  13. }
  14. export const FileBlooms: React.FunctionComponent<FileBloomsProps> = ({
  15. cluster,
  16. logicalFile
  17. }) => {
  18. const [file, , , refreshData] = useFile(cluster, logicalFile);
  19. // Grid ---
  20. const store = useConst(new Observable(new Memory("FieldNames")));
  21. const [Grid, , refreshTable, copyButtons] = useGrid({
  22. store,
  23. sort: [{ attribute: "FieldNames", "descending": false }],
  24. filename: "fileBlooms",
  25. columns: {
  26. FieldNames: { label: nlsHPCC.FieldNames, sortable: true, },
  27. Limit: { label: nlsHPCC.Limit, sortable: true, },
  28. Probability: { label: nlsHPCC.Probability, sortable: true, }
  29. }
  30. });
  31. React.useEffect(() => {
  32. const fileBlooms = file?.Blooms?.DFUFileBloom;
  33. if (fileBlooms) {
  34. store.setData(fileBlooms.map(bloom => {
  35. return {
  36. ...bloom,
  37. FieldNames: bloom?.FieldNames?.Item[0] || "",
  38. };
  39. }));
  40. refreshTable();
  41. }
  42. }, [file?.Blooms?.DFUFileBloom, refreshTable, store]);
  43. // Command Bar ---
  44. const buttons = React.useMemo((): ICommandBarItemProps[] => [
  45. {
  46. key: "refresh", text: nlsHPCC.Refresh, iconProps: { iconName: "Refresh" },
  47. onClick: () => refreshData()
  48. },
  49. ], [refreshData]);
  50. return <HolyGrail
  51. header={<CommandBar items={buttons} farItems={copyButtons} />}
  52. main={
  53. <Grid />
  54. }
  55. />;
  56. };