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

feat: add vertical tab rendering of sections in a data set #389

Merged
merged 2 commits into from
Jul 4, 2024
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
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)
}
}
Loading