Skip to content

Commit

Permalink
add date time
Browse files Browse the repository at this point in the history
  • Loading branch information
NikhilShahi committed Aug 8, 2022
1 parent c3356c4 commit aaa683e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
2 changes: 2 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"chart.js": "^3.8.2",
"framer-motion": "^6.3.0",
"js-yaml": "^4.1.0",
"luxon": "^3.0.1",
"next": "latest",
"prism-react-renderer": "^1.3.5",
"react": "^18.2.0",
Expand All @@ -28,6 +29,7 @@
},
"devDependencies": {
"@types/js-yaml": "^4.0.5",
"@types/luxon": "^3.0.0",
"@types/node": "^18.0.0",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/components/Endpoint/Overview.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { ApiEndpointDetailed, Endpoint } from "@common/types";
import { ApiEndpointDetailed } from "@common/types";
import {
Box,
Badge,
Expand All @@ -16,6 +16,7 @@ import darkTheme from "prism-react-renderer/themes/duotoneDark";
import lightTheme from "prism-react-renderer/themes/github";
import { openAPISpec } from "testData";
import EndpointPIIChart from "./PIIChart";
import { getDateTimeString } from "../../utils";

interface EndpointOverviewProps {
endpoint: ApiEndpointDetailed;
Expand Down Expand Up @@ -57,11 +58,11 @@ const EndpointOverview: React.FC<EndpointOverviewProps> = React.memo(
</GridItem>
<GridItem>
<DataHeading>First Detected</DataHeading>
<DataAttribute>{endpoint.firstDetected?.toString()}</DataAttribute>
<DataAttribute>{getDateTimeString(endpoint.firstDetected) || "N/A"}</DataAttribute>
</GridItem>
<GridItem>
<DataHeading>Last Active</DataHeading>
<DataAttribute>{endpoint.lastActive?.toString()}</DataAttribute>
<DataAttribute>{getDateTimeString(endpoint.lastActive) || "N/A"}</DataAttribute>
</GridItem>
<GridItem w="100%" colSpan={2}>
<DataHeading>Usage</DataHeading>
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/components/EndpointList/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import DataTable, { SortOrder, TableColumn } from "react-data-table-component";
import { METHOD_TO_COLOR, RISK_TO_COLOR } from "../../constants";
import { getCustomStyles, rowStyles, SkeletonCell } from "../utils/TableUtils";
import { ApiEndpoint } from "@common/types";
import { getDateTimeString } from "../../utils";

const PAGE_SIZE = 10;

Expand Down Expand Up @@ -156,14 +157,14 @@ const List: React.FC<EndpointTablesProps> = React.memo(
{
name: "First Detected",
sortable: true,
selector: (row: ApiEndpoint) => row.firstDetected?.toString() || "",
selector: (row: ApiEndpoint) => getDateTimeString(row.firstDetected) || "N/A",
id: "firstDetected",
grow: 2,
},
{
name: "Last Active",
sortable: true,
selector: (row: ApiEndpoint) => row.lastActive?.toString() || "",
selector: (row: ApiEndpoint) => getDateTimeString(row.lastActive) || "N/A",
id: "lastActive",
grow: 2,
},
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { DateTime } from "luxon"

export const getDateTimeString = (date: Date) => {
if (date) {
return DateTime.fromISO(date.toString()).toLocaleString(DateTime.DATETIME_MED);
}
return null;
}
10 changes: 10 additions & 0 deletions frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,11 @@
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.182.tgz#05301a4d5e62963227eaafe0ce04dd77c54ea5c2"
integrity sha512-/THyiqyQAP9AfARo4pF+aCGcyiQ94tX/Is2I7HofNRqoYLgN1PBoOWu2/zTA5zMxzP5EFutMtWtGAFRKUe961Q==

"@types/luxon@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@types/luxon/-/luxon-3.0.0.tgz#47fb7891e41875fce7018a8bd3d09b204c5621f5"
integrity sha512-Lx+EZoJxUKw4dp8uei9XiUVNlgkYmax5+ovqt6Xf3LzJOnWhlfJw/jLBmqfGVwOP/pDr4HT8bI1WtxK0IChMLw==

"@types/node@^18.0.0":
version "18.6.1"
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.6.1.tgz#828e4785ccca13f44e2fb6852ae0ef11e3e20ba5"
Expand Down Expand Up @@ -1441,6 +1446,11 @@ loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.4.0:
dependencies:
js-tokens "^3.0.0 || ^4.0.0"

luxon@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/luxon/-/luxon-3.0.1.tgz#6901111d10ad06fd267ad4e4128a84bef8a77299"
integrity sha512-hF3kv0e5gwHQZKz4wtm4c+inDtyc7elkanAsBq+fundaCdUBNJB1dHEGUZIM6SfSBUlbVFduPwEtNjFK8wLtcw==

memoize-one@^5.0.0:
version "5.2.1"
resolved "https://registry.yarnpkg.com/memoize-one/-/memoize-one-5.2.1.tgz#8337aa3c4335581839ec01c3d594090cebe8f00e"
Expand Down

0 comments on commit aaa683e

Please sign in to comment.