Skip to content

Commit

Permalink
IA-2456 quarterlyNov in frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
mestachs committed Dec 20, 2024
1 parent dcf36ad commit aad4bd6
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ const FormForm: FunctionComponent<FormFormProps> = ({
<Grid container spacing={2} justifyContent="flex-start">
<Grid xs={6} item>
{/* Splitting the Typography to be able to align it with the checkbox */}

<InputComponent
keyValue="name"
onChange={(key, value) => setFieldValue(key, value)}
Expand Down
1 change: 1 addition & 0 deletions hat/assets/js/apps/Iaso/domains/forms/types/forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ type PeriodType =
| 'NO_PERIOD'
| 'MONTH'
| 'QUARTER'
| 'QUARTER_NOV'
| 'SIX_MONTH'
| 'YEAR'
| null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ import {
PERIOD_TYPE_MONTH,
PERIOD_TYPE_PLACEHOLDER,
PERIOD_TYPE_QUARTER,
PERIOD_TYPE_QUARTER_NOV,
PERIOD_TYPE_SIX_MONTH,
PERIOD_TYPE_YEAR,
QUARTERS,
QUARTERS_RANGE,
QUARTERS_NOV_RANGE,
SEMESTERS,
SEMESTERS_RANGE,
} from '../constants';
Expand Down Expand Up @@ -115,7 +117,8 @@ const PeriodPicker: FunctionComponent<Props> = ({
}
setCurrentPeriod(newPeriod);
onChange(getPeriodPickerString(periodType, newPeriod, value));
};
};


const handleChangeDay = useCallback(
date => {
Expand All @@ -133,6 +136,13 @@ const PeriodPicker: FunctionComponent<Props> = ({
);

const getQuarterOptionLabel = (value, label) => {

if (periodType == PERIOD_TYPE_QUARTER_NOV) {
return `${label} (${formatMessage(
QUARTERS_NOV_RANGE[value][0],
)}-${formatMessage(QUARTERS_NOV_RANGE[value][1])})`;
}

if (hasFeatureFlag(currentUser, HIDE_PERIOD_QUARTER_NAME)) {
return `${formatMessage(QUARTERS_RANGE[value][0])}-${formatMessage(
QUARTERS_RANGE[value][1],
Expand Down Expand Up @@ -211,7 +221,7 @@ const PeriodPicker: FunctionComponent<Props> = ({
)}

{(periodType === PERIOD_TYPE_MONTH ||
periodType === PERIOD_TYPE_QUARTER ||
periodType === PERIOD_TYPE_QUARTER || periodType === PERIOD_TYPE_QUARTER_NOV ||
periodType === PERIOD_TYPE_SIX_MONTH) && (
<Grid item sm={6}>
{periodType === PERIOD_TYPE_MONTH && (
Expand All @@ -237,7 +247,7 @@ const PeriodPicker: FunctionComponent<Props> = ({
label={MESSAGES.month}
/>
)}
{periodType === PERIOD_TYPE_QUARTER && (
{periodType === PERIOD_TYPE_QUARTER || periodType === PERIOD_TYPE_QUARTER_NOV && (
<InputComponent
keyValue="quarter"
onChange={handleChange}
Expand Down
18 changes: 18 additions & 0 deletions hat/assets/js/apps/Iaso/domains/periods/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ export const PERIOD_TYPE_DAY = 'DAY';
export const PERIOD_TYPE_YEAR = 'YEAR';
export const PERIOD_TYPE_SIX_MONTH = 'SIX_MONTH';
export const PERIOD_TYPE_QUARTER = 'QUARTER';
export const PERIOD_TYPE_QUARTER_NOV = 'QUARTER_NOV'
export const PERIOD_TYPE_MONTH = 'MONTH';
export const PERIOD_TYPE_PLACEHOLDER = 'EMPTY';
export const NO_PERIOD = 'NO_PERIOD';

export const PERIOD_TYPES = [
PERIOD_TYPE_MONTH,
PERIOD_TYPE_QUARTER,
PERIOD_TYPE_QUARTER_NOV,
PERIOD_TYPE_SIX_MONTH,
PERIOD_TYPE_YEAR,
];
Expand All @@ -19,6 +21,7 @@ export const periodTypeOptions = [
PERIOD_TYPE_DAY,
PERIOD_TYPE_MONTH,
PERIOD_TYPE_QUARTER,
PERIOD_TYPE_QUARTER_NOV,
PERIOD_TYPE_YEAR,
].map(periodType => ({
value: periodType,
Expand All @@ -38,6 +41,14 @@ export const QUARTERS = {
4: 'Q4',
};

export const QUARTERS_NOV = {
1: 'NovQ1',
2: 'NovQ2',
3: 'NovQ3',
4: 'NovQ4',
};


export const SEMESTERS = {
1: 'S1',
2: 'S2',
Expand Down Expand Up @@ -65,6 +76,13 @@ export const QUARTERS_RANGE = {
4: [MONTHS[10], MONTHS[12]],
};

export const QUARTERS_NOV_RANGE = {
1: [MONTHS[11], MONTHS[1]],
2: [MONTHS[2], MONTHS[4]],
3: [MONTHS[5], MONTHS[7]],
4: [MONTHS[8], MONTHS[10]],
};

export const SEMESTERS_RANGE = {
1: [MONTHS[1], MONTHS[6]],
2: [MONTHS[7], MONTHS[12]],
Expand Down
4 changes: 4 additions & 0 deletions hat/assets/js/apps/Iaso/domains/periods/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const MESSAGES = defineMessages({
id: 'iaso.label.quarter',
defaultMessage: 'Quarter',
},
quarter_nov: {
id: 'iaso.label.quater_nov',
defaultMessage: 'Quarter November',
},
month: {
id: 'iaso.label.month',
defaultMessage: 'Month',
Expand Down
69 changes: 69 additions & 0 deletions hat/assets/js/apps/Iaso/domains/periods/models.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
PERIOD_TYPE_DAY,
PERIOD_TYPE_MONTH,
PERIOD_TYPE_QUARTER,
PERIOD_TYPE_QUARTER_NOV,
PERIOD_TYPE_SIX_MONTH,
PERIOD_TYPE_YEAR,
} from './constants';
Expand Down Expand Up @@ -331,6 +332,74 @@ describe('Periods model', () => {
});
});


describe('quarterly nov string', () => {
before(() => {
periodString = '2018NovQ1';
period = new Period(periodString);
expectedPeriod = {
periodType: PERIOD_TYPE_QUARTER_NOV,
month: 3,
day: 1,
quarter: 1,
semester: 1,
year: 2018,
periodString,
};
});
it('should create a quarterly period object', () => {
expect(period).to.eql(expectedPeriod);
});
it('asPeriodType should create a quarterly period object', () => {
expect(period.asPeriodType(PERIOD_TYPE_QUARTER_NOV)).to.eql(
expectedPeriod,
);
});
it('monthRange should return correct month range', () => {
expect(period.monthRange).to.eql(getMonthRange(month));
});
it('toCode should return correct code', () => {
expect(period.toCode()).to.eql('NovQ1/2018');
});
it('nextQuarter should return next quarter string', () => {
expect(period.next(periodString)).to.eql(`2018NovQ2`);
});
it('previousQuarter should return previous year last quarter string', () => {
expect(period.previous(periodString)).to.eql("2017NovQ4");
});
it('nextQuarter should return next year quarter string', () => {
expect(period.next("2020NovQ4")).to.eql(`2021NovQ1`);
});
it('previousQuarter should return previous quarter string', () => {
expect(period.previous("2024NovQ4")).to.eql(`2024NovQ3`);
});
it('nextPeriods should return next 2 quarters', () => {
expect(period.nextPeriods(2)).to.eql(['2018NovQ2', '2018NovQ3']);
});
it('previousPeriods should return previous 2 quarters', () => {
expect(period.previousPeriods(2)).to.eql(['2017NovQ3', '2017NovQ4']);
});
it('getPeriodType should correct period type', () => {
expect(Period.getPeriodType('2017NovQ3')).to.eql(PERIOD_TYPE_QUARTER_NOV);
});
describe('isBefore', () => {
it('should return true', () => {
expect(Period.isBefore('2017NovQ3', '2017NovQ4')).to.eql(true);
});
it('should return false', () => {
expect(Period.isBefore('2017NovQ4', '2017NovQ3')).to.eql(false);
});
});
describe('isAfter', () => {
it('should return true', () => {
expect(Period.isAfter('2017NovQ4', '2017NovQ3')).to.eql(true);
});
it('should return false', () => {
expect(Period.isAfter('2017NovQ3', '2017NovQ4')).to.eql(false);
});
});
});

describe('sixmonthly string', () => {
before(() => {
periodString = '2020S1';
Expand Down
Loading

0 comments on commit aad4bd6

Please sign in to comment.