Skip to content

Commit e2a6b29

Browse files
committed
Improved id and timestamp layout on jobs table
1 parent 575f96a commit e2a6b29

File tree

5 files changed

+78
-10
lines changed

5 files changed

+78
-10
lines changed

__tests__/JobsList.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,27 +89,27 @@ describe('JobsList', () => {
8989
// Verify default sorting
9090
table = result.getByRole('table');
9191
expect(table.querySelectorAll('tbody tr:nth-child(1) td')[3].textContent).eq(
92-
'10/30/2023, 10:30:38 AM'
92+
'30/10/2023 10:30:38'
9393
);
9494
expect(table.querySelectorAll('tbody tr:nth-child(2) td')[3].textContent).eq(
95-
'10/30/2023, 10:15:38 AM'
95+
'30/10/2023 10:15:38'
9696
);
9797
expect(table.querySelectorAll('tbody tr:nth-child(3) td')[3].textContent).eq(
98-
'10/30/2023, 10:00:38 AM'
98+
'30/10/2023 10:00:38'
9999
);
100100

101101
// Sort by start date
102102
const startDateSorter = table.querySelector('thead th:nth-child(4)');
103103
await fireEvent.click(startDateSorter);
104104
table = result.getByRole('table');
105105
expect(table.querySelectorAll('tbody tr:nth-child(1) td')[3].textContent).eq(
106-
'10/30/2023, 10:00:38 AM'
106+
'30/10/2023 10:00:38'
107107
);
108108
expect(table.querySelectorAll('tbody tr:nth-child(2) td')[3].textContent).eq(
109-
'10/30/2023, 10:15:38 AM'
109+
'30/10/2023 10:15:38'
110110
);
111111
expect(table.querySelectorAll('tbody tr:nth-child(3) td')[3].textContent).eq(
112-
'10/30/2023, 10:30:38 AM'
112+
'30/10/2023 10:30:38'
113113
);
114114
});
115115

__tests__/TimestampCell.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { describe, it, expect } from 'vitest';
2+
import { render } from '@testing-library/svelte';
3+
4+
import TimestampCell from '../src/lib/components/jobs/TimestampCell.svelte';
5+
6+
describe('TimestampCell', () => {
7+
it('handles null timestamp', async () => {
8+
const result = render(TimestampCell, {
9+
props: { timestamp: null }
10+
});
11+
expect(result.container.textContent).eq('-');
12+
});
13+
14+
it('handles empty timestamp', async () => {
15+
const result = render(TimestampCell, {
16+
props: { timestamp: '' }
17+
});
18+
expect(result.container.textContent).eq('-');
19+
});
20+
21+
it('handles valid timestamp', async () => {
22+
const result = render(TimestampCell, {
23+
props: { timestamp: '2024-02-09T10:35:56.237579+00:00' }
24+
});
25+
expect(result.container.textContent).eq('9/2/2024 11:35:56');
26+
});
27+
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"lint": "prettier --check . && eslint .",
1212
"format": "prettier --write .",
1313
"pre-commit": "lint-staged",
14-
"test": "TZ=Europe/Rome vitest"
14+
"test": "TZ=Europe/Rome LANG='it-IT' vitest"
1515
},
1616
"devDependencies": {
1717
"@playwright/test": "^1.40.0",

src/lib/components/jobs/JobsList.svelte

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import { onDestroy, onMount } from 'svelte';
1111
import { removeDuplicatedItems } from '$lib/common/component_utilities';
1212
import StandardDismissableAlert from '../common/StandardDismissableAlert.svelte';
13+
import TimestampCell from './TimestampCell.svelte';
1314
1415
/** @type {() => Promise<import('$lib/types').ApplyWorkflow[]>} */
1516
export let jobUpdater;
@@ -178,7 +179,7 @@
178179
<table class="table jobs-table">
179180
<colgroup>
180181
{#if !columnsToHide.includes('id')}
181-
<col width="40" />
182+
<col width="60" />
182183
{/if}
183184
<col width="100" />
184185
<col width="110" />
@@ -334,10 +335,10 @@
334335
{/if}
335336
</td>
336337
<td>
337-
{row.start_timestamp ? new Date(row.start_timestamp).toLocaleString() : '-'}
338+
<TimestampCell timestamp={row.start_timestamp} />
338339
</td>
339340
<td>
340-
{row.end_timestamp ? new Date(row.end_timestamp).toLocaleString() : '-'}
341+
<TimestampCell timestamp={row.end_timestamp} />
341342
</td>
342343
{#if !columnsToHide.includes('project')}
343344
<td>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<script>
2+
/** @type {string|null} */
3+
export let timestamp;
4+
5+
let date = '';
6+
let time = '';
7+
8+
$: {
9+
if (timestamp) {
10+
const dateObj = new Date(timestamp);
11+
date = dateObj.toLocaleString([], {
12+
day: 'numeric',
13+
month: 'numeric',
14+
year: 'numeric'
15+
});
16+
time = dateObj.toLocaleString([], {
17+
hour: 'numeric',
18+
minute: 'numeric',
19+
second: 'numeric',
20+
hour12: false
21+
});
22+
} else {
23+
date = '';
24+
time = '';
25+
}
26+
}
27+
</script>
28+
29+
{#if date === ''}
30+
-
31+
{:else}
32+
<span class="nowrap">{date}</span>
33+
<span class="nowrap">{time}</span>
34+
{/if}
35+
36+
<style>
37+
.nowrap {
38+
display: inline-block;
39+
}
40+
</style>

0 commit comments

Comments
 (0)