Skip to content

Commit

Permalink
memoize and change one case to default
Browse files Browse the repository at this point in the history
  • Loading branch information
birm committed Oct 10, 2024
1 parent cb081c2 commit 2dc5f5c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion source/components/Layout/VisGridView/VisGridSplitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const VisGridSplitter = ({ layout, size, fullVisScreenHandler, fullScreened }) =

const renderSingleView = () => (
<div className="vis-grid-splitter single">
<VisGridView fullVisScreenHandler={fullVisScreenHandler} designation="*" fullScreened={fullScreened} />
<VisGridView fullVisScreenHandler={fullVisScreenHandler} designation="default" fullScreened={fullScreened} />
</div>
);

Expand Down
12 changes: 6 additions & 6 deletions source/components/Layout/VisGridView/VisGridView.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {
useState, useRef, useEffect, useContext,
useState, useRef, useEffect, useContext, useMemo,
} from 'react';
import { debounce } from 'lodash';
import GridLayout from 'react-grid-layout';
Expand Down Expand Up @@ -29,10 +29,9 @@ function VisGridView({ fullVisScreenHandler, fullScreened, designation }) {
});
const self = useRef();

let visConfig = AllVisConfig.filter((x)=>{
return x.designation == designation
|| (!x.designation && designation == "default")
});
const visConfig = useMemo(() => {
return AllVisConfig.filter((x) => x.designation === designation || (!x.designation && designation === "default"));
}, [AllVisConfig, designation]);

const updateViewSize = () => {
const rect = self.current.getBoundingClientRect();
Expand Down Expand Up @@ -66,13 +65,14 @@ function VisGridView({ fullVisScreenHandler, fullScreened, designation }) {
SetIsResizing(false);
SetResizingItemId(null);
};

useEffect(() => {
updateViewSize();
window.addEventListener('resize', debouncedUpdateViewSize);
return () => {
window.removeEventListener('resize', debouncedUpdateViewSize);
};
}, [appLayout.currentCols, config.UNIT_OF_GRID_VIEW, config.UNIT_OF_GRID_VIEW, visConfig]);
}, [appLayout.currentCols, config.UNIT_OF_GRID_VIEW, visConfig]);

useEffect(() => {
const rect = self.current.getBoundingClientRect();
Expand Down

0 comments on commit 2dc5f5c

Please sign in to comment.