fix build
This commit is contained in:
@@ -25,6 +25,12 @@ export type ResourceSelectorDialogProps<TClient extends ResourcePageClient> = {
|
||||
crudProps: Omit<CrudResourceProps<TClient>, "render" | "tableProps">
|
||||
/** Optional rowKey for selection identity. Defaults to "id" */
|
||||
rowKey?: keyof ResourceItem<TClient>
|
||||
/**
|
||||
* Selection mode.
|
||||
* - "multi" (default): checkbox multi-select + Confirm button
|
||||
* - "single": row click immediately fires onConfirm with the clicked row
|
||||
*/
|
||||
selectionMode?: "single" | "multi"
|
||||
}
|
||||
|
||||
export function ResourceSelectorDialog<TClient extends ResourcePageClient>({
|
||||
@@ -34,6 +40,7 @@ export function ResourceSelectorDialog<TClient extends ResourcePageClient>({
|
||||
onConfirm,
|
||||
crudProps,
|
||||
rowKey,
|
||||
selectionMode = "multi",
|
||||
}: ResourceSelectorDialogProps<TClient>) {
|
||||
type TItem = ResourceItem<TClient>
|
||||
|
||||
@@ -58,6 +65,11 @@ export function ResourceSelectorDialog<TClient extends ResourcePageClient>({
|
||||
onOpenChange(false)
|
||||
}
|
||||
|
||||
const handleRowClick = (row: TItem) => {
|
||||
onConfirm([row])
|
||||
onOpenChange(false)
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={(v) => { if (!v) handleCancel() }}>
|
||||
<DialogContent className="min-w-4xl max-h-[90vh] flex flex-col">
|
||||
@@ -67,26 +79,35 @@ export function ResourceSelectorDialog<TClient extends ResourcePageClient>({
|
||||
<div className="flex-1 overflow-auto">
|
||||
<Card className="rounded-none border-0 shadow-none">
|
||||
<CardContent className="p-0">
|
||||
<CrudResource<TClient>
|
||||
{...crudProps}
|
||||
tableProps={{
|
||||
selection: {
|
||||
onSelectionChange: handleSelectionChange,
|
||||
...(rowKey ? { rowKey } : {}),
|
||||
},
|
||||
}}
|
||||
/>
|
||||
{selectionMode === "single" ? (
|
||||
<CrudResource<TClient>
|
||||
{...crudProps}
|
||||
onRowClick={handleRowClick}
|
||||
/>
|
||||
) : (
|
||||
<CrudResource<TClient>
|
||||
{...crudProps}
|
||||
tableProps={{
|
||||
selection: {
|
||||
onSelectionChange: handleSelectionChange,
|
||||
...(rowKey ? { rowKey } : {}),
|
||||
},
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={handleCancel}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button onClick={handleConfirm} disabled={count === 0}>
|
||||
Confirm{count > 0 ? ` (${count})` : ""}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
{selectionMode === "multi" && (
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={handleCancel}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button onClick={handleConfirm} disabled={count === 0}>
|
||||
Confirm{count > 0 ? ` (${count})` : ""}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
)}
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user