Skip to content

Commit

Permalink
Merge pull request #905 from PEM-Humboldt/feature/compensationBug
Browse files Browse the repository at this point in the history
Fix HeaderNames bug
  • Loading branch information
erikasv authored Feb 1, 2024
2 parents 3405251 + e37c079 commit 8bcdde8
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 31 deletions.
19 changes: 8 additions & 11 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import "indicators/dist/bundle.css";

import isFlagEnabled from "utils/isFlagEnabled";

import { LogosConfig } from "types/layoutTypes";
import { LogosConfig, Names } from "types/layoutTypes";

import { UserTypes } from "types/loginUimProps";

Expand All @@ -30,7 +30,10 @@ interface LoadComponentTypes {

const App: React.FunctionComponent = () => {
const [user, setUser] = useState<UserTypes | null>(null);
const [headerNames, setHeaderNames] = useState<object>({});
const [headerNames, setHeaderNames] = useState<Names>({
parent: "",
child: "",
});
const [showCBMDashboard, setShowCBMDashboard] = useState<boolean>(false);

const location = useLocation();
Expand All @@ -41,12 +44,6 @@ const App: React.FunctionComponent = () => {

const buildQuery = (queryString: string) => new URLSearchParams(queryString);

const setHeaderNamesFunc = (parent: string, child: string) => {
setHeaderNames({
headerNames: { parent, child },
});
};

const loadHome = () =>
loadComponent({
logoSet: "default",
Expand All @@ -63,7 +60,7 @@ const App: React.FunctionComponent = () => {
<Search
selectedAreaTypeId={query.get("area_type")}
selectedAreaId={query.get("area_id")}
setHeaderNames={setHeaderNamesFunc}
setHeaderNames={setHeaderNames}
/>
),
className: "fullgrid",
Expand All @@ -83,7 +80,7 @@ const App: React.FunctionComponent = () => {
return loadComponent({
logoSet: null,
name: "Compensación ambiental",
component: <Compensation setHeaderNames={setHeaderNamesFunc} />,
component: <Compensation setHeaderNames={setHeaderNames} />,
className: "fullgrid",
});
}
Expand Down Expand Up @@ -139,7 +136,7 @@ const App: React.FunctionComponent = () => {
<Route exact path="/" render={loadHome} />
<Route path="/Consultas" render={loadSearch} />
<Route path="/Indicadores" render={loadIndicator} />
<Route path="/GEB/Compensaciones" component={loadCompensator} />
<Route path="/GEB/Compensaciones" render={loadCompensator} />
<Route path="/Portafolios" render={loadPortfolio} />
<Route path="/Alertas" render={loadHome} />
<Route
Expand Down
7 changes: 1 addition & 6 deletions src/app/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import Footer from "app/layout/Footer";
import Header from "app/layout/Header";

import { LogosConfig } from "types/layoutTypes";

interface Names {
parent?: string;
child?: string;
}
import { LogosConfig, Names } from "types/layoutTypes";

interface LayoutProps {
children: React.ReactNode;
Expand Down
18 changes: 12 additions & 6 deletions src/app/layout/header/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ const Menu: React.FunctionComponent = () => {
const [showCBMDashboard, setShowCBMDashboard] = useState<boolean>(false);

useEffect(() => {
isFlagEnabled("alertsModule").then((value: boolean) =>
setShowAlerts(value)
);
let isMounted = true;

isFlagEnabled("CBMModule").then((value: boolean) =>
setShowCBMDashboard(value)
);
isFlagEnabled("alertsModule").then((value: boolean) => {
if (isMounted) setShowAlerts(value);
});

isFlagEnabled("CBMModule").then((value: boolean) => {
if (isMounted) setShowCBMDashboard(value);
});

return () => {
isMounted = false;
};
}, []);

const changeMenuState = () => {
Expand Down
6 changes: 3 additions & 3 deletions src/pages/Compensation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Compensation extends Component {

componentWillUnmount() {
const { setHeaderNames } = this.props;
setHeaderNames(null, null);
setHeaderNames({ parent: "", child: "" });
}

loadProjectsList = () => {
Expand Down Expand Up @@ -161,7 +161,7 @@ class Compensation extends Component {
currentCompany,
currentProject: { id_region: idRegion, label, prj_status: prjStatus },
} = this.state;
setHeaderNames(`${currentCompany} ${idRegion}`, `${prjStatus} ${label}`);
setHeaderNames({ parent: `${currentCompany} ${idRegion}`, child: `${prjStatus} ${label}` });
});
});
}
Expand Down Expand Up @@ -305,7 +305,7 @@ class Compensation extends Component {
biomesImpacted: [],
}, () => {
const { setHeaderNames } = this.props;
setHeaderNames(null, null);
setHeaderNames({ parent: "", child: "" });
});
this.loadProjectsList();
}
Expand Down
10 changes: 5 additions & 5 deletions src/pages/Search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Search extends Component {

componentWillUnmount() {
const { setHeaderNames } = this.props;
setHeaderNames(null, null);
setHeaderNames({ parent: "", child: "" });
}

/**
Expand Down Expand Up @@ -142,7 +142,7 @@ class Search extends Component {
{ selectedArea: inputId },
() => {
const { selectedAreaType, selectedArea } = this.state;
setHeaderNames(selectedAreaType.name, selectedArea.name);
setHeaderNames({ parent: selectedAreaType.name, child: selectedArea.name });
},
);
} else {
Expand Down Expand Up @@ -1375,7 +1375,7 @@ class Search extends Component {
const { selectedAreaType, selectedArea } = this.state;
if (selectedAreaType && selectedArea) {
history.push(`?area_type=${selectedAreaType.id}&area_id=${selectedArea.id || selectedArea.name}`);
setHeaderNames(selectedAreaType.name, selectedArea.name);
setHeaderNames({ parent: selectedAreaType.name, child: selectedArea.name });
ReactGA.send({ hitType: "pageview", page: location.pathname + location.search, title: "Consultas" });
}
},
Expand Down Expand Up @@ -1413,7 +1413,7 @@ class Search extends Component {
layerError: false,
loadingLayer: true,
}));
setHeaderNames("Polígono", "Área Consultada");
setHeaderNames({ parent: "Polígono", child: "Área Consultada"});
this.updateBounds(polygonBounds);
}

Expand Down Expand Up @@ -1462,7 +1462,7 @@ class Search extends Component {
}, () => {
const { history, setHeaderNames } = this.props;
history.replace(history.location.pathname);
setHeaderNames(null, null);
setHeaderNames({ parent: "", child: "" });
});
}

Expand Down
5 changes: 5 additions & 0 deletions src/types/layoutTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ export interface LogosConfig {
default: Array<KEYS>;
monitoreo: Array<KEYS>;
}

export interface Names {
parent: string;
child: string;
}

0 comments on commit 8bcdde8

Please sign in to comment.