@svadmin/ui 0.40.6 → 0.41.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -34,7 +34,7 @@
34
34
  cell_getValue,
35
35
  } from '@tanstack/table-core/static-functions';
36
36
 
37
- import { captureAdminContext, useList, useDelete, useDeleteMany, getResource, notify } from '@svadmin/core';
37
+ import { captureAdminContext, useList, useDelete, useDeleteMany, getResource, notifyWithProvider } from '@svadmin/core';
38
38
  import type {
39
39
  BaseRecord,
40
40
  FieldDefinition,
@@ -43,7 +43,7 @@
43
43
  Pagination as PaginationState,
44
44
  Sort,
45
45
  } from '@svadmin/core';
46
- import { useCan, getAccessControlProvider } from '@svadmin/core';
46
+ import { useCan } from '@svadmin/core';
47
47
  import { readURLState, writeURLState } from '@svadmin/core';
48
48
  import { useTranslation } from '@svadmin/core/i18n';
49
49
 
@@ -259,13 +259,15 @@
259
259
  const deleteManyMutation = deleteManyResult.mutation;
260
260
 
261
261
  // ─── Permissions ──────────────────────────────────────────────
262
- const acEnabled = $derived(!!getAccessControlProvider());
262
+ const acEnabled = $derived(!!adminContext.accessControlProvider);
263
263
  const canCreatePerm = useCan(() => ({ resource: resourceName, action: 'create', queryOptions: { enabled: acEnabled } }));
264
264
  const canEditPerm = useCan(() => ({ resource: resourceName, action: 'edit', queryOptions: { enabled: acEnabled } }));
265
+ const canShowPerm = useCan(() => ({ resource: resourceName, action: 'show', queryOptions: { enabled: acEnabled } }));
265
266
  const canDeletePerm = useCan(() => ({ resource: resourceName, action: 'delete', queryOptions: { enabled: acEnabled } }));
266
267
  const canExportPerm = useCan(() => ({ resource: resourceName, action: 'export', queryOptions: { enabled: acEnabled } }));
267
268
  const canCreate = $derived(canCreatePerm.allowed && resource.canCreate !== false);
268
269
  const canEdit = $derived(canEditPerm.allowed && resource.canEdit !== false);
270
+ const canShow = $derived(canShowPerm.allowed && resource.canShow !== false);
269
271
  const canDelete = $derived(canDeletePerm.allowed && resource.canDelete !== false);
270
272
  const canExport = $derived(canExportPerm.allowed);
271
273
 
@@ -505,9 +507,15 @@
505
507
  confirmAction = async () => {
506
508
  try {
507
509
  await deleteManyMutation.mutateAsync({ ids, resource: resourceName });
508
- notify({ type: 'success', message: i18n.t('common.batchDeleteSuccess', { count: ids.length }) });
510
+ notifyWithProvider(
511
+ { type: 'success', message: i18n.t('common.batchDeleteSuccess', { count: ids.length }) },
512
+ adminContext.notificationProvider,
513
+ );
509
514
  } catch {
510
- notify({ type: 'error', message: i18n.t('common.batchDeletePartialFail', { failed: 1, total: ids.length }) });
515
+ notifyWithProvider(
516
+ { type: 'error', message: i18n.t('common.batchDeletePartialFail', { failed: 1, total: ids.length }) },
517
+ adminContext.notificationProvider,
518
+ );
511
519
  }
512
520
  rowSelectionAtom.set({});
513
521
  confirmOpen = false;
@@ -831,9 +839,11 @@
831
839
  <Pencil class="h-4 w-4" /> {i18n.t('common.edit')}
832
840
  </ContextMenu.Item>
833
841
  {/if}
834
- <ContextMenu.Item onclick={() => adminContext.navigate(`/${resourceName}/show/${id}`)} class="gap-2">
835
- <Eye class="h-4 w-4" /> {i18n.t('common.detail')}
836
- </ContextMenu.Item>
842
+ {#if canShow}
843
+ <ContextMenu.Item onclick={() => adminContext.navigate(`/${resourceName}/show/${id}`)} class="gap-2">
844
+ <Eye class="h-4 w-4" /> {i18n.t('common.detail')}
845
+ </ContextMenu.Item>
846
+ {/if}
837
847
  <ContextMenu.Item onclick={() => navigator.clipboard?.writeText(String(id))} class="gap-2">
838
848
  <Copy class="h-4 w-4" /> {i18n.t('common.copyId')}
839
849
  </ContextMenu.Item>
@@ -907,9 +917,11 @@
907
917
  <Pencil class="h-4 w-4" />
908
918
  </TooltipButton>
909
919
  {/if}
910
- <TooltipButton tooltip={i18n.t('common.detail')} variant="ghost" size="icon-sm" onclick={() => adminContext.navigate(`/${resourceName}/show/${id}`)}>
911
- <Eye class="h-4 w-4" />
912
- </TooltipButton>
920
+ {#if canShow}
921
+ <TooltipButton tooltip={i18n.t('common.detail')} variant="ghost" size="icon-sm" onclick={() => adminContext.navigate(`/${resourceName}/show/${id}`)}>
922
+ <Eye class="h-4 w-4" />
923
+ </TooltipButton>
924
+ {/if}
913
925
  {#if canDelete}
914
926
  <TooltipButton tooltip={i18n.t('common.delete')} variant="ghost" size="icon-sm" onclick={() => confirmDelete(id)} class="hover:text-destructive">
915
927
  <Trash2 class="h-4 w-4" />
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import { getTaskProvider } from '@svadmin/core';
2
+ import { captureAdminContext } from '@svadmin/core';
3
3
  import { useQueryClient } from '@tanstack/svelte-query';
4
4
  import { useTranslation } from '@svadmin/core/i18n';
5
5
 
@@ -7,10 +7,11 @@
7
7
  import { Loader2, Ban } from '@lucide/svelte';
8
8
 
9
9
  const i18n = useTranslation();
10
+ const adminContext = captureAdminContext();
10
11
 
11
12
  let {
12
13
  taskId,
13
- taskProvider = getTaskProvider({ optional: true }),
14
+ taskProvider = adminContext.taskProvider ?? undefined,
14
15
  onSuccess,
15
16
  onError,
16
17
  disabled = false,
@@ -37,8 +38,15 @@
37
38
  try {
38
39
  await taskProvider.cancel(taskId);
39
40
  await Promise.all([
40
- queryClient.invalidateQueries({ queryKey: ['taskList'] }),
41
- queryClient.invalidateQueries({ queryKey: ['task', taskId] }),
41
+ queryClient.invalidateQueries({
42
+ predicate: (query) => query.queryKey[0] === 'taskList'
43
+ && adminContext.matchesTenantQuery(query.queryKey),
44
+ }),
45
+ queryClient.invalidateQueries({
46
+ predicate: (query) => query.queryKey[0] === 'task'
47
+ && query.queryKey[1] === taskId
48
+ && adminContext.matchesTenantQuery(query.queryKey),
49
+ }),
42
50
  ]);
43
51
  onSuccess?.();
44
52
  } catch (error) {