Skip to content

Commit 9723a0e

Browse files
committed
Fix <Confirm> ignore simple string title and content props
1 parent e4fd550 commit 9723a0e

File tree

6 files changed

+104
-21
lines changed

6 files changed

+104
-21
lines changed

packages/ra-ui-materialui/src/button/DeleteWithConfirmButton.spec.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { Notification } from '../layout';
2323
import {
2424
Basic,
2525
NoRecordRepresentation,
26+
WithCustomTitleAndContent,
2627
WithDefaultTranslation,
2728
} from './DeleteWithConfirmButton.stories';
2829

@@ -341,6 +342,19 @@ describe('<DeleteWithConfirmButton />', () => {
341342
});
342343
});
343344

345+
it('should use the provided strings as the confirmation title and content', async () => {
346+
render(<WithCustomTitleAndContent />);
347+
fireEvent.click(
348+
within(
349+
(await screen.findByText('War and Peace')).closest(
350+
'tr'
351+
) as HTMLElement
352+
).getByText('Delete')
353+
);
354+
await screen.findByText('Delete me?');
355+
await screen.findByText('Please confirm the deletion');
356+
});
357+
344358
it('should use the record representation in the confirmation title and content with a resource specific translation', async () => {
345359
render(<Basic />);
346360
fireEvent.click(

packages/ra-ui-materialui/src/button/DeleteWithConfirmButton.stories.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,29 @@ export const WithDefaultTranslation = () => (
231231
</TestMemoryRouter>
232232
);
233233

234+
export const WithCustomTitleAndContent = () => (
235+
<TestMemoryRouter initialEntries={['/books']}>
236+
<AdminContext
237+
dataProvider={dataProvider}
238+
i18nProvider={i18nProviderDefault}
239+
>
240+
<AdminUI>
241+
<Resource
242+
name="books"
243+
list={
244+
<BookList>
245+
<DeleteWithConfirmButton
246+
confirmTitle="Delete me?"
247+
confirmContent="Please confirm the deletion"
248+
/>
249+
</BookList>
250+
}
251+
/>
252+
</AdminUI>
253+
</AdminContext>
254+
</TestMemoryRouter>
255+
);
256+
234257
export const NoRecordRepresentation = () => (
235258
<TestMemoryRouter initialEntries={['/authors']}>
236259
<AdminContext dataProvider={dataProvider} i18nProvider={i18nProvider}>

packages/ra-ui-materialui/src/button/DeleteWithConfirmButton.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,26 @@ export const DeleteWithConfirmButton = <RecordType extends RaRecord = any>(
100100
recordRepresentation,
101101
name: resourceName,
102102
id: record?.id,
103-
_: translate('ra.message.delete_title', {
104-
recordRepresentation,
105-
name: resourceName,
106-
id: record?.id,
107-
}),
103+
_:
104+
confirmTitleProp ??
105+
translate('ra.message.delete_title', {
106+
recordRepresentation,
107+
name: resourceName,
108+
id: record?.id,
109+
}),
108110
...titleTranslateOptions,
109111
}}
110112
contentTranslateOptions={{
111113
recordRepresentation,
112114
name: resourceName,
113115
id: record?.id,
114-
_: translate('ra.message.delete_content', {
115-
recordRepresentation,
116-
name: resourceName,
117-
id: record?.id,
118-
}),
116+
_:
117+
confirmContentProp ??
118+
translate('ra.message.delete_content', {
119+
recordRepresentation,
120+
name: resourceName,
121+
id: record?.id,
122+
}),
119123
...contentTranslateOptions,
120124
}}
121125
onConfirm={handleDelete}

packages/ra-ui-materialui/src/button/UpdateWithConfirmButton.spec.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { MutationOptions } from './UpdateButton.stories';
1919
import {
2020
Basic,
2121
NoRecordRepresentation,
22+
WithCustomTitleAndContent,
2223
WithDefaultTranslation,
2324
} from './UpdateWithConfirmButton.stories';
2425

@@ -280,6 +281,19 @@ describe('<UpdateWithConfirmButton />', () => {
280281
).toBeNull();
281282
});
282283

284+
it('should use the provided strings as the confirmation title and content', async () => {
285+
render(<WithCustomTitleAndContent />);
286+
fireEvent.click(
287+
within(
288+
(await screen.findByText('War and Peace')).closest(
289+
'tr'
290+
) as HTMLElement
291+
).getByText('Update')
292+
);
293+
await screen.findByText('Update me?');
294+
await screen.findByText('Please confirm the update');
295+
});
296+
283297
it('should use the record representation in the confirmation title and content with a resource specific translation', async () => {
284298
render(<Basic />);
285299
fireEvent.click(

packages/ra-ui-materialui/src/button/UpdateWithConfirmButton.stories.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,30 @@ export const Basic = () => (
213213
</TestMemoryRouter>
214214
);
215215

216+
export const WithCustomTitleAndContent = () => (
217+
<TestMemoryRouter initialEntries={['/books']}>
218+
<AdminContext
219+
dataProvider={dataProvider}
220+
i18nProvider={i18nProviderDefault}
221+
>
222+
<AdminUI>
223+
<Resource
224+
name="books"
225+
list={
226+
<BookList>
227+
<UpdateWithConfirmButton
228+
data={{ title: 'modified' }}
229+
confirmTitle="Update me?"
230+
confirmContent="Please confirm the update"
231+
/>
232+
</BookList>
233+
}
234+
/>
235+
</AdminUI>
236+
</AdminContext>
237+
</TestMemoryRouter>
238+
);
239+
216240
export const WithDefaultTranslation = () => (
217241
<TestMemoryRouter initialEntries={['/books']}>
218242
<AdminContext

packages/ra-ui-materialui/src/button/UpdateWithConfirmButton.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export const UpdateWithConfirmButton = (
9696
}
9797
);
9898

99-
const handleClick = e => {
99+
const handleClick = (e: React.MouseEvent) => {
100100
setOpen(true);
101101
e.stopPropagation();
102102
};
@@ -155,21 +155,25 @@ export const UpdateWithConfirmButton = (
155155
smart_count: 1,
156156
name: resourceName,
157157
recordRepresentation,
158-
_: translate('ra.message.bulk_update_title', {
159-
smart_count: 1,
160-
name: resourceName,
161-
recordRepresentation,
162-
}),
158+
_:
159+
confirmTitleProp ??
160+
translate('ra.message.bulk_update_title', {
161+
smart_count: 1,
162+
name: resourceName,
163+
recordRepresentation,
164+
}),
163165
}}
164166
contentTranslateOptions={{
165167
smart_count: 1,
166168
name: resourceName,
167169
recordRepresentation,
168-
_: translate('ra.message.bulk_update_content', {
169-
smart_count: 1,
170-
name: resourceName,
171-
recordRepresentation,
172-
}),
170+
_:
171+
confirmContentProp ??
172+
translate('ra.message.bulk_update_content', {
173+
smart_count: 1,
174+
name: resourceName,
175+
recordRepresentation,
176+
}),
173177
}}
174178
onConfirm={handleUpdate}
175179
onClose={handleDialogClose}

0 commit comments

Comments
 (0)