Skip to content
This repository was archived by the owner on May 26, 2023. It is now read-only.

Commit d1d9772

Browse files
authored
Implement Proto Time changes (#89)
* Implement Proto Time changes * Refactor time based utils
1 parent b0eada5 commit d1d9772

17 files changed

+155
-156
lines changed

client/helpers/timestamp-to-date.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import moment from 'moment';
22

3-
const timestampToDate = timestamp => {
3+
const timestampToDate = (timestamp) => {
44
if (!timestamp) {
55
return timestamp;
66
}
@@ -10,7 +10,7 @@ const timestampToDate = timestamp => {
1010
if (typeof timestamp === 'number') {
1111
ts = timestamp;
1212
} else if (typeof timestamp === 'string') {
13-
ts = parseInt(timestamp);
13+
return moment(timestamp);
1414
} else if (typeof timestamp === 'object') {
1515
if (typeof timestamp.value === 'string') {
1616
ts = parseInt(timestamp.value);

client/routes/namespace/workflow-list.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,8 @@ export default pagedGrid({
324324
workflowId: data.execution.workflowId,
325325
runId: data.execution.runId,
326326
workflowName: data.type.name,
327-
startTime: moment(data.startTime).format('lll'),
328-
endTime: data.closeTime
329-
? moment(data.closeTime).format('lll')
330-
: '',
327+
startTime: data.startTime.format('lll'),
328+
endTime: data.closeTime ? data.closeTime.format('lll') : '',
331329
status: (data.status || 'open').toLowerCase(),
332330
}));
333331

client/routes/workflow/helpers/get-event-details.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { getKeyValuePairs } from '~helpers';
22

3-
const getEventDetails = event => {
4-
const { details, eventId, eventType, timeStampDisplay } = event;
3+
const getEventDetails = (event) => {
4+
const { details, eventId, eventType, eventTimeDisplay } = event;
55
const kvps = getKeyValuePairs({
6-
timestamp: timeStampDisplay,
6+
eventTime: eventTimeDisplay,
77
eventId,
88
...details,
99
});
@@ -13,7 +13,7 @@ const getEventDetails = event => {
1313
eventId,
1414
eventType,
1515
kvps,
16-
timestamp: timeStampDisplay,
16+
eventTime: eventTimeDisplay,
1717
};
1818
};
1919

client/routes/workflow/helpers/get-history-events.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,25 @@ const getHistoryEvents = (events) => {
1212

1313
return events
1414
.map((event) => {
15-
const timestamp = timestampToDate(event.timestamp);
15+
const eventTime = timestampToDate(event.eventTime);
1616

1717
return {
1818
...event,
19-
timestamp,
19+
eventTime,
2020
};
2121
})
2222
.map((event, index, eventList) => {
23-
const timeStampDisplay = getTimeStampDisplay(event);
24-
const timeElapsedDisplay = getTimeElapsedDisplay(event, index, eventList);
23+
const eventTimeDisplay = getTimeStampDisplay(event.eventTime);
24+
const eventTimes = eventList.map((a) => a.eventTime);
25+
const timeElapsedDisplay = getTimeElapsedDisplay(
26+
event.eventTime,
27+
index,
28+
eventTimes
29+
);
2530

2631
return {
2732
...event,
28-
timeStampDisplay,
33+
eventTimeDisplay,
2934
timeElapsedDisplay,
3035
};
3136
})

client/routes/workflow/helpers/get-time-elapsed-display.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import moment from 'moment';
22

3-
const getTimeElapsedDisplay = ({ timestamp }, index, eventList) => {
3+
const getTimeElapsedDisplay = (timestamp, index, timestamps) => {
44
if (!timestamp || index === -1) {
55
return '';
66
}
@@ -9,10 +9,8 @@ const getTimeElapsedDisplay = ({ timestamp }, index, eventList) => {
99
return timestamp.format('MMM Do h:mm:ss a');
1010
}
1111

12-
const deltaFromPrev = moment.duration(
13-
timestamp - eventList[index - 1].timestamp
14-
);
15-
let elapsed = moment.duration(timestamp - eventList[0].timestamp).format();
12+
const deltaFromPrev = moment.duration(timestamp - timestamps[index - 1]);
13+
let elapsed = moment.duration(timestamp - timestamps[0]).format();
1614

1715
if (deltaFromPrev.asSeconds() >= 1) {
1816
elapsed += ` (+${deltaFromPrev.format()})`;

client/routes/workflow/helpers/get-time-elapsed-display.spec.js

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,52 +5,39 @@ describe('getTimeElapsedDisplay', () => {
55
const DATE = '2020-01-01 00:00:00';
66
const DATE_PLUS_ONE_HOUR = '2020-01-01 01:00:00';
77

8-
describe('When passed an event with no timestamp', () => {
8+
describe('When passed no timestamp', () => {
99
it('should return "".', () => {
10-
const event = {};
11-
const output = getTimeElapsedDisplay(event);
10+
const output = getTimeElapsedDisplay(null);
1211

1312
expect(output).toEqual('');
1413
});
1514
});
1615

17-
describe('When passed an event with a timestamp and index = -1', () => {
16+
describe('When passed a timestamp and index = -1', () => {
1817
it('should return "".', () => {
19-
const event = {
20-
timestamp: moment(DATE),
21-
};
18+
const ts = moment(DATE);
2219
const index = -1;
23-
const output = getTimeElapsedDisplay(event, index);
20+
const output = getTimeElapsedDisplay(ts, index);
2421

2522
expect(output).toEqual('');
2623
});
2724
});
2825

29-
describe('When passed an event with a timestamp and index = 0', () => {
26+
describe('When passed a timestamp and index = 0', () => {
3027
it('should return the date string.', () => {
31-
const event = {
32-
timestamp: moment(DATE),
33-
};
28+
const ts = moment(DATE);
3429
const index = 0;
35-
const output = getTimeElapsedDisplay(event, index);
30+
const output = getTimeElapsedDisplay(ts, index);
3631

3732
expect(output).toEqual('Jan 1st 12:00:00 am');
3833
});
3934
});
4035

41-
describe('When passed an event with a timestamp and index = 1 and eventList', () => {
42-
it('should return the elapsed time between the first event and the second.', () => {
43-
const eventList = [
44-
{
45-
timestamp: moment(DATE),
46-
},
47-
{
48-
timestamp: moment(DATE_PLUS_ONE_HOUR),
49-
},
50-
];
36+
describe('When passed a timestamp and index = 1 and list of times', () => {
37+
it('should return the elapsed time between the first time and the second.', () => {
38+
const times = [moment(DATE), moment(DATE_PLUS_ONE_HOUR)];
5139
const index = 1;
52-
const event = eventList[index];
53-
const output = getTimeElapsedDisplay(event, index, eventList);
40+
const output = getTimeElapsedDisplay(times[index], index, times);
5441

5542
expect(output).toEqual('1h (+1h)');
5643
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const getTimeStampDisplay = ({ timestamp }, index) =>
1+
const getTimeStampDisplay = (timestamp, index) =>
22
!timestamp || index === -1 ? '' : timestamp.format('MMM Do h:mm:ss a');
33

44
export default getTimeStampDisplay;

client/routes/workflow/helpers/get-time-stamp-display.spec.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,29 @@ import getTimeStampDisplay from './get-time-stamp-display';
44
describe('getTimeStampDisplay', () => {
55
const DATE = '2020-01-01 00:00:00';
66

7-
describe('When passed an event with no timestamp', () => {
7+
describe('When passed no timestamp', () => {
88
it('should return "".', () => {
9-
const event = {};
10-
const output = getTimeStampDisplay(event);
9+
const output = getTimeStampDisplay(undefined);
1110

1211
expect(output).toEqual('');
1312
});
1413
});
1514

16-
describe('When passed an event with a timestamp and index = -1', () => {
15+
describe('When passed a timestamp and index = -1', () => {
1716
it('should return "".', () => {
18-
const event = {
19-
timestamp: moment(DATE),
20-
};
17+
const ts = moment(DATE);
2118
const index = -1;
22-
const output = getTimeStampDisplay(event, index);
19+
const output = getTimeStampDisplay(ts, index);
2320

2421
expect(output).toEqual('');
2522
});
2623
});
2724

28-
describe('When passed an event with a timestamp and index = 0', () => {
25+
describe('When passed a timestamp and index = 0', () => {
2926
it('should return the date string.', () => {
30-
const event = {
31-
timestamp: moment(DATE),
32-
};
27+
const ts = moment(DATE);
3328
const index = 0;
34-
const output = getTimeStampDisplay(event, index);
29+
const output = getTimeStampDisplay(ts, index);
3530

3631
expect(output).toEqual('Jan 1st 12:00:00 am');
3732
});

client/routes/workflow/helpers/map-timeline-events.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default function(historyEvents) {
3434
id: `activity${activityId}`,
3535
className: 'activity',
3636
eventIds: [e.eventId],
37-
start: moment(scheduledEvent.timestamp),
37+
start: moment(scheduledEvent.eventTime),
3838
ongoing: true,
3939
content: `Activity ${activityId}: ${shortName(
4040
scheduledEvent.details.activityType &&
@@ -60,7 +60,7 @@ export default function(historyEvents) {
6060
e.eventType !== 'ActivityTaskScheduled' &&
6161
e.eventType !== 'ActivityTaskStarted'
6262
) {
63-
assignEnd(item, e.timestamp);
63+
assignEnd(item, e.eventTime);
6464
item.className = `activity ${e.eventType
6565
.replace('ActivityTask', '')
6666
.toLowerCase()}`;
@@ -78,7 +78,7 @@ export default function(historyEvents) {
7878
id: `childWf${initiatedEventId}`,
7979
className: 'child-workflow',
8080
eventIds: [e.eventId],
81-
start: moment(initiatedEvent.timestamp),
81+
start: moment(initiatedEvent.eventTime),
8282
ongoing: true,
8383
content: `Child Workflow: ${shortName(e.details.workflowType.name)}`,
8484
details: {
@@ -107,7 +107,7 @@ export default function(historyEvents) {
107107
e.eventType !== 'StartChildWorkflowExecutionInitiated' &&
108108
e.eventType !== 'ChildWorkflowExecutionStarted'
109109
) {
110-
assignEnd(item, e.timestamp);
110+
assignEnd(item, e.eventTime);
111111
item.className = `child-workflow ${e.eventType
112112
.replace('ChildWorkflowExecution', '')
113113
.toLowerCase()}`;
@@ -117,8 +117,8 @@ export default function(historyEvents) {
117117
id: `timer${e.details.timerId}`,
118118
className: 'timer',
119119
eventIds: [e.eventId],
120-
start: moment(e.timestamp),
121-
end: moment(e.timestamp).add(
120+
start: moment(e.eventTime),
121+
end: moment(e.eventTime).add(
122122
e.details.startToFireTimeoutSeconds,
123123
'seconds'
124124
),
@@ -142,7 +142,7 @@ export default function(historyEvents) {
142142
id: `marker${e.eventId}`,
143143
className: `marker marker-${markerName}`,
144144
eventIds: [e.eventId],
145-
start: moment(e.timestamp),
145+
start: moment(e.eventTime),
146146
content:
147147
{
148148
Version: 'Version Marker',
@@ -156,7 +156,7 @@ export default function(historyEvents) {
156156
id: `signal${e.eventId}`,
157157
className: 'signal',
158158
eventIds: [e.eventId],
159-
start: moment(e.timestamp),
159+
start: moment(e.eventTime),
160160
content: 'Workflow Signaled',
161161
details: {
162162
input: e.details.input,
@@ -167,7 +167,7 @@ export default function(historyEvents) {
167167
id: `extsignal${e.eventId}`,
168168
className: 'external-signal',
169169
eventIds: [e.eventId],
170-
start: moment(e.timestamp),
170+
start: moment(e.eventTime),
171171
ongoing: true,
172172
content: 'External Workflow Signaled',
173173
details: summarizeEvents.SignalExternalWorkflowExecutionInitiated(
@@ -180,7 +180,7 @@ export default function(historyEvents) {
180180
if (initiatedEvent) {
181181
initiatedEvent.eventIds.push(e.eventId);
182182
// TODO - code will break as item is not defined.
183-
// assignEnd(item, e.timestamp);
183+
// assignEnd(item, e.eventTime);
184184
}
185185
} else if (
186186
e.eventType === 'WorkflowTaskFailed' ||
@@ -192,7 +192,7 @@ export default function(historyEvents) {
192192
.replace('WorkflowTask', '')
193193
.toLowerCase()}`,
194194
eventIds: [e.eventId],
195-
start: moment(e.timestamp),
195+
start: moment(e.eventTime),
196196
content: e.eventType,
197197
details: e.details,
198198
});

client/routes/workflow/history.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152
{{
153153
tsFormat === 'elapsed'
154154
? item.timeElapsedDisplay
155-
: item.timeStampDisplay
155+
: item.eventTimeDisplay
156156
}}
157157
</div>
158158
<div class="td col-summary">
@@ -390,7 +390,7 @@ export default {
390390
}
391391
392392
return {
393-
timestamp: this.selectedEvent.timestamp.format('MMM Do h:mm:ss a'),
393+
eventTime: this.selectedEvent.eventTime.format('MMM Do h:mm:ss a'),
394394
eventId: this.selectedEvent.eventId,
395395
...this.selectedEvent.details,
396396
};

0 commit comments

Comments
 (0)