Skip to content

Commit

Permalink
fix(period-select): update when periodType changes (#61)
Browse files Browse the repository at this point in the history
* chore: fix prop-type warnings in tests and runtime

* fix(period-select): do not render selection UI if year is unavailable

* fix(period-select): update year when periodType changes
  • Loading branch information
HendrikThePendric authored Aug 24, 2021
1 parent 5652efe commit ab91327
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/top-bar/context-select/context-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ const ContextSelect = ({
}

ContextSelect.propTypes = {
children: PropTypes.node.isRequired,
dataTest: PropTypes.string.isRequired,
placeholder: PropTypes.string.isRequired,
prefix: PropTypes.string.isRequired,
onClose: PropTypes.func.isRequired,
onOpen: PropTypes.func.isRequired,
children: PropTypes.node,
disabled: PropTypes.bool,
open: PropTypes.bool,
popoverMaxWidth: PropTypes.number,
Expand Down
1 change: 1 addition & 0 deletions src/top-bar/context-select/context-select.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('<ContextSelect>', () => {
value: 'value',
onClose: () => {},
onOpen: () => {},
dataTest: 'context-select',
}
describe('base state - not open or disabled', () => {
const onOpen = jest.fn()
Expand Down
2 changes: 1 addition & 1 deletion src/top-bar/org-unit-select/org-unit-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const OrgUnitSelect = () => {
)}
/>
</div>
<Divider margin={0} />
<Divider margin="0" />
<ApprovalStatusIconsLegend />
</div>
</ContextSelect>
Expand Down
30 changes: 20 additions & 10 deletions src/top-bar/period-select/period-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ const PeriodSelect = () => {

useEffect(() => {
if (workflow?.periodType) {
setMaxYear(computeMaxYear(workflow?.periodType))
const newMaxYear = computeMaxYear(workflow?.periodType)
setMaxYear(newMaxYear)

if (!period?.year) {
setYear(newMaxYear)
}
}
}, [workflow?.periodType])

Expand All @@ -45,15 +50,20 @@ const PeriodSelect = () => {
onClose={() => setOpenedSelect('')}
requiredValuesMessage={i18n.t('Choose a workflow first')}
>
<YearNavigator
maxYear={maxYear}
year={year}
onYearChange={year => {
selectPeriod(null)
setYear(year)
}}
/>
<PeriodMenu periodType={workflow?.periodType} year={year} />
{year && (
<>
<YearNavigator
maxYear={maxYear}
year={year}
onYearChange={year => {
selectPeriod(null)
setYear(year)
}}
/>

<PeriodMenu periodType={workflow?.periodType} year={year} />
</>
)}
</ContextSelect>
)
}
Expand Down

0 comments on commit ab91327

Please sign in to comment.