Skip to content

Commit

Permalink
[FEATURE] Set default time range to 24 hrs and share the same setting…
Browse files Browse the repository at this point in the history
… for all UI pages opensearch-project#253

[FEATURE] Charts should show the entire time range selected in the filter opensearch-project#258
[FEATURE] Add chart data to the tooltips opensearch-project#263

Signed-off-by: Jovan Cvetkovic <[email protected]>
  • Loading branch information
jovancvetkovic3006 committed Dec 27, 2022
1 parent 9abd700 commit a49e84e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 23 deletions.
15 changes: 0 additions & 15 deletions public/pages/Overview/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,3 @@ export const summaryGroupByOptions = [
];

export const moreLink = 'https://opensearch.org/docs/latest/security-analytics/';

/**
* Time axis' timeUnit map
* for each time search unit there is a mapped chart timeUnit
*/
export const TimeUnitsMap: {
[key: string]: string;
} = {
minutes: 'yearmonthdatehoursminutes',
hours: 'yearmonthdatehoursminutes',
days: 'yearmonthdatehours',
weeks: 'yearmonthdatehours',
months: 'yearmonthdatehours',
years: 'yearmonthdate',
};
58 changes: 50 additions & 8 deletions public/pages/Overview/utils/helper.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,53 @@
import { getChartTimeUnit } from './helpers';
import { TimeUnitsMap } from './constants';
import { getChartTimeUnit, TimeUnit, TimeUnits } from './helpers';

describe('helper utilities spec', () => {
describe('tests getChartTimeUnit function', () => {
const defaultTimeUnit = 'yearmonthdatehoursminutes';
const defaultTimeUnit = {
timeUnit: { unit: 'yearmonthdatehoursminutes', step: 1 },
dateFormat: '%Y-%m-%d %H:%M',
};
it(' - function should return default timeUnit if fn params are invalid', () => {
expect(getChartTimeUnit('', '')).toBe(defaultTimeUnit);
const timeUnits = getChartTimeUnit('', '');
expect(timeUnits.dateFormat).toBe(defaultTimeUnit.dateFormat);
expect(timeUnits.timeUnit.unit).toBe(defaultTimeUnit.timeUnit.unit);
expect(timeUnits.timeUnit.step).toBe(defaultTimeUnit.timeUnit.step);
});

it(' - function should return default timeUnit if one is passed as param', () => {
const defaultFormat = 'yearmonthdate';
expect(getChartTimeUnit('', '', defaultFormat)).toBe(defaultFormat);
const defaultFormat = 'yearmonthdatehoursminutes';
const timeUnits = getChartTimeUnit('', '', defaultFormat);
expect(timeUnits.timeUnit.unit).toBe(defaultFormat);
});

const timeUnitsExpected: {
[key: string]: TimeUnits;
} = {
minutes: {
dateFormat: '%Y-%m-%d %H:%M',
timeUnit: { step: 1, unit: 'yearmonthdatehoursminutes' },
},
hours: {
dateFormat: '%Y-%m-%d %H:%M',
timeUnit: { step: 1, unit: 'yearmonthdatehours' },
},
days: {
dateFormat: '%Y-%m-%d',
timeUnit: { step: 1, unit: 'yearmonthdate' },
},
weeks: {
dateFormat: '%Y-%m-%d',
timeUnit: { step: 1, unit: 'yearmonthdate' },
},
months: {
dateFormat: '%Y-%m-%d',
timeUnit: { step: 1, unit: 'yearmonthdate' },
},
years: {
dateFormat: '%Y',
timeUnit: { step: 1, unit: 'year' },
},
};

const timeUnits: {
[key: string]: string;
} = {
Expand All @@ -24,9 +59,16 @@ describe('helper utilities spec', () => {
years: 'now-15y',
};

const validateTimeUnit = (timeUnit: TimeUnits, expectedTimeUnit: TimeUnits) => {
expect(timeUnit.dateFormat).toBe(expectedTimeUnit.dateFormat);
expect(timeUnit.timeUnit.unit).toBe(expectedTimeUnit.timeUnit.unit);
expect(timeUnit.timeUnit.step).toBe(expectedTimeUnit.timeUnit.step);
};

for (const [unit, start] of Object.entries(timeUnits)) {
it(` - function should return ${TimeUnitsMap[unit]} if unit is ${unit}`, () => {
expect(getChartTimeUnit(start, 'now')).toBe(TimeUnitsMap[unit]);
it(` - filter ${start} should return valid timeUnit object`, () => {
const timeUnitResult = getChartTimeUnit(start, 'now');
validateTimeUnit(timeUnitResult, timeUnitsExpected[unit]);
});
}
});
Expand Down

0 comments on commit a49e84e

Please sign in to comment.