Skip to content

Commit

Permalink
Merged in bcal-171-offline-toggle-fix (pull request #6135)
Browse files Browse the repository at this point in the history
BCAL-171: Fixing offline case to farmer, pesisting field mode state in localstorage, bumping version to 2.4.3

Approved-by: Dennis Hernandez
  • Loading branch information
jtoliver-quoin committed Aug 25, 2022
2 parents 39f86f8 + 826c119 commit 48f20ed
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const Datatable = ({
checkOnline = false,
columns,
data,
defaultFilters,
defaultFilters = fromJS({}),
errors,
isRowSelectable,
loading,
Expand All @@ -53,8 +53,8 @@ const Datatable = ({
const filters = useMemoizedSelector(state => getFilters(state, recordType));

const hasData = !loading && Boolean(data?.size);
const order = filters.get("order");
const orderBy = filters.get("order_by");
const order = filters?.get("order");
const orderBy = filters?.get("order_by");
const componentColumns = buildComponentColumns(
typeof columns === "function" ? columns(data) : columns,
order,
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/components/nav/component.unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ describe("<Nav />", () => {
it("should fetch alerts", () => {
const storeActions = component.props().store.getActions();

expect(storeActions[0]).to.deep.equal(expectedAction);
expect(storeActions[7]).to.deep.equal(expectedAction);
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { ListItem, ListItemIcon, ListItemText } from "@material-ui/core";
import { useDispatch } from "react-redux";
import { useState, useEffect } from "react";

import { useI18n } from "../../../i18n";
import { setUserToggleOffline } from "../../../connectivity/action-creators";
import ListIcon from "../../../list-icon";
import { useMemoizedSelector } from "../../../../libs";
import { getFieldMode } from "../../../application/selectors";
import ToggleSwitch from "../toggle-switch/component";
import { selectUserToggleOffline } from "../../../connectivity/selectors";

import css from "./styles.css";

Expand All @@ -16,7 +16,22 @@ function Component() {
const dispatch = useDispatch();

const fieldMode = useMemoizedSelector(state => getFieldMode(state));
const fieldModeStatus = useMemoizedSelector(state => selectUserToggleOffline(state));

const [fieldModeStatus, setFieldModeStatus] = useState(localStorage.getItem("fieldMode") === "true");

const setFieldMode = checked => {
setFieldModeStatus(checked);

dispatch(setUserToggleOffline(checked));
};

useEffect(() => {
localStorage.setItem("fieldMode", fieldModeStatus);
}, [fieldModeStatus]);

useEffect(() => {
dispatch(setUserToggleOffline(fieldModeStatus));
}, []);

if (!fieldMode) {
return false;
Expand All @@ -25,7 +40,7 @@ function Component() {
const handleStatusChange = event => {
const { checked } = event.target;

dispatch(setUserToggleOffline(checked));
setFieldMode(checked);
};

const mode = {
Expand All @@ -47,7 +62,7 @@ function Component() {
<ListIcon icon={mode.icon} />
</ListItemIcon>
<ListItemText classes={{ primary: css.listText }}>{i18n.t("field_mode", { mode: mode.text })}</ListItemText>
<ToggleSwitch color="default" onChange={handleStatusChange} value={fieldModeStatus} />
<ToggleSwitch color="default" onChange={handleStatusChange} checked={fieldModeStatus} />
</ListItem>
);
}
Expand Down
2 changes: 1 addition & 1 deletion config/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

class Primero::Application
VERSION = '2.4.2.4'
VERSION = '2.4.3'
end

0 comments on commit 48f20ed

Please sign in to comment.