Skip to content

Commit b7916ca

Browse files
jhoward1994pwizla
andauthored
feat: add more before examples for helper plugin migration (#2209)
* feat: add more before examples for helper plugin migration * Update docusaurus/docs/dev-docs/migration/v4-to-v5/additional-resources/helper-plugin.md --------- Co-authored-by: Pierre Wizla <pwizla@users.noreply.github.com>
1 parent 7279a58 commit b7916ca

File tree

1 file changed

+132
-3
lines changed
  • docusaurus/docs/dev-docs/migration/v4-to-v5/additional-resources

1 file changed

+132
-3
lines changed

docusaurus/docs/dev-docs/migration/v4-to-v5/additional-resources/helper-plugin.md

Lines changed: 132 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ This component has been removed and refactored to be part of the `Page` componen
2626
// Before
2727
import { AnErrorOccurred } from '@strapi/helper-plugin';
2828

29+
const MyPage = () => {
30+
// ...
31+
32+
if (error) {
33+
return <AnErrorOccurred />;
34+
}
35+
36+
// ...
37+
};
38+
2939
// After
3040
import { Page } from '@strapi/strapi/admin';
3141

@@ -44,7 +54,8 @@ const MyPage = () => {
4454

4555
This component has been removed and not replaced. If you feel like you need this component, please open an issue on the Strapi repository to discuss your usecase.
4656

47-
We recommend using the `Page.Protect` component from `@strapi/strapi/admin` instead. See below for an example. If you need to check permissions for a lower level component you can use the useRBAC hook.
57+
We recommend using the `Page.Protect` component from `@strapi/strapi/admin` instead (see [`CheckPagePermissions`](#checkpagepermissions) for an example). If you need to check permissions for a lower level component you can use [the `useRBAC` hook](#userbac).
58+
4859

4960
### CheckPagePermissions
5061

@@ -54,14 +65,24 @@ This component has been removed and refactored to be part of the `Page` componen
5465
// Before
5566
import { CheckPagePermissions } from '@strapi/helper-plugin';
5667

68+
const MyProtectedPage = () => {
69+
return (
70+
<CheckPagePermissions
71+
permissions={[action: 'plugin::my-plugin.read']}
72+
>
73+
<MyPag />
74+
</CheckPagePermissions>
75+
);
76+
};
77+
5778
// After
5879
import { Page } from '@strapi/strapi/admin';
5980

6081
const MyProtectedPage = () => {
82+
<Page.Protect permissions={[action: 'plugin::my-plugin.read']}>
6183
return (
62-
<Page.Protect permissions={[action: 'plugin::my-plugin.read']}>
63-
<MyPage />
6484
</Page.Protect>
85+
<MyPage />
6586
);
6687
};
6788
```
@@ -102,10 +123,14 @@ import { DateTimePicker } from '@strapi/design-system';
102123

103124
This component was previously deprecated and has now been removed. Similar to the deprecation notice, we recommend using the `Table` component from `@strapi/strapi/admin`.
104125

126+
Please see the contributors [documentation for the `Table` component](https://v5.contributor.strapi.io/exports/namespaces/Table) for more information.
127+
105128
### EmptyBodyTable
106129

107130
This component has been removed and is part of the `Table` component.
108131

132+
Please see the contributors [documentation for the `Table` component](https://v5.contributor.strapi.io/exports/namespaces/Table) for more information.
133+
109134
### EmptyStateLayout
110135

111136
This component has been removed and not replaced. You should use `EmptyStateLayout` from `@strapi/design-system`:
@@ -130,6 +155,13 @@ This component was moved to the `admin` package and can now be imported via the
130155
// Before
131156
import { FilterListURLQuery } from '@strapi/helper-plugin';
132157

158+
const MyComponent = () => {
159+
return (
160+
<FilterListURLQuery filtersSchema={[{name: 'name', metadatas: {label: 'Name'}, fieldSchema: {type: 'string'}}]} />
161+
);
162+
};
163+
164+
133165
// After
134166
import { Filters } from '@strapi/strapi/admin';
135167

@@ -185,6 +217,19 @@ This component has been removed and refactored to become the `InputRenderer` com
185217
// Before
186218
import { GenericInput } from '@strapi/helper-plugin';
187219

220+
const MyComponent = () => {
221+
return (
222+
<GenericInput
223+
type={'type'}
224+
hint={'hint'}
225+
label={'label'}
226+
name={'name'}
227+
onChange={onMetaChange}
228+
value={'value'}
229+
/>
230+
);
231+
};
232+
188233
// After
189234
import { InputRenderer } from '@strapi/strapi/admin';
190235
```
@@ -264,6 +309,16 @@ This component has been removed and refactored to be part of the `Page` componen
264309
// Before
265310
import { LoadingIndicatorPage } from '@strapi/helper-plugin';
266311

312+
const MyPage = () => {
313+
// ...
314+
315+
if (isLoading) {
316+
return <LoadingIndicatorPage />;
317+
}
318+
319+
// ...
320+
};
321+
267322
// After
268323
import { Page } from '@strapi/strapi/admin';
269324

@@ -283,6 +338,7 @@ const MyPage = () => {
283338
This component has been removed and not replaced, you should use the `EmptyStateLayout` component from `@strapi/design-system`.
284339

285340
```tsx
341+
// Before
286342
import { NoContent } from '@strapi/helper-plugin';
287343

288344
<NoContent
@@ -315,6 +371,16 @@ This component has been removed and refactored to be part of the `Page` componen
315371
// Before
316372
import { NoPermissions } from '@strapi/helper-plugin';
317373

374+
const MyPage = () => {
375+
// ...
376+
377+
if (!canRead) {
378+
return <NoPermissions />;
379+
}
380+
381+
// ...
382+
};
383+
318384
// After
319385
import { Page } from '@strapi/strapi/admin';
320386

@@ -356,6 +422,12 @@ This component was moved to the `admin` package and can now be imported via the
356422
// Before
357423
import { PageSizeURLQuery } from '@strapi/helper-plugin';
358424

425+
const MyComponent = () => {
426+
return (
427+
<PageSizeURLQuery options={['12', '24', '50', '100']} defaultValue="24" />
428+
);
429+
};
430+
359431
// After
360432
import { Pagination } from '@strapi/strapi/admin';
361433

@@ -424,6 +496,16 @@ This component should be imported from the `@strapi/design-system` package:
424496
// Before
425497
import { Status } from '@strapi/helper-plugin';
426498

499+
const MyComponent = () => {
500+
return (
501+
<Status variant={statusColor} showBullet={false} size="S">
502+
<Typography fontWeight="bold" textColor={`${statusColor}700`}>
503+
{stateMessage[status]}
504+
</Typography>
505+
</Status>
506+
);
507+
};
508+
427509
// After
428510
import { Status } from '@strapi/design-system';
429511
```
@@ -436,6 +518,46 @@ This component should be imported from the `@strapi/strapi/admin` package:
436518
// Before
437519
import { Table } from '@strapi/helper-plugin';
438520

521+
const MyComponent = () => {
522+
return (
523+
<Table colCount={2} rowCount={2}>
524+
<Thead>
525+
<Tr>
526+
<Th>
527+
<Typography variant="sigma" textColor="neutral600">
528+
{`Name`}
529+
</Typography>
530+
</Th>
531+
<Th>
532+
<Typography variant="sigma" textColor="neutral600">
533+
{`Description`}
534+
</Typography>
535+
</Th>
536+
</Tr>
537+
</Thead>
538+
<Tbody>
539+
{data?.map(({ name, description }) => {
540+
return (
541+
<Tr key={name}>
542+
<Td>
543+
<Typography textColor="neutral800" variant="omega" fontWeight="bold">
544+
{name}
545+
</Typography>
546+
</Td>
547+
<Td>
548+
<Typography textColor="neutral800">
549+
{description}
550+
</Typography>
551+
</Td>
552+
</Tr>
553+
);
554+
})}
555+
</Tbody>
556+
</Table>
557+
);
558+
};
559+
560+
439561
// After
440562
import { Table } from '@strapi/strapi/admin';
441563
```
@@ -789,6 +911,11 @@ This util has been removed. If you need to use it, you should use the `checkUser
789911
// Before
790912
import { hasPermissions } from '@strapi/helper-plugin';
791913

914+
915+
const permissions = await Promise.all(
916+
generalSectionRawLinks.map(({ permissions }) => hasPermissions(userPermissions, permissions))
917+
);
918+
792919
// After
793920
import { useAuth } from '@strapi/strapi/admin';
794921

@@ -827,6 +954,8 @@ const prefixPluginTranslations = (
827954
};
828955
```
829956

957+
If you feel like you need this util, please open an issue on the Strapi repository to discuss your usecase.
958+
830959
### pxToRem
831960

832961
This util has been removed and not replaced. You should use directly this code in place of the pxToRem:

0 commit comments

Comments
 (0)