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
| Prop | Type | Default | Description |
|---|---|---|---|
grantsPath | string | /secured/admin/roles | Base path the key icon links to: <grantsPath>/<roleName> |
hideHeading | boolean | false | Hide the component's own heading, e.g. when the page around it already shows a title. The toolbar stays. |
hideRefresh | boolean | false | Hide 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 sethideRefreshto drop the built-in one.toolbarslot — your own buttons, placed beside the built-in ones.changedevent — 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 (getRolereturns exactly the same object, so there is no extra request) on a copy. Editing keeps going through the edit dialog andMongocampRoleGrants. - 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
addRolecall). A refused clone (e.g. name already taken) keeps the dialog open with the reason. - Add / Edit — name,
isAdminflag. - 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. A role that is already gone (404) counts as deleted. - 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. - Server proxy mode — the roles of the api key's user (
useMongocampSelfroles) cannot be deleted or selected (the disabled delete says why), and an admin role among them stays one: Edit shows the Admin switch locked. Either change could cut off the app. Until the server has answered who the key belongs to, no role can be deleted. Session mode is unchanged. - 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
MongocampErrorAlertwith retry; no rows shows an empty state. - Grant management itself lives in
MongocampRoleGrants, reached via the key icon.