Skip to content

Commit

Permalink
Merge pull request #64 from chentex/add-date-formating
Browse files Browse the repository at this point in the history
Adds datetime formatting to the display table
  • Loading branch information
chentex authored Dec 5, 2023
2 parents 9dc61a9 + 745d87b commit 6fdbedd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import {Table, Thead, Tr, Th, Tbody, Td, ExpandableRowContent} from '@patternfly/react-table';
import {Puff} from "react-loading-icons";
import React, {useEffect, useState} from "react";
import {getFormattedDate} from "../../../helpers/Formatters";



export const TableView = ({columns , rows = [], initialState = true, stickyHeader=false,
Expand Down Expand Up @@ -29,7 +31,7 @@ export const TableView = ({columns , rows = [], initialState = true, stickyHeade
return <Tbody>
{ rows &&
rows.map( (item, index)=> <Tr key={index}>
{item.tableRows.map( (value, idx) => <Td dataLabel={columns[idx]} key={idx}>{value}</Td> )}
{item.tableRows.map( (value, idx) => <Td dataLabel={columns[idx]} key={idx}>{ columns[idx] === "Start Date" || columns[idx] === "End Date" ? getFormattedDate(value) : value }</Td> )}
</Tr>
)
}
Expand All @@ -46,7 +48,7 @@ export const TableView = ({columns , rows = [], initialState = true, stickyHeade
isExpanded: expand[index],
onToggle: handleToggle
}} />
{item.tableRows.map( (value, idx) => <Td dataLabel={columns[idx]} key={idx}>{value}</Td> )}
{item.tableRows.map( (value, idx) => <Td dataLabel={columns[idx]} key={idx}>{ columns[idx] === "Start Date" || columns[idx] === "End Date" ? getFormattedDate(value) : value }</Td> )}
</Tr>
<Tr isExpanded={expand[index]}>
<Td dataLabel={columns[index]} noPadding colSpan={columns.length + 1}>
Expand Down
20 changes: 18 additions & 2 deletions frontend/src/helpers/Formatters.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function formatTime(time) {
export function formatTime(time) {
// Hours, minutes and seconds
var hrs = ~~(time / 3600);
var mins = ~~((time % 3600) / 60);
Expand All @@ -12,4 +12,20 @@ export function formatTime(time) {
ret += "" + mins + ":" + (secs < 10 ? "0" : "");
ret += "" + secs;
return ret;
}
}

export function getFormattedDate(date) {
let d = new Date();
if (typeof date === 'string' || date instanceof String)
d = new Date(date);
else
d = new Date(date.props.value);

var year = d.getFullYear();
var month = ("0" + (d.getMonth() + 1)).slice(-2);
var day = ("0" + (d.getDate())).slice(-2);
var hour = ("0" + (d.getHours())).slice(-2);
var min = ("0" + (d.getMinutes())).slice(-2);
var sec = ("0" + (d.getSeconds())).slice(-2);
return year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec;
}
8 changes: 4 additions & 4 deletions frontend/src/store/reducers/InitialData.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ export const OCP_INITIAL_DATA = {
startDate: '',
endDate: '',
tableData : [{ name: "Benchmark", value: "benchmark" },
{name:"ReleaseStream", value: "releaseStream"},
{name: "WorkerCount", value: "workerNodesCount"},
{name: "StartDate", value: "startDate"},
{name: "EndDate", value: "endDate"},
{name:"Release Stream", value: "releaseStream"},
{name: "Worker Count", value: "workerNodesCount"},
{name: "Start Date", value: "startDate"},
{name: "End Date", value: "endDate"},
{name: "Status", value: "jobStatus"}],
}

Expand Down

0 comments on commit 6fdbedd

Please sign in to comment.