-
Notifications
You must be signed in to change notification settings - Fork 304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HPCC-32594 ECL Watch v9 prevent duplicate errors logged on File Details #19094
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import * as React from "react"; | ||
import { LogicalFile } from "@hpcc-js/comms"; | ||
import { scopedLogger } from "@hpcc-js/util"; | ||
import { singletonDebounce } from "../../util/throttle"; | ||
import { useCounter } from "../../hooks/util"; | ||
|
||
const logger = scopedLogger("../components/controls/FileContext.tsx"); | ||
|
||
const FileContext = React.createContext(null); | ||
|
||
export const FileContextProvider = ({ cluster, logicalFile, children }) => { | ||
const [file, setFile] = React.useState<LogicalFile>(); | ||
const [isProtected, setIsProtected] = React.useState(false); | ||
const [lastUpdate, setLastUpdate] = React.useState(Date.now()); | ||
const [count, increment] = useCounter(); | ||
|
||
React.useEffect(() => { | ||
const file = LogicalFile.attach({ baseUrl: "" }, cluster === "undefined" ? undefined : cluster, logicalFile); | ||
let active = true; | ||
let handle; | ||
const fetchInfo = singletonDebounce(file, "fetchInfo"); | ||
fetchInfo() | ||
.then((response) => { | ||
if (active) { | ||
setFile(file); | ||
setIsProtected(response.ProtectList?.DFUFileProtect?.length > 0 || false); | ||
setLastUpdate(Date.now()); | ||
handle = file.watch(() => { | ||
setIsProtected(response.ProtectList?.DFUFileProtect?.length > 0 || false); | ||
setLastUpdate(Date.now()); | ||
}); | ||
} | ||
}) | ||
.catch(err => logger.error(err)); | ||
|
||
return () => { | ||
active = false; | ||
handle?.release(); | ||
}; | ||
}, [cluster, count, logicalFile]); | ||
|
||
return ( | ||
<FileContext.Provider value={{ file, isProtected, lastUpdate, increment }}> | ||
{children} | ||
</FileContext.Provider> | ||
); | ||
}; | ||
|
||
export const useFileContext = () => { | ||
const context = React.useContext(FileContext); | ||
if (!context) { | ||
throw new Error("useFileContext must be used within a FileContextProvider"); | ||
} | ||
return context; | ||
}; | ||
|
||
export default FileContextProvider; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Picky: For consistency, there is no need to have a default export... |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import * as React from "react"; | ||
import { Route, RouterContext } from "universal-router"; | ||
import { initialize, parsePage, parseSearch, parseSort, pushUrl, replaceUrl } from "./util/history"; | ||
import nlsHPCC from "src/nlsHPCC"; | ||
|
||
declare const dojoConfig; | ||
|
||
|
@@ -130,19 +131,40 @@ export const routes: RoutesEx = [ | |
}) | ||
}, | ||
{ | ||
path: "/:Name", action: (ctx, params) => import("./components/FileDetails").then(_ => { | ||
return <_.FileDetails cluster={undefined} logicalFile={params.Name as string} />; | ||
}) | ||
path: "/:Name", action: (ctx, params) => { | ||
const FileContextProvider = React.lazy(() => import("./components/contexts/FileContext")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bit different, but I wasn't quite sure what would be better for conditionally loading more than one component in these router callbacks. I found this React.lazy in the docs, and it required wrapping in this React.Suspense to render properly. lazy() also expects the component being loaded to have a default export, hence the one line change to FileDetails. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My understanding is that the only diff between a raw |
||
const FileDetails = React.lazy(() => import("./components/FileDetails")); | ||
|
||
return <React.Suspense fallback={<div>{nlsHPCC.Loading}</div>}> | ||
<FileContextProvider cluster={undefined} logicalFile={params.Name as string}> | ||
<FileDetails cluster={undefined} logicalFile={params.Name as string} /> | ||
</FileContextProvider> | ||
</React.Suspense>; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like an "anti-pattern"? Why is FileDetails visible here? |
||
}, | ||
{ | ||
path: "/:NodeGroup/:Name", action: (ctx, params) => import("./components/FileDetails").then(_ => { | ||
return <_.FileDetails cluster={params.NodeGroup as string} logicalFile={params.Name as string} />; | ||
}) | ||
path: "/:NodeGroup/:Name", action: (ctx, params) => { | ||
const FileContextProvider = React.lazy(() => import("./components/contexts/FileContext")); | ||
const FileDetails = React.lazy(() => import("./components/FileDetails")); | ||
|
||
return <React.Suspense fallback={<div>{nlsHPCC.Loading}</div>}> | ||
<FileContextProvider cluster={params.NodeGroup as string} logicalFile={params.Name as string}> | ||
<FileDetails cluster={params.NodeGroup as string} logicalFile={params.Name as string} /> | ||
</FileContextProvider> | ||
</React.Suspense>; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto |
||
}, | ||
{ | ||
path: "/:NodeGroup/:Name/:Tab", action: (ctx, params) => import("./components/FileDetails").then(_ => { | ||
return <_.FileDetails cluster={params.NodeGroup as string} logicalFile={params.Name as string} tab={params.Tab as string} sort={{ [params.Tab as string]: parseSort(ctx.search) }} queryParams={{ [params.Tab as string]: parseSearch(ctx.search) as any }} />; | ||
}) | ||
path: "/:NodeGroup/:Name/:Tab", action: (ctx, params) => { | ||
const FileContextProvider = React.lazy(() => import("./components/contexts/FileContext")); | ||
const FileDetails = React.lazy(() => import("./components/FileDetails")); | ||
|
||
return <React.Suspense fallback={<div>{nlsHPCC.Loading}</div>}> | ||
<FileContextProvider cluster={params.NodeGroup as string} logicalFile={params.Name as string}> | ||
<FileDetails cluster={params.NodeGroup as string} logicalFile={params.Name as string} tab={params.Tab as string} sort={{ [params.Tab as string]: parseSort(ctx.search) }} queryParams={{ [params.Tab as string]: parseSearch(ctx.search) as any }} /> | ||
</FileContextProvider> | ||
</React.Suspense>; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto |
||
}, | ||
] | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Picky: For consistency, there is no need to have a default export...