Coverage for src / lexigram / admin / actions / row_manager / actions.py: 0%
12 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-08-11 02:25 +0800
« prev ^ index » next coverage.py v7.13.5, created at 2026-08-11 02:25 +0800
1"""
2Row action definitions and configurations.
4Provides predefined actions for common row operations.
5"""
7from __future__ import annotations
9from lexigram.admin.actions.row_manager.types import ActionStyle, RowAction
12def create_view_action(
13 url_template: str = "/admin/{resource}/{id}",
14 open_in_modal: bool = True,
15 label: str = "View",
16 icon: str = "eye",
17 keyboard_shortcut: str = "v",
18) -> RowAction:
19 """Create a view action."""
20 return RowAction(
21 name="view",
22 label=label,
23 icon=icon,
24 style=ActionStyle.INFO,
25 url=url_template,
26 method="GET",
27 open_in_modal=open_in_modal,
28 keyboard_shortcut=keyboard_shortcut,
29 tooltip="View details",
30 )
33def create_edit_action(
34 url_template: str = "/admin/{resource}/{id}/edit",
35 open_in_modal: bool = False,
36 label: str = "Edit",
37 icon: str = "pencil",
38 keyboard_shortcut: str = "e",
39) -> RowAction:
40 """Create an edit action."""
41 return RowAction(
42 name="edit",
43 label=label,
44 icon=icon,
45 style=ActionStyle.PRIMARY,
46 url=url_template,
47 method="GET",
48 open_in_modal=open_in_modal,
49 keyboard_shortcut=keyboard_shortcut,
50 tooltip="Edit record",
51 )
54def create_delete_action(
55 confirm_message: str = "Are you sure you want to delete this record?",
56 label: str = "Delete",
57 icon: str = "trash",
58 keyboard_shortcut: str = "Delete",
59) -> RowAction:
60 """Create a delete action."""
61 return RowAction(
62 name="delete",
63 label=label,
64 icon=icon,
65 style=ActionStyle.DANGER,
66 confirm=True,
67 confirm_message=confirm_message,
68 keyboard_shortcut=keyboard_shortcut,
69 tooltip="Delete record",
70 )
73def create_duplicate_action(
74 label: str = "Duplicate",
75 icon: str = "copy",
76 keyboard_shortcut: str = "Ctrl+D",
77) -> RowAction:
78 """Create a duplicate action."""
79 return RowAction(
80 name="duplicate",
81 label=label,
82 icon=icon,
83 style=ActionStyle.SECONDARY,
84 keyboard_shortcut=keyboard_shortcut,
85 tooltip="Duplicate record",
86 )
89# Predefined action sets
90BASIC_ROW_ACTIONS = [
91 create_view_action(),
92 create_edit_action(),
93 create_delete_action(),
94]
96STANDARD_ROW_ACTIONS = [
97 create_view_action(),
98 create_edit_action(),
99 create_duplicate_action(),
100 create_delete_action(),
101]