Skip to content

Commit

Permalink
#464 Partial updates
Browse files Browse the repository at this point in the history
  • Loading branch information
tariqksoliman committed May 6, 2024
1 parent 188a64b commit 6f1a3d1
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 13 deletions.
41 changes: 35 additions & 6 deletions configure/src/components/Tabs/Tools/Modals/ToolModal/ToolModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@ import React, { useState } from "react";
import { useSelector, useDispatch } from "react-redux";

import { calls } from "../../../../../core/calls";
import { getLayerByUUID } from "../../../../../core/utils";
import {
getLayerByUUID,
getIn,
setIn,
getToolFromConfiguration,
updateToolInConfiguration,
} from "../../../../../core/utils";

import {
setMissions,
setModal,
setSnackBarText,
setConfiguration,
} from "../../../../../core/ConfigureStore";

import Typography from "@mui/material/Typography";
Expand Down Expand Up @@ -139,12 +145,14 @@ const ToolModal = (props) => {
const c = useStyles();

let modal = useSelector((state) => state.core.modal[MODAL_NAME]);
const configuration = useSelector((state) => state.core.configuration);

const open = modal !== false;

modal = modal || {};
const toolName = modal.toolName;
const toolConfig = modal.toolConfig;
const tool = getToolFromConfiguration(toolName, configuration) || {};

const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down("md"));
Expand All @@ -158,6 +166,9 @@ const ToolModal = (props) => {

console.log(modal);

let toolActive = tool.name != null ? true : false;
if (tool?.on != null) toolActive = tool.on;

return (
<Dialog
className={c.Modal}
Expand Down Expand Up @@ -201,21 +212,39 @@ const ToolModal = (props) => {
control={
<Switch
className={c.switch}
checked={true}
checked={toolActive}
onChange={(e) => {
//updateConfiguration(forceField || com.field, e.target.value, layer);
const nextConfiguration = JSON.parse(
JSON.stringify(configuration)
);
if (tool != null) {
updateToolInConfiguration(
tool.name,
nextConfiguration,
["on"],
!toolActive
);
} else {
nextConfiguration.tools.push({
on: true,
name: toolName,
icon: toolConfig.defaultIcon,
js: Object.keys(toolConfig.paths)[0],
});
}
dispatch(setConfiguration(nextConfiguration));
}}
/>
}
label="ON"
label={toolActive ? "ON" : "OFF"}
labelPlacement="start"
/>
</FormGroup>
<TextField
className={c.text}
variant="filled"
size="small"
value={modal?.tool?.icon || toolConfig?.defaultIcon || ""}
value={tool?.icon || toolConfig?.defaultIcon || ""}
label={"Icon Name"}
onChange={(e) => {
//updateConfiguration(forceField || com.field, e.target.value, layer);
Expand Down
10 changes: 4 additions & 6 deletions configure/src/components/Tabs/Tools/Tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,14 @@ export default function Tools() {
);
}, []);

const handleClick = (toolName, toolConfig, tool) => {
const handleClick = (toolName, toolConfig) => {
dispatch(
setModal({
name: "tool",
on: true,
toolName,
toolConfig,
tool,
onClose: () => {
console.log("closed");
},
onClose: () => {},
})
);
};
Expand All @@ -140,6 +137,7 @@ export default function Tools() {
t = {};
toolActive = false;
}
if (t?.on != null) toolActive = t.on;
cards.push(
<Grid
item
Expand All @@ -149,7 +147,7 @@ export default function Tools() {
lg={4}
xl={3}
onClick={() => {
handleClick(key, tConfig, t);
handleClick(key, tConfig);
}}
>
<div key={idx} className={c.card}>
Expand Down
7 changes: 6 additions & 1 deletion src/essence/Basics/ToolController_/ToolController_.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ let ToolController_ = {
activeBG: 'var(--color-i)',
loaded: false,
init: function (tools) {
this.tools = tools
// remove tools that start have on: false (on null still allowed)
const toolsOn = []
tools.forEach((t) => {
if (t.on !== false) toolsOn.push(t)
})
this.tools = toolsOn

var mainDiv = d3
.select('#toolbar')
Expand Down

0 comments on commit 6f1a3d1

Please sign in to comment.