Skip to content
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

Enable ESLint rule: react/jsx-no-constructed-context-values #1685

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ module.exports = {
'nonblock-statement-body-position': 'off',
'react/jsx-curly-newline': 'off',
'react/jsx-indent': 'off',
'react/jsx-no-constructed-context-values': 'off',
'react/jsx-no-useless-fragment': ['error', { allowExpressions: true }],
'react/no-unused-prop-types': 'off',
'consistent-return': 'off',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,22 @@ const MonitoringDashboard: React.FC = () => {
return {};
}, [applicationSets, subscriptions, discovered, loaded, loadError]);

const dRResourcesContext = {
drClusterAppsMap: aggregatedAppsMap,
loaded,
loadError,
};
const dRResourcesContext = React.useMemo(() => {
return {
drClusterAppsMap: aggregatedAppsMap,
loaded,
loadError,
};
}, [aggregatedAppsMap, loaded, loadError]);

const csvContextData = React.useMemo(() => {
return { csvData, csvError, csvLoading };
}, [csvData, csvError, csvLoading]);

// ToDo(Sanjal): combime multiple Context together to make it scalable
// refer: https://javascript.plainenglish.io/how-to-combine-context-providers-for-cleaner-react-code-9ed24f20225e
return (
<CSVStatusesContext.Provider value={{ csvData, csvError, csvLoading }}>
<CSVStatusesContext.Provider value={csvContextData}>
<DRResourcesContext.Provider value={dRResourcesContext}>
<UpperSection />
</DRResourcesContext.Provider>
Expand Down
5 changes: 4 additions & 1 deletion packages/ocs/dashboards/block-pool/block-pool-dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ const mainCards = [
const rightCards = [{ Card: MirroringCard }];

export const BlockPoolDashboard: React.FC<PoolDashboardProps> = ({ obj }) => {
const contextData = React.useMemo(() => {
return { obj };
}, [obj]);
return (
<BlockPoolDashboardContext.Provider value={{ obj }}>
<BlockPoolDashboardContext.Provider value={contextData}>
<Overview>
<OverviewGrid
mainCards={mainCards}
Expand Down
8 changes: 5 additions & 3 deletions packages/odf/components/s3-browser/noobaa-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,12 @@ export const NoobaaS3Provider: React.FC<NoobaaS3ProviderType> = ({
const anyError =
odfNsLoadError || secretError || routeError || noobaaS3Error || error;

const contextData = React.useMemo(() => {
return { noobaaS3, noobaaS3Route: s3Route.current };
}, [noobaaS3]);

return allLoaded && !anyError ? (
<NoobaaS3Context.Provider
value={{ noobaaS3, noobaaS3Route: s3Route.current }}
>
<NoobaaS3Context.Provider value={contextData}>
{children}
</NoobaaS3Context.Provider>
) : (
Expand Down
49 changes: 32 additions & 17 deletions packages/odf/components/topology/Topology.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -571,24 +571,39 @@ const Topology: React.FC = () => {

const zones = memoizedNodes.map(getTopologyDomain);

const topologyDataContextData = React.useMemo(() => {
return {
nodes: memoizedNodes,
storageCluster: storageCluster,
zones,
deployments: memoizedDeployments,
visualizationLevel: visualizationLevel,
activeNode,
setActiveNode,
nodeDeploymentMap,
selectedElement,
setSelectedElement: setSelectedElement as any,
};
}, [
memoizedNodes,
storageCluster,
zones,
memoizedDeployments,
visualizationLevel,
activeNode,
setActiveNode,
nodeDeploymentMap,
selectedElement,
setSelectedElement,
]);

const topologySearchContextData = React.useMemo(() => {
return { activeItemsUID, setActiveItemsUID, activeItem, setActiveItem };
}, [activeItemsUID, setActiveItemsUID, activeItem, setActiveItem]);

return (
<TopologyDataContext.Provider
value={{
nodes: memoizedNodes,
storageCluster: storageCluster,
zones,
deployments: memoizedDeployments,
visualizationLevel: visualizationLevel,
activeNode,
setActiveNode,
nodeDeploymentMap,
selectedElement,
setSelectedElement: setSelectedElement as any,
}}
>
<TopologySearchContext.Provider
value={{ activeItemsUID, setActiveItemsUID, activeItem, setActiveItem }}
>
<TopologyDataContext.Provider value={topologyDataContextData}>
<TopologySearchContext.Provider value={topologySearchContextData}>
<VisualizationProvider controller={controller}>
<div className="odf__topology-view" id="odf-topology">
<TopologyTopBar />
Expand Down
Loading