Skip to content

Commit

Permalink
Remove months and years from the time window
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Apr 11, 2024
1 parent 607703d commit f73ec73
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 23 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/common/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export const NONE_CONNECTOR_ID: string = 'none';
export const CASES_CONNECTOR_ID = '.cases';
export const CASES_CONNECTOR_TITLE = 'Cases';

export const CASES_CONNECTOR_TIME_WINDOW_REGEX = '^[1-9][0-9]*[d,w,M,y]$';
export const CASES_CONNECTOR_TIME_WINDOW_REGEX = '^[1-9][0-9]*[d,w]$';

/**
* This field is used for authorization of the entities within the cases plugin. Each entity within Cases will have the owner field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@ describe('CasesParamsFields renders', () => {
expect(await screen.findByTestId('time-window-unit-select')).toBeInTheDocument();

fireEvent.change(await screen.findByTestId('time-window-unit-select'), {
target: { value: 'M' },
target: { value: 'd' },
});

expect(editAction.mock.calls[0][1].timeWindow).toEqual('6M');
expect(editAction.mock.calls[0][1].timeWindow).toEqual('6d');
});

it('updates reopenClosedCases', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ export const CasesParamsFieldsComponent: React.FunctionComponent<

const parsedTimeWindowSize = timeWindow.slice(0, timeWindow.length - 1);
const parsedTimeWindowUnit = timeWindow.slice(-1);

const timeWindowSize = isNaN(parseInt(parsedTimeWindowSize, 10))
? DEFAULT_TIME_WINDOW[0]
: parsedTimeWindowSize.toString();

const timeWindowUnit = Object.values(TIME_UNITS).includes(parsedTimeWindowUnit as TIME_UNITS)
? parsedTimeWindowUnit
: DEFAULT_TIME_WINDOW[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@ export const DEFAULT_TIME_WINDOW = '7d';
export enum TIME_UNITS {
DAYS = 'd',
WEEKS = 'w',
MONTHS = 'M',
YEARS = 'y',
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ describe('getTimeUnitOptions', () => {
expect(timeUnitValue).toMatchObject([
{ text: 'day', value: 'd' },
{ text: 'week', value: 'w' },
{ text: 'month', value: 'M' },
{ text: 'year', value: 'y' },
]);
});

Expand All @@ -23,8 +21,6 @@ describe('getTimeUnitOptions', () => {
expect(timeUnitValue).toMatchObject([
{ text: 'days', value: 'd' },
{ text: 'weeks', value: 'w' },
{ text: 'months', value: 'M' },
{ text: 'years', value: 'y' },
]);
});

Expand All @@ -33,8 +29,6 @@ describe('getTimeUnitOptions', () => {
expect(timeUnitValue).toMatchObject([
{ text: 'days', value: 'd' },
{ text: 'weeks', value: 'w' },
{ text: 'months', value: 'M' },
{ text: 'years', value: 'y' },
]);
});

Expand All @@ -43,8 +37,6 @@ describe('getTimeUnitOptions', () => {
expect(timeUnitValue).toMatchObject([
{ text: 'days', value: 'd' },
{ text: 'weeks', value: 'w' },
{ text: 'months', value: 'M' },
{ text: 'years', value: 'y' },
]);
});

Expand All @@ -53,8 +45,6 @@ describe('getTimeUnitOptions', () => {
expect(timeUnitValue).toMatchObject([
{ text: 'days', value: 'd' },
{ text: 'weeks', value: 'w' },
{ text: 'months', value: 'M' },
{ text: 'years', value: 'y' },
]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,5 @@ export const getTimeUnitLabels = (timeUnit = TIME_UNITS.DAYS, timeValue = '0') =
return i18n.DAYS(timeValue);
case TIME_UNITS.WEEKS:
return i18n.WEEKS(timeValue);
case TIME_UNITS.MONTHS:
return i18n.MONTHS(timeValue);
case TIME_UNITS.YEARS:
return i18n.YEARS(timeValue);
}
};
4 changes: 2 additions & 2 deletions x-pack/plugins/cases/server/connectors/cases/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ describe('CasesConnectorRunParamsSchema', () => {
).not.toThrow();
});

it.each(['s', 'm', 'H', 'h'])('does not allow time unit %s', (unit) => {
it.each(['s', 'm', 'H', 'h', 'M', 'y'])('does not allow time unit %s', (unit) => {
expect(() =>
CasesConnectorRunParamsSchema.validate(getParams({ timeWindow: `5${unit}` }))
).toThrow();
});

it.each(['d', 'w', 'M', 'y'])('allows time unit %s', (unit) => {
it.each(['d', 'w'])('allows time unit %s', (unit) => {
expect(() =>
CasesConnectorRunParamsSchema.validate(getParams({ timeWindow: `5${unit}` }))
).not.toThrow();
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/cases/server/connectors/cases/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ const TimeWindowSchema = schema.string({
* Acceptable format:
* - First character should be a digit from 1 to 9
* - All next characters should be a digit from 0 to 9
* - The last character should be d (day) or w (week) or M (month) or Y (year)
* - The last character should be d (day) or w (week)
*
* Example: 20d, 2w, 1M, etc
* Example: 20d, 2w, etc
*/
const timeWindowRegex = new RegExp(CASES_CONNECTOR_TIME_WINDOW_REGEX, 'g');

Expand Down

0 comments on commit f73ec73

Please sign in to comment.