Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 69 additions & 25 deletions src/lib/components/DomainTest/History.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
import { languageTag } from '@/paraglide/runtime';
import Button from '@/lib/components/Button/Button.svelte';
import ButtonGroup from '@/lib/components/ButtonGroup/ButtonGroup.svelte';
import { getTestHistory, type ResultData, type TestHistoryItem } from '@/lib/client.js';
import {
getTestHistory,
type ResultData,
type TestHistoryItem,
} from '@/lib/client.js';
import { navigate } from '@/lib/router.svelte';
import { formatDate } from '@/lib/formatDate.ts';

Expand All @@ -20,27 +24,28 @@
const filterOptions = $derived([
{ key: 'all', value: m.historyAll() },
{ key: 'delegated', value: m.delegated() },
{ key: 'undelegated', value: m.undelegated() }
{ key: 'undelegated', value: m.undelegated() },
]);

function onClick() {
const historyDialog = document.getElementById('historyDialog') as HTMLDialogElement;
const historyDialog = document.getElementById(
'historyDialog',
) as HTMLDialogElement;

getTestHistory({ domain: data.params.domain })
.then((data) => {
history = data;
applyFilter();
historyDialog.showModal();
});
getTestHistory({ domain: data.params.domain }).then((data) => {
history = data;
applyFilter();
historyDialog.showModal();
});
}

function applyFilter() {
if (filter === 'all') {
filteredHistory = history;
} else if (filter === 'delegated') {
filteredHistory = history.filter(item => !item.undelegated);
filteredHistory = history.filter((item) => !item.undelegated);
} else if (filter === 'undelegated') {
filteredHistory = history.filter(item => item.undelegated);
filteredHistory = history.filter((item) => item.undelegated);
}
page = 1; // Reset to first page when filter changes
}
Expand All @@ -54,15 +59,21 @@
e.preventDefault();

const target = e.target as HTMLAnchorElement;
const historyDialog = document.getElementById('historyDialog') as HTMLDialogElement;
const historyDialog = document.getElementById(
'historyDialog',
) as HTMLDialogElement;

navigate(target.getAttribute('href') as string);
historyDialog.close();
}

const itemsPerPage = 10;
const paginatedHistory = $derived(filteredHistory.slice((page - 1) * itemsPerPage, page * itemsPerPage));
const totalPages = $derived(Math.ceil(filteredHistory.length / itemsPerPage));
const paginatedHistory = $derived(
filteredHistory.slice((page - 1) * itemsPerPage, page * itemsPerPage),
);
const totalPages = $derived(
Math.ceil(filteredHistory.length / itemsPerPage),
);

function goToPage(newPage: number) {
if (newPage >= 1 && newPage <= totalPages) {
Expand All @@ -71,7 +82,13 @@
}
</script>

<Button variant="secondary" size="small" type="button" onClick={onClick} id="zmHistoryButton">
<Button
variant="secondary"
size="small"
type="button"
{onClick}
id="zmHistoryButton"
>
<i class="bi bi-clock-history"></i>
{m.history()}
</Button>
Expand All @@ -91,8 +108,11 @@
</header>
<ul>
{#each paginatedHistory as item}
<li class="{item.overall_result}">
<a href={`${import.meta.env.BASE_URL}${languageTag()}/result/${item.id}`} onclick={onClickLink}>
<li class={item.overall_result}>
<a
href={`${import.meta.env.BASE_URL}${languageTag()}/result/${item.id}`}
onclick={onClickLink}
>
{formatDate(item.created_at)}
</a>
{#if item.undelegated}
Expand All @@ -103,10 +123,22 @@
{/each}
</ul>
<footer>
<Button variant="secondary" size="small" type="button" onClick={() => goToPage(1)} disabled={page === 1}>
<Button
variant="secondary"
size="small"
type="button"
onClick={() => goToPage(1)}
disabled={page === 1}
>
<i class="bi bi-chevron-double-left"></i>
</Button>
<Button variant="secondary" size="small" type="button" onClick={() => page--} disabled={page === 1}>
<Button
variant="secondary"
size="small"
type="button"
onClick={() => page--}
disabled={page === 1}
>
<i class="bi bi-chevron-left"></i>
</Button>

Expand All @@ -116,7 +148,7 @@
<!-- Show all pages if 5 or fewer total pages -->
{@const pageNum = i + 1}
<Button
variant={pageNum === page ? "primary" : "secondary"}
variant={pageNum === page ? 'primary' : 'secondary'}
size="small"
type="button"
onClick={() => goToPage(pageNum)}
Expand All @@ -127,7 +159,7 @@
<!-- First 5 pages when current page is near the beginning -->
{@const pageNum = i + 1}
<Button
variant={pageNum === page ? "primary" : "secondary"}
variant={pageNum === page ? 'primary' : 'secondary'}
size="small"
type="button"
onClick={() => goToPage(pageNum)}
Expand All @@ -138,7 +170,7 @@
<!-- Last 5 pages when current page is near the end -->
{@const pageNum = totalPages - 4 + i}
<Button
variant={pageNum === page ? "primary" : "secondary"}
variant={pageNum === page ? 'primary' : 'secondary'}
size="small"
type="button"
onClick={() => goToPage(pageNum)}
Expand All @@ -149,7 +181,7 @@
<!-- Middle pages with current page in center -->
{@const pageNum = page - 2 + i}
<Button
variant={pageNum === page ? "primary" : "secondary"}
variant={pageNum === page ? 'primary' : 'secondary'}
size="small"
type="button"
onClick={() => goToPage(pageNum)}
Expand All @@ -160,10 +192,22 @@
{/each}
{/if}

<Button variant="secondary" size="small" type="button" onClick={() => page++} disabled={page === totalPages}>
<Button
variant="secondary"
size="small"
type="button"
onClick={() => page++}
disabled={page === totalPages}
>
<i class="bi bi-chevron-right"></i>
</Button>
<Button variant="secondary" size="small" type="button" onClick={() => goToPage(totalPages)} disabled={page === totalPages}>
<Button
variant="secondary"
size="small"
type="button"
onClick={() => goToPage(totalPages)}
disabled={page === totalPages}
>
<i class="bi bi-chevron-double-right"></i>
</Button>
</footer>
Expand Down
30 changes: 19 additions & 11 deletions src/lib/components/DomainTest/ResultInfo.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
query: '',
});
const rawData = $derived(data.results);
const result = $state(groupResult(data.results));
const result = $derived(groupResult(data.results));
let showExport = $state(false);
let showShare = $state(false);
let showURL = $state(false);
Expand Down Expand Up @@ -149,10 +149,10 @@
type="button"
aria-controls="copyTLDURLDialog"
onclick={() => {
showURL = !showURL;
showExport = false;
showShare = false;
}}
showURL = !showURL;
showExport = false;
showShare = false;
}}
id="zmTLDURLButton"
>
<i class="bi bi-link-45deg"></i>
Expand All @@ -166,8 +166,8 @@
>
<div
class="{stack.stack} {stack.stretch} {stack.spaceBetween} {stack[
'gap--s'
]}"
'gap--s'
]}"
>
<Input
matchContentWidth
Expand Down Expand Up @@ -211,19 +211,27 @@
>
<button
class="zm-popover__plain-btn"
onmousedown={() => exportJson(data)}> {m.exportJson()}</button
onmousedown={() => exportJson(data)}
>
{m.exportJson()}</button
>
<button
class="zm-popover__plain-btn"
onmousedown={() => exportHTML(data)}> {m.exportHtml()}</button
onmousedown={() => exportHTML(data)}
>
{m.exportHtml()}</button
>
<button
class="zm-popover__plain-btn"
onmousedown={() => exportCSV(data)}> {m.exportCsv()}</button
onmousedown={() => exportCSV(data)}
>
{m.exportCsv()}</button
>
<button
class="zm-popover__plain-btn"
onmousedown={() => exportText(data)}> {m.exportText()}</button
onmousedown={() => exportText(data)}
>
{m.exportText()}</button
>
</div>
</div>
Expand Down