Skip to content

Commit

Permalink
js: replace envID & by envIDs[0]
Browse files Browse the repository at this point in the history
  • Loading branch information
David Hartmann authored and JackUrb committed Mar 27, 2023
1 parent 6092fb9 commit d046ddf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 34 deletions.
40 changes: 13 additions & 27 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,16 @@ const GridLayout = WidthProvider(ReactGridLayout);
const sortLayout = ReactGridLayout.utils.sortLayoutItemsByRowCol;
const getLayoutItem = ReactGridLayout.utils.getLayoutItem;

var use_env = null;
var use_envs = null;
if (ACTIVE_ENV !== '') {
if (ACTIVE_ENV.indexOf('+') > -1) {
// Compare case
use_env = null;
use_envs = ACTIVE_ENV.split('+');
} else {
// not compare case
use_env = ACTIVE_ENV;
use_envs = [ACTIVE_ENV];
}
} else {
use_env = localStorage.getItem('envID') || 'main';
use_envs = JSON.parse(localStorage.getItem('envIDs')) || ['main'];
}

Expand Down Expand Up @@ -89,7 +85,6 @@ function App() {
const [showViewModal, setShowViewModal] = useState(false);
const [focusedPaneID, setFocusedPaneID] = useState(null);
const [selection, setSelection] = useState({
envID: use_env,
envIDs: use_envs,
layoutID: DEFAULT_LAYOUT,
// Bad form... make a copy of the global var we generated in python.
Expand Down Expand Up @@ -129,7 +124,7 @@ function App() {
// ---------------- //

// append env to pane id for localStorage key
const keyLS = (key) => selection.envID + '_' + key;
const keyLS = (key) => selection.envIDs[0] + '_' + key;

// Ensure the regex filter is valid
const getValidFilter = (filter) => {
Expand Down Expand Up @@ -414,7 +409,7 @@ function App() {
sendSocketMessage({
cmd: 'close',
data: paneID,
eid: selection.envID,
eid: selection.envIDs[0],
});
}

Expand Down Expand Up @@ -460,13 +455,8 @@ function App() {
}
}
}
var envID = null;
if (selectedNodes.length == 1) {
envID = selectedNodes[0];
}
setSelection((prev) => ({
...prev,
envID: envID,
envIDs: selectedNodes,
}));
setStoreData((prev) => ({
Expand All @@ -475,7 +465,6 @@ function App() {
layout: isSameEnv ? storeData.layout : [],
}));
setFocusedPaneID(isSameEnv ? focusedPaneID : null);
localStorage.setItem('envID', envID);
localStorage.setItem('envIDs', JSON.stringify(selectedNodes));
postForEnv(selectedNodes);
};
Expand Down Expand Up @@ -523,7 +512,7 @@ function App() {
sendSocketMessage({
cmd: 'save',
data: payload,
prev_eid: selection.envID,
prev_eid: selection.envIDs[0],
eid: env,
});

Expand All @@ -549,7 +538,6 @@ function App() {
}));
setSelection((prev) => ({
...prev,
envID: env,
envIDs: [env],
}));
};
Expand Down Expand Up @@ -638,8 +626,8 @@ function App() {
};

const getCurrLayoutList = () => {
if (storeMeta.layoutLists.has(selection.envID)) {
return storeMeta.layoutLists.get(selection.envID);
if (storeMeta.layoutLists.has(selection.envIDs[0])) {
return storeMeta.layoutLists.get(selection.envIDs[0]);
} else {
return new Map();
}
Expand Down Expand Up @@ -725,7 +713,7 @@ function App() {
}) => {
sendSocketMessage({
cmd: 'layout_item_update',
eid: selection.envID,
eid: selection.envIDs[0],
win: i,
data: { i, h, w, x, y, moved, static: staticBool },
});
Expand Down Expand Up @@ -800,7 +788,7 @@ function App() {
}
let finalData = {
target: target,
eid: selection.envID,
eid: selection.envIDs[0],
};
$.extend(finalData, data);
sendSocketMessage({
Expand All @@ -815,7 +803,7 @@ function App() {
}
let finalData = {
target: focusedPaneID,
eid: selection.envID,
eid: selection.envIDs[0],
};
$.extend(finalData, data);
sendSocketMessage({
Expand Down Expand Up @@ -853,7 +841,7 @@ function App() {
layoutMap.set(sorted[idx].i, [idx, currLayout.h, currLayout.w]);
}
let layoutLists = storeMeta.layoutLists;
layoutLists.get(selection.envID).set(layoutName, layoutMap);
layoutLists.get(selection.envIDs[0]).set(layoutName, layoutMap);
exportLayoutsToServer(layoutLists);
setStoreMeta((prev) => ({
...prev,
Expand All @@ -868,15 +856,15 @@ function App() {
const onLayoutDelete = (layoutName) => {
// Deletes the selected view, pushes to server
let layoutLists = storeMeta.layoutLists;
layoutLists.get(selection.envID).delete(layoutName);
layoutLists.get(selection.envIDs[0]).delete(layoutName);
exportLayoutsToServer(layoutLists);
setStoreMeta((prev) => ({
...prev,
layoutLists: layoutLists,
}));
setSelection((prev) => ({
...prev,
layoutID: layoutLists.get(selection.envID).keys()[0],
layoutID: layoutLists.get(selection.envIDs[0]).keys()[0],
}));
};

Expand Down Expand Up @@ -909,7 +897,6 @@ function App() {
setSelection((prev) => ({
...prev,
envIDs: ['main'],
envID: 'main',
}));
postForEnv(['main']);
}
Expand Down Expand Up @@ -1008,7 +995,7 @@ function App() {
let modals = [
<EnvModal
key="EnvModal"
activeEnv={selection.envID}
activeEnv={selection.envIDs[0]}
connected={connected}
envList={storeMeta.envList}
onEnvDelete={onEnvDelete}
Expand All @@ -1031,7 +1018,6 @@ function App() {
let envControls = (
<EnvControls
connected={connected}
envID={selection.envID}
envIDs={selection.envIDs}
envList={storeMeta.envList}
envSelectorStyle={{
Expand All @@ -1047,7 +1033,7 @@ function App() {
<ViewControls
activeLayout={selection.layoutID}
connected={connected}
envID={selection.envID}
envIDs={selection.envIDs}
layoutList={getCurrLayoutList()}
onRepackButton={() => {
relayout();
Expand Down
5 changes: 2 additions & 3 deletions js/topbar/EnvControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ function EnvControls(props) {
const {
connected,
envList,
envID,
envIDs,
readonly,
envSelectorStyle,
Expand Down Expand Up @@ -101,7 +100,7 @@ function EnvControls(props) {
title={confirmClear ? 'Are you sure?' : 'Clear Current Environment'}
data-placement="bottom"
className={confirmClear ? 'btn btn-warning' : 'btn btn-default'}
disabled={!(connected && envID && !readonly)}
disabled={!(connected && envIDs.length > 0 && !readonly)}
onClick={() => {
if (confirmClear) {
onEnvClear();
Expand All @@ -117,7 +116,7 @@ function EnvControls(props) {
title="Manage Environments"
data-placement="bottom"
className="btn btn-default"
disabled={!(connected && envID && !readonly)}
disabled={!(connected && envIDs.length > 0 && !readonly)}
onClick={onEnvManageButton}
>
<span className="glyphicon glyphicon-folder-open" />
Expand Down
8 changes: 4 additions & 4 deletions js/topbar/ViewControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import React from 'react';
function ViewControls(props) {
const {
connected,
envID,
envIDs,
activeLayout,
layoutList,
readonly,
Expand Down Expand Up @@ -50,9 +50,9 @@ function ViewControls(props) {
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="true"
disabled={!(connected && envID)}
disabled={!(connected && envIDs.length > 0)}
>
{envID == null ? 'compare' : activeLayout}
{envIDs.length > 0 == null ? 'compare' : activeLayout}
&nbsp;
<span className="caret" />
</button>
Expand All @@ -74,7 +74,7 @@ function ViewControls(props) {
title="Manage Views"
data-placement="bottom"
className="btn btn-default"
disabled={!(connected && envID && !readonly)}
disabled={!(connected && envIDs.length > 0 && !readonly)}
onClick={onViewManageButton}
>
<span className="glyphicon glyphicon-folder-open" />
Expand Down

0 comments on commit d046ddf

Please sign in to comment.