Skip to content

Commit 9157e9c

Browse files
committed
🐛 fixed crash because of v4 new grid layouts
1 parent 12b6c3e commit 9157e9c

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

admin/src/pages/Dashboard.jsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import PolarChart from '../components/ChartbrewCharts/PolarChart';
2929
import DoughnutChart from '../components/ChartbrewCharts/DoughnutChart';
3030
import Illo from '../components/Illo';
3131
import KpiChart from '../components/ChartbrewCharts/KpiChart';
32-
import { widthSize } from '../utils/layoutBreakpoints';
32+
import { widthSize, heightSize, cols, margin } from '../utils/layoutBreakpoints';
3333

3434
const ResponsiveGridLayout = WidthProvider(Responsive, { measureBeforeMount: true });
3535

@@ -45,7 +45,7 @@ function Dashboard() {
4545
const [team, setTeam] = useState({});
4646
const [teams, setTeams] = useState([]);
4747
const [dropdownTeam, setDropdownTeam] = useState('');
48-
const [layouts, setLayouts] = useState({ xxs: [], xs: [], sm: [], md: [], lg: [] });
48+
const [layouts, setLayouts] = useState(null);
4949

5050
useEffect(() => {
5151
getSettings().then((data) => setStore(data));
@@ -87,7 +87,11 @@ function Dashboard() {
8787
useEffect(() => {
8888
if (charts && charts.length > 0) {
8989
// set the grid layout
90-
const newLayouts = { xxs: [], xs: [], sm: [], md: [], lg: [] };
90+
const newLayouts = Object.keys(widthSize).reduce((acc, key) => {
91+
acc[key] = [];
92+
return acc;
93+
}, {});
94+
9195
charts.forEach((chart) => {
9296
if (chart.layout) {
9397
Object.keys(chart.layout).forEach((key) => {
@@ -305,9 +309,9 @@ function Dashboard() {
305309
<ResponsiveGridLayout
306310
className="layout"
307311
layouts={layouts}
308-
margin={{ lg: [12, 12], md: [12, 12], sm: [12, 12], xs: [12, 12], xxs: [12, 12] }}
312+
margin={margin}
309313
breakpoints={widthSize}
310-
cols={{ lg: 12, md: 10, sm: 8, xs: 6, xxs: 4 }}
314+
cols={cols}
311315
rowHeight={150}
312316
isDraggable={false}
313317
isResizable={false}

admin/src/utils/layoutBreakpoints.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
export const widthSize = { lg: 1200, md: 996, sm: 768, xs: 480, xxs: 240 };
1+
export const widthSize = { xxxl: 3840, xxl: 2560, xl: 1600, lg: 1200, md: 996, sm: 768, xs: 480, xxs: 240 };
22

33
const rowHeight = 150;
4-
export const heightSize = { lg: 5 * rowHeight, md: 4 * rowHeight, sm: 3 * rowHeight, xs: 2 * rowHeight, xxs: rowHeight };
4+
export const heightSize = { xxxl: 5 * rowHeight, xxl: 5 * rowHeight, xl: 5 * rowHeight, lg: 5 * rowHeight, md: 4 * rowHeight, sm: 3 * rowHeight, xs: 2 * rowHeight, xxs: rowHeight };
55

66
export const getWidthBreakpoint = (containerRef) => {
77
if (!containerRef?.current?.offsetWidth) return "md";
@@ -29,4 +29,8 @@ export const getHeightBreakpoint = (containerRef) => {
2929
});
3030

3131
return chartBreakpoint;
32-
};
32+
};
33+
34+
export const cols = { xxxl: 16, xxl: 16, xl: 14, lg: 12, md: 10, sm: 8, xs: 6, xxs: 4 };
35+
36+
export const margin = { xxxl: [12, 12], xxl: [12, 12], xl: [12, 12], lg: [12, 12], md: [12, 12], sm: [12, 12], xs: [12, 12], xxs: [12, 12] };

0 commit comments

Comments
 (0)