Skip to content

Commit

Permalink
[#noissue] Support colon-base time format
Browse files Browse the repository at this point in the history
  • Loading branch information
binDongKim committed Jul 4, 2024
1 parent ae66fc2 commit 8f491ab
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
44 changes: 36 additions & 8 deletions web-frontend/src/main/v3/apps/web/src/routes/loader/serverMap.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { SEARCH_PARAMETER_DATE_FORMAT } from '@pinpoint-fe/constants';
import {
SEARCH_PARAMETER_DATE_FORMAT,
SEARCH_PARAMETER_DATE_FORMAT_WHITE_LIST,
} from '@pinpoint-fe/constants';
import {
convertParamsToQueryString,
getApplicationTypeAndName,
getFormattedDateRange,
getParsedDateRange,
isValidDateRange,
} from '@pinpoint-fe/utils';
Expand All @@ -19,10 +24,7 @@ export const serverMapRouteLoader = ({ params, request }: LoaderFunctionArgs) =>
const to = queryParam?.to as string;

const currentDate = new Date();
const parsedDateRange = {
from: parse(from, SEARCH_PARAMETER_DATE_FORMAT, currentDate),
to: parse(to, SEARCH_PARAMETER_DATE_FORMAT, currentDate),
};
const validationRange = isValidDateRange(2);
const defaultParsedDateRange = getParsedDateRange({ from, to });
const defaultFormattedDateRange = {
from: format(defaultParsedDateRange.from, SEARCH_PARAMETER_DATE_FORMAT),
Expand All @@ -34,11 +36,37 @@ export const serverMapRouteLoader = ({ params, request }: LoaderFunctionArgs) =>
if (conditions.length === 0) {
return redirect(defaultDestination);
} else if (conditions.includes('from')) {
if (conditions.includes('to') && isValidDateRange(2)(parsedDateRange)) {
return application;
} else {
if (!conditions.includes('to')) {
return redirect(defaultDestination);
}

const matchedFormat = SEARCH_PARAMETER_DATE_FORMAT_WHITE_LIST.find((dateFormat) => {
const parsedDateRange = {
from: parse(from, dateFormat, currentDate),
to: parse(to, dateFormat, currentDate),
};

return validationRange(parsedDateRange);
});

if (!matchedFormat) {
return redirect(defaultDestination);
}

if (matchedFormat !== SEARCH_PARAMETER_DATE_FORMAT) {
const parsedDateRange = {
from: parse(from, matchedFormat, currentDate),
to: parse(to, matchedFormat, currentDate),
};
const formattedDataRange = getFormattedDateRange(parsedDateRange);
const destination = `${basePath}?${convertParamsToQueryString({
...queryParam,
...formattedDataRange,
})}`;
return redirect(destination);
}

return application;
}
}

Expand Down
4 changes: 4 additions & 0 deletions web-frontend/src/main/v3/packages/constants/src/date.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export const SEARCH_PARAMETER_DATE_FORMAT = 'yyyy-MM-dd-HH-mm-ss';
export const SEARCH_PARAMETER_DATE_FORMAT_WHITE_LIST = [
'yyyy-MM-dd-HH-mm-ss',
'yyyy-MM-dd-HH:mm:ss',
];

export const MAX_DATE_RANGE = {
INSPECTOR: 1209600000, // 14day
Expand Down

0 comments on commit 8f491ab

Please sign in to comment.