Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
Fix validation in PlantingAttributeEditForm for multi-selected plants…
Browse files Browse the repository at this point in the history
… and areas (#1280)

This PR fixes the connetected issue #1211. The zod validator for the
plant attribute form is adapted and a typo in calculating the common
area/plant sizes is fixed which lead to additional trouble.

<!--
Check relevant points but **please do not remove entries**.
-->

## Basics

<!--
These points need to be fulfilled for every PR.
-->

- [x] The PR is rebased with current master
- [x] I added a line to [changelog.md](/doc/changelog.md)
- [x] Details of what I changed are in the commit messages
- [x] References to issues, e.g. `close #X`, are in the commit messages
and changelog
- [x] The buildserver is happy

<!--
If you have any troubles fulfilling these criteria, please write about
the trouble as comment in the PR.
We will help you, but we cannot accept PRs that do not fulfill the
basics.
-->

## Checklist

<!--
For documentation fixes, spell checking, and similar none of these
points below need to be checked.
Otherwise please check these points when getting a PR done:
-->

- [x] I fully described what my PR does in the documentation
- [ ] I fixed all affected documentation
- [ ] I fixed the introduction tour
- [ ] I wrote migrations in a way that they are compatible with already
present data
- [ ] I fixed all affected decisions
- [ ] I added automated tests or a [manual test
protocol](../doc/tests/manual/protocol.md)
- [ ] I added code comments, logging, and assertions as appropriate
- [ ] I translated all strings visible to the user
- [ ] I mentioned [every code or
binary](https://github.com/ElektraInitiative/PermaplanT/blob/master/.reuse/dep5)
not directly written or done by me in [reuse
syntax](https://reuse.software/)
- [x] I created left-over issues for things that are still to be done
- [x] Code is conforming to [our Architecture](/doc/architecture)
- [x] Code is conforming to [our Guidelines](/doc/guidelines)
- [x] Code is consistent to [our Design Decisions](/doc/decisions)
- [ ] Exceptions to any guidelines are documented

## Review

<!--
Reviewers can copy&check the following to their review.
Also the checklist above can be used.
But also the PR creator should check these points when getting a PR
done:
-->

- [ ] I've tested the code
- [ ] I've read through the whole code
- [ ] I've read through the whole documentation
- [ ] I've checked conformity to guidelines
- [ ] I've checked conformity to requirements
- [ ] I've checked that the requirements are tested
  • Loading branch information
markus2330 authored Apr 12, 2024
2 parents bb2fd90 + 4c8ce27 commit 3383e93
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion doc/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Syntax: `- short text describing the change _(Your Name)_`
- Refactor transformer into a separate store _(Paul)_
- Replace old date picker with new timeline component using sliders to select date _(Daniel Steinkogler)_
- Fix broken dark mode for LanguageSwitcher, SelectMenu & PaginatedSelectMenu _(Lukas Anton Lakits)_
- _()_
- Fix validation in PlantingAttributeEditForm for multi-selected plants and areas _(Lukas Anton Lakits)_
- Fixed small issues in the documentation (typos/links/phrasing) _(Andrei Dinu)_

## 0.3.6 - 21.11.2023 (151 commits)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const PlantingAttributeEditFormSchema = z
addDate: z.nullable(z.string()).transform((value) => value || undefined),
removeDate: z.nullable(z.string()).transform((value) => value || undefined),
plantingNotes: z.nullable(z.string()),
sizeX: z.number().int().nullable(),
sizeY: z.number().int().nullable(),
sizeX: z.optional(z.number().int()),
sizeY: z.optional(z.number().int()),
})
.refine((schema) => !schema.removeDate || !schema.addDate || schema.addDate < schema.removeDate, {
path: ['dateRelation'],
Expand Down Expand Up @@ -139,12 +139,12 @@ export function MultiplePlantingsAttributeForm({

const getCommonWidth = () => {
const comparisonWidth = plantings[0].sizeX;
const existsCommonWidth = plantings.every((planting) => planting.sizeY === comparisonWidth);
const existsCommonWidth = plantings.every((planting) => planting.sizeX === comparisonWidth);
return existsCommonWidth ? comparisonWidth : undefined;
};

const getCommonHeight = () => {
const comparisonHeight = plantings[0].sizeX;
const comparisonHeight = plantings[0].sizeY;
const existsCommonHeight = plantings.every((planting) => planting.sizeY === comparisonHeight);
return existsCommonHeight ? comparisonHeight : undefined;
};
Expand Down

0 comments on commit 3383e93

Please sign in to comment.