Skip to content

Commit

Permalink
Convert dates used in the activity log api calls to UTC (#2692)
Browse files Browse the repository at this point in the history
  • Loading branch information
finnar-bin authored Apr 24, 2024
1 parent 5ebbb4a commit c81aafe
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
18 changes: 18 additions & 0 deletions src/apps/reports/src/app/views/ActivityLog/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import moment from "moment";

// This assumes the date passed in the param has a format of YYYY-MM-DD
export const toUTC = (originalDate: string) => {
if (!originalDate || !moment(originalDate).isValid) return;

const [year, month, date] = originalDate.split("-");

if (isNaN(Number(year)) || isNaN(Number(month)) || isNaN(Number(date)))
return;

return moment()
.year(Number(year))
.month(Number(month) - 1)
.date(Number(date))
.utc()
.format("L");
};
5 changes: 3 additions & 2 deletions src/apps/reports/src/app/views/ActivityLog/views/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { TopUsers } from "../components/TopUsers";
import { isEmpty, omitBy, uniqBy } from "lodash";
import { EmptyState } from "../components/EmptyState";
import { ApiErrorState } from "../components/ApiErrorState";
import { toUTC } from "../utils";

const tabPaths = ["resources", "users", "timeline", "insights"];

Expand Down Expand Up @@ -91,10 +92,10 @@ export const Home = () => {
} = instanceApi.useGetAuditsQuery(
{
...(params.get("from") && {
start_date: moment(params.get("from")).format("L"),
start_date: toUTC(params.get("from")),
}),
...(params.get("to") && {
end_date: moment(params.get("to")).format("L"),
end_date: toUTC(params.get("to")),
}),
},
{ skip: !initialized }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { resolveUrlFromAudit } from "../../../../../../../utility/resolveResourc
import { CustomBreadcrumbs } from "../../../../../../../shell/components/CustomBreadcrumbs";
import { ResourceHeaderTitle } from "../components/ResourceHeaderTitle";
import { useGetInstanceSettingsQuery } from "../../../../../../../shell/services/instance";
import { toUTC } from "../utils";

const Crumbs = [
{
Expand Down Expand Up @@ -98,10 +99,10 @@ export const ResourceDetails = () => {
} = instanceApi.useGetAuditsQuery(
{
...(params.get("from") && {
start_date: moment(params.get("from")).format("L"),
start_date: toUTC(params.get("from")),
}),
...(params.get("to") && {
end_date: moment(params.get("to")).format("L"),
end_date: toUTC(params.get("to")),
}),
},
{ skip: !initialized }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { notify } from "shell/store/notifications";
import { useDispatch } from "react-redux";
import EmailIcon from "@mui/icons-material/Email";
import { UserHeaderTitle } from "../components/UserHeaderTitle";
import { toUTC } from "../utils";

export const UserDetails = () => {
const dispatch = useDispatch();
Expand Down Expand Up @@ -50,10 +51,10 @@ export const UserDetails = () => {
{
userZUID: zuid,
...(params.get("from") && {
start_date: moment(params.get("from")).format("L"),
start_date: toUTC(params.get("from")),
}),
...(params.get("to") && {
end_date: moment(params.get("to")).format("L"),
end_date: toUTC(params.get("to")),
}),
},
{ skip: !initialized }
Expand Down
9 changes: 7 additions & 2 deletions src/apps/schema/src/app/components/ModelActivityLog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from "../../../../../shell/services/instance";
import { useParams as useSearchParams } from "../../../../../shell/hooks/useParams";
import { filterByParams } from "../../../../../utility/filterByParams";
import { toUTC } from "../../../../reports/src/app/views/ActivityLog/utils";

type Params = {
id: string;
Expand All @@ -34,8 +35,12 @@ export const ModelActivityLog = () => {
isFetching: isFetchingAudits,
} = useGetAuditsQuery(
{
start_date: moment(searchParams.get("from")).format("L"),
end_date: moment(searchParams.get("to")).format("L"),
...(searchParams.get("from") && {
start_date: toUTC(searchParams.get("from")),
}),
...(searchParams.get("to") && {
end_date: toUTC(searchParams.get("to")),
}),
},
{ skip: !initialized }
);
Expand Down

0 comments on commit c81aafe

Please sign in to comment.