Skip to content

Commit

Permalink
fix: [M3-8451] - List events in event landing page in chronological o…
Browse files Browse the repository at this point in the history
…rder (linode#11339)

* change: [M3-8451] - List events in a chronological order

* code clean up

* Added changeset: Events landing page lists events in wrong order

* improved unit test coverage

* event table ux update

* delete eventUtils.ts
  • Loading branch information
harsh-akamai authored Dec 19, 2024
1 parent cbc317e commit 31bcae2
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 102 deletions.
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-11339-fixed-1732776925827.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Fixed
---

Events landing page lists events in wrong order ([#11339](https://github.com/linode/manager/pull/11339))
22 changes: 15 additions & 7 deletions packages/manager/src/features/Events/EventRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { DateTimeDisplay } from 'src/components/DateTimeDisplay';
import { Hidden } from 'src/components/Hidden';
import { TableCell } from 'src/components/TableCell';
import { TableRow } from 'src/components/TableRow';
import { TextTooltip } from 'src/components/TextTooltip';
import { useProfile } from 'src/queries/profile/profile';
import { getEventTimestamp } from 'src/utilities/eventUtils';

import {
formatProgressEvent,
Expand All @@ -27,7 +27,6 @@ interface EventRowProps {
export const EventRow = (props: EventRowProps) => {
const { event } = props;
const theme = useTheme();
const timestamp = getEventTimestamp(event);
const { action, message, username } = {
action: event.action,
message: getEventMessage(event),
Expand All @@ -39,7 +38,11 @@ export const EventRow = (props: EventRowProps) => {
return null;
}

const { progressEventDisplay, showProgress } = formatProgressEvent(event);
const {
progressEventDate,
progressEventDuration,
showProgress,
} = formatProgressEvent(event);

return (
<TableRow data-qa-event-row data-test-id={action}>
Expand Down Expand Up @@ -72,8 +75,13 @@ export const EventRow = (props: EventRowProps) => {
</Box>
</TableCell>
</Hidden>
<TableCell parentColumn="Relative Date">
{progressEventDisplay}
<TableCell parentColumn="Start Date">
<TextTooltip
displayText={progressEventDate}
minWidth={130}
placement="top"
tooltipText={<DateTimeDisplay value={event.created} />}
/>
{username && (
<Hidden smUp>
<br />
Expand All @@ -84,8 +92,8 @@ export const EventRow = (props: EventRowProps) => {
)}
</TableCell>
<Hidden mdDown>
<TableCell data-qa-event-created-cell parentColumn="Absolute Date">
<DateTimeDisplay value={timestamp.toString()} />
<TableCell data-qa-event-created-cell parentColumn="Duration">
{progressEventDuration}
</TableCell>
</Hidden>
</TableRow>
Expand Down
6 changes: 3 additions & 3 deletions packages/manager/src/features/Events/EventsLanding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ export const EventsLanding = (props: Props) => {
User
</TableCell>
</Hidden>
<StyledTableCell sx={{ width: 175 }}>Relative Date</StyledTableCell>
<StyledTableCell sx={{ width: 175 }}>Start Date</StyledTableCell>
<Hidden mdDown>
<StyledTableCell data-qa-events-time-header sx={{ width: 150 }}>
Absolute Date
<StyledTableCell data-qa-events-time-header sx={{ width: 175 }}>
Duration
</StyledTableCell>
</Hidden>
</TableRow>
Expand Down
16 changes: 6 additions & 10 deletions packages/manager/src/features/Events/utils.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,9 @@ describe('formatProgressEvent', () => {
seconds: 1,
});
vi.setSystemTime(currentDateMock.toJSDate());
const { progressEventDisplay, showProgress } = formatProgressEvent(
mockEvent1
);
const { progressEventDate, showProgress } = formatProgressEvent(mockEvent1);

expect(progressEventDisplay).toBe('1 second ago');
expect(progressEventDate).toBe('1 second ago');
expect(showProgress).toBe(false);
});

Expand All @@ -201,21 +199,19 @@ describe('formatProgressEvent', () => {
seconds: 1,
});
vi.setSystemTime(currentDateMock.toJSDate());
const { progressEventDisplay, showProgress } = formatProgressEvent(
mockEvent2
);
const { progressEventDate, showProgress } = formatProgressEvent(mockEvent2);

expect(progressEventDisplay).toBe('Started 1 second ago');
expect(progressEventDate).toBe('Started 1 second ago');
expect(showProgress).toBe(true);
});

it('returns the correct format for a "started" event with time remaining', () => {
const { progressEventDisplay, showProgress } = formatProgressEvent({
const { progressEventDuration, showProgress } = formatProgressEvent({
...mockEvent2,

time_remaining: '0:50:00',
});
expect(progressEventDisplay).toBe('~50 minutes remaining');
expect(progressEventDuration).toBe('~50 minutes remaining');
expect(showProgress).toBe(true);
});
});
24 changes: 15 additions & 9 deletions packages/manager/src/features/Events/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { Duration } from 'luxon';

import { ACTIONS_TO_INCLUDE_AS_PROGRESS_EVENTS } from 'src/features/Events/constants';
import { isInProgressEvent } from 'src/queries/events/event.helpers';
import { getEventTimestamp } from 'src/utilities/eventUtils';
import { parseAPIDate } from 'src/utilities/date';
import { formatDuration } from 'src/utilities/formatDuration';

import { ACTIONS_WITHOUT_USERNAMES } from './constants';
import { eventMessages } from './factory';
Expand Down Expand Up @@ -112,7 +113,8 @@ const shouldShowEventProgress = (event: Event): boolean => {
};

interface ProgressEventDisplay {
progressEventDisplay: null | string;
progressEventDate: string;
progressEventDuration: string;
showProgress: boolean;
}

Expand All @@ -124,16 +126,20 @@ interface ProgressEventDisplay {
*/
export const formatProgressEvent = (event: Event): ProgressEventDisplay => {
const showProgress = shouldShowEventProgress(event);
const parsedTimeRemaining = formatEventTimeRemaining(event.time_remaining);
const startDate = parseAPIDate(event.created).toRelative();
const progressEventDate = showProgress ? `Started ${startDate}` : startDate;

const progressEventDisplay = showProgress
? parsedTimeRemaining
? `~${parsedTimeRemaining}`
: `Started ${getEventTimestamp(event).toRelative()}`
: getEventTimestamp(event).toRelative();
const parsedTimeRemaining = formatEventTimeRemaining(event.time_remaining);
const eventDuration = event.duration
? formatDuration(Duration.fromObject({ seconds: event.duration }))
: '-';
const progressEventDuration = parsedTimeRemaining
? `~${parsedTimeRemaining}`
: eventDuration;

return {
progressEventDisplay,
progressEventDate,
progressEventDuration,
showProgress,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const NotificationCenterEvent = React.memo(
return null;
}

const { progressEventDisplay, showProgress } = formatProgressEvent(event);
const { progressEventDate, showProgress } = formatProgressEvent(event);

return (
<NotificationEventStyledBox
Expand Down Expand Up @@ -73,7 +73,7 @@ export const NotificationCenterEvent = React.memo(
/>
)}
<Typography sx={{ fontSize: '0.8rem' }}>
{progressEventDisplay} | {username}
{progressEventDate} | {username}
</Typography>
</Box>
</NotificationEventStyledBox>
Expand Down
39 changes: 0 additions & 39 deletions packages/manager/src/utilities/eventUtils.test.ts

This file was deleted.

32 changes: 0 additions & 32 deletions packages/manager/src/utilities/eventUtils.ts

This file was deleted.

0 comments on commit 31bcae2

Please sign in to comment.