Skip to content

Commit

Permalink
Merge pull request #389 from dhis2/DHIS2-17506/vertical-and-horizonta…
Browse files Browse the repository at this point in the history
…l-tabs

feat: add vertical tab rendering of sections in a data set
  • Loading branch information
flaminic authored Jul 4, 2024
2 parents 30037eb + 09e253b commit ba87a5f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
31 changes: 29 additions & 2 deletions src/data-workspace/section-form/section-form.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
import { Tab, TabBar } from '@dhis2/ui'
import cx from 'classnames'
import PropTypes from 'prop-types'
import React from 'react'
import { useSectionFilter } from '../../shared/index.js'
import { SectionFormSection } from './section.js'
import styles from './section.module.css'

const parseDisplayOptions = (displayOptionString) => {
try {
return displayOptionString && JSON.parse(displayOptionString)
} catch (e) {
console.error(e)
return undefined
}
}

export const SectionForm = ({ dataSet, globalFilterText }) => {
const [sectionId] = useSectionFilter()
const filteredSections = sectionId
? dataSet.sections.filter((s) => s.id === sectionId)
: dataSet.sections

const { displayOptions: displayOptionString } = dataSet
const displayOptions = parseDisplayOptions(displayOptionString)

if (dataSet.renderAsTabs) {
return (
<TabbedSectionForm
globalFilterText={globalFilterText}
sections={dataSet.sections}
dataSetId={dataSet.id}
direction={displayOptions?.tabsDirection}
/>
)
}
Expand All @@ -37,6 +51,9 @@ export const SectionForm = ({ dataSet, globalFilterText }) => {

SectionForm.propTypes = {
dataSet: PropTypes.shape({
displayOptions: PropTypes.shape({
tabsDirection: PropTypes.oneOf(['vertical', 'horizontal']),
}),
id: PropTypes.string,
renderAsTabs: PropTypes.bool,
sections: PropTypes.arrayOf(
Expand All @@ -54,15 +71,24 @@ SectionForm.propTypes = {
globalFilterText: PropTypes.string,
}

const TabbedSectionForm = ({ dataSetId, sections, globalFilterText }) => {
const TabbedSectionForm = ({
dataSetId,
sections,
globalFilterText,
direction,
}) => {
const [sectionId, setSelectedId] = useSectionFilter()

const section = sectionId
? sections.find((s) => s.id === sectionId)
: sections[0]

return (
<div>
<div
className={cx(styles.sectionTabWrapper, {
[styles.verticalSectionTabWrapper]: direction === 'vertical',
})}
>
<TabBar className={styles.sectionTab}>
{sections.map((s) => (
<Tab
Expand All @@ -87,6 +113,7 @@ const TabbedSectionForm = ({ dataSetId, sections, globalFilterText }) => {

TabbedSectionForm.propTypes = {
dataSetId: PropTypes.string,
direction: PropTypes.oneOf(['vertical', 'horizontal']),
globalFilterText: PropTypes.string,
sections: PropTypes.arrayOf(
PropTypes.shape({
Expand Down
21 changes: 20 additions & 1 deletion src/data-workspace/section-form/section.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,25 @@

.sectionTab {
margin-bottom: 8px;

}

.verticalSectionTabWrapper .sectionTab div{
flex-direction: column;
}

.sectionTab button{
align-self: stretch;
}

.sectionTabWrapper{
display: flex;
gap: 6px;
flex-direction: column;
}

.verticalSectionTabWrapper{
flex-direction: row;
}

@media print {
Expand All @@ -85,4 +104,4 @@
.sectionDescription :global(a):hover,
.sectionDescription :global(a):active {
color: var(--colors-blue700)
}
}

1 comment on commit ba87a5f

@dhis2-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.