Skip to content

Commit

Permalink
Add onError callback
Browse files Browse the repository at this point in the history
  • Loading branch information
laurakwhit committed Aug 19, 2024
1 parent 8ce7489 commit 1eed4d5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/lib/pages/schedules.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import SchedulesTableRow from '$lib/components/schedule/schedules-table-row.svelte';
import SearchAttributeFilter from '$lib/components/search-attribute-filter/index.svelte';
import ConfigurableTableHeadersDrawer from '$lib/components/workflow/configurable-table-headers-drawer/index.svelte';
import Alert from '$lib/holocene/alert.svelte';
import Button from '$lib/holocene/button.svelte';
import EmptyState from '$lib/holocene/empty-state.svelte';
import Input from '$lib/holocene/input/input.svelte';
Expand All @@ -30,13 +31,15 @@
searchAttributes,
} from '$lib/stores/search-attributes';
import { toListWorkflowFilters } from '$lib/utilities/query/to-list-workflow-filters';
import type { APIErrorResponse } from '$lib/utilities/request-from-api';
import { routeForScheduleCreate } from '$lib/utilities/route-for';
import { writeActionsAreAllowed } from '$lib/utilities/write-actions-are-allowed';
let refresh = Date.now();
let coreUser = coreUserStore();
let customizationDrawerOpen = false;
let search = '';
let error = '';
const openCustomizationDrawer = () => {
customizationDrawerOpen = true;
Expand All @@ -55,7 +58,10 @@
},
);
$: query = $page.url.searchParams.get('query');
$: onFetch = () => fetchPaginatedSchedules(namespace, query);
$: onFetch = () => {
error = '';
return fetchPaginatedSchedules(namespace, query, onError);
};
$: availableColumns = availableScheduleColumns(namespace);
onMount(() => {
Expand All @@ -64,12 +70,17 @@
$scheduleFilters = toListWorkflowFilters(query, $searchAttributes);
}
});
const onError = (err: APIErrorResponse) => {
error = err?.body?.message || translate('schedules.error-message-fetching');
};
</script>

{#key [namespace, query, refresh]}
<PaginatedTable
let:visibleItems
{onFetch}
{onError}
total={$schedulesCount}
aria-label={translate('common.schedules')}
pageSizeSelectLabel={translate('common.per-page')}
Expand Down Expand Up @@ -156,7 +167,13 @@
{/each}

<svelte:fragment slot="empty">
{#if query}
{#if error}
<EmptyState title={translate('schedules.empty-state-title')}>
<Alert intent="warning" icon="warning" class="mx-12">
{error}
</Alert>
</EmptyState>
{:else if query}
<EmptyState
title={translate('schedules.empty-state-title')}
content={translate('schedules.empty-state-description')}
Expand Down
2 changes: 2 additions & 0 deletions src/lib/services/schedule-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type PaginatedSchedulesPromise = (
export const fetchPaginatedSchedules = async (
namespace: string,
query: string,
onError: ErrorCallback,
request = fetch,
): Promise<PaginatedSchedulesPromise> => {
return (pageSize = 100, token = '') => {
Expand All @@ -45,6 +46,7 @@ export const fetchPaginatedSchedules = async (
...(query ? { query } : {}),
},
request,
onError,
}).then(({ schedules, nextPageToken }) => {
return {
items: schedules,
Expand Down

0 comments on commit 1eed4d5

Please sign in to comment.