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 Include Date option in reporting configuration form #1407

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
28 changes: 28 additions & 0 deletions src/components/ReportingConfig/ReportingConfigForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class ReportingConfigForm extends React.Component {
active: this.props.config ? this.props.config.active : false,
enableCompression: this.props.config ? this.props.config.enableCompression : true,
submitState: SUBMIT_STATES.DEFAULT,
includeDate: this.props.config ? this.props.config.includeDate : false,
};

/**
Expand Down Expand Up @@ -127,6 +128,7 @@ class ReportingConfigForm extends React.Component {
let requiredFields = [];
formData.append('active', this.state.active);
formData.append('enableCompression', this.state.enableCompression);
formData.append('includeDate', this.state.includeDate);
if (formData.get('deliveryMethod') === 'email') {
requiredFields = config ? [...REQUIRED_EMAIL_FIELDS] : [...REQUIRED_NEW_EMAIL_FIELDS];
// transform email field to match what the api is looking for
Expand Down Expand Up @@ -257,6 +259,7 @@ class ReportingConfigForm extends React.Component {
active,
enableCompression,
submitState,
includeDate,
} = this.state;
const selectedCatalogs = (config?.enterpriseCustomerCatalogs || []).map(item => item.uuid);
const dataTypesOptions = reportingConfigTypes.dataType.map((item, index) => ({
Expand Down Expand Up @@ -515,6 +518,30 @@ class ReportingConfigForm extends React.Component {
</Form.Text>
</Form.Group>
</div>
<div className="col">
<Form.Group>
<Form.Label>
<FormattedMessage
id="admin.portal.reporting.config.include.date"
defaultMessage="Include Date"
description="Label for the Include Date field in the reporting configuration form"
/>
</Form.Label>
<Form.Checkbox
data-testid="includeDateCheckbox"
className="ml-3"
checked={includeDate}
onChange={() => this.setState(prevState => ({ includeDate: !prevState.includeDate }))}
/>
<Form.Text>
<FormattedMessage
id="admin.portal.reporting.config.include.date.option.help"
defaultMessage="Specifies whether the report's filename should include the date."
description="Help text for the Include Date field in the reporting configuration form"
/>
</Form.Text>
</Form.Group>
</div>
<div className="row justify-content-between align-items-center form-group">
<Form.Group
className="mb-0"
Expand Down Expand Up @@ -596,6 +623,7 @@ ReportingConfigForm.propTypes = {
config: PropTypes.shape({
active: PropTypes.bool,
enableCompression: PropTypes.bool,
includeDate: PropTypes.bool,
dataType: PropTypes.string,
dayOfMonth: PropTypes.number,
dayOfWeek: PropTypes.number,
Expand Down
25 changes: 25 additions & 0 deletions src/components/ReportingConfig/ReportingConfigForm.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ReportingConfigForm from './ReportingConfigForm';
const defaultConfig = {
enterpriseCustomerId: 'test-customer-uuid',
active: true,
includeDate: false,
deliveryMethod: 'email',
email: ['test_email@example.com'],
emailRaw: 'test_email@example.com',
Expand Down Expand Up @@ -377,4 +378,28 @@ describe('<ReportingConfigForm />', () => {
instance.handleAPIErrorResponse(null);
expect(mock).not.toHaveBeenCalled();
});
it("should update the includeDate state when the 'Include Date' checkbox is clicked", async () => {
const wrapper = mount((
<IntlProvider locale="en">
<ReportingConfigForm
config={defaultConfig}
createConfig={createConfig}
updateConfig={updateConfig}
availableCatalogs={availableCatalogs}
reportingConfigTypes={reportingConfigTypes}
enterpriseCustomerUuid={enterpriseCustomerUuid}
/>
</IntlProvider>
));

const instance = wrapper.find('ReportingConfigForm').instance();
expect(instance.state.includeDate).toBeFalsy();

await act(async () => {
wrapper.find('[data-testid="includeDateCheckbox"]').first().prop('onChange')();
});

wrapper.update();
expect(instance.state.includeDate).toBeTruthy();
});
});