Skip to content

Commit

Permalink
fix: soil selector warning (#1747)
Browse files Browse the repository at this point in the history
* refactor: pull DepthEditor component out of SoilDepthSummary

* chore: update client shared dep

* chore: update dep after merge
  • Loading branch information
tm-ruxandra authored Jul 11, 2024
1 parent 9aac3a8 commit dce64d9
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 54 deletions.
4 changes: 2 additions & 2 deletions dev-client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dev-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"react-native-screens": "^3.32.0",
"react-native-svg": "^15.3.0",
"react-native-tab-view": "^3.5.2",
"terraso-client-shared": "github:techmatters/terraso-client-shared#f059d42",
"terraso-client-shared": "github:techmatters/terraso-client-shared#e1b4e4d",
"uuid": "^10.0.0",
"yup": "^1.4.0"
},
Expand Down
67 changes: 67 additions & 0 deletions dev-client/src/screens/SoilScreen/components/DepthEditor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright © 2024 Technology Matters
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
import {useTranslation} from 'react-i18next';

import {AggregatedInterval} from 'terraso-client-shared/selectors';
import {soilPitMethods} from 'terraso-client-shared/soilId/soilIdSlice';

import {
Heading,
Row,
} from 'terraso-mobile-client/components/NativeBaseAdapters';
import {RestrictBySiteRole} from 'terraso-mobile-client/components/RestrictByRole';
import {EditDepthModal} from 'terraso-mobile-client/screens/SoilScreen/components/EditDepthModal';
import {renderDepth} from 'terraso-mobile-client/screens/SoilScreen/components/RenderValues';

export type DepthEditorProps = {
siteId: string;
aggregatedInterval: AggregatedInterval;
requiredInputs: (typeof soilPitMethods)[number][];
};

export const DepthEditor = ({
siteId,
aggregatedInterval: {isFromPreset, interval},
requiredInputs,
}: DepthEditorProps) => {
const {t} = useTranslation();

return (
<Row
backgroundColor="primary.dark"
justifyContent="space-between"
px="12px"
py="8px">
<Heading variant="h6" color="primary.contrast">
{renderDepth(t, interval)}
</Heading>
<RestrictBySiteRole
role={[
{kind: 'project', role: 'MANAGER'},
{kind: 'project', role: 'CONTRIBUTOR'},
{kind: 'site', role: 'OWNER'},
]}>
<EditDepthModal
siteId={siteId}
depthInterval={interval.depthInterval}
requiredInputs={requiredInputs}
mutable={!isFromPreset}
/>
</RestrictBySiteRole>
</Row>
);
};
54 changes: 3 additions & 51 deletions dev-client/src/screens/SoilScreen/components/SoilDepthSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,60 +29,12 @@ import {
} from 'terraso-client-shared/soilId/soilIdSlice';

import {DataInputSummary} from 'terraso-mobile-client/components/DataInputSummary';
import {
Box,
Column,
Heading,
Row,
} from 'terraso-mobile-client/components/NativeBaseAdapters';
import {RestrictBySiteRole} from 'terraso-mobile-client/components/RestrictByRole';
import {Box, Column} from 'terraso-mobile-client/components/NativeBaseAdapters';
import {useNavigation} from 'terraso-mobile-client/navigation/hooks/useNavigation';
import {EditDepthModal} from 'terraso-mobile-client/screens/SoilScreen/components/EditDepthModal';
import {
pitMethodSummary,
renderDepth,
} from 'terraso-mobile-client/screens/SoilScreen/components/RenderValues';
import {DepthEditor} from 'terraso-mobile-client/screens/SoilScreen/components/DepthEditor';
import {pitMethodSummary} from 'terraso-mobile-client/screens/SoilScreen/components/RenderValues';
import {useSelector} from 'terraso-mobile-client/store';

type DepthEditorProps = {
siteId: string;
aggregatedInterval: AggregatedInterval;
requiredInputs: (typeof soilPitMethods)[number][];
};

const DepthEditor = ({
siteId,
aggregatedInterval: {isFromPreset, interval},
requiredInputs,
}: DepthEditorProps) => {
const {t} = useTranslation();

return (
<Row
backgroundColor="primary.dark"
justifyContent="space-between"
px="12px"
py="8px">
<Heading variant="h6" color="primary.contrast">
{renderDepth(t, interval)}
</Heading>
<RestrictBySiteRole
role={[
{kind: 'project', role: 'MANAGER'},
{kind: 'project', role: 'CONTRIBUTOR'},
{kind: 'site', role: 'OWNER'},
]}>
<EditDepthModal
siteId={siteId}
depthInterval={interval.depthInterval}
requiredInputs={requiredInputs}
mutable={!isFromPreset}
/>
</RestrictBySiteRole>
</Row>
);
};

type Props = {
siteId: string;
requiredInputs: (typeof soilPitMethods)[number][];
Expand Down

0 comments on commit dce64d9

Please sign in to comment.