Skip to content

Commit a95d20f

Browse files
authored
Merge pull request #1407 from omar-sarfraz/osarfraz/ENT-9945
feat: Add Include Date option in enterprise reporting configuration form
2 parents 519feab + a70b8a3 commit a95d20f

File tree

2 files changed

+130
-57
lines changed

2 files changed

+130
-57
lines changed

src/components/ReportingConfig/ReportingConfigForm.jsx

Lines changed: 79 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class ReportingConfigForm extends React.Component {
5151
active: this.props.config ? this.props.config.active : false,
5252
enableCompression: this.props.config ? this.props.config.enableCompression : true,
5353
submitState: SUBMIT_STATES.DEFAULT,
54+
includeDate: this.props.config ? this.props.config.includeDate : true,
5455
};
5556

5657
/**
@@ -127,6 +128,7 @@ class ReportingConfigForm extends React.Component {
127128
let requiredFields = [];
128129
formData.append('active', this.state.active);
129130
formData.append('enableCompression', this.state.enableCompression);
131+
formData.append('includeDate', this.state.includeDate);
130132
if (formData.get('deliveryMethod') === 'email') {
131133
requiredFields = config ? [...REQUIRED_EMAIL_FIELDS] : [...REQUIRED_NEW_EMAIL_FIELDS];
132134
// transform email field to match what the api is looking for
@@ -257,6 +259,7 @@ class ReportingConfigForm extends React.Component {
257259
active,
258260
enableCompression,
259261
submitState,
262+
includeDate,
260263
} = this.state;
261264
const selectedCatalogs = (config?.enterpriseCustomerCatalogs || []).map(item => item.uuid);
262265
const dataTypesOptions = reportingConfigTypes.dataType.map((item, index) => ({
@@ -456,65 +459,83 @@ class ReportingConfigForm extends React.Component {
456459
handleBlur={this.handleBlur}
457460
/>
458461
)}
459-
<div className="col">
460-
<Form.Group
461-
isInvalid={!!APIErrors.enableCompression}
462+
<Form.Group
463+
isInvalid={!!APIErrors.enableCompression}
464+
>
465+
<Form.Label>
466+
<FormattedMessage
467+
id="admin.portal.reporting.config.enable.compression"
468+
defaultMessage="Enable Compression"
469+
description="Label for the Enable Compression field in the reporting configuration form"
470+
/>
471+
</Form.Label>
472+
<Form.Checkbox
473+
data-testid="compressionCheckbox"
474+
className="ml-3"
475+
checked={enableCompression}
476+
onChange={() => this.setState(prevState => ({ enableCompression: !prevState.enableCompression }))}
477+
/>
478+
<Form.Text>
479+
<FormattedMessage
480+
id="admin.portal.reporting.config.enable.compression.help"
481+
defaultMessage="Specifies whether report should be compressed. Without compression files will not be password protected or encrypted."
482+
description="Help text for the Enable Compression field in the reporting configuration form"
483+
/>
484+
</Form.Text>
485+
{!!APIErrors.enableCompression && (
486+
<Form.Control.Feedback type="invalid">
487+
{APIErrors.enableCompression}
488+
</Form.Control.Feedback>
489+
)}
490+
</Form.Group>
491+
<Form.Group>
492+
<Form.Label>
493+
<FormattedMessage
494+
id="admin.portal.reporting.config.include.date"
495+
defaultMessage="Include Date"
496+
description="Label for the Include Date field in the reporting configuration form"
497+
/>
498+
</Form.Label>
499+
<Form.Checkbox
500+
data-testid="includeDateCheckbox"
501+
className="ml-3"
502+
checked={includeDate}
503+
onChange={() => this.setState(prevState => ({ includeDate: !prevState.includeDate }))}
504+
/>
505+
<Form.Text>
506+
<FormattedMessage
507+
id="admin.portal.reporting.config.include.date.option.help"
508+
defaultMessage="Specifies whether the report's filename should include the date."
509+
description="Help text for the Include Date field in the reporting configuration form"
510+
/>
511+
</Form.Text>
512+
</Form.Group>
513+
<Form.Group controlId="enterpriseCustomerCatalogs">
514+
<Form.Label>
515+
<FormattedMessage
516+
id="admin.portal.reporting.config.enterprise.customer.catalogs"
517+
defaultMessage="Enterprise Customer Catalogs"
518+
description="Label for the Enterprise Customer Catalogs field in the reporting configuration form"
519+
/>
520+
</Form.Label>
521+
<Form.Control
522+
as="select"
523+
name="enterpriseCustomerCatalogUuids"
524+
multiple
525+
defaultValue={selectedCatalogs}
462526
>
463-
<Form.Label>
464-
<FormattedMessage
465-
id="admin.portal.reporting.config.enable.compression"
466-
defaultMessage="Enable Compression"
467-
description="Label for the Enable Compression field in the reporting configuration form"
468-
/>
469-
</Form.Label>
470-
<Form.Checkbox
471-
data-testid="compressionCheckbox"
472-
className="ml-3"
473-
checked={enableCompression}
474-
onChange={() => this.setState(prevState => ({ enableCompression: !prevState.enableCompression }))}
527+
{availableCatalogs && (availableCatalogs.map((item) => (
528+
<option key={item.uuid} value={item.uuid}>Catalog {item.title} with UUID {item.uuid}</option>
529+
)))}
530+
</Form.Control>
531+
<Form.Text>
532+
<FormattedMessage
533+
id="admin.portal.reporting.config.enterprise.customer.catalogs.help"
534+
defaultMessage="The catalogs that should be included in the report. No selection means all catalogs will be included."
535+
description="Help text for the Enterprise Customer Catalogs field in the reporting configuration form"
475536
/>
476-
<Form.Text>
477-
<FormattedMessage
478-
id="admin.portal.reporting.config.enable.compression.help"
479-
defaultMessage="Specifies whether report should be compressed. Without compression files will not be password protected or encrypted."
480-
description="Help text for the Enable Compression field in the reporting configuration form"
481-
/>
482-
</Form.Text>
483-
{!!APIErrors.enableCompression && (
484-
<Form.Control.Feedback type="invalid">
485-
{APIErrors.enableCompression}
486-
</Form.Control.Feedback>
487-
)}
488-
</Form.Group>
489-
</div>
490-
<div className="col">
491-
<Form.Group controlId="enterpriseCustomerCatalogs">
492-
<Form.Label>
493-
<FormattedMessage
494-
id="admin.portal.reporting.config.enterprise.customer.catalogs"
495-
defaultMessage="Enterprise Customer Catalogs"
496-
description="Label for the Enterprise Customer Catalogs field in the reporting configuration form"
497-
/>
498-
</Form.Label>
499-
<Form.Control
500-
as="select"
501-
name="enterpriseCustomerCatalogUuids"
502-
multiple
503-
defaultValue={selectedCatalogs}
504-
>
505-
{availableCatalogs && (availableCatalogs.map((item) => (
506-
<option key={item.uuid} value={item.uuid}>Catalog {item.title} with UUID {item.uuid}</option>
507-
)))}
508-
</Form.Control>
509-
<Form.Text>
510-
<FormattedMessage
511-
id="admin.portal.reporting.config.enterprise.customer.catalogs.help"
512-
defaultMessage="The catalogs that should be included in the report. No selection means all catalogs will be included."
513-
description="Help text for the Enterprise Customer Catalogs field in the reporting configuration form"
514-
/>
515-
</Form.Text>
516-
</Form.Group>
517-
</div>
537+
</Form.Text>
538+
</Form.Group>
518539
<div className="row justify-content-between align-items-center form-group">
519540
<Form.Group
520541
className="mb-0"
@@ -596,6 +617,7 @@ ReportingConfigForm.propTypes = {
596617
config: PropTypes.shape({
597618
active: PropTypes.bool,
598619
enableCompression: PropTypes.bool,
620+
includeDate: PropTypes.bool,
599621
dataType: PropTypes.string,
600622
dayOfMonth: PropTypes.number,
601623
dayOfWeek: PropTypes.number,

src/components/ReportingConfig/ReportingConfigForm.test.jsx

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import ReportingConfigForm from './ReportingConfigForm';
77
const defaultConfig = {
88
enterpriseCustomerId: 'test-customer-uuid',
99
active: true,
10+
enableCompression: true,
11+
includeDate: false,
1012
deliveryMethod: 'email',
1113
email: ['[email protected]'],
1214
emailRaw: '[email protected]',
@@ -362,6 +364,7 @@ describe('<ReportingConfigForm />', () => {
362364
const errorResponse = {
363365
data: {
364366
pgp_encryption_key: ['Please enter a valid PGP encryption key.'],
367+
enableCompression: ['Test Compression Error'],
365368
},
366369
};
367370
await act(async () => {
@@ -377,4 +380,52 @@ describe('<ReportingConfigForm />', () => {
377380
instance.handleAPIErrorResponse(null);
378381
expect(mock).not.toHaveBeenCalled();
379382
});
383+
it("should update the includeDate state when the 'Include Date' checkbox is clicked", async () => {
384+
const wrapper = mount((
385+
<IntlProvider locale="en">
386+
<ReportingConfigForm
387+
config={defaultConfig}
388+
createConfig={createConfig}
389+
updateConfig={updateConfig}
390+
availableCatalogs={availableCatalogs}
391+
reportingConfigTypes={reportingConfigTypes}
392+
enterpriseCustomerUuid={enterpriseCustomerUuid}
393+
/>
394+
</IntlProvider>
395+
));
396+
397+
const instance = wrapper.find('ReportingConfigForm').instance();
398+
expect(instance.state.includeDate).toBeFalsy();
399+
400+
await act(async () => {
401+
wrapper.find('[data-testid="includeDateCheckbox"]').first().prop('onChange')();
402+
});
403+
404+
wrapper.update();
405+
expect(instance.state.includeDate).toBeTruthy();
406+
});
407+
it("should update enableCompression state when the 'Enable Compression' checkbox is clicked", async () => {
408+
const wrapper = mount((
409+
<IntlProvider locale="en">
410+
<ReportingConfigForm
411+
config={defaultConfig}
412+
createConfig={createConfig}
413+
updateConfig={updateConfig}
414+
availableCatalogs={availableCatalogs}
415+
reportingConfigTypes={reportingConfigTypes}
416+
enterpriseCustomerUuid={enterpriseCustomerUuid}
417+
/>
418+
</IntlProvider>
419+
));
420+
421+
const instance = wrapper.find('ReportingConfigForm').instance();
422+
expect(instance.state.enableCompression).toBeTruthy();
423+
424+
await act(async () => {
425+
wrapper.find('[data-testid="compressionCheckbox"]').first().prop('onChange')();
426+
});
427+
428+
wrapper.update();
429+
expect(instance.state.enableCompression).toBeFalsy();
430+
});
380431
});

0 commit comments

Comments
 (0)