- human readable dates
Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
@@ -54,7 +54,9 @@ export function JobLifecycleComponent({bodyshop, job, ...rest}) {
|
|||||||
'duration',
|
'duration',
|
||||||
'type',
|
'type',
|
||||||
'created_at',
|
'created_at',
|
||||||
'updated_at'
|
'updated_at',
|
||||||
|
'start_readable',
|
||||||
|
'end_readable',
|
||||||
];
|
];
|
||||||
|
|
||||||
const columns = columnKeys.map(key => ({
|
const columns = columnKeys.map(key => ({
|
||||||
@@ -71,7 +73,7 @@ export function JobLifecycleComponent({bodyshop, job, ...rest}) {
|
|||||||
const entires = Object
|
const entires = Object
|
||||||
.entries(lifecycleData.durations)
|
.entries(lifecycleData.durations)
|
||||||
.filter(([name, value]) => {
|
.filter(([name, value]) => {
|
||||||
return value !== 0;
|
return value > 0;
|
||||||
})
|
})
|
||||||
|
|
||||||
return entires.map(([name, value], index) => (
|
return entires.map(([name, value], index) => (
|
||||||
@@ -88,7 +90,7 @@ export function JobLifecycleComponent({bodyshop, job, ...rest}) {
|
|||||||
*/
|
*/
|
||||||
const durationsData = useCallback(() => {
|
const durationsData = useCallback(() => {
|
||||||
return Object.entries(lifecycleData.durations) .filter(([name, value]) => {
|
return Object.entries(lifecycleData.durations) .filter(([name, value]) => {
|
||||||
return value !== 0;
|
return value > 0;
|
||||||
}).map(([name, value]) => ({
|
}).map(([name, value]) => ({
|
||||||
name,
|
name,
|
||||||
value: value / 1000
|
value: value / 1000
|
||||||
@@ -108,7 +110,7 @@ export function JobLifecycleComponent({bodyshop, job, ...rest}) {
|
|||||||
<Timeline>
|
<Timeline>
|
||||||
{lifecycleData.lifecycle.map((item, index) => (
|
{lifecycleData.lifecycle.map((item, index) => (
|
||||||
<Timeline.Item key={index} color={item.value === 'Open' ? 'green' : item.value === 'Scheduled' ? 'yellow' : 'red'}>
|
<Timeline.Item key={index} color={item.value === 'Open' ? 'green' : item.value === 'Scheduled' ? 'yellow' : 'red'}>
|
||||||
{item.value} - {new Date(item.start).toLocaleString()}
|
{item.value} - {item.start_readable}
|
||||||
</Timeline.Item>
|
</Timeline.Item>
|
||||||
))}
|
))}
|
||||||
</Timeline>
|
</Timeline>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
const _ = require("lodash");
|
const _ = require("lodash");
|
||||||
const queries = require("../graphql-client/queries");
|
const queries = require("../graphql-client/queries");
|
||||||
|
const moment = require("moment");
|
||||||
|
|
||||||
const calculateStatusDuration = (transitions) => {
|
const calculateStatusDuration = (transitions) => {
|
||||||
let statusDuration = {};
|
let statusDuration = {};
|
||||||
@@ -52,17 +53,30 @@ const jobLifecycle = async (req, res) => {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const transitionsByJobId = _.groupBy(resp.transitions, 'jobid');
|
const transitionsByJobId = _.groupBy(resp.transitions, 'jobid');
|
||||||
|
|
||||||
const groupedTransitions = {};
|
const groupedTransitions = {};
|
||||||
|
moment.relativeTimeThreshold('m', 30)
|
||||||
for (let jobId in transitionsByJobId) {
|
for (let jobId in transitionsByJobId) {
|
||||||
|
let lifecycle = transitionsByJobId[jobId].map(transition => {
|
||||||
|
if (transition.start) {
|
||||||
|
transition.start_readable = moment(transition.start).fromNow();
|
||||||
|
}
|
||||||
|
if (transition.end) {
|
||||||
|
transition.end_readable = moment(transition.end).fromNow();
|
||||||
|
}
|
||||||
|
return transition;
|
||||||
|
});
|
||||||
|
|
||||||
groupedTransitions[jobId] = {
|
groupedTransitions[jobId] = {
|
||||||
lifecycle: transitionsByJobId[jobId],
|
lifecycle: lifecycle,
|
||||||
durations: calculateStatusDuration(transitionsByJobId[jobId])
|
durations: calculateStatusDuration(lifecycle)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.dir(groupedTransitions, {depth: null});
|
||||||
|
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
jobIDs,
|
jobIDs,
|
||||||
transition: groupedTransitions,
|
transition: groupedTransitions,
|
||||||
|
|||||||
Reference in New Issue
Block a user