Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React input editor #5

Merged
merged 24 commits into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c1423bf
Fix modal button still loading
reyery Nov 19, 2019
19aae50
Update style for schedule editor error text
reyery Nov 19, 2019
19b507f
Add tooltips to column headers
reyery Nov 20, 2019
28509fc
Update schedule editor logic for selected buildings
reyery Nov 20, 2019
2fe3a2c
Add diff function for schedules table
reyery Nov 20, 2019
dbf8edf
Fix discard changes message popup too high
reyery Nov 20, 2019
a14de47
Refactor input editor to share table buttons
reyery Nov 21, 2019
68507de
Update data of table instead of replacing when data changes
reyery Nov 21, 2019
e4f33f9
Rewrite updateChanges into a function
reyery Nov 21, 2019
5704325
Add basic input validation for year table
reyery Nov 21, 2019
8479e2d
Adjust column width when selecting new buildings and changing tab
reyery Nov 21, 2019
9aa8955
Add schedule editor redux actions
reyery Nov 21, 2019
a4fba31
Add parameter to fetchBuildingSchedule to fetch all buildings
reyery Nov 22, 2019
f8638e7
Update save and discard changes to include schedules
reyery Nov 22, 2019
a14b4ce
Fix hour header to start from 1 instead of 0
reyery Nov 22, 2019
1124d7c
Fix table redrawing before data is fetched
reyery Nov 22, 2019
93c4b6b
Revert adding fetchBuildingSchedule fetch all parameter
reyery Nov 22, 2019
a399914
Add debouncing to fetching building schedules
reyery Nov 22, 2019
c211020
Fix change summary showing wrong hour
reyery Nov 22, 2019
50552ba
Enable multi selection while holding ctrl
reyery Nov 22, 2019
b6689e1
Add colors to table cells based on its values
reyery Nov 25, 2019
f682eb2
Add tooltip for multi selection
reyery Nov 25, 2019
c791f84
Add GFA to tooltip for zone buildings
reyery Nov 25, 2019
e466bc8
Fix debounce logic for fetching schedules
reyery Nov 25, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"antd": "^3.21.3",
"axios": "^0.19.0",
"babel-plugin-import": "^1.12.0",
"color-interpolate": "^1.0.5",
"connected-react-router": "^6.5.2",
"deck.gl": "^7.2.2",
"electron-updater": "^4.1.2",
Expand Down
112 changes: 65 additions & 47 deletions src/renderer/actions/inputEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export const REQUEST_MAPDATA = 'REQUEST_MAPDATA';
export const RECEIVE_MAPDATA = 'RECEIVE_MAPDATA';
export const SET_SELECTED = 'SET_SELECTED';
export const UPDATE_INPUTDATA = 'UPDATE_INPUTDATA';
export const UPDATE_YEARSCHEDULE = 'UPDATE_YEARSCHEDULE';
export const UPDATE_DAYSCHEDULE = 'UPDATE_DAYSCHEDULE';
export const DELETE_BUILDINGS = 'DELETE_BUILDINGS';
export const SAVE_INPUTDATA = 'SAVE_INPUTDATA';
export const SAVE_INPUTDATA_SUCCESS = 'SAVE_INPUTDATA_SUCCESS';
Expand All @@ -38,69 +40,69 @@ export const fetchInputData = () =>
export const saveChanges = () => (dispatch, getState) =>
// eslint-disable-next-line no-undef
new Promise((resolve, reject) => {
const { tables, geojsons, crs } = getState().inputData;
const { tables, geojsons, crs, schedules } = getState().inputData;
dispatch(
httpAction({
url: '/inputs/all-inputs',
method: 'PUT',
type: SAVE_INPUTDATA,
data: { tables, geojsons, crs },
data: { tables, geojsons, crs, schedules },
onSuccess: data => resolve(data),
onFailure: error => reject(error)
})
);
});

export const fetchBuildingSchedule = buildings => (dispatch, getState) => {
const toFetch = buildings.filter(
building => !Object.keys(getState().inputData.schedules).includes(building)
export const fetchBuildingSchedule = buildings => dispatch => {
dispatch({ type: REQUEST_BUILDINGSCHEDULE });
let errors = {};
const promises = buildings.map(building =>
axios
.get(`http://localhost:5050/api/inputs/building-schedule/${building}`)
.then(resp => {
return { [building]: resp.data };
})
.catch(error => {
errors[building] = error.response.data;
})
);
if (toFetch.length) {
dispatch({ type: REQUEST_BUILDINGSCHEDULE });
let errors = {};
const promises = buildings.map(building =>
axios
.get(`http://localhost:5050/api/inputs/building-schedule/${building}`)
.then(resp => {
return { [building]: resp.data };
})
.catch(error => {
errors[building] = error.response.data;
})
);
// eslint-disable-next-line no-undef
return Promise.all(promises).then(values => {
if (Object.keys(errors).length) {
throw errors;
} else {
let out = {};
for (const schedule of values) {
const building = Object.keys(schedule)[0];
out[building] = schedule[building];
}
dispatch({
type: REQUEST_BUILDINGSCHEDULE_SUCCESS,
payload: out
});
}
});
}
// eslint-disable-next-line no-undef
return Promise.resolve();
return Promise.all(promises).then(values => {
if (Object.keys(errors).length) {
throw errors;
} else {
let out = {};
for (const schedule of values) {
const building = Object.keys(schedule)[0];
out[building] = schedule[building];
}
dispatch({
type: REQUEST_BUILDINGSCHEDULE_SUCCESS,
payload: out
});
}
});
};

export const discardChanges = () => dispatch =>
export const discardChanges = () => (dispatch, getState) =>
// eslint-disable-next-line no-undef
new Promise((resolve, reject) => {
dispatch(
httpAction({
url: '/inputs/all-inputs',
type: DISCARD_INPUTDATA_CHANGES,
onSuccess: data => resolve(data),
onFailure: error => reject(error)
})
);
});
Promise.all([
// eslint-disable-next-line no-undef
new Promise((resolve, reject) => {
dispatch(
httpAction({
url: '/inputs/all-inputs',
type: DISCARD_INPUTDATA_CHANGES,
onSuccess: data => resolve(data),
onFailure: error => reject(error)
})
);
}),
fetchBuildingSchedule(Object.keys(getState().inputData.schedules))(
dispatch,
getState
)
]);

export const updateInputData = (
table = '',
Expand All @@ -111,6 +113,22 @@ export const updateInputData = (
payload: { table, buildings, properties }
});

export const updateYearSchedule = (buildings = [], month = '', value = 0) => ({
type: UPDATE_YEARSCHEDULE,
payload: { buildings, month, value }
});

export const updateDaySchedule = (
buildings = [],
tab = '',
day = '',
hour = 0,
value = ''
) => ({
type: UPDATE_DAYSCHEDULE,
payload: { buildings, tab, day, hour, value }
});

export const deleteBuildings = (buildings = []) => ({
type: DELETE_BUILDINGS,
payload: { buildings }
Expand Down
3 changes: 1 addition & 2 deletions src/renderer/components/InputEditor/InputEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import CenterSpinner from '../HomePage/CenterSpinner';
import NavigationPrompt from './NavigationPrompt';
import { withErrorBoundary } from '../../utils/ErrorBoundary';
import './InputEditor.css';
import ScheduleEditor from './ScheduleEditor';

const MAP_STYLE = {
height: '500px',
Expand Down Expand Up @@ -78,7 +77,7 @@ const InputTable = () => {
{TabPanes}
</Tabs>
<div className="cea-input-editor-table">
{tab != 'schedules' ? <Table tab={tab} /> : <ScheduleEditor />}
<Table tab={tab} />
</div>
</div>
);
Expand Down
8 changes: 8 additions & 0 deletions src/renderer/components/InputEditor/ScheduleEditor.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@
.cea-schedule-no-data {
grid-column: 1/-1;
grid-row: 1/-1;
margin: auto;
}

.cea-schedule-error {
grid-column: 1/-1;
grid-row: 1/-1;
overflow: auto;
text-align: center;
height: 100%;
width: 100%;
}
Loading