@adula/ui 1.2.0 → 2.1.0
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.
- package/LICENSE +1 -1
- package/README.md +3 -3
- package/build/calendar-date.json +1 -1
- package/build/can.json +1 -1
- package/build/data-table.json +1 -1
- package/build/manifest.json +59 -59
- package/build/record-assignments.json +1 -1
- package/build/record-collaboration.json +1 -1
- package/build/record-workflows.json +1 -1
- package/build/resource-actions.json +1 -1
- package/build/resource-field.json +1 -1
- package/build/resource-form.json +1 -1
- package/build/resource-import.json +1 -1
- package/build/resource-page.json +1 -1
- package/build/resource-show.json +1 -1
- package/build/resource-value.json +1 -1
- package/build/theme.css +16 -16
- package/build/ui-preferences.json +1 -1
- package/package.json +4 -4
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @adula/ui
|
|
2
2
|
|
|
3
|
-
Version 1.0.
|
|
3
|
+
Version 2.1.0. For complete consumer setup, use the canonical [installation guide](https://github.com/adulash/adulajs/blob/main/docs/installation.md).
|
|
4
4
|
|
|
5
5
|
Arabic RTL shadcn registry for project-owned React components. This package ships JSON assets, not a runtime React component library. Install with `node ace adula:ui add all` or `node ace adula:ui add dialog`. The command invokes the pinned shadcn CLI and records each generated file hash in `ui.lock.json`. Project modifications are preserved; use `--preview` to review upstream differences before merging an update.
|
|
6
6
|
|
|
@@ -8,7 +8,7 @@ The 25 primitives are based on the official shadcn new-york-v4 registry. See LIC
|
|
|
8
8
|
|
|
9
9
|
Build with `pnpm --filter @adula/ui build`. Refreshing upstream sources is an explicit maintenance task: run scripts/sync-ui-registry.mjs, review changes, run scripts/prepare-ui-registry.mjs to recheck dependency metadata and adapt sources, then build and visually test.
|
|
10
10
|
|
|
11
|
-
Required host tooling: Node 24, React 19, shadcn 4.21.0, Tailwind CSS 4.3.3 and @tailwindcss/vite 4.3.3.
|
|
11
|
+
Required host tooling: Node 24, React 19, shadcn 4.21.0, Tailwind CSS 4.3.3 and @tailwindcss/vite 4.3.3. AdulaJS installer supports the official AdonisJS React starter layout. The registry is unpublished until explicitly authorized.
|
|
12
12
|
|
|
13
13
|
The theme disables automatic Tailwind source discovery and explicitly scans the consumer's inertia directory. It does not scan node_modules or unrelated workspace files. Add explicit source paths for any additional application-owned frontend directories.
|
|
14
14
|
|
|
@@ -16,7 +16,7 @@ Components merge `className` with `cn` (shadcn's clsx + tailwind-merge replaceme
|
|
|
16
16
|
|
|
17
17
|
## Resource components
|
|
18
18
|
|
|
19
|
-
Nine
|
|
19
|
+
Nine AdulaJS components sit on top of the primitives and are registered by `scripts/register-resource-ui.mjs`. They consume the `ResourceDescription`, `ResourceList`, `ResourceEditor`, `ResourceShow`, `ResourceChildren`, `ResourceLookups` and `ResourceActivity` contracts exported by `adula`; the copied files are project-owned like every other registry item.
|
|
20
20
|
|
|
21
21
|
| Component | Role |
|
|
22
22
|
|---|---|
|
package/build/calendar-date.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
{
|
|
8
8
|
"path": "registry/ui/calendar_date.ts",
|
|
9
9
|
"type": "registry:ui",
|
|
10
|
-
"content": "import type { CalendarSystem, CalendarPreference } from '
|
|
10
|
+
"content": "import type { CalendarSystem, CalendarPreference } from 'adula'\n\nconst dayMs = 86400000\nconst hijri = new Intl.DateTimeFormat('en-u-nu-latn', {\n calendar: 'islamic-umalqura',\n timeZone: 'UTC',\n year: 'numeric',\n month: '2-digit',\n day: '2-digit',\n})\n\nexport function calendarInput(iso: string, calendar: CalendarSystem): string {\n if (!iso) return ''\n if (calendar === 'gregory') return iso.slice(0, 10)\n const date = new Date(`${iso.slice(0, 10)}T00:00:00Z`)\n if (Number.isNaN(date.getTime())) return ''\n const parts = Object.fromEntries(hijri.formatToParts(date).map((part) => [part.type, part.value]))\n return `${parts.year.padStart(4, '0')}-${parts.month.padStart(2, '0')}-${parts.day.padStart(2, '0')}`\n}\n\n/** Invert the platform's Umm al-Qura calendar; never approximate lunar months. */\nexport function calendarIso(raw: string, calendar: CalendarSystem): string {\n const value = raw\n .replace(/[٠-٩]/g, (d) => String('٠١٢٣٤٥٦٧٨٩'.indexOf(d)))\n .replace(/[۰-۹]/g, (d) => String('۰۱۲۳۴۵۶۷۸۹'.indexOf(d)))\n .trim()\n if (!value) return ''\n if (!/^\\d{4}-\\d{2}-\\d{2}$/.test(value)) throw new Error('أدخل التاريخ بصيغة سنة-شهر-يوم')\n if (calendar === 'gregory') {\n const date = new Date(`${value}T00:00:00Z`)\n if (Number.isNaN(date.getTime()) || date.toISOString().slice(0, 10) !== value)\n throw new Error('التاريخ الميلادي غير صالح')\n return value\n }\n const [year, month, day] = value.split('-').map(Number)\n if (year < 1300 || year > 1600 || month < 1 || month > 12 || day < 1 || day > 30)\n throw new Error('اختر تاريخ أم القرى بين عامي 1300 و1600 هـ')\n let low = Math.floor(Date.UTC(1882, 0, 1) / dayMs)\n let high = Math.floor(Date.UTC(2175, 11, 31) / dayMs)\n while (low <= high) {\n const middle = Math.floor((low + high) / 2)\n const iso = new Date(middle * dayMs).toISOString().slice(0, 10)\n const candidate = calendarInput(iso, calendar)\n if (candidate === value) return iso\n if (candidate < value) low = middle + 1\n else high = middle - 1\n }\n throw new Error('هذا اليوم غير موجود في تقويم أم القرى')\n}\n\nexport function calendarDisplay(\n value: unknown,\n calendar: CalendarPreference,\n withTime = false\n): string {\n if (!value) return '—'\n if (calendar === 'both')\n return `${calendarDisplay(value, 'gregory', withTime)} · ${calendarDisplay(value, 'islamic-umalqura', withTime)}`\n const date = new Date(String(value))\n if (Number.isNaN(date.getTime())) return String(value)\n // ICU wraps Arabic separators in bidi marks, which scramble the digits in any\n // container whose direction differs from the text; callers isolate the value instead.\n return new Intl.DateTimeFormat('ar-u-nu-latn', {\n calendar,\n dateStyle: 'medium',\n ...(withTime ? { timeStyle: 'short' as const } : { timeZone: 'UTC' }),\n })\n .format(date)\n .replace(/[\\u200e\\u200f\\u061c]/g, '')\n}\n",
|
|
11
11
|
"target": "inertia/components/ui/calendar_date.ts"
|
|
12
12
|
}
|
|
13
13
|
],
|
package/build/can.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
{
|
|
8
8
|
"path": "registry/ui/can.tsx",
|
|
9
9
|
"type": "registry:ui",
|
|
10
|
-
"content": "import type { ReactNode } from 'react'\nimport type { Action, RecordPermissions } from '
|
|
10
|
+
"content": "import type { ReactNode } from 'react'\nimport type { Action, RecordPermissions } from 'adula'\n\n/** CASL is evaluated server-side before redaction; hidden condition fields stay private. */\nexport function Can({ permissions, action, children }: {\n permissions: RecordPermissions; action: Action; children: ReactNode\n}) {\n return permissions[action] ? children : null\n}\n",
|
|
11
11
|
"target": "inertia/components/ui/can.tsx"
|
|
12
12
|
}
|
|
13
13
|
],
|
package/build/data-table.json
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
{
|
|
25
25
|
"path": "registry/ui/data-table.tsx",
|
|
26
26
|
"type": "registry:ui",
|
|
27
|
-
"content": "import {\n useEffect,\n useId,\n useRef,\n useState,\n type ComponentRef,\n type MouseEvent,\n type ReactNode,\n} from 'react'\nimport { InfiniteScroll, router, usePage } from '@inertiajs/react'\nimport { Link } from '@adonisjs/inertia/react'\nimport { tableFeatures, useTable } from '@tanstack/react-table'\nimport { useVirtualizer } from '@tanstack/react-virtual'\nimport axios from 'axios'\nimport {\n ArrowDown,\n ArrowDownUp,\n ArrowUp,\n Check,\n ChevronsUpDown,\n Download,\n Inbox,\n Loader2,\n Bookmark,\n BookmarkPlus,\n Search,\n SlidersHorizontal,\n X,\n} from 'lucide-react'\nimport type {\n ResourceDescription,\n ResourceField,\n ResourceList,\n SavedView,\n SavedViewQuery,\n SerializedRecord,\n} from '@adula/kit'\nimport { Badge } from '~/components/ui/badge'\nimport { Button } from '~/components/ui/button'\nimport { useUiPreferences } from '~/components/ui/ui-preferences'\nimport { Can } from '~/components/ui/can'\nimport { Input } from '~/components/ui/input'\nimport { ResourceActions } from '~/components/ui/resource-actions'\nimport { openRecord, rememberListView } from '~/components/ui/resource-surface'\nimport { FieldControl, ResourceSelect } from '~/components/ui/resource-field'\nimport {\n Command,\n CommandEmpty,\n CommandGroup,\n CommandInput,\n CommandItem,\n CommandList,\n} from '~/components/ui/command'\nimport { Popover, PopoverContent, PopoverTrigger } from '~/components/ui/popover'\nimport {\n csvCell,\n displayValue,\n parseValue,\n relationLabel,\n type LookupOptions,\n type Option,\n} from '~/components/ui/resource-value'\n\n/** Rows above this count render through the virtualizer (plan section 13). */\nexport const VIRTUAL_ROWS = 200\nconst ROW_HEIGHT = 52\nconst PAGE_SIZE = 100\nconst features = tableFeatures({})\ntype Query = Record<string, string | undefined>\n\nexport function DataTable({\n resource,\n result,\n lookups = {},\n savedViews = [],\n}: {\n resource: ResourceDescription\n result: ResourceList\n lookups?: LookupOptions\n savedViews?: SavedView[]\n}) {\n const { calendar } = useUiPreferences()\n const { url } = usePage()\n const query = new URL(url, 'http://localhost').searchParams\n const [search, setSearch] = useState(query.get('search') ?? '')\n const [failure, setFailure] = useState('')\n const container = useRef<HTMLDivElement>(null)\n const scroller = useRef<ComponentRef<typeof InfiniteScroll>>(null)\n // Opening one of this list's records remembers the view, so closing the dialog returns to it.\n useEffect(\n () =>\n router.on('before', (event) => {\n const { pathname } = event.detail.visit.url\n if (pathname.startsWith(`/resources/${resource.name}/`)) rememberListView(pathname)\n }),\n [resource.name]\n )\n // Inertia merges `result.data` page by page; permissions and labels of earlier pages accumulate here.\n const store = useRef<{\n source: ResourceList | null\n permissions: ResourceList['permissions']\n related: ResourceList['related']\n }>({ source: null, permissions: {}, related: {} })\n if (store.current.source !== result) {\n const related = { ...store.current.related }\n for (const [key, rows] of Object.entries(result.related))\n related[key] = [\n ...new Map([...(related[key] ?? []), ...rows].map((row) => [String(row.id), row])).values(),\n ]\n store.current = {\n source: result,\n permissions: { ...store.current.permissions, ...result.permissions },\n related,\n }\n }\n const { permissions, related } = store.current\n const fields = resource.fields.filter(\n (field) => resource.list.includes(field.key) && field.type !== 'hasMany'\n )\n const filterable = fields.filter((field) => field.filterable)\n const table = useTable({\n features,\n data: result.data,\n columns: fields.map((field) => ({ accessorKey: field.key, id: field.key })),\n getRowId: (row) => String(row.id),\n })\n const rows = table.getRowModel().rows\n const virtualized = rows.length > VIRTUAL_ROWS\n const virtual = useVirtualizer({\n count: rows.length,\n getScrollElement: () => container.current,\n estimateSize: () => ROW_HEIGHT,\n overscan: 10,\n enabled: virtualized,\n getItemKey: (index) => rows[index].id,\n })\n const items = virtualized\n ? virtual.getVirtualItems()\n : rows.map((_, index) => ({ index, start: 0, end: 0 }))\n const navigate = (changes: Query) => {\n const next = new URLSearchParams(query)\n next.delete('cursor')\n for (const [key, value] of Object.entries(changes))\n value ? next.set(key, value) : next.delete(key)\n const suffix = next.toString()\n router.get(\n `/resources/${resource.name}${suffix ? `?${suffix}` : ''}`,\n {},\n { preserveScroll: true }\n )\n }\n const sort = query.get('sort')\n const direction = query.get('direction') === 'desc' ? 'desc' : 'asc'\n const activeFilters = filterable.filter((field) => query.get(`filters[${field.key}]`))\n const csv = () => {\n const content = [\n fields.map((field) => field.label.ar),\n ...result.data.map((row) =>\n fields.map((field) => displayValue(field, row, related, lookups, calendar))\n ),\n ]\n const href = URL.createObjectURL(\n new Blob(['' + content.map((row) => row.map(csvCell).join(',')).join('\\r\\n')], {\n type: 'text/csv;charset=utf-8',\n })\n )\n const link = document.createElement('a')\n link.href = href\n link.download = `${resource.label}.csv`\n link.click()\n URL.revokeObjectURL(href)\n }\n const refresh = () => router.visit(url, { preserveScroll: true })\n // Records open in a dialog over this list, which stays mounted (#31); modified clicks\n // (new tab, new window) keep the link's own behavior.\n const overlay = (event: MouseEvent, id: string, mode: 'show' | 'edit') => {\n if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey)\n return\n event.preventDefault()\n void openRecord(resource.name, id, mode)\n }\n const currentQuery = (): SavedViewQuery => {\n const view: SavedViewQuery = {}\n const text = query.get('search')\n if (text) view.search = text\n if (sort) {\n view.sort = sort\n view.direction = direction\n }\n const filters: Record<string, string> = {}\n for (const field of filterable) {\n const value = query.get(`filters[${field.key}]`)\n if (value) filters[field.key] = value\n }\n if (Object.keys(filters).length) view.filters = filters\n return view\n }\n const applyView = (view: SavedView) => {\n const next = new URLSearchParams()\n if (view.query.search) next.set('search', view.query.search)\n if (view.query.sort) {\n next.set('sort', view.query.sort)\n next.set('direction', view.query.direction ?? 'asc')\n }\n for (const [key, value] of Object.entries(view.query.filters ?? {}))\n if (value !== null) next.set(`filters[${key}]`, String(value))\n setSearch(view.query.search ?? '')\n const suffix = next.toString()\n router.get(\n `/resources/${resource.name}${suffix ? `?${suffix}` : ''}`,\n {},\n { preserveScroll: true }\n )\n }\n return (\n <section\n aria-label={`قائمة ${resource.label}`}\n className=\"min-w-0 overflow-hidden rounded-xl border border-border bg-white shadow-[0_2px_10px_#1c302804]\"\n >\n <div className=\"flex flex-wrap items-center justify-between gap-4 border-b px-5 py-4\">\n <div className=\"flex flex-wrap items-center gap-3\">\n <h2 className=\"text-sm font-semibold\">سجل {resource.label}</h2>\n <Badge variant=\"secondary\" className=\"font-normal tabular-nums\">\n {rows.length} معروض\n </Badge>\n <span className=\"text-xs text-muted-foreground\">\n {result.meta.estimatedTotal !== undefined\n ? `نحو ${result.meta.estimatedTotal} سجل ضمن نطاقك`\n : 'حسب نطاق صلاحياتك'}\n </span>\n </div>\n <Button variant=\"outline\" size=\"sm\" onClick={csv} disabled={!rows.length}>\n <Download size={15} />\n تصدير المعروض\n </Button>\n </div>\n {(resource.searchable || filterable.length > 0) && (\n <SavedViewsBar\n resource={resource}\n views={savedViews}\n current={currentQuery}\n onApply={applyView}\n onChanged={refresh}\n onFailure={setFailure}\n />\n )}\n {(resource.searchable || filterable.length > 0) && (\n <div className=\"flex flex-wrap items-end gap-3 border-b px-5 py-4\">\n {resource.searchable && (\n <form\n role=\"search\"\n className=\"relative w-full max-w-sm\"\n onSubmit={(event) => {\n event.preventDefault()\n navigate({ search })\n }}\n >\n <Search\n className=\"pointer-events-none absolute start-3 top-2.5 text-muted-foreground\"\n size={16}\n />\n <Input\n aria-label={`البحث في ${resource.label}`}\n value={search}\n onChange={(event) => setSearch(event.target.value)}\n placeholder=\"ابحث في السجلات...\"\n className=\"h-9 bg-background/60 ps-10 text-xs\"\n />\n </form>\n )}\n {filterable.length > 0 && (\n <span className=\"flex items-center gap-2 text-xs text-muted-foreground\">\n <SlidersHorizontal size={15} />\n تصفية\n </span>\n )}\n {filterable.map((field) => (\n <Filter\n key={field.key}\n resource={resource.name}\n field={field}\n value={query.get(`filters[${field.key}]`) ?? ''}\n options={lookups[field.key]}\n related={related[field.key]}\n onApply={(value) => navigate({ [`filters[${field.key}]`]: value })}\n />\n ))}\n {activeFilters.length > 0 && (\n <Button\n variant=\"ghost\"\n size=\"sm\"\n onClick={() =>\n navigate(\n Object.fromEntries(\n activeFilters.map((field) => [`filters[${field.key}]`, undefined])\n )\n )\n }\n >\n <X size={14} />\n مسح التصفية\n </Button>\n )}\n </div>\n )}\n <InfiniteScroll\n ref={(instance) => {\n scroller.current = instance\n }}\n data=\"result\"\n manual\n onlyNext\n preserveUrl\n params={{\n data: { limit: PAGE_SIZE },\n onBefore: () => {\n setFailure('')\n },\n onHttpException: () => {\n setFailure('تعذر تحميل السجلات التالية. أعد المحاولة.')\n return false\n },\n onNetworkError: () => {\n setFailure('تعذر الاتصال بالخادم. تحقق من الاتصال ثم أعد المحاولة.')\n return false\n },\n }}\n next={({ fetch, loading, hasMore }) => (\n <div className=\"flex flex-wrap items-center justify-center gap-4 border-t px-5 py-3 text-xs text-muted-foreground\">\n {failure && (\n <p role=\"alert\" className=\"text-destructive\">\n {failure}\n </p>\n )}\n {loading ? (\n <span role=\"status\" className=\"inline-flex items-center gap-2\">\n <Loader2 size={14} className=\"animate-spin\" />\n جارٍ تحميل المزيد...\n </span>\n ) : hasMore ? (\n <Button variant=\"ghost\" size=\"sm\" onClick={fetch}>\n تحميل المزيد\n </Button>\n ) : (\n <span>{rows.length ? 'نهاية السجلات' : ''}</span>\n )}\n </div>\n )}\n >\n <div\n ref={container}\n data-slot=\"table-scroll\"\n className=\"max-h-[600px] overflow-auto\"\n onScroll={(event) => {\n const element = event.currentTarget\n if (\n !failure &&\n element.scrollHeight - element.scrollTop - element.clientHeight < 200 &&\n scroller.current?.hasNext()\n )\n scroller.current.fetchNext()\n }}\n >\n <table\n className=\"w-full min-w-[720px] text-start text-sm\"\n aria-rowcount={rows.length + 1}\n aria-label={resource.label}\n >\n <thead className=\"sticky top-0 z-10 bg-muted text-xs text-muted-foreground\">\n <tr>\n {fields.map((field) => (\n <th\n key={field.key}\n scope=\"col\"\n className=\"h-11 whitespace-nowrap px-5 text-start font-medium\"\n aria-sort={\n sort === field.key\n ? direction === 'desc'\n ? 'descending'\n : 'ascending'\n : undefined\n }\n >\n {field.sortable ? (\n <button\n type=\"button\"\n className=\"inline-flex items-center gap-2 hover:text-foreground\"\n onClick={() =>\n navigate({\n sort: field.key,\n direction: sort === field.key && direction === 'asc' ? 'desc' : 'asc',\n })\n }\n >\n {field.label.ar}\n {sort === field.key ? (\n direction === 'desc' ? (\n <ArrowDown size={12} />\n ) : (\n <ArrowUp size={12} />\n )\n ) : (\n <ArrowDownUp size={12} className=\"opacity-60\" />\n )}\n </button>\n ) : (\n field.label.ar\n )}\n </th>\n ))}\n <th\n scope=\"col\"\n className=\"sticky end-0 border-s bg-muted px-5 text-start font-medium\"\n >\n الإجراءات\n </th>\n </tr>\n </thead>\n <tbody>\n {virtualized && items[0] && items[0].start > 0 && (\n <tr aria-hidden=\"true\">\n <td colSpan={fields.length + 1} style={{ height: items[0].start }} />\n </tr>\n )}\n {items.map(({ index }) => {\n const row = rows[index].original\n const id = String(row.id)\n return (\n <tr\n key={id}\n aria-rowindex={index + 2}\n className=\"group border-b last:border-0 hover:bg-background\"\n style={{ height: ROW_HEIGHT }}\n >\n {fields.map((field) => (\n <Cell\n key={field.key}\n field={field}\n row={row}\n related={related}\n lookups={lookups}\n />\n ))}\n {/* Pinned at the inline end so wide tables keep their row actions in view. */}\n <td className=\"sticky end-0 whitespace-nowrap border-s bg-card px-5 text-xs group-hover:bg-background\">\n <span className=\"inline-flex items-center gap-1\">\n <Button variant=\"ghost\" size=\"sm\" asChild>\n <Link\n href={`/resources/${resource.name}/${id}`}\n aria-label={`عرض السجل ${id}`}\n onClick={(event) => overlay(event, id, 'show')}\n >\n عرض\n </Link>\n </Button>\n <Can permissions={permissions[id] ?? {}} action=\"update\">\n <Button variant=\"ghost\" size=\"sm\" asChild>\n <Link\n href={`/resources/${resource.name}/${id}/edit`}\n aria-label={`تعديل السجل ${id}`}\n onClick={(event) => overlay(event, id, 'edit')}\n >\n تعديل\n </Link>\n </Button>\n </Can>\n <ResourceActions\n resource={resource.name}\n id={id}\n version={row.version ?? undefined}\n permissions={permissions[id] ?? {}}\n label={`السجل ${id}`}\n size=\"sm\"\n variant=\"ghost\"\n onDone={refresh}\n />\n </span>\n </td>\n </tr>\n )\n })}\n {virtualized && (\n <tr aria-hidden=\"true\">\n <td\n colSpan={fields.length + 1}\n style={{\n height: Math.max(0, virtual.getTotalSize() - (items.at(-1)?.end ?? 0)),\n }}\n />\n </tr>\n )}\n {!rows.length && (\n <tr>\n <td colSpan={fields.length + 1} className=\"py-16 text-center\">\n <Inbox\n className=\"mx-auto mb-3 text-muted-foreground\"\n size={30}\n strokeWidth={1.3}\n />\n <p className=\"text-sm font-medium\">لا توجد سجلات مطابقة</p>\n <p className=\"mt-1 text-xs text-muted-foreground\">\n {query.get('search') || activeFilters.length\n ? 'غيّر البحث أو التصفية لعرض سجلات أخرى.'\n : 'لم تُضف سجلات ضمن نطاقك بعد.'}\n </p>\n </td>\n </tr>\n )}\n </tbody>\n </table>\n </div>\n </InfiniteScroll>\n </section>\n )\n}\n\n/** Presets over the same query keys the list already accepts; the kit validates every one. */\nfunction SavedViewsBar({\n resource,\n views,\n current,\n onApply,\n onChanged,\n onFailure,\n}: {\n resource: ResourceDescription\n views: SavedView[]\n current: () => SavedViewQuery\n onApply: (view: SavedView) => void\n onChanged: () => void\n onFailure: (message: string) => void\n}) {\n const [naming, setNaming] = useState(false)\n const [name, setName] = useState('')\n const [shared, setShared] = useState(false)\n const [busy, setBusy] = useState(false)\n const base = `/resources/${resource.name}/views`\n const save = async (event: React.FormEvent) => {\n event.preventDefault()\n setBusy(true)\n onFailure('')\n try {\n await axios.post(\n base,\n { name, query: current(), shared },\n { headers: { Accept: 'application/json' }, withXSRFToken: true }\n )\n setNaming(false)\n setName('')\n setShared(false)\n onChanged()\n } catch (error) {\n onFailure(\n axios.isAxiosError(error) && error.response?.data?.error?.message\n ? String(error.response.data.error.message)\n : 'تعذر حفظ العرض.'\n )\n } finally {\n setBusy(false)\n }\n }\n const remove = async (view: SavedView) => {\n setBusy(true)\n onFailure('')\n try {\n await axios.delete(`${base}/${view.id}`, {\n headers: { Accept: 'application/json' },\n withXSRFToken: true,\n })\n onChanged()\n } catch {\n onFailure('تعذر حذف العرض.')\n } finally {\n setBusy(false)\n }\n }\n return (\n <div className=\"flex flex-wrap items-center gap-2 border-b px-5 py-3\">\n <span className=\"flex items-center gap-2 text-xs text-muted-foreground\">\n <Bookmark size={15} />\n العروض المحفوظة\n </span>\n {views.length === 0 && <span className=\"text-xs text-muted-foreground\">لا عروض بعد</span>}\n {views.map((view) => (\n <span\n key={view.id}\n className=\"flex items-center gap-1 rounded-full border border-border bg-background/60 ps-1 pe-3\"\n >\n <Button\n variant=\"ghost\"\n size=\"sm\"\n className=\"h-7 rounded-full px-2 text-xs\"\n onClick={() => onApply(view)}\n >\n {view.name}\n {!view.own && <span className=\"text-muted-foreground\"> · مشترك</span>}\n </Button>\n {view.own && (\n <button\n type=\"button\"\n aria-label={`حذف العرض ${view.name}`}\n disabled={busy}\n onClick={() => remove(view)}\n className=\"text-muted-foreground transition-colors hover:text-destructive\"\n >\n <X size={13} />\n </button>\n )}\n </span>\n ))}\n {naming ? (\n <form onSubmit={save} className=\"flex flex-wrap items-center gap-2\">\n <Input\n aria-label=\"اسم العرض\"\n value={name}\n autoFocus\n maxLength={60}\n onChange={(event) => setName(event.target.value)}\n placeholder=\"اسم العرض\"\n className=\"h-8 w-44 text-xs\"\n />\n <label className=\"flex items-center gap-1 text-xs text-muted-foreground\">\n <input\n type=\"checkbox\"\n checked={shared}\n onChange={(event) => setShared(event.target.checked)}\n />\n مشترك\n </label>\n <Button type=\"submit\" size=\"sm\" className=\"h-8\" disabled={busy || !name.trim()}>\n حفظ\n </Button>\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"sm\"\n className=\"h-8\"\n onClick={() => setNaming(false)}\n >\n إلغاء\n </Button>\n </form>\n ) : (\n <Button variant=\"outline\" size=\"sm\" className=\"h-8 text-xs\" onClick={() => setNaming(true)}>\n <BookmarkPlus size={14} />\n حفظ العرض الحالي\n </Button>\n )}\n </div>\n )\n}\n\nfunction Cell({\n field,\n row,\n related,\n lookups,\n}: {\n field: ResourceField\n row: SerializedRecord\n related: ResourceList['related']\n lookups: LookupOptions\n}) {\n const { calendar } = useUiPreferences()\n const text = displayValue(field, row, related, lookups, calendar)\n const numeric = ['money', 'integer', 'date', 'datetime'].includes(field.type)\n return (\n <td\n className={`max-w-[280px] truncate px-5 ${numeric ? 'tabular-nums' : ''}`}\n dir={numeric ? 'ltr' : undefined}\n title={text}\n >\n {field.type === 'boolean' && row[field.key] !== null && row[field.key] !== undefined ? (\n <Badge variant={row[field.key] ? 'default' : 'secondary'}>{text}</Badge>\n ) : (\n text\n )}\n </td>\n )\n}\n\nfunction Filter({\n resource,\n field,\n value,\n options,\n related,\n onApply,\n}: {\n resource: string\n field: ResourceField\n value: string\n options?: Option[]\n related?: SerializedRecord[]\n onApply: (value: string | undefined) => void\n}): ReactNode {\n const [draft, setDraft] = useState(value)\n const id = `filter-${field.key}`\n const select = (choices: Option[]) => (\n <ResourceSelect\n id={id}\n className=\"h-9 w-44 text-xs\"\n value={value}\n placeholder=\"الكل\"\n options={choices}\n onChange={(next) => onApply(next || undefined)}\n />\n )\n return (\n <label htmlFor={id} className=\"flex flex-col gap-1 text-xs text-muted-foreground\">\n {field.label.ar}\n {field.type === 'lookup' ? (\n select(options ?? [])\n ) : field.type === 'boolean' ? (\n select([\n { value: 'true', label: 'نعم' },\n { value: 'false', label: 'لا' },\n ])\n ) : field.type === 'belongsTo' || field.type === 'user' ? (\n <RelationFilter\n resource={resource}\n field={field}\n value={value}\n related={related}\n onApply={onApply}\n />\n ) : field.type === 'date' ? (\n <div className=\"w-56\">\n <FieldControl\n field={field}\n id={id}\n value={draft}\n label={`تصفية ${field.label.ar}`}\n onChange={(next) => {\n setDraft(next)\n try {\n const parsed = parseValue(field, next)\n onApply(parsed ? String(parsed) : undefined)\n } catch {\n // Keep partial or invalid input without issuing an invalid date query.\n }\n }}\n />\n </div>\n ) : (\n <Input\n id={id}\n className=\"h-9 w-44 text-xs\"\n value={draft}\n placeholder=\"اضغط Enter للتطبيق\"\n onChange={(event) => setDraft(event.target.value)}\n onKeyDown={(event) => {\n if (event.key === 'Enter') {\n event.preventDefault()\n onApply(draft || undefined)\n }\n }}\n />\n )}\n </label>\n )\n}\n\n/**\n * Filters by a related record through the target list route, which enforces the target's\n * own rules. User fields list users through the field's options route instead.\n */\nfunction RelationFilter({\n resource,\n field,\n value,\n related = [],\n onApply,\n}: {\n resource: string\n field: ResourceField & { type: 'belongsTo' | 'user' }\n value: string\n /** Related rows already loaded with the list; they label the active filter after a reload. */\n related?: SerializedRecord[]\n onApply: (value: string | undefined) => void\n}) {\n const [open, setOpen] = useState(false)\n const [term, setTerm] = useState('')\n const [choices, setChoices] = useState<Option[]>([])\n const [selected, setSelected] = useState<Option | null>(null)\n const [busy, setBusy] = useState(false)\n const timer = useRef<ReturnType<typeof setTimeout>>(undefined)\n const listId = useId()\n const load = async (search: string) => {\n setBusy(true)\n try {\n if (field.type === 'user') {\n const users = await axios.get<{ data: Option[] }>(\n `/resources/${resource}/options/${field.key}`,\n {\n params: { purpose: 'filter', ...(search ? { search } : {}) },\n headers: { Accept: 'application/json' },\n }\n )\n setChoices(users.data.data)\n return\n }\n const response = await axios.get<ResourceList>(`/resources/${field.resource}`, {\n params: {\n limit: 50,\n estimate: 'false',\n ...(search ? { search } : {}),\n },\n headers: { Accept: 'application/json' },\n })\n setChoices(\n response.data.data.map((row) => ({\n value: String(row.id),\n label: relationLabel(row, row.id),\n }))\n )\n } catch {\n setChoices([])\n } finally {\n setBusy(false)\n }\n }\n const loaded = related.find((row) => String(row.id) === value)\n const current =\n choices.find((choice) => choice.value === value) ??\n (selected?.value === value ? selected : null) ??\n (loaded ? { value, label: relationLabel(loaded, value) } : null)\n const choose = (option: Option | null) => {\n setSelected(option)\n setOpen(false)\n onApply(option?.value)\n }\n return (\n <Popover\n open={open}\n onOpenChange={(next) => {\n setOpen(next)\n if (next && !choices.length) void load(term)\n }}\n >\n <PopoverTrigger asChild>\n <Button\n id={`filter-${field.key}`}\n type=\"button\"\n role=\"combobox\"\n variant=\"outline\"\n aria-expanded={open}\n aria-controls={listId}\n className={`h-9 w-44 justify-between bg-transparent text-xs font-normal ${value ? '' : 'text-muted-foreground'}`}\n >\n <span className=\"truncate\">{value ? (current?.label ?? `#${value}`) : 'الكل'}</span>\n <ChevronsUpDown className=\"opacity-50\" />\n </Button>\n </PopoverTrigger>\n <PopoverContent className=\"w-64 p-0\" align=\"start\">\n <Command shouldFilter={false}>\n <CommandInput\n placeholder=\"ابحث في السجلات المرتبطة\"\n aria-label={`البحث في ${field.label.ar}`}\n value={term}\n onValueChange={(next) => {\n setTerm(next)\n clearTimeout(timer.current)\n timer.current = setTimeout(() => void load(next), 300)\n }}\n />\n <CommandList id={listId}>\n <CommandEmpty>{busy ? 'جارٍ البحث...' : 'لا توجد سجلات مطابقة'}</CommandEmpty>\n <CommandGroup>\n <CommandItem value=\"__all__\" onSelect={() => choose(null)}>\n <Check className={value ? 'opacity-0' : 'opacity-100'} />\n الكل\n </CommandItem>\n {choices.map((choice) => (\n <CommandItem\n key={choice.value}\n value={choice.value}\n onSelect={() => choose(choice)}\n >\n <Check className={choice.value === value ? 'opacity-100' : 'opacity-0'} />\n {choice.label}\n </CommandItem>\n ))}\n </CommandGroup>\n </CommandList>\n </Command>\n </PopoverContent>\n </Popover>\n )\n}\n",
|
|
27
|
+
"content": "import {\n useEffect,\n useId,\n useRef,\n useState,\n type ComponentRef,\n type MouseEvent,\n type ReactNode,\n} from 'react'\nimport { InfiniteScroll, router, usePage } from '@inertiajs/react'\nimport { Link } from '@adonisjs/inertia/react'\nimport { tableFeatures, useTable } from '@tanstack/react-table'\nimport { useVirtualizer } from '@tanstack/react-virtual'\nimport axios from 'axios'\nimport {\n ArrowDown,\n ArrowDownUp,\n ArrowUp,\n Check,\n ChevronsUpDown,\n Download,\n Inbox,\n Loader2,\n Bookmark,\n BookmarkPlus,\n Search,\n SlidersHorizontal,\n X,\n} from 'lucide-react'\nimport type {\n ResourceDescription,\n ResourceField,\n ResourceList,\n SavedView,\n SavedViewQuery,\n SerializedRecord,\n} from 'adula'\nimport { Badge } from '~/components/ui/badge'\nimport { Button } from '~/components/ui/button'\nimport { useUiPreferences } from '~/components/ui/ui-preferences'\nimport { Can } from '~/components/ui/can'\nimport { Input } from '~/components/ui/input'\nimport { ResourceActions } from '~/components/ui/resource-actions'\nimport { openRecord, rememberListView } from '~/components/ui/resource-surface'\nimport { FieldControl, ResourceSelect } from '~/components/ui/resource-field'\nimport {\n Command,\n CommandEmpty,\n CommandGroup,\n CommandInput,\n CommandItem,\n CommandList,\n} from '~/components/ui/command'\nimport { Popover, PopoverContent, PopoverTrigger } from '~/components/ui/popover'\nimport {\n csvCell,\n displayValue,\n parseValue,\n relationLabel,\n type LookupOptions,\n type Option,\n} from '~/components/ui/resource-value'\n\n/** Rows above this count render through the virtualizer (plan section 13). */\nexport const VIRTUAL_ROWS = 200\nconst ROW_HEIGHT = 52\nconst PAGE_SIZE = 100\nconst features = tableFeatures({})\ntype Query = Record<string, string | undefined>\n\nexport function DataTable({\n resource,\n result,\n lookups = {},\n savedViews = [],\n}: {\n resource: ResourceDescription\n result: ResourceList\n lookups?: LookupOptions\n savedViews?: SavedView[]\n}) {\n const { calendar } = useUiPreferences()\n const { url } = usePage()\n const query = new URL(url, 'http://localhost').searchParams\n const [search, setSearch] = useState(query.get('search') ?? '')\n const [failure, setFailure] = useState('')\n const container = useRef<HTMLDivElement>(null)\n const scroller = useRef<ComponentRef<typeof InfiniteScroll>>(null)\n // Opening one of this list's records remembers the view, so closing the dialog returns to it.\n useEffect(\n () =>\n router.on('before', (event) => {\n const { pathname } = event.detail.visit.url\n if (pathname.startsWith(`/resources/${resource.name}/`)) rememberListView(pathname)\n }),\n [resource.name]\n )\n // Inertia merges `result.data` page by page; permissions and labels of earlier pages accumulate here.\n const store = useRef<{\n source: ResourceList | null\n permissions: ResourceList['permissions']\n related: ResourceList['related']\n }>({ source: null, permissions: {}, related: {} })\n if (store.current.source !== result) {\n const related = { ...store.current.related }\n for (const [key, rows] of Object.entries(result.related))\n related[key] = [\n ...new Map([...(related[key] ?? []), ...rows].map((row) => [String(row.id), row])).values(),\n ]\n store.current = {\n source: result,\n permissions: { ...store.current.permissions, ...result.permissions },\n related,\n }\n }\n const { permissions, related } = store.current\n const fields = resource.fields.filter(\n (field) => resource.list.includes(field.key) && field.type !== 'hasMany'\n )\n const filterable = fields.filter((field) => field.filterable)\n const table = useTable({\n features,\n data: result.data,\n columns: fields.map((field) => ({ accessorKey: field.key, id: field.key })),\n getRowId: (row) => String(row.id),\n })\n const rows = table.getRowModel().rows\n const virtualized = rows.length > VIRTUAL_ROWS\n const virtual = useVirtualizer({\n count: rows.length,\n getScrollElement: () => container.current,\n estimateSize: () => ROW_HEIGHT,\n overscan: 10,\n enabled: virtualized,\n getItemKey: (index) => rows[index].id,\n })\n const items = virtualized\n ? virtual.getVirtualItems()\n : rows.map((_, index) => ({ index, start: 0, end: 0 }))\n const navigate = (changes: Query) => {\n const next = new URLSearchParams(query)\n next.delete('cursor')\n for (const [key, value] of Object.entries(changes))\n value ? next.set(key, value) : next.delete(key)\n const suffix = next.toString()\n router.get(\n `/resources/${resource.name}${suffix ? `?${suffix}` : ''}`,\n {},\n { preserveScroll: true }\n )\n }\n const sort = query.get('sort')\n const direction = query.get('direction') === 'desc' ? 'desc' : 'asc'\n const activeFilters = filterable.filter((field) => query.get(`filters[${field.key}]`))\n const csv = () => {\n const content = [\n fields.map((field) => field.label.ar),\n ...result.data.map((row) =>\n fields.map((field) => displayValue(field, row, related, lookups, calendar))\n ),\n ]\n const href = URL.createObjectURL(\n new Blob(['' + content.map((row) => row.map(csvCell).join(',')).join('\\r\\n')], {\n type: 'text/csv;charset=utf-8',\n })\n )\n const link = document.createElement('a')\n link.href = href\n link.download = `${resource.label}.csv`\n link.click()\n URL.revokeObjectURL(href)\n }\n const refresh = () => router.visit(url, { preserveScroll: true })\n // Records open in a dialog over this list, which stays mounted (#31); modified clicks\n // (new tab, new window) keep the link's own behavior.\n const overlay = (event: MouseEvent, id: string, mode: 'show' | 'edit') => {\n if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey)\n return\n event.preventDefault()\n void openRecord(resource.name, id, mode)\n }\n const currentQuery = (): SavedViewQuery => {\n const view: SavedViewQuery = {}\n const text = query.get('search')\n if (text) view.search = text\n if (sort) {\n view.sort = sort\n view.direction = direction\n }\n const filters: Record<string, string> = {}\n for (const field of filterable) {\n const value = query.get(`filters[${field.key}]`)\n if (value) filters[field.key] = value\n }\n if (Object.keys(filters).length) view.filters = filters\n return view\n }\n const applyView = (view: SavedView) => {\n const next = new URLSearchParams()\n if (view.query.search) next.set('search', view.query.search)\n if (view.query.sort) {\n next.set('sort', view.query.sort)\n next.set('direction', view.query.direction ?? 'asc')\n }\n for (const [key, value] of Object.entries(view.query.filters ?? {}))\n if (value !== null) next.set(`filters[${key}]`, String(value))\n setSearch(view.query.search ?? '')\n const suffix = next.toString()\n router.get(\n `/resources/${resource.name}${suffix ? `?${suffix}` : ''}`,\n {},\n { preserveScroll: true }\n )\n }\n return (\n <section\n aria-label={`قائمة ${resource.label}`}\n className=\"min-w-0 overflow-hidden rounded-xl border border-border bg-white shadow-[0_2px_10px_#1c302804]\"\n >\n <div className=\"flex flex-wrap items-center justify-between gap-4 border-b px-5 py-4\">\n <div className=\"flex flex-wrap items-center gap-3\">\n <h2 className=\"text-sm font-semibold\">سجل {resource.label}</h2>\n <Badge variant=\"secondary\" className=\"font-normal tabular-nums\">\n {rows.length} معروض\n </Badge>\n <span className=\"text-xs text-muted-foreground\">\n {result.meta.estimatedTotal !== undefined\n ? `نحو ${result.meta.estimatedTotal} سجل ضمن نطاقك`\n : 'حسب نطاق صلاحياتك'}\n </span>\n </div>\n <Button variant=\"outline\" size=\"sm\" onClick={csv} disabled={!rows.length}>\n <Download size={15} />\n تصدير المعروض\n </Button>\n </div>\n {(resource.searchable || filterable.length > 0) && (\n <SavedViewsBar\n resource={resource}\n views={savedViews}\n current={currentQuery}\n onApply={applyView}\n onChanged={refresh}\n onFailure={setFailure}\n />\n )}\n {(resource.searchable || filterable.length > 0) && (\n <div className=\"flex flex-wrap items-end gap-3 border-b px-5 py-4\">\n {resource.searchable && (\n <form\n role=\"search\"\n className=\"relative w-full max-w-sm\"\n onSubmit={(event) => {\n event.preventDefault()\n navigate({ search })\n }}\n >\n <Search\n className=\"pointer-events-none absolute start-3 top-2.5 text-muted-foreground\"\n size={16}\n />\n <Input\n aria-label={`البحث في ${resource.label}`}\n value={search}\n onChange={(event) => setSearch(event.target.value)}\n placeholder=\"ابحث في السجلات...\"\n className=\"h-9 bg-background/60 ps-10 text-xs\"\n />\n </form>\n )}\n {filterable.length > 0 && (\n <span className=\"flex items-center gap-2 text-xs text-muted-foreground\">\n <SlidersHorizontal size={15} />\n تصفية\n </span>\n )}\n {filterable.map((field) => (\n <Filter\n key={field.key}\n resource={resource.name}\n field={field}\n value={query.get(`filters[${field.key}]`) ?? ''}\n options={lookups[field.key]}\n related={related[field.key]}\n onApply={(value) => navigate({ [`filters[${field.key}]`]: value })}\n />\n ))}\n {activeFilters.length > 0 && (\n <Button\n variant=\"ghost\"\n size=\"sm\"\n onClick={() =>\n navigate(\n Object.fromEntries(\n activeFilters.map((field) => [`filters[${field.key}]`, undefined])\n )\n )\n }\n >\n <X size={14} />\n مسح التصفية\n </Button>\n )}\n </div>\n )}\n <InfiniteScroll\n ref={(instance) => {\n scroller.current = instance\n }}\n data=\"result\"\n manual\n onlyNext\n preserveUrl\n params={{\n data: { limit: PAGE_SIZE },\n onBefore: () => {\n setFailure('')\n },\n onHttpException: () => {\n setFailure('تعذر تحميل السجلات التالية. أعد المحاولة.')\n return false\n },\n onNetworkError: () => {\n setFailure('تعذر الاتصال بالخادم. تحقق من الاتصال ثم أعد المحاولة.')\n return false\n },\n }}\n next={({ fetch, loading, hasMore }) => (\n <div className=\"flex flex-wrap items-center justify-center gap-4 border-t px-5 py-3 text-xs text-muted-foreground\">\n {failure && (\n <p role=\"alert\" className=\"text-destructive\">\n {failure}\n </p>\n )}\n {loading ? (\n <span role=\"status\" className=\"inline-flex items-center gap-2\">\n <Loader2 size={14} className=\"animate-spin\" />\n جارٍ تحميل المزيد...\n </span>\n ) : hasMore ? (\n <Button variant=\"ghost\" size=\"sm\" onClick={fetch}>\n تحميل المزيد\n </Button>\n ) : (\n <span>{rows.length ? 'نهاية السجلات' : ''}</span>\n )}\n </div>\n )}\n >\n <div\n ref={container}\n data-slot=\"table-scroll\"\n className=\"max-h-[600px] overflow-auto\"\n onScroll={(event) => {\n const element = event.currentTarget\n if (\n !failure &&\n element.scrollHeight - element.scrollTop - element.clientHeight < 200 &&\n scroller.current?.hasNext()\n )\n scroller.current.fetchNext()\n }}\n >\n <table\n className=\"w-full min-w-[720px] text-start text-sm\"\n aria-rowcount={rows.length + 1}\n aria-label={resource.label}\n >\n <thead className=\"sticky top-0 z-10 bg-muted text-xs text-muted-foreground\">\n <tr>\n {fields.map((field) => (\n <th\n key={field.key}\n scope=\"col\"\n className=\"h-11 whitespace-nowrap px-5 text-start font-medium\"\n aria-sort={\n sort === field.key\n ? direction === 'desc'\n ? 'descending'\n : 'ascending'\n : undefined\n }\n >\n {field.sortable ? (\n <button\n type=\"button\"\n className=\"inline-flex items-center gap-2 hover:text-foreground\"\n onClick={() =>\n navigate({\n sort: field.key,\n direction: sort === field.key && direction === 'asc' ? 'desc' : 'asc',\n })\n }\n >\n {field.label.ar}\n {sort === field.key ? (\n direction === 'desc' ? (\n <ArrowDown size={12} />\n ) : (\n <ArrowUp size={12} />\n )\n ) : (\n <ArrowDownUp size={12} className=\"opacity-60\" />\n )}\n </button>\n ) : (\n field.label.ar\n )}\n </th>\n ))}\n <th\n scope=\"col\"\n className=\"sticky end-0 border-s bg-muted px-5 text-start font-medium\"\n >\n الإجراءات\n </th>\n </tr>\n </thead>\n <tbody>\n {virtualized && items[0] && items[0].start > 0 && (\n <tr aria-hidden=\"true\">\n <td colSpan={fields.length + 1} style={{ height: items[0].start }} />\n </tr>\n )}\n {items.map(({ index }) => {\n const row = rows[index].original\n const id = String(row.id)\n return (\n <tr\n key={id}\n aria-rowindex={index + 2}\n className=\"group border-b last:border-0 hover:bg-background\"\n style={{ height: ROW_HEIGHT }}\n >\n {fields.map((field) => (\n <Cell\n key={field.key}\n field={field}\n row={row}\n related={related}\n lookups={lookups}\n />\n ))}\n {/* Pinned at the inline end so wide tables keep their row actions in view. */}\n <td className=\"sticky end-0 whitespace-nowrap border-s bg-card px-5 text-xs group-hover:bg-background\">\n <span className=\"inline-flex items-center gap-1\">\n <Button variant=\"ghost\" size=\"sm\" asChild>\n <Link\n href={`/resources/${resource.name}/${id}`}\n aria-label={`عرض السجل ${id}`}\n onClick={(event) => overlay(event, id, 'show')}\n >\n عرض\n </Link>\n </Button>\n <Can permissions={permissions[id] ?? {}} action=\"update\">\n <Button variant=\"ghost\" size=\"sm\" asChild>\n <Link\n href={`/resources/${resource.name}/${id}/edit`}\n aria-label={`تعديل السجل ${id}`}\n onClick={(event) => overlay(event, id, 'edit')}\n >\n تعديل\n </Link>\n </Button>\n </Can>\n <ResourceActions\n resource={resource.name}\n id={id}\n version={row.version ?? undefined}\n permissions={permissions[id] ?? {}}\n label={`السجل ${id}`}\n size=\"sm\"\n variant=\"ghost\"\n onDone={refresh}\n />\n </span>\n </td>\n </tr>\n )\n })}\n {virtualized && (\n <tr aria-hidden=\"true\">\n <td\n colSpan={fields.length + 1}\n style={{\n height: Math.max(0, virtual.getTotalSize() - (items.at(-1)?.end ?? 0)),\n }}\n />\n </tr>\n )}\n {!rows.length && (\n <tr>\n <td colSpan={fields.length + 1} className=\"py-16 text-center\">\n <Inbox\n className=\"mx-auto mb-3 text-muted-foreground\"\n size={30}\n strokeWidth={1.3}\n />\n <p className=\"text-sm font-medium\">لا توجد سجلات مطابقة</p>\n <p className=\"mt-1 text-xs text-muted-foreground\">\n {query.get('search') || activeFilters.length\n ? 'غيّر البحث أو التصفية لعرض سجلات أخرى.'\n : 'لم تُضف سجلات ضمن نطاقك بعد.'}\n </p>\n </td>\n </tr>\n )}\n </tbody>\n </table>\n </div>\n </InfiniteScroll>\n </section>\n )\n}\n\n/** Presets over the same query keys the list already accepts; AdulaJS validates every one. */\nfunction SavedViewsBar({\n resource,\n views,\n current,\n onApply,\n onChanged,\n onFailure,\n}: {\n resource: ResourceDescription\n views: SavedView[]\n current: () => SavedViewQuery\n onApply: (view: SavedView) => void\n onChanged: () => void\n onFailure: (message: string) => void\n}) {\n const [naming, setNaming] = useState(false)\n const [name, setName] = useState('')\n const [shared, setShared] = useState(false)\n const [busy, setBusy] = useState(false)\n const base = `/resources/${resource.name}/views`\n const save = async (event: React.FormEvent) => {\n event.preventDefault()\n setBusy(true)\n onFailure('')\n try {\n await axios.post(\n base,\n { name, query: current(), shared },\n { headers: { Accept: 'application/json' }, withXSRFToken: true }\n )\n setNaming(false)\n setName('')\n setShared(false)\n onChanged()\n } catch (error) {\n onFailure(\n axios.isAxiosError(error) && error.response?.data?.error?.message\n ? String(error.response.data.error.message)\n : 'تعذر حفظ العرض.'\n )\n } finally {\n setBusy(false)\n }\n }\n const remove = async (view: SavedView) => {\n setBusy(true)\n onFailure('')\n try {\n await axios.delete(`${base}/${view.id}`, {\n headers: { Accept: 'application/json' },\n withXSRFToken: true,\n })\n onChanged()\n } catch {\n onFailure('تعذر حذف العرض.')\n } finally {\n setBusy(false)\n }\n }\n return (\n <div className=\"flex flex-wrap items-center gap-2 border-b px-5 py-3\">\n <span className=\"flex items-center gap-2 text-xs text-muted-foreground\">\n <Bookmark size={15} />\n العروض المحفوظة\n </span>\n {views.length === 0 && <span className=\"text-xs text-muted-foreground\">لا عروض بعد</span>}\n {views.map((view) => (\n <span\n key={view.id}\n className=\"flex items-center gap-1 rounded-full border border-border bg-background/60 ps-1 pe-3\"\n >\n <Button\n variant=\"ghost\"\n size=\"sm\"\n className=\"h-7 rounded-full px-2 text-xs\"\n onClick={() => onApply(view)}\n >\n {view.name}\n {!view.own && <span className=\"text-muted-foreground\"> · مشترك</span>}\n </Button>\n {view.own && (\n <button\n type=\"button\"\n aria-label={`حذف العرض ${view.name}`}\n disabled={busy}\n onClick={() => remove(view)}\n className=\"text-muted-foreground transition-colors hover:text-destructive\"\n >\n <X size={13} />\n </button>\n )}\n </span>\n ))}\n {naming ? (\n <form onSubmit={save} className=\"flex flex-wrap items-center gap-2\">\n <Input\n aria-label=\"اسم العرض\"\n value={name}\n autoFocus\n maxLength={60}\n onChange={(event) => setName(event.target.value)}\n placeholder=\"اسم العرض\"\n className=\"h-8 w-44 text-xs\"\n />\n <label className=\"flex items-center gap-1 text-xs text-muted-foreground\">\n <input\n type=\"checkbox\"\n checked={shared}\n onChange={(event) => setShared(event.target.checked)}\n />\n مشترك\n </label>\n <Button type=\"submit\" size=\"sm\" className=\"h-8\" disabled={busy || !name.trim()}>\n حفظ\n </Button>\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"sm\"\n className=\"h-8\"\n onClick={() => setNaming(false)}\n >\n إلغاء\n </Button>\n </form>\n ) : (\n <Button variant=\"outline\" size=\"sm\" className=\"h-8 text-xs\" onClick={() => setNaming(true)}>\n <BookmarkPlus size={14} />\n حفظ العرض الحالي\n </Button>\n )}\n </div>\n )\n}\n\nfunction Cell({\n field,\n row,\n related,\n lookups,\n}: {\n field: ResourceField\n row: SerializedRecord\n related: ResourceList['related']\n lookups: LookupOptions\n}) {\n const { calendar } = useUiPreferences()\n const text = displayValue(field, row, related, lookups, calendar)\n const numeric = ['money', 'integer', 'date', 'datetime'].includes(field.type)\n return (\n <td\n className={`max-w-[280px] truncate px-5 ${numeric ? 'tabular-nums' : ''}`}\n dir={numeric ? 'ltr' : undefined}\n title={text}\n >\n {field.type === 'boolean' && row[field.key] !== null && row[field.key] !== undefined ? (\n <Badge variant={row[field.key] ? 'default' : 'secondary'}>{text}</Badge>\n ) : (\n text\n )}\n </td>\n )\n}\n\nfunction Filter({\n resource,\n field,\n value,\n options,\n related,\n onApply,\n}: {\n resource: string\n field: ResourceField\n value: string\n options?: Option[]\n related?: SerializedRecord[]\n onApply: (value: string | undefined) => void\n}): ReactNode {\n const [draft, setDraft] = useState(value)\n const id = `filter-${field.key}`\n const select = (choices: Option[]) => (\n <ResourceSelect\n id={id}\n className=\"h-9 w-44 text-xs\"\n value={value}\n placeholder=\"الكل\"\n options={choices}\n onChange={(next) => onApply(next || undefined)}\n />\n )\n return (\n <label htmlFor={id} className=\"flex flex-col gap-1 text-xs text-muted-foreground\">\n {field.label.ar}\n {field.type === 'lookup' ? (\n select(options ?? [])\n ) : field.type === 'boolean' ? (\n select([\n { value: 'true', label: 'نعم' },\n { value: 'false', label: 'لا' },\n ])\n ) : field.type === 'belongsTo' || field.type === 'user' ? (\n <RelationFilter\n resource={resource}\n field={field}\n value={value}\n related={related}\n onApply={onApply}\n />\n ) : field.type === 'date' ? (\n <div className=\"w-56\">\n <FieldControl\n field={field}\n id={id}\n value={draft}\n label={`تصفية ${field.label.ar}`}\n onChange={(next) => {\n setDraft(next)\n try {\n const parsed = parseValue(field, next)\n onApply(parsed ? String(parsed) : undefined)\n } catch {\n // Keep partial or invalid input without issuing an invalid date query.\n }\n }}\n />\n </div>\n ) : (\n <Input\n id={id}\n className=\"h-9 w-44 text-xs\"\n value={draft}\n placeholder=\"اضغط Enter للتطبيق\"\n onChange={(event) => setDraft(event.target.value)}\n onKeyDown={(event) => {\n if (event.key === 'Enter') {\n event.preventDefault()\n onApply(draft || undefined)\n }\n }}\n />\n )}\n </label>\n )\n}\n\n/**\n * Filters by a related record through the target list route, which enforces the target's\n * own rules. User fields list users through the field's options route instead.\n */\nfunction RelationFilter({\n resource,\n field,\n value,\n related = [],\n onApply,\n}: {\n resource: string\n field: ResourceField & { type: 'belongsTo' | 'user' }\n value: string\n /** Related rows already loaded with the list; they label the active filter after a reload. */\n related?: SerializedRecord[]\n onApply: (value: string | undefined) => void\n}) {\n const [open, setOpen] = useState(false)\n const [term, setTerm] = useState('')\n const [choices, setChoices] = useState<Option[]>([])\n const [selected, setSelected] = useState<Option | null>(null)\n const [busy, setBusy] = useState(false)\n const timer = useRef<ReturnType<typeof setTimeout>>(undefined)\n const listId = useId()\n const load = async (search: string) => {\n setBusy(true)\n try {\n if (field.type === 'user') {\n const users = await axios.get<{ data: Option[] }>(\n `/resources/${resource}/options/${field.key}`,\n {\n params: { purpose: 'filter', ...(search ? { search } : {}) },\n headers: { Accept: 'application/json' },\n }\n )\n setChoices(users.data.data)\n return\n }\n const response = await axios.get<ResourceList>(`/resources/${field.resource}`, {\n params: {\n limit: 50,\n estimate: 'false',\n ...(search ? { search } : {}),\n },\n headers: { Accept: 'application/json' },\n })\n setChoices(\n response.data.data.map((row) => ({\n value: String(row.id),\n label: relationLabel(row, row.id),\n }))\n )\n } catch {\n setChoices([])\n } finally {\n setBusy(false)\n }\n }\n const loaded = related.find((row) => String(row.id) === value)\n const current =\n choices.find((choice) => choice.value === value) ??\n (selected?.value === value ? selected : null) ??\n (loaded ? { value, label: relationLabel(loaded, value) } : null)\n const choose = (option: Option | null) => {\n setSelected(option)\n setOpen(false)\n onApply(option?.value)\n }\n return (\n <Popover\n open={open}\n onOpenChange={(next) => {\n setOpen(next)\n if (next && !choices.length) void load(term)\n }}\n >\n <PopoverTrigger asChild>\n <Button\n id={`filter-${field.key}`}\n type=\"button\"\n role=\"combobox\"\n variant=\"outline\"\n aria-expanded={open}\n aria-controls={listId}\n className={`h-9 w-44 justify-between bg-transparent text-xs font-normal ${value ? '' : 'text-muted-foreground'}`}\n >\n <span className=\"truncate\">{value ? (current?.label ?? `#${value}`) : 'الكل'}</span>\n <ChevronsUpDown className=\"opacity-50\" />\n </Button>\n </PopoverTrigger>\n <PopoverContent className=\"w-64 p-0\" align=\"start\">\n <Command shouldFilter={false}>\n <CommandInput\n placeholder=\"ابحث في السجلات المرتبطة\"\n aria-label={`البحث في ${field.label.ar}`}\n value={term}\n onValueChange={(next) => {\n setTerm(next)\n clearTimeout(timer.current)\n timer.current = setTimeout(() => void load(next), 300)\n }}\n />\n <CommandList id={listId}>\n <CommandEmpty>{busy ? 'جارٍ البحث...' : 'لا توجد سجلات مطابقة'}</CommandEmpty>\n <CommandGroup>\n <CommandItem value=\"__all__\" onSelect={() => choose(null)}>\n <Check className={value ? 'opacity-0' : 'opacity-100'} />\n الكل\n </CommandItem>\n {choices.map((choice) => (\n <CommandItem\n key={choice.value}\n value={choice.value}\n onSelect={() => choose(choice)}\n >\n <Check className={choice.value === value ? 'opacity-100' : 'opacity-0'} />\n {choice.label}\n </CommandItem>\n ))}\n </CommandGroup>\n </CommandList>\n </Command>\n </PopoverContent>\n </Popover>\n )\n}\n",
|
|
28
28
|
"target": "inertia/components/ui/data-table.tsx"
|
|
29
29
|
}
|
|
30
30
|
],
|
package/build/manifest.json
CHANGED
|
@@ -1,215 +1,215 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
3
|
-
"
|
|
2
|
+
"version": "2.1.0",
|
|
3
|
+
"adulaCompatibility": "2.1",
|
|
4
4
|
"items": [
|
|
5
5
|
{
|
|
6
6
|
"name": "button",
|
|
7
|
-
"version": "1.
|
|
7
|
+
"version": "2.1.0",
|
|
8
8
|
"hash": "cf1a045e41f5029fe9a8e3f3513a142dbe6550d6ffbe560b652a0aed1bb76f94"
|
|
9
9
|
},
|
|
10
10
|
{
|
|
11
11
|
"name": "input",
|
|
12
|
-
"version": "1.
|
|
12
|
+
"version": "2.1.0",
|
|
13
13
|
"hash": "5a398efe048aff90155d858e63290dee2b7ad31c060936ac5bfce5ecf691e022"
|
|
14
14
|
},
|
|
15
15
|
{
|
|
16
16
|
"name": "textarea",
|
|
17
|
-
"version": "1.
|
|
17
|
+
"version": "2.1.0",
|
|
18
18
|
"hash": "f0f615a9112e64ccb0d580d9325558c97750c24bcce933211acd2fa01c24b008"
|
|
19
19
|
},
|
|
20
20
|
{
|
|
21
21
|
"name": "select",
|
|
22
|
-
"version": "1.
|
|
22
|
+
"version": "2.1.0",
|
|
23
23
|
"hash": "25524a9856101efd64d4fa9922cd3c3ab36da05d84d75f06aec102f9fbc3b554"
|
|
24
24
|
},
|
|
25
25
|
{
|
|
26
26
|
"name": "checkbox",
|
|
27
|
-
"version": "1.
|
|
27
|
+
"version": "2.1.0",
|
|
28
28
|
"hash": "631d1bacffcb6856a210bb2a40301f589cd0a74dfe28363e6fe3393e6c658ffa"
|
|
29
29
|
},
|
|
30
30
|
{
|
|
31
31
|
"name": "switch",
|
|
32
|
-
"version": "1.
|
|
32
|
+
"version": "2.1.0",
|
|
33
33
|
"hash": "f41dc7b8d0b3d36a5b74460b651f20046c70a825321ea5ba8e32b575e87e9fb4"
|
|
34
34
|
},
|
|
35
35
|
{
|
|
36
36
|
"name": "radio-group",
|
|
37
|
-
"version": "1.
|
|
37
|
+
"version": "2.1.0",
|
|
38
38
|
"hash": "2f6e9ad7d314703388e20cbea51d3f3bae35e0aedb239fe7e58f71dc892110e0"
|
|
39
39
|
},
|
|
40
40
|
{
|
|
41
41
|
"name": "table",
|
|
42
|
-
"version": "1.
|
|
42
|
+
"version": "2.1.0",
|
|
43
43
|
"hash": "2a76f50a6672357e167a2ebc1ea82535c9298629d94f5aa9ee57108e5c535f66"
|
|
44
44
|
},
|
|
45
45
|
{
|
|
46
46
|
"name": "form",
|
|
47
|
-
"version": "1.
|
|
47
|
+
"version": "2.1.0",
|
|
48
48
|
"hash": "2b164e3985524723c3997a334fe04b3232a52a4a37ac81c1acac25968f709628"
|
|
49
49
|
},
|
|
50
50
|
{
|
|
51
51
|
"name": "label",
|
|
52
|
-
"version": "1.
|
|
52
|
+
"version": "2.1.0",
|
|
53
53
|
"hash": "adb3d62721dfe74a6e812cee5ac8b2a0f5ad8821140a0d017e4bdabd2fd7b966"
|
|
54
54
|
},
|
|
55
55
|
{
|
|
56
56
|
"name": "dialog",
|
|
57
|
-
"version": "1.
|
|
57
|
+
"version": "2.1.0",
|
|
58
58
|
"hash": "04b47b3d9de9d4998eb610a6753c115cf3aa5db88e6889caac337f2d95f708bc"
|
|
59
59
|
},
|
|
60
60
|
{
|
|
61
61
|
"name": "sheet",
|
|
62
|
-
"version": "1.
|
|
62
|
+
"version": "2.1.0",
|
|
63
63
|
"hash": "8b511eba90dbab3ea69faafa384e6b27d5aa1ba4742b47dc526238b2babcf97a"
|
|
64
64
|
},
|
|
65
65
|
{
|
|
66
66
|
"name": "dropdown-menu",
|
|
67
|
-
"version": "1.
|
|
67
|
+
"version": "2.1.0",
|
|
68
68
|
"hash": "622b2ba53ab5d9ebf28de16078a0051adb5a1035d63f5febeb3992fc1c094ff9"
|
|
69
69
|
},
|
|
70
70
|
{
|
|
71
71
|
"name": "popover",
|
|
72
|
-
"version": "1.
|
|
72
|
+
"version": "2.1.0",
|
|
73
73
|
"hash": "288f01bbff64e03473dfb7c0b680f0ca77d610f646653b29364ae245d8491e03"
|
|
74
74
|
},
|
|
75
75
|
{
|
|
76
76
|
"name": "command",
|
|
77
|
-
"version": "1.
|
|
77
|
+
"version": "2.1.0",
|
|
78
78
|
"hash": "47fc8607025e87f3a35f974a55a946d9fee2d0eebd9a681276028e01731d1845"
|
|
79
79
|
},
|
|
80
80
|
{
|
|
81
81
|
"name": "calendar",
|
|
82
|
-
"version": "1.
|
|
82
|
+
"version": "2.1.0",
|
|
83
83
|
"hash": "a536d790c69a67daf9aad8e76901dd668e02520d38677a3f27e1eadcf6a90ad7"
|
|
84
84
|
},
|
|
85
85
|
{
|
|
86
86
|
"name": "badge",
|
|
87
|
-
"version": "1.
|
|
87
|
+
"version": "2.1.0",
|
|
88
88
|
"hash": "08a668f461549c6edf7da629899d59373e7cae5686d1533fd5d451fbf7c2e33e"
|
|
89
89
|
},
|
|
90
90
|
{
|
|
91
91
|
"name": "card",
|
|
92
|
-
"version": "1.
|
|
92
|
+
"version": "2.1.0",
|
|
93
93
|
"hash": "0c7ac44916cc64285da5d8734fd34896a72cabecada2119b68f7f04ac6995b9a"
|
|
94
94
|
},
|
|
95
95
|
{
|
|
96
96
|
"name": "tabs",
|
|
97
|
-
"version": "1.
|
|
97
|
+
"version": "2.1.0",
|
|
98
98
|
"hash": "ceac90f0124b6c52d5f0268226fc36ec1689feb8540664414158aa8fdebac0f7"
|
|
99
99
|
},
|
|
100
100
|
{
|
|
101
101
|
"name": "sonner",
|
|
102
|
-
"version": "1.
|
|
102
|
+
"version": "2.1.0",
|
|
103
103
|
"hash": "433f224e2266ddfa0f42fe7f81a87a55cb4e6284dce8187b97256154409fe10d"
|
|
104
104
|
},
|
|
105
105
|
{
|
|
106
106
|
"name": "skeleton",
|
|
107
|
-
"version": "1.
|
|
107
|
+
"version": "2.1.0",
|
|
108
108
|
"hash": "8dd2b789d3a4b70fb62a99922ef48ee7a0d23a7cda09b00cc1df49c8c29fac90"
|
|
109
109
|
},
|
|
110
110
|
{
|
|
111
111
|
"name": "pagination",
|
|
112
|
-
"version": "1.
|
|
112
|
+
"version": "2.1.0",
|
|
113
113
|
"hash": "d1119e2d1e6e80c2556b510c715370c4b9e039e8851461aa28e71c3c1d9d1329"
|
|
114
114
|
},
|
|
115
115
|
{
|
|
116
116
|
"name": "tooltip",
|
|
117
|
-
"version": "1.
|
|
117
|
+
"version": "2.1.0",
|
|
118
118
|
"hash": "616d81f4386a0fb6b714e74515fd77328db0314ddb573003adfaf4693f100fe6"
|
|
119
119
|
},
|
|
120
120
|
{
|
|
121
121
|
"name": "separator",
|
|
122
|
-
"version": "1.
|
|
122
|
+
"version": "2.1.0",
|
|
123
123
|
"hash": "deb8eb9daf72092fd11d69af65891b721f154fd1bb8d3c7fabb46f33cf612c87"
|
|
124
124
|
},
|
|
125
125
|
{
|
|
126
126
|
"name": "alert",
|
|
127
|
-
"version": "1.
|
|
127
|
+
"version": "2.1.0",
|
|
128
128
|
"hash": "17940923e71122bb30d830c569e36e3886109cbfdfb405fd3954774fed1f0ead"
|
|
129
129
|
},
|
|
130
130
|
{
|
|
131
131
|
"name": "can",
|
|
132
|
-
"version": "1.
|
|
133
|
-
"hash": "
|
|
132
|
+
"version": "2.1.0",
|
|
133
|
+
"hash": "325cc32dac417e6001146ff59ba45b0c2231b672c92cebf389eaff378b82120c"
|
|
134
134
|
},
|
|
135
135
|
{
|
|
136
136
|
"name": "resource-value",
|
|
137
|
-
"version": "1.
|
|
138
|
-
"hash": "
|
|
137
|
+
"version": "2.1.0",
|
|
138
|
+
"hash": "f63bb60aad14e8a11b4e15fec95d160035307c91d10703412a06d0673b010931"
|
|
139
139
|
},
|
|
140
140
|
{
|
|
141
141
|
"name": "resource-field",
|
|
142
|
-
"version": "1.
|
|
143
|
-
"hash": "
|
|
142
|
+
"version": "2.1.0",
|
|
143
|
+
"hash": "faf47b734ee7c466e7b73066114faba23957b26157f7cc1e3d843601bc0cea1b"
|
|
144
144
|
},
|
|
145
145
|
{
|
|
146
146
|
"name": "data-table",
|
|
147
|
-
"version": "1.
|
|
148
|
-
"hash": "
|
|
147
|
+
"version": "2.1.0",
|
|
148
|
+
"hash": "ee435ba760462decf9172cee64c823e08edbe49246f75f3786c75c6783602096"
|
|
149
149
|
},
|
|
150
150
|
{
|
|
151
151
|
"name": "resource-form",
|
|
152
|
-
"version": "1.
|
|
153
|
-
"hash": "
|
|
152
|
+
"version": "2.1.0",
|
|
153
|
+
"hash": "177ea294c9485fc3b9d9633982c29faad56baee495f7c2e69feba868c33a84e9"
|
|
154
154
|
},
|
|
155
155
|
{
|
|
156
156
|
"name": "record-collaboration",
|
|
157
|
-
"version": "1.
|
|
158
|
-
"hash": "
|
|
157
|
+
"version": "2.1.0",
|
|
158
|
+
"hash": "578412b5a1153d8fa1777179ca39e172460af5d4f7c2a17b2c643c6507385857"
|
|
159
159
|
},
|
|
160
160
|
{
|
|
161
161
|
"name": "record-assignments",
|
|
162
|
-
"version": "1.
|
|
163
|
-
"hash": "
|
|
162
|
+
"version": "2.1.0",
|
|
163
|
+
"hash": "3e19c7c033e80ed91952a33a23d604455874fe97e4d5b2a0012fcb1d6c30ec8c"
|
|
164
164
|
},
|
|
165
165
|
{
|
|
166
166
|
"name": "record-workflows",
|
|
167
|
-
"version": "1.
|
|
168
|
-
"hash": "
|
|
167
|
+
"version": "2.1.0",
|
|
168
|
+
"hash": "94ed2b1e30255fd02447af36f5c51cc8af2ab6bdc7ff07b7a91f4e6420c36224"
|
|
169
169
|
},
|
|
170
170
|
{
|
|
171
171
|
"name": "resource-show",
|
|
172
|
-
"version": "1.
|
|
173
|
-
"hash": "
|
|
172
|
+
"version": "2.1.0",
|
|
173
|
+
"hash": "1a894acdcf94e2204ff94ebfa2d2a7059378292eca8a4e1a6d09234e25de5bbc"
|
|
174
174
|
},
|
|
175
175
|
{
|
|
176
176
|
"name": "resource-import",
|
|
177
|
-
"version": "1.
|
|
178
|
-
"hash": "
|
|
177
|
+
"version": "2.1.0",
|
|
178
|
+
"hash": "0adbc6376480b46c7b0e2e947ffdeba5a13e82ec20d926d10b3cdeb804d675f7"
|
|
179
179
|
},
|
|
180
180
|
{
|
|
181
181
|
"name": "resource-page",
|
|
182
|
-
"version": "1.
|
|
183
|
-
"hash": "
|
|
182
|
+
"version": "2.1.0",
|
|
183
|
+
"hash": "c67bd28de750b552091c8614f48499609a4e6a167b3fc8d97f843764b5e81199"
|
|
184
184
|
},
|
|
185
185
|
{
|
|
186
186
|
"name": "resource-actions",
|
|
187
|
-
"version": "1.
|
|
188
|
-
"hash": "
|
|
187
|
+
"version": "2.1.0",
|
|
188
|
+
"hash": "9c66535433d81b9f574763c310ecfd0df036ce926f8f560222d49348fcd62cea"
|
|
189
189
|
},
|
|
190
190
|
{
|
|
191
191
|
"name": "resource-surface",
|
|
192
|
-
"version": "1.
|
|
192
|
+
"version": "2.1.0",
|
|
193
193
|
"hash": "a7723c7e3baeb925a81b91142133e423a702df3ebbc5efb9aa3d99b6589034cb"
|
|
194
194
|
},
|
|
195
195
|
{
|
|
196
196
|
"name": "ui-preferences",
|
|
197
|
-
"version": "1.
|
|
198
|
-
"hash": "
|
|
197
|
+
"version": "2.1.0",
|
|
198
|
+
"hash": "c5430a68726b1b01dd1259481fac4cd60ddfdd6cd986dc2c6fe63cc35e2d5cdb"
|
|
199
199
|
},
|
|
200
200
|
{
|
|
201
201
|
"name": "calendar-date",
|
|
202
|
-
"version": "1.
|
|
203
|
-
"hash": "
|
|
202
|
+
"version": "2.1.0",
|
|
203
|
+
"hash": "f166217803da3ae1beac2662f8c5528ea52c96b1fb4891dfc19b71090b345ff2"
|
|
204
204
|
},
|
|
205
205
|
{
|
|
206
206
|
"name": "hijri-calendar",
|
|
207
|
-
"version": "1.
|
|
207
|
+
"version": "2.1.0",
|
|
208
208
|
"hash": "39ca5de9c1df32e65e434241f3cbbae629463c9f21da93205274c177fc8b85f3"
|
|
209
209
|
},
|
|
210
210
|
{
|
|
211
211
|
"name": "confirm-action",
|
|
212
|
-
"version": "1.
|
|
212
|
+
"version": "2.1.0",
|
|
213
213
|
"hash": "7710115860f595324ab94f752abb1de09b58acc9256aadf56ea0113b3dd4bb09"
|
|
214
214
|
}
|
|
215
215
|
],
|
|
@@ -224,7 +224,7 @@
|
|
|
224
224
|
"sonner": "2.0.8",
|
|
225
225
|
"date-fns": "4.4.0",
|
|
226
226
|
"tw-animate-css": "1.4.0",
|
|
227
|
-
"@fontsource/
|
|
227
|
+
"@fontsource/ibm-plex-sans-arabic": "5.3.0",
|
|
228
228
|
"@tanstack/react-table": "9.2.4",
|
|
229
229
|
"@tanstack/react-virtual": "3.14.13",
|
|
230
230
|
"axios": "1.19.0"
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
{
|
|
21
21
|
"path": "registry/ui/record-assignments.tsx",
|
|
22
22
|
"type": "registry:ui",
|
|
23
|
-
"content": "import { useCallback, useEffect, useState } from 'react'\nimport axios from 'axios'\nimport { ListChecks, Plus } from 'lucide-react'\nimport type { Assignment, MentionCandidate } from '
|
|
23
|
+
"content": "import { useCallback, useEffect, useState } from 'react'\nimport axios from 'axios'\nimport { ListChecks, Plus } from 'lucide-react'\nimport type { Assignment, MentionCandidate } from 'adula'\nimport { Badge } from '~/components/ui/badge'\nimport { Button } from '~/components/ui/button'\nimport { Input } from '~/components/ui/input'\nimport { Label } from '~/components/ui/label'\nimport { Textarea } from '~/components/ui/textarea'\nimport {\n Dialog,\n DialogContent,\n DialogDescription,\n DialogFooter,\n DialogHeader,\n DialogTitle,\n} from '~/components/ui/dialog'\nimport {\n Select,\n SelectContent,\n SelectItem,\n SelectTrigger,\n SelectValue,\n} from '~/components/ui/select'\nimport { formatDate } from '~/components/ui/resource-value'\nimport { useUiPreferences } from '~/components/ui/ui-preferences'\n\nconst json = { headers: { Accept: 'application/json' }, withXSRFToken: true }\nconst statusLabel: Record<Assignment['status'], string> = {\n open: 'مفتوحة',\n done: 'منجزة',\n cancelled: 'ملغاة',\n}\n\n/** Tasks assigned on one record, with an assignment dialog for users who may update it. */\nexport function RecordAssignments({\n resource,\n id,\n canAssign,\n}: {\n resource: string\n id: number | string\n canAssign: boolean\n}) {\n const { calendar } = useUiPreferences()\n const base = `/resources/${resource}/${id}`\n const [rows, setRows] = useState<Assignment[] | null>(null)\n const [open, setOpen] = useState(false)\n const [people, setPeople] = useState<MentionCandidate[]>([])\n const [assigneeId, setAssigneeId] = useState('')\n const [title, setTitle] = useState('')\n const [note, setNote] = useState('')\n const [dueOn, setDueOn] = useState('')\n const [error, setError] = useState('')\n const [busy, setBusy] = useState(false)\n\n const load = useCallback(async () => {\n try {\n const response = await axios.get<{ data: Assignment[] }>(`${base}/assignments`, json)\n setRows(response.data.data)\n } catch {\n setRows([])\n }\n }, [base])\n useEffect(() => {\n void load()\n }, [load])\n useEffect(() => {\n if (!open) return\n axios\n .get<{ data: MentionCandidate[] }>(`${base}/mentions`, json)\n .then((response) => setPeople(response.data.data))\n .catch(() => setPeople([]))\n }, [open, base])\n\n const submit = async (event: React.FormEvent) => {\n event.preventDefault()\n setBusy(true)\n setError('')\n try {\n await axios.post(\n `${base}/assignments`,\n { assigneeId: Number(assigneeId), title, note, dueOn },\n json\n )\n setOpen(false)\n setTitle('')\n setNote('')\n setDueOn('')\n setAssigneeId('')\n await load()\n } catch (caught) {\n setError(\n axios.isAxiosError(caught) && caught.response?.data?.error?.message\n ? String(caught.response.data.error.message)\n : 'تعذر إسناد المهمة.'\n )\n } finally {\n setBusy(false)\n }\n }\n\n return (\n <section aria-label=\"المهام المسندة\" className=\"rounded-xl border bg-white\">\n <div className=\"flex items-center gap-2 border-b px-7 py-4\">\n <ListChecks size={16} className=\"text-muted-foreground\" />\n <h2 className=\"text-sm font-semibold\">المهام المسندة</h2>\n {canAssign && (\n <Button\n type=\"button\"\n size=\"sm\"\n variant=\"outline\"\n className=\"ms-auto\"\n onClick={() => setOpen(true)}\n >\n <Plus size={14} />\n إسناد مهمة\n </Button>\n )}\n </div>\n {rows === null ? (\n <p role=\"status\" className=\"px-7 py-5 text-xs text-muted-foreground\">\n جارٍ تحميل المهام…\n </p>\n ) : rows.length === 0 ? (\n <p className=\"px-7 py-5 text-xs text-muted-foreground\">لا مهام على هذا السجل.</p>\n ) : (\n <ul className=\"divide-y\">\n {rows.map((row) => (\n <li\n key={row.id}\n className=\"flex flex-wrap items-center gap-x-4 gap-y-1 px-7 py-3 text-sm\"\n >\n <span className=\"font-medium\">{row.title}</span>\n <Badge variant={row.status === 'open' ? 'default' : 'secondary'}>\n {statusLabel[row.status]}\n </Badge>\n <span className=\"text-xs text-muted-foreground\">\n المكلف: {row.assigneeName ?? `#${row.assigneeId}`}\n </span>\n {row.dueOn && (\n <span className=\"text-xs text-muted-foreground\">\n الاستحقاق <bdi className=\"tabular-nums\">{formatDate(row.dueOn, calendar)}</bdi>\n </span>\n )}\n </li>\n ))}\n </ul>\n )}\n <Dialog open={open} onOpenChange={setOpen}>\n <DialogContent dir=\"rtl\" className=\"sm:max-w-lg\">\n <DialogHeader>\n <DialogTitle>إسناد مهمة</DialogTitle>\n <DialogDescription>\n تظهر المهمة في «مهامي» لدى المكلف، ويُشعَر بها فوراً.\n </DialogDescription>\n </DialogHeader>\n <form id=\"assignment-form\" className=\"space-y-4\" onSubmit={submit}>\n <div className=\"space-y-2\">\n <Label htmlFor=\"assignment-assignee\">المكلف</Label>\n <Select value={assigneeId} onValueChange={setAssigneeId}>\n <SelectTrigger id=\"assignment-assignee\" aria-label=\"المكلف\">\n <SelectValue placeholder=\"اختر زميلاً يملك صلاحية العرض\" />\n </SelectTrigger>\n <SelectContent>\n {people.map((person) => (\n <SelectItem key={person.id} value={String(person.id)}>\n {person.name}\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n </div>\n <div className=\"space-y-2\">\n <Label htmlFor=\"assignment-title\">عنوان المهمة</Label>\n <Input\n id=\"assignment-title\"\n value={title}\n maxLength={200}\n required\n onChange={(event) => setTitle(event.target.value)}\n />\n </div>\n <div className=\"space-y-2\">\n <Label htmlFor=\"assignment-due\">تاريخ الاستحقاق</Label>\n <Input\n id=\"assignment-due\"\n type=\"date\"\n value={dueOn}\n onChange={(event) => setDueOn(event.target.value)}\n />\n </div>\n <div className=\"space-y-2\">\n <Label htmlFor=\"assignment-note\">ملاحظة</Label>\n <Textarea\n id=\"assignment-note\"\n value={note}\n maxLength={2000}\n onChange={(event) => setNote(event.target.value)}\n />\n </div>\n {error && (\n <p role=\"alert\" className=\"rounded-lg bg-red-50 px-3 py-2 text-xs text-red-800\">\n {error}\n </p>\n )}\n </form>\n <DialogFooter>\n <Button type=\"button\" variant=\"outline\" onClick={() => setOpen(false)}>\n إلغاء\n </Button>\n <Button\n type=\"submit\"\n form=\"assignment-form\"\n disabled={busy || !assigneeId || !title.trim()}\n >\n إسناد\n </Button>\n </DialogFooter>\n </DialogContent>\n </Dialog>\n </section>\n )\n}\n",
|
|
24
24
|
"target": "inertia/components/ui/record-assignments.tsx"
|
|
25
25
|
}
|
|
26
26
|
],
|