MCPcopy
hub / github.com/marmelab/react-admin / DataTableRow

Function DataTableRow

packages/ra-core/src/test-ui/DataTable.tsx:86–149  ·  view source on GitHub ↗
(props: {
    children: React.ReactNode;
    record?: RaRecord;
    resource?: string;
})

Source from the content-addressed store, hash-verified

84};
85
86const DataTableRow = (props: {
87 children: React.ReactNode;
88 record?: RaRecord;
89 resource?: string;
90}) => {
91 const getPathForRecord = useGetPathForRecordCallback();
92 const navigate = useNavigate();
93 const record = useRecordContext(props);
94 if (!record) {
95 throw new Error(
96 'DataTableRow can only be used within a RecordContext or be passed a record prop'
97 );
98 }
99 const resource = useResourceContext(props);
100 if (!resource) {
101 throw new Error(
102 'DataTableRow can only be used within a ResourceContext or be passed a resource prop'
103 );
104 }
105
106 const { hasBulkActions = false } = useDataTableConfigContext();
107 const { handleToggleItem, rowClick } = useDataTableCallbacksContext();
108 const selectedIds = useDataTableSelectedIdsContext();
109
110 const handleClick = useEvent(async (event: React.MouseEvent) => {
111 event.persist();
112 const temporaryLink =
113 typeof rowClick === 'function'
114 ? rowClick(record.id, resource, record)
115 : rowClick;
116
117 const link = isPromise(temporaryLink)
118 ? await temporaryLink
119 : temporaryLink;
120
121 const path = await getPathForRecord({
122 record,
123 resource,
124 link,
125 });
126 if (path === false || path == null) {
127 return;
128 }
129 navigate(path, {
130 state: { _scrollToTop: true },
131 });
132 });
133
134 return (
135 <tr onClick={handleClick}>
136 {hasBulkActions && (
137 <DataTableCol>
138 <input
139 aria-label="Select this row"
140 type="checkbox"
141 checked={selectedIds?.includes(record.id)}
142 onChange={event => handleToggleItem!(record.id, event)}
143 />

Callers

nothing calls this directly

Calls 11

useNavigateFunction · 0.90
useRecordContextFunction · 0.90
useResourceContextFunction · 0.90
useEventFunction · 0.90
rowClickFunction · 0.85
isPromiseFunction · 0.70
navigateFunction · 0.50

Tested by

no test coverage detected