Skip to content

Commit

Permalink
Fix configure-beta layer rendering speed
Browse files Browse the repository at this point in the history
  • Loading branch information
tariqksoliman committed Oct 29, 2024
1 parent f0c691d commit 924f9db
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
33 changes: 27 additions & 6 deletions configure/src/components/Tabs/Layers/Layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { makeStyles } from "@mui/styles";
import clsx from "clsx";

import { reorderArray, insertLayerAfterUUID } from "../../../core/utils";
import ConfigureStore from "../../../core/ConfigureStore";
import { setModal, setConfiguration } from "../../../core/ConfigureStore";

import LayerModal from "./Modals/LayerModal/LayerModal";
Expand Down Expand Up @@ -163,19 +164,39 @@ const useStyles = makeStyles((theme) => ({
},
}));

let savedLayersConfiguration = "";
let configuration = {};
let savedMinLayers = "";
export default function Layers() {
const c = useStyles();

const dispatch = useDispatch();
const [flatLayers, setFlatLayers] = useState([]);

const mission = useSelector((state) => state.core.mission);
const configuration = useSelector((state) => state.core.configuration);
const minLayersStr = useSelector((state) => {
if (state.core.configuration?.layers == null) return "[]";

configuration = state.core.configuration;

const minLayers = [];
traverseLayers(state.core.configuration.layers, (layer, path, i, depth) => {
minLayers.push({
layer: {
name: layer.name,
uuid: layer.uuid,
type: layer.type,
visibility: layer.visibility,
},
depth,
});
});
return JSON.stringify(minLayers);
});
const minLayers = JSON.parse(minLayersStr);

useEffect(() => {
return () => {
savedLayersConfiguration = "";
savedMinLayers = "";
};
}, []);

Expand All @@ -194,14 +215,14 @@ export default function Layers() {
return <div className={c.Layers}>Not found</div>;
}

const strConf = JSON.stringify(configuration.layers);
if (savedLayersConfiguration != strConf) {
const strConf = JSON.stringify(minLayers);
if (savedMinLayers != strConf) {
const nextFlatLayers = [];
traverseLayers(configuration.layers, (layer, path, i, depth) => {
nextFlatLayers.push({ layer, depth });
});
setFlatLayers(nextFlatLayers);
savedLayersConfiguration = strConf;
savedMinLayers = strConf;
}

const onIndent = (layer, idx) => {
Expand Down
5 changes: 5 additions & 0 deletions configure/src/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ export const setIn = (obj, keyArray, value, force) => {
let object = obj;
for (let i = 0; i < keyArray.length - 1; i++) {
if (force) {
// If string but setting a number index at the end of keyArray, turn into array
if (i === keyArray.length - 2) {
if (isNumeric(keyArray[i + 1]) && !Array.isArray(object[keyArray[i]]))
object[keyArray[i]] = Array(object[keyArray[i]]);
}
if (!object.hasOwnProperty(keyArray[i]))
object[keyArray[i]] =
i === keyArray.length - 2 && isNumeric(keyArray[i + 1]) ? [] : {};
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/Setup/ENVs/ENVs.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Password of Postgres database | string | default `null`

#### `PORT=`

Port to run on | positive integer | default `3000`
Port to run on | positive integer | default `8888`

#### `DB_POOL_MAX=`

Expand Down

0 comments on commit 924f9db

Please sign in to comment.