Skip to content

Commit

Permalink
Merge pull request #58 from indec-it/feat/sectionHeaderStatus
Browse files Browse the repository at this point in the history
feat(sectionHeader): add icon status
  • Loading branch information
maximilianoforlenza authored Jul 12, 2023
2 parents 89e163b + 5da5730 commit 253dbb5
Show file tree
Hide file tree
Showing 7 changed files with 2,481 additions and 1,914 deletions.
4,291 changes: 2,407 additions & 1,884 deletions package-lock.json

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@indec/form-builder",
"version": "1.10.1",
"version": "1.11.0",
"description": "Form builder",
"main": "index.js",
"private": false,
Expand Down Expand Up @@ -41,14 +41,14 @@
"@babel/preset-react": "^7.18.6",
"@commitlint/cli": "^17.6.3",
"@commitlint/config-conventional": "^17.6.3",
"@storybook/addon-actions": "^7.0.12",
"@storybook/addon-essentials": "^7.0.12",
"@storybook/addon-interactions": "^7.0.12",
"@storybook/addon-links": "^7.0.12",
"@storybook/cli": "^7.0.12",
"@storybook/react": "^7.0.12",
"@storybook/react-webpack5": "^7.0.12",
"@storybook/testing-library": "^0.1.0",
"@storybook/addon-actions": "^7.0.26",
"@storybook/addon-essentials": "^7.0.26",
"@storybook/addon-interactions": "^7.0.26",
"@storybook/addon-links": "^7.0.26",
"@storybook/cli": "^7.0.26",
"@storybook/react": "^7.0.26",
"@storybook/react-webpack5": "^7.0.26",
"@storybook/testing-library": "^0.2.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.0.0",
"babel-loader": "^9.1.2",
Expand All @@ -68,7 +68,7 @@
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"jest-watch-typeahead": "^2.2.2",
"storybook": "^7.0.12"
"storybook": "^7.0.26"
},
"dependencies": {
"@emotion/react": "^11.11.0",
Expand Down
11 changes: 3 additions & 8 deletions src/components/FormBuilder/FormBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ function FormBuilder({
<FieldArray
name={section.name}
render={
sectionHelpers => values
&& values[section.name]
&& values[section.name].map((currentSection, index) => (
sectionHelpers => values?.[section.name]?.map((currentSection, index) => (
<Box key={currentSection.id} mb={2}>
{
components.SectionHeader
Expand All @@ -90,6 +88,7 @@ function FormBuilder({
section={section}
values={currentSection}
isReadOnly={isReadOnly}
isValid={validateSchema.isValidSync({[section.name]: [currentSection]})}
/>
)
: (
Expand All @@ -101,6 +100,7 @@ function FormBuilder({
section={section}
values={currentSection}
isReadOnly={isReadOnly}
isValid={validateSchema.isValidSync({[section.name]: [currentSection]})}
/>
)
}
Expand All @@ -117,11 +117,6 @@ function FormBuilder({
)}
<Modals
open={selectedSectionId === currentSection.id}
values={currentSection}
index={index}
section={section}
readOnlyMode
cancelButtonLabel="Cerrar"
options={section.interruption.options}
label={section.interruption.reason}
name={`${section.name}.${index}.${section.interruption.name}`}
Expand Down
20 changes: 20 additions & 0 deletions src/components/FormBuilder/FormBuilder.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,26 @@ WithInitialValues.args = {
value: 12345678
}
]
},
S1P4: {
id: 4,
answer: {
value: '1',
specifications: {
S1P1SQ1: {
id: 1,
answer: {
value: 'test'
}
},
S1P1SQ2: {
id: 2,
answer: {
value: ''
}
}
}
}
}
}
]
Expand Down
9 changes: 2 additions & 7 deletions src/components/FormBuilder/Modals/Modals.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@ const getChildren = (modal, {options, label, name}) => {
};

function Modals({
modal, acceptButtonLabel, cancelButtonLabel, onAccept, open, onClose, ...props
modal, onAccept, open, onClose, ...props
}) {
return (
<Modal
open={open}
modal={modal}
acceptButtonLabel={acceptButtonLabel}
cancelButtonLabel={cancelButtonLabel}
cancelButtonLabel="Cerrar"
onAccept={onAccept}
onClose={onClose}
>
Expand All @@ -47,17 +46,13 @@ function Modals({
Modals.propTypes = {
onClose: PropTypes.func.isRequired,
onAccept: PropTypes.func,
acceptButtonLabel: PropTypes.string,
cancelButtonLabel: PropTypes.string,
modal: PropTypes.oneOf(Object.values(modals)),
selectedSection: PropTypes.number,
open: PropTypes.bool
};

Modals.defaultProps = {
onAccept: undefined,
acceptButtonLabel: undefined,
cancelButtonLabel: undefined,
selectedSection: undefined,
modal: undefined,
open: false
Expand Down
19 changes: 15 additions & 4 deletions src/components/FormBuilder/SectionHeader/SectionHeader.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import PropTypes from 'prop-types';
import Box from '@mui/material/Box';
import Stack from '@mui/material/Stack';
import IconButton from '@mui/material/IconButton';
import Typography from '@mui/material/Typography';
import CheckCircleIcon from '@mui/icons-material/CheckCircle';
import ErrorIcon from '@mui/icons-material/Error';
import DeleteIcon from '@mui/icons-material/Delete';
import EditIcon from '@mui/icons-material/Edit';
import VisibilityIcon from '@mui/icons-material/Visibility';
Expand Down Expand Up @@ -33,7 +36,7 @@ const getHeaders = (questions, values, headers) => {
};

function SectionHeader({
section, sectionsLength, onView, onEdit, onDelete, values, isReadOnly
section, sectionsLength, onView, onEdit, onDelete, values, isReadOnly, isValid
}) {
return (
<Box sx={{
Expand All @@ -45,13 +48,20 @@ function SectionHeader({
flexWrap: 'wrap'
}}
>
<Box sx={{display: 'flex', flexDirection: 'column'}}>
<Typography variant="h6" fontWeight="bold">{section.label}</Typography>
<Stack>
<Stack direction="row" spacing={2} justifyContent="center" alignItems="center">
<Typography variant="h6" fontWeight="bold">{section.label}</Typography>
{
isValid
? <CheckCircleIcon color="success" data-testid="success-icon" />
: <ErrorIcon color="error" data-testid="error-icon" />
}
</Stack>
{section.introduction && (
<Typography data-testid="introduction" fontWeight="bold" color="gray">{section.introduction}</Typography>
)}
<Typography>{getHeaders(section.questions, values, section.headers)}</Typography>
</Box>
</Stack>
<Box>
<IconButton data-testid="read-only-button" color="warning" onClick={onView}>
<VisibilityIcon />
Expand Down Expand Up @@ -80,6 +90,7 @@ SectionHeader.propTypes = {
sectionsLength: PropTypes.number.isRequired,
section: sectionPropTypes.isRequired,
values: PropTypes.shape({}).isRequired,
isValid: PropTypes.bool.isRequired,
isReadOnly: PropTypes.bool
};

Expand Down
25 changes: 24 additions & 1 deletion src/components/FormBuilder/SectionHeader/SectionHeader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ describe('<SectionHeader>', () => {
values: {
S1P1: {id: 1, answer: {value: ''}},
S1P2: {id: 2, answer: {value: ''}}
}
},
isValid: false
};
});

Expand Down Expand Up @@ -195,4 +196,26 @@ describe('<SectionHeader>', () => {
});
});
});

describe('when `props.isValid` is `false`', () => {
beforeEach(() => {
props.isValid = false;
});

it('should render an error icon', () => {
const {container} = getComponent();
expect(getByTestId(container, 'error-icon')).toBeInTheDocument();
});
});

describe('when `props.isValid` is `true`', () => {
beforeEach(() => {
props.isValid = true;
});

it('should render a check icon', () => {
const {container} = getComponent();
expect(getByTestId(container, 'success-icon')).toBeInTheDocument();
});
});
});

0 comments on commit 253dbb5

Please sign in to comment.