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

fix: data crashes #1116

Merged
merged 1 commit into from
Oct 5, 2023
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
16 changes: 12 additions & 4 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import {
getOrganizationData,
getPickLists,
getProjects,
} from './store/actions/climateWarehouseActions';
import { initiateSocket } from './store/actions/socket';

Expand All @@ -28,12 +29,19 @@ const App = () => {
const { socketStatus } = useSelector(state => state.app);
const appStore = useSelector(state => state.app);
const [translationTokens, setTranslationTokens] = useState();
const { projects } = useSelector(store => store.climateWarehouse);

useEffect(() => {
dispatch(initiateSocket(appStore.serverAddress));
dispatch(getOrganizationData());
dispatch(getPickLists());
dispatch(getUser());

const hydrateData = () => {
dispatch(getOrganizationData());
dispatch(getPickLists());
dispatch(getUser());
dispatch(getProjects({ useMockedResponse: false, useApiMock: false }));
};

hydrateData();
}, [dispatch, appStore.serverAddress]);

useEffect(() => {
Expand All @@ -52,7 +60,7 @@ const App = () => {
}
}, [appStore.locale]);

if (!translationTokens) {
if (!translationTokens || !projects) {
return <IndeterminateProgressOverlay />;
}

Expand Down
6 changes: 5 additions & 1 deletion src/components/blocks/APIDataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,14 @@ const APIDataTable = withTheme(

const getFullRecord = useCallback(
partialRecord => {
if (!projects) {
return null;
}

let fullRecord = null;

if (actions === 'Projects') {
fullRecord = projects.filter(
fullRecord = projects?.filter(
project =>
project.warehouseProjectId === partialRecord.warehouseProjectId,
)[0];
Expand Down
26 changes: 19 additions & 7 deletions src/components/blocks/UnitsDetails.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import React, { useMemo, useEffect } from 'react';
import { FormattedMessage } from 'react-intl';
import { useSelector } from 'react-redux';
import { useSelector, useDispatch } from 'react-redux';
import { useNavigate, useLocation } from 'react-router-dom';
import styledComponents from 'styled-components';

Expand All @@ -14,6 +14,7 @@ import { SpanTwoColumnsContainer } from '../layout';
import { detailsViewData } from '../../utils/functionUtils';
import { MagnifyGlassIcon } from '..';
import { getUpdatedUrl } from '../../utils/urlUtils';
import { getProjects } from '../../store/actions/climateWarehouseActions';

const StyledCursor = styledComponents('div')`
cursor: zoom-in;
Expand All @@ -23,17 +24,28 @@ const UnitsDetails = ({ data, stagingData, changeColor }) => {
const { issuances, projects } = useSelector(store => store.climateWarehouse);
const navigate = useNavigate();
let location = useLocation();
const dispatch = useDispatch();

useEffect(() => {
dispatch(getProjects({ useMockedResponse: false, useApiMock: false }));
}, [data]);

const unitBelongsToProjectId =
data &&
issuances?.filter(issuanceItem => issuanceItem.id === data.issuanceId)[0]
?.warehouseProjectId;

const unitBelongsToProjectName =
data &&
projects?.filter(
projectItem => projectItem.warehouseProjectId === unitBelongsToProjectId,
)[0]?.projectName;
const unitBelongsToProjectName = useMemo(() => {
if (data && projects) {
const projectData = projects.data || projects;
return projectData?.filter(
projectItem =>
projectItem.warehouseProjectId === unitBelongsToProjectId,
)[0]?.projectName;
}

return '--';
}, [data, projects]);

const projectUrl =
data &&
Expand Down
4 changes: 2 additions & 2 deletions src/components/forms/ProjectEditModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ const ProjectEditModal = ({
}) => {
const projectToBeEdited = useSelector(
state =>
state.climateWarehouse.projects.filter(
state.climateWarehouse.projects?.filter(
project => project.warehouseProjectId === record.warehouseProjectId,
)[0],
)?.[0],
);
const [project, setProject] = useState(null);
const [tabValue, setTabValue] = useState(0);
Expand Down
4 changes: 2 additions & 2 deletions src/components/forms/ProjectTransferModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ const ProjectTransferModal = ({
}) => {
const projectToBeTransferred = useSelector(
state =>
state.climateWarehouse.projects.filter(
state.climateWarehouse.projects?.filter(
project => project.warehouseProjectId === record.warehouseProjectId,
)[0],
)?.[0],
);
const [project, setProject] = useState(null);
const [tabValue, setTabValue] = useState(0);
Expand Down
60 changes: 40 additions & 20 deletions src/components/forms/UnitDetailsForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ const UnitDetailsForm = () => {

const projectsSelectOptions = useMemo(() => {
if (myProjects) {
return myProjects.map(projectItem => ({
const projectData = myProjects.data || myProjects;
return projectData.map(projectItem => ({
value: projectItem,
label: projectItem.projectName,
}));
Expand Down Expand Up @@ -155,7 +156,8 @@ const UnitDetailsForm = () => {
<ToolTipContainer
tooltip={intl.formatMessage({
id: 'select-existing-project',
})}>
})}
>
<DescriptionIcon height="14" width="14" />
</ToolTipContainer>
</Body>
Expand Down Expand Up @@ -211,7 +213,8 @@ const UnitDetailsForm = () => {
<ToolTipContainer
tooltip={intl.formatMessage({
id: 'units-project-location-id-description',
})}>
})}
>
<DescriptionIcon height="14" width="14" />
</ToolTipContainer>
</Body>
Expand Down Expand Up @@ -249,7 +252,8 @@ const UnitDetailsForm = () => {
<ToolTipContainer
tooltip={intl.formatMessage({
id: 'units-unit-owner-description',
})}>
})}
>
<DescriptionIcon height="14" width="14" />
</ToolTipContainer>
</Body>
Expand Down Expand Up @@ -283,7 +287,8 @@ const UnitDetailsForm = () => {
<ToolTipContainer
tooltip={intl.formatMessage({
id: 'units-unit-block-start-description',
})}>
})}
>
<DescriptionIcon height="14" width="14" />
</ToolTipContainer>
</Body>
Expand Down Expand Up @@ -317,7 +322,8 @@ const UnitDetailsForm = () => {
<ToolTipContainer
tooltip={intl.formatMessage({
id: 'units-unit-block-end-description',
})}>
})}
>
<DescriptionIcon height="14" width="14" />
</ToolTipContainer>
</Body>
Expand Down Expand Up @@ -351,7 +357,8 @@ const UnitDetailsForm = () => {
<ToolTipContainer
tooltip={intl.formatMessage({
id: 'units-unit-count-description',
})}>
})}
>
<DescriptionIcon height="14" width="14" />
</ToolTipContainer>
</Body>
Expand Down Expand Up @@ -385,7 +392,8 @@ const UnitDetailsForm = () => {
<ToolTipContainer
tooltip={intl.formatMessage({
id: 'units-in-country-jurisdiction-of-owner-description',
})}>
})}
>
<DescriptionIcon height="14" width="14" />
</ToolTipContainer>
</Body>
Expand Down Expand Up @@ -422,7 +430,8 @@ const UnitDetailsForm = () => {
<ToolTipContainer
tooltip={intl.formatMessage({
id: 'units-country-jurisdiction-of-owner-description',
})}>
})}
>
<DescriptionIcon height="14" width="14" />
</ToolTipContainer>
</Body>
Expand Down Expand Up @@ -453,7 +462,8 @@ const UnitDetailsForm = () => {
<ToolTipContainer
tooltip={intl.formatMessage({
id: 'units-unit-type-description',
})}>
})}
>
<DescriptionIcon height="14" width="14" />
</ToolTipContainer>
</Body>
Expand Down Expand Up @@ -482,7 +492,8 @@ const UnitDetailsForm = () => {
<ToolTipContainer
tooltip={intl.formatMessage({
id: 'units-unit-status-description',
})}>
})}
>
<DescriptionIcon height="14" width="14" />
</ToolTipContainer>
</Body>
Expand Down Expand Up @@ -512,7 +523,8 @@ const UnitDetailsForm = () => {
<ToolTipContainer
tooltip={intl.formatMessage({
id: 'units-unit-status-reason-description',
})}>
})}
>
<DescriptionIcon height="14" width="14" />
</ToolTipContainer>
</Body>
Expand Down Expand Up @@ -546,7 +558,8 @@ const UnitDetailsForm = () => {
<ToolTipContainer
tooltip={intl.formatMessage({
id: 'units-unit-registry-link-description',
})}>
})}
>
<DescriptionIcon height="14" width="14" />
</ToolTipContainer>
</Body>
Expand Down Expand Up @@ -579,7 +592,8 @@ const UnitDetailsForm = () => {
<ToolTipContainer
tooltip={intl.formatMessage({
id: 'units-vintage-year-description',
})}>
})}
>
<DescriptionIcon height="14" width="14" />
</ToolTipContainer>
</Body>
Expand Down Expand Up @@ -612,7 +626,8 @@ const UnitDetailsForm = () => {
<ToolTipContainer
tooltip={intl.formatMessage({
id: 'units-marketplace-description',
})}>
})}
>
<DescriptionIcon height="14" width="14" />
</ToolTipContainer>
</Body>
Expand Down Expand Up @@ -646,7 +661,8 @@ const UnitDetailsForm = () => {
<ToolTipContainer
tooltip={intl.formatMessage({
id: 'units-marketplace-identifier-description',
})}>
})}
>
<DescriptionIcon height="14" width="14" />
</ToolTipContainer>
</Body>
Expand Down Expand Up @@ -683,7 +699,8 @@ const UnitDetailsForm = () => {
<ToolTipContainer
tooltip={intl.formatMessage({
id: 'units-marketplace-link-description',
})}>
})}
>
<DescriptionIcon height="14" width="14" />
</ToolTipContainer>
</Body>
Expand Down Expand Up @@ -717,7 +734,8 @@ const UnitDetailsForm = () => {
<ToolTipContainer
tooltip={intl.formatMessage({
id: 'units-corresponding-adjustment-declaration-description',
})}>
})}
>
<DescriptionIcon height="14" width="14" />
</ToolTipContainer>
</Body>
Expand Down Expand Up @@ -748,7 +766,8 @@ const UnitDetailsForm = () => {
<ToolTipContainer
tooltip={intl.formatMessage({
id: 'units-corresponding-adjustment-status-description',
})}>
})}
>
<DescriptionIcon height="14" width="14" />
</ToolTipContainer>
</Body>
Expand Down Expand Up @@ -783,7 +802,8 @@ const UnitDetailsForm = () => {
<ToolTipContainer
tooltip={intl.formatMessage({
id: 'units-unit-tags-description',
})}>
})}
>
<DescriptionIcon height="14" width="14" />
</ToolTipContainer>
</Body>
Expand Down
4 changes: 3 additions & 1 deletion src/pages/Projects/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,9 @@ const Projects = withTheme(({ theme }) => {
return null;
}

return projects.map(project =>
const projectData = projects.data || projects;

return projectData.map(project =>
_.pick(project, [
'warehouseProjectId',
'currentRegistry',
Expand Down
Loading