Skip to content

Commit

Permalink
feat: add vertical tab rendering of sections in a data set
Browse files Browse the repository at this point in the history
  • Loading branch information
Flaminia Cavallo authored and Flaminia Cavallo committed Jun 27, 2024
1 parent 30037eb commit a3f389b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
23 changes: 21 additions & 2 deletions src/data-workspace/section-form/section-form.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
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'
Expand All @@ -11,12 +12,17 @@ export const SectionForm = ({ dataSet, globalFilterText }) => {
? dataSet.sections.filter((s) => s.id === sectionId)
: dataSet.sections

const { displayOptions: displayOptionString } = dataSet
const displayOptions =
displayOptionString && JSON.parse(displayOptionString)

if (dataSet.renderAsTabs) {
return (
<TabbedSectionForm
globalFilterText={globalFilterText}
sections={dataSet.sections}
dataSetId={dataSet.id}
direction={displayOptions?.tabsDirection}
/>
)
}
Expand All @@ -37,6 +43,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 +63,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 +105,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)
}
}

0 comments on commit a3f389b

Please sign in to comment.