FileSummary.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. import * as React from "react";
  2. import { CommandBar, ContextualMenuItemType, ICommandBarItemProps, ScrollablePane, ScrollbarVisibility, Sticky, StickyPositionType } from "@fluentui/react";
  3. import nlsHPCC from "src/nlsHPCC";
  4. import * as WsDfu from "src/WsDfu";
  5. import * as Utility from "src/Utility";
  6. import { getStateImageName, IFile } from "src/ESPLogicalFile";
  7. import { useFile } from "../hooks/file";
  8. import { ShortVerticalDivider } from "./Common";
  9. import { TableGroup } from "./forms/Groups";
  10. import { CopyFile } from "./forms/CopyFile";
  11. import { DesprayFile } from "./forms/DesprayFile";
  12. import { RenameFile } from "./forms/RenameFile";
  13. import { ReplicateFile } from "./forms/ReplicateFile";
  14. import "react-reflex/styles.css";
  15. interface FileSummaryProps {
  16. cluster?: string;
  17. logicalFile: string;
  18. tab?: string;
  19. }
  20. export const FileSummary: React.FunctionComponent<FileSummaryProps> = ({
  21. cluster,
  22. logicalFile,
  23. tab = "summary"
  24. }) => {
  25. const [file, isProtected, , refresh] = useFile(cluster, logicalFile);
  26. const [description, setDescription] = React.useState("");
  27. const [_protected, setProtected] = React.useState(false);
  28. const [restricted, setRestricted] = React.useState(false);
  29. const [canReplicateFlag, setCanReplicateFlag] = React.useState(false);
  30. const [replicateFlag, setReplicateFlag] = React.useState(false);
  31. const [showCopyFile, setShowCopyFile] = React.useState(false);
  32. const [showRenameFile, setShowRenameFile] = React.useState(false);
  33. const [showDesprayFile, setShowDesprayFile] = React.useState(false);
  34. const [showReplicateFile, setShowReplicateFile] = React.useState(false);
  35. const isDFUWorkunit = React.useMemo(() => {
  36. return file?.Wuid?.length && file?.Wuid[0] === "D";
  37. }, [file?.Wuid]);
  38. React.useEffect(() => {
  39. setDescription(file?.Description || "");
  40. setProtected(file?.ProtectList?.DFUFileProtect?.length > 0 || false);
  41. setRestricted(file?.IsRestricted || false);
  42. if (file?.DFUFilePartsOnClusters?.DFUFilePartsOnCluster?.length > 0) {
  43. let _canReplicate = false;
  44. let _replicate = false;
  45. file?.DFUFilePartsOnClusters?.DFUFilePartsOnCluster.forEach(part => {
  46. _canReplicate = _canReplicate && part.CanReplicate;
  47. _replicate = _replicate && part.Replicate;
  48. });
  49. setCanReplicateFlag(_canReplicate);
  50. setReplicateFlag(_replicate);
  51. }
  52. }, [file?.DFUFilePartsOnClusters?.DFUFilePartsOnCluster, file?.Description, file?.IsRestricted, file?.ProtectList?.DFUFileProtect?.length]);
  53. const canSave = React.useMemo(() => {
  54. return file && (
  55. description !== file?.Description ||
  56. _protected !== isProtected ||
  57. restricted !== file?.IsRestricted
  58. );
  59. }, [_protected, description, file, isProtected, restricted]);
  60. const buttons = React.useMemo((): ICommandBarItemProps[] => [
  61. {
  62. key: "refresh", text: nlsHPCC.Refresh, iconProps: { iconName: "Refresh" },
  63. onClick: () => {
  64. refresh();
  65. }
  66. },
  67. {
  68. key: "copyFilename", text: nlsHPCC.CopyLogicalFilename, iconProps: { iconName: "Copy" },
  69. onClick: () => {
  70. navigator?.clipboard?.writeText(logicalFile);
  71. }
  72. },
  73. { key: "divider_1", itemType: ContextualMenuItemType.Divider, onRender: () => <ShortVerticalDivider /> },
  74. {
  75. key: "save", text: nlsHPCC.Save, iconProps: { iconName: "Save" }, disabled: !canSave,
  76. onClick: () => {
  77. file?.update({
  78. UpdateDescription: true,
  79. FileDesc: description,
  80. Protect: _protected ? "1" : "2",
  81. Restrict: restricted ? "1" : "2",
  82. });
  83. }
  84. },
  85. {
  86. key: "delete", text: nlsHPCC.Delete, iconProps: { iconName: "Delete" }, disabled: !file,
  87. onClick: () => {
  88. if (confirm(nlsHPCC.YouAreAboutToDeleteThisFile)) {
  89. WsDfu.DFUArrayAction([file], "Delete").then(response => {
  90. const actionInfo = response?.DFUArrayActionResponse?.ActionResults?.DFUActionInfo;
  91. if (actionInfo && actionInfo.length && !actionInfo[0].Failed) {
  92. window.history.back();
  93. }
  94. });
  95. }
  96. }
  97. },
  98. { key: "divider_2", itemType: ContextualMenuItemType.Divider, onRender: () => <ShortVerticalDivider /> },
  99. {
  100. key: "copyFile", text: nlsHPCC.Copy, disabled: !file,
  101. onClick: () => setShowCopyFile(true)
  102. },
  103. {
  104. key: "rename", text: nlsHPCC.Rename, disabled: !file,
  105. onClick: () => setShowRenameFile(true)
  106. },
  107. {
  108. key: "despray", text: nlsHPCC.Despray, disabled: !file,
  109. onClick: () => setShowDesprayFile(true)
  110. },
  111. { key: "divider_3", itemType: ContextualMenuItemType.Divider, onRender: () => <ShortVerticalDivider /> },
  112. {
  113. key: "replicate", text: nlsHPCC.Replicate, disabled: !canReplicateFlag || !replicateFlag,
  114. onClick: () => setShowReplicateFile(true)
  115. },
  116. ], [_protected, canReplicateFlag, canSave, description, file, logicalFile, refresh, replicateFlag, restricted]);
  117. const protectedImage = _protected ? Utility.getImageURL("locked.png") : Utility.getImageURL("unlocked.png");
  118. const stateImage = Utility.getImageURL(getStateImageName(file as unknown as IFile));
  119. const compressedImage = file?.IsCompressed ? Utility.getImageURL("compressed.png") : "";
  120. return <>
  121. <ScrollablePane scrollbarVisibility={ScrollbarVisibility.auto}>
  122. <Sticky stickyPosition={StickyPositionType.Header}>
  123. <CommandBar items={buttons} />
  124. </Sticky>
  125. <Sticky stickyPosition={StickyPositionType.Header}>
  126. <div style={{ display: "inline-block" }}>
  127. <h2>
  128. <img src={compressedImage} />&nbsp;
  129. <img src={protectedImage} />&nbsp;
  130. <img src={stateImage} />&nbsp;
  131. {file?.Name}
  132. </h2>
  133. </div>
  134. </Sticky>
  135. <TableGroup fields={{
  136. "Wuid": { label: nlsHPCC.Workunit, type: "link", value: file?.Wuid, href: `#/${isDFUWorkunit ? "dfu" : ""}workunits/${file?.Wuid}`, readonly: true, },
  137. "Owner": { label: nlsHPCC.Owner, type: "string", value: file?.Owner, readonly: true },
  138. "SuperOwner": { label: nlsHPCC.SuperFile, type: "links", links: file?.Superfiles?.DFULogicalFile?.map(row => ({ label: "", type: "link", value: row.Name, href: `#/superfiles/${row.Name}` })) },
  139. "NodeGroup": { label: nlsHPCC.ClusterName, type: "string", value: file?.NodeGroup, readonly: true },
  140. "Description": { label: nlsHPCC.Description, type: "string", value: description },
  141. "JobName": { label: nlsHPCC.JobName, type: "string", value: file?.JobName, readonly: true },
  142. "isProtected": { label: nlsHPCC.Protected, type: "checkbox", value: _protected },
  143. "isRestricted": { label: nlsHPCC.Restricted, type: "checkbox", value: restricted },
  144. "ContentType": { label: nlsHPCC.ContentType, type: "string", value: file?.ContentType, readonly: true },
  145. "KeyType": { label: nlsHPCC.KeyType, type: "string", value: file?.KeyType, readonly: true },
  146. "Filesize": { label: nlsHPCC.FileSize, type: "string", value: file?.Filesize, readonly: true },
  147. "Format": { label: nlsHPCC.Format, type: "string", value: file?.Format, readonly: true },
  148. "IsCompressed": { label: nlsHPCC.IsCompressed, type: "checkbox", value: file?.IsCompressed, readonly: true },
  149. "CompressedFileSizeString": { label: nlsHPCC.CompressedFileSize, type: "string", value: file?.CompressedFileSize ? file?.CompressedFileSize.toString() : "", readonly: true },
  150. "PercentCompressed": { label: nlsHPCC.PercentCompressed, type: "string", value: file?.PercentCompressed, readonly: true },
  151. "Modified": { label: nlsHPCC.Modified, type: "string", value: file?.Modified, readonly: true },
  152. "ExpireDays": { label: nlsHPCC.ExpireDays, type: "string", value: file?.ExpireDays ? file?.ExpireDays.toString() : "", readonly: true },
  153. "Directory": { label: nlsHPCC.Directory, type: "string", value: file?.Dir, readonly: true },
  154. "PathMask": { label: nlsHPCC.PathMask, type: "string", value: file?.PathMask, readonly: true },
  155. "RecordSize": { label: nlsHPCC.RecordSize, type: "string", value: file?.RecordSize, readonly: true },
  156. "RecordCount": { label: nlsHPCC.RecordCount, type: "string", value: file?.RecordCount, readonly: true },
  157. "IsReplicated": { label: nlsHPCC.IsReplicated, type: "checkbox", value: file?.DFUFilePartsOnClusters?.DFUFilePartsOnCluster?.length > 0, readonly: true },
  158. "NumParts": { label: nlsHPCC.FileParts, type: "number", value: file?.NumParts, readonly: true },
  159. "MinSkew": { label: nlsHPCC.MinSkew, type: "string", value: file?.Stat?.MinSkew, readonly: true },
  160. "MaxSkew": { label: nlsHPCC.MaxSkew, type: "string", value: file?.Stat?.MaxSkew, readonly: true },
  161. "MinSkewPart": { label: nlsHPCC.MinSkewPart, type: "string", value: file?.Stat?.MinSkewPart === undefined ? "" : file?.Stat?.MinSkewPart?.toString(), readonly: true },
  162. "MaxSkewPart": { label: nlsHPCC.MaxSkewPart, type: "string", value: file?.Stat?.MaxSkewPart === undefined ? "" : file?.Stat?.MaxSkewPart?.toString(), readonly: true },
  163. }} onChange={(id, value) => {
  164. switch (id) {
  165. case "Description":
  166. setDescription(value);
  167. break;
  168. case "isProtected":
  169. setProtected(value);
  170. break;
  171. case "isRestricted":
  172. setRestricted(value);
  173. break;
  174. }
  175. }} />
  176. </ScrollablePane>
  177. <CopyFile cluster={cluster} logicalFile={logicalFile} showForm={showCopyFile} setShowForm={setShowCopyFile} />
  178. <DesprayFile cluster={cluster} logicalFile={logicalFile} showForm={showDesprayFile} setShowForm={setShowDesprayFile} />
  179. <RenameFile cluster={cluster} logicalFile={logicalFile} showForm={showRenameFile} setShowForm={setShowRenameFile} />
  180. <ReplicateFile cluster={cluster} logicalFile={logicalFile} showForm={showReplicateFile} setShowForm={setShowReplicateFile} />
  181. </>;
  182. };