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: avoid breaking selects (v39) [DHIS2-16264] (#1963) #1965

Merged
merged 1 commit into from
Dec 15, 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
2 changes: 1 addition & 1 deletion src/components/ElementSchemes/DataElementIdScheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
fetchAttributes(`${baseUrl}/api/`, 'dataElementAttribute')
.then((attributes) => setSchemes(attributes))
.catch((error) => setError(error))
setLoading(false)
.finally(() => setLoading(false))
}, [])

Check warning on line 26 in src/components/ElementSchemes/DataElementIdScheme.js

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has a missing dependency: 'baseUrl'. Either include it or remove the dependency array

const validationText =
error &&
Expand Down
2 changes: 1 addition & 1 deletion src/components/ElementSchemes/OrgUnitIdScheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
fetchAttributes(`${baseUrl}/api/`, 'organisationUnitAttribute')
.then((attributes) => setSchemes(attributes))
.catch((error) => setError(error))
setLoading(false)
.finally(() => setLoading(false))
}, [])

Check warning on line 21 in src/components/ElementSchemes/OrgUnitIdScheme.js

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has a missing dependency: 'baseUrl'. Either include it or remove the dependency array

const validationText =
error &&
Expand Down
18 changes: 15 additions & 3 deletions src/components/MoreOptions/MoreOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import PropTypes from 'prop-types'
import React, { useState } from 'react'
import styles from './MoreOptions.module.css'

/**
* If not initially visible, doesn't render children. After opening the first
* time, however, children are instead hidden by CSS on toggle to preserve
* state
*/
const MoreOptions = ({
children,
initiallyVisible,
Expand All @@ -13,8 +18,12 @@ const MoreOptions = ({
dataTest = 'interaction-more-options',
}) => {
const [hidden, setHidden] = useState(!initiallyVisible)
const [hasOpened, setHasOpened] = useState(initiallyVisible)

const onToggle = () => {
if (!hasOpened) {
setHasOpened(true)
}
setHidden(!hidden)
}

Expand All @@ -38,9 +47,12 @@ const MoreOptions = ({
</div>
<h2 className={styles.label}>{label}</h2>
</header>
<Divider />
<div className={styles.children} data-test={`${dataTest}-children`}>
{!hidden && children}
{!hidden && <Divider />}
<div
className={cx(styles.children, { [styles.hidden]: hidden })}
data-test={`${dataTest}-children`}
>
{hasOpened && children}
</div>
</section>
)
Expand Down
4 changes: 4 additions & 0 deletions src/components/MoreOptions/MoreOptions.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
margin-top: var(--spacers-dp4);
}

.hidden {
display: none;
}

.header svg {
margin-left: -3px;
margin-right: 5px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ exports[`matches snapshot when not toggled 1`] = `
</h2>
</header>
<div
class="jsx-1555285825 jsx-876534464 "
data-test="dhis2-uicore-divider"
/>
<div
class="children"
class="children hidden"
data-test="more-options-children"
/>
</section>
Expand Down
6 changes: 1 addition & 5 deletions src/components/Page/__snapshots__/Page.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -563,11 +563,7 @@ exports[`matches snapshot when not loading and a mini summary task 1`] = `
</h2>
</header>
<div
class="jsx-1555285825 jsx-876534464 "
data-test="dhis2-uicore-divider"
/>
<div
class="children"
class="children hidden"
data-test="mini-job-summary-container-MoreOptions-children"
/>
</section>
Expand Down
Loading