Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion webapp/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sensebox-data-dashboard",
"private": true,
"version": "0.4.1",
"version": "0.4.2",
"description": "sensebox-data-dashboard",
"browserslist": "> 0.5%, last 2 versions, not dead",
"authors": [],
Expand Down
20 changes: 11 additions & 9 deletions webapp/src/components/dashboard_header/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,13 @@ const DashboardHeader = () => {
onClose={() => setOpened(false)}
title="Find a Sensebox"
>
<div className="sbd-search-grid">
<form className="sbd-search-grid" onSubmit={e => {
e?.preventDefault();
posthog.capture("Search SenseBox on dashboard", {
property: searchContent,
});
handleSearchExecution();
}}>
<TextInput
size="md"
defaultValue={searchContent}
Expand All @@ -211,16 +217,12 @@ const DashboardHeader = () => {
/>
<Button
size="md"
onClick={() => {
posthog.capture("Search SenseBox on dashboard", {
property: searchContent,
});
handleSearchExecution();
}}
autoFocus
type="submit"
>
Search
Search
</Button>
</div>
</form>

<Divider
my="xs"
Expand Down
14 changes: 12 additions & 2 deletions webapp/src/pages/dashboard/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import DashboardBoxInfo from "../../components/dashboard_box_info";
import DashboardHeader from "../../components/dashboard_header";
import LiveAnalyticsContainer from "../../containers/live_analytics";
import "./style.scss";
import { useSearchParams } from "react-router-dom";
import { useSearchParams, useNavigate } from "react-router-dom";
import { useDispatch, useSelector } from "react-redux";
import { getSenseboxInfoData } from "../../redux/selectors/appState";
import { requestSenseboxInfoDataFetch } from "../../redux/actions/app_state";
Expand All @@ -22,6 +22,7 @@ const DashboardContext = createContext();

const DashboardContextProvider = (props) => {
const [search] = useSearchParams();
const navigate = useNavigate();
const dispatch = useDispatch();
const senseboxInfoData = useSelector(getSenseboxInfoData);
const [selectedSenseboxId, setSelectedSenseboxId] = useState();
Expand All @@ -39,12 +40,21 @@ const DashboardContextProvider = (props) => {

useEffect(() => {
const param = search.get(CONSTANTS.ROUTING.SENSEBOX_ID);
const lastSenseboxId = localStorage.getItem(CONSTANTS.LAST_SENSEBOX_ID);
if (!param) {
setSelectedSenseboxId(undefined);
if (lastSenseboxId){
//dispatch(requestSenseboxInfoDataFetch({ id: lastSenseboxId }));
//setIsLoadingSenseboxInfoData(true);
navigate(`/dashboard?${CONSTANTS.ROUTING.SENSEBOX_ID}=${lastSenseboxId}`);
//search.set(CONSTANTS.ROUTING.SENSEBOX_ID, lastSenseboxId);
} else {
setSelectedSenseboxId(undefined);
}
} else {
dispatch(requestSenseboxInfoDataFetch({ id: param }));
setIsLoadingSenseboxInfoData(true);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [search, dispatch]);

return (
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/pages/home/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const HomePage = () => {
radius="xl"
size="xl"
component={Link}
to={`/dashboard?${CONSTANTS.ROUTING.SENSEBOX_ID}=61bc908c67e5ad001b462766`}
to="dashboard"
onClick={() =>
posthog.capture(
"Click on button: change page from Landingpage to dashboard",
Expand Down
6 changes: 4 additions & 2 deletions webapp/src/redux/sagas/app_state.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { showNotification } from "@mantine/notifications";
import QUERY_DATA_MODIFIERS from "./api/query_data_modifiers";
import { getSenseboxInfoData } from "../selectors/appState";
import { getLocalTime } from "../../utils/helpers";
import CONSTANTS from "../../utils/constants";

// TODO: implement generic resolution generator function for sagas
/* function* completeSagaAction(success, action, actionValue) {
Expand Down Expand Up @@ -155,6 +156,8 @@ function* fetchSenseboxInfoData(action) {
})
);

localStorage.setItem(CONSTANTS.LAST_SENSEBOX_ID, action?.payload?.id);

const coordinates = rawData?.currentLocation?.coordinates;
if (coordinates) {
const [lon, lat] = coordinates;
Expand Down Expand Up @@ -266,8 +269,7 @@ function* fetchSenseboxSensorData(action) {

const notificationConfig = buildSagaFailNotificationConfig(
"sensebox_sensor_data",
`Could not fetch sensor data for Sensebox (ID: ${
action.payload.senseboxID ?? "NO_ID"
`Could not fetch sensor data for Sensebox (ID: ${action.payload.senseboxID ?? "NO_ID"
})`
);
showNotification(notificationConfig);
Expand Down
25 changes: 13 additions & 12 deletions webapp/src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
const CONSTANTS = {
SENSEBOX_INACTIVITY_TIME_DAYS: 3,
SENSEBOX_SENSOR_INACTIVITY_TIME_HOURS: 25,
MAX_BOOKMARKED_BOXES: 5,
MIN_SENSEBOX_SEARCH_CHARACTERS: 3,
LIVE_ANALYTICS_INTERVAL_STEPS: 5, // s
DEFAULT_NULL_FALLBACK_VALUE: "-",
MIN_LIVE_UPDATE_DISPATCH_INTERVAL: 60, //s
MAX_LIVE_UPDATE_DISPATCH_INTERVAL: 360, //s - 6 minutes
ROUTING: {
SENSEBOX_ID: "boxid"
},
DATE_FORMAT: "MMM Do YY",
SENSEBOX_INACTIVITY_TIME_DAYS: 3,
SENSEBOX_SENSOR_INACTIVITY_TIME_HOURS: 25,
MAX_BOOKMARKED_BOXES: 5,
MIN_SENSEBOX_SEARCH_CHARACTERS: 3,
LIVE_ANALYTICS_INTERVAL_STEPS: 5, // s
DEFAULT_NULL_FALLBACK_VALUE: "-",
MIN_LIVE_UPDATE_DISPATCH_INTERVAL: 60, //s
MAX_LIVE_UPDATE_DISPATCH_INTERVAL: 360, //s - 6 minutes
ROUTING: {
SENSEBOX_ID: "boxid"
},
DATE_FORMAT: "MMM Do YY",
LAST_SENSEBOX_ID: "LAST_SENSEBOX_ID"
};

export default CONSTANTS;