Skip to content

MongocampRoles ​

Full CRUD table for managing roles — create, edit (admin flag, collection grants), and delete. Includes a server-side debounced search input and sortable column headers. The key icon on each row links to the grant management page.

Usage ​

vue
<template>
  <MongocampRoles grants-path="/secured/admin/roles" />
</template>

Props ​

PropTypeDefaultDescription
grantsPathstring/secured/admin/rolesBase path the key icon links to: <grantsPath>/<roleName>
hideHeadingbooleanfalseHide the component's own heading, e.g. when the page around it already shows a title. The toolbar stays.
hideRefreshbooleanfalseHide the component's own reload button, e.g. when the page calls the exposed refresh() from its own header.

In a page with its own header ​

The component can hand its toolbar to the page around it:

  • refresh() is exposed — call it through a template ref from your own reload button, and set hideRefresh to drop the built-in one.
  • toolbar slot — your own buttons, placed beside the built-in ones.
  • changed event — emitted after a role was added, edited, cloned or deleted, once the component has reloaded. Never on a failed or cancelled action, never on a plain reload.
vue
<script setup lang="ts">
const list = useTemplateRef<{ refresh: () => void }>('list')
</script>

<template>
  <header>
    <h1>My title</h1>
    <UButton icon="i-lucide-refresh-cw" @click="list?.refresh()" />
  </header>
  <MongocampRoles ref="list" hide-heading hide-refresh @changed="reloadOtherLists">
    <template #toolbar>
      <UButton>Mine</UButton>
    </template>
  </MongocampRoles>
</template>

Behavior ​

  • List — fetched via useMongocampAdmin().listRoles(filter), debounced 300ms on the search input.
  • Details — the info icon opens a read-only side drawer with the role's Admin/Standard badge and its grants (MongocampGrantList), rendered from the list row (getRole returns exactly the same object, so there is no extra request) on a copy. Editing keeps going through the edit dialog and MongocampRoleGrants.
  • Clone — the copy icon opens a dialog asking for the new role name; the new role gets the source role's admin flag and a copy of all its grants (created with a single addRole call). A refused clone (e.g. name already taken) keeps the dialog open with the reason.
  • Add / Edit — name, isAdmin flag.
  • Delete — confirmation modal before calling deleteRole. If the server refuses, the dialog stays open and shows why so you can try again or cancel; the list is only reloaded after a successful delete.
  • Bulk delete — a checkbox column (with select-all) and a selection bar; confirming deletes the selected roles a few at a time (MongocampBulkDelete). The selection is cleared on every reload; failures are reported and stay selected.
  • Paging — 25 rows a page with a pager below the table once there are more. The table pages its sorted rows, so a header sort orders the whole list; the selection is kept across pages and select-all selects the page on screen. A shorter list after a delete never leaves you past the last page; a new search starts at page 1.
  • Errors / empty — a failed load shows MongocampErrorAlert with retry; no rows shows an empty state.
  • Grant management itself lives in MongocampRoleGrants, reached via the key icon.

Released under the MIT License.