Skip to content

Commit 880dbe9

Browse files
committed
feat: upgrade Strapi to v5
1 parent 7234730 commit 880dbe9

34 files changed

+26259
-18047
lines changed

Diff for: README.md

+20-4
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,32 @@ A strapi plugin to sync your strapi content with Algolia.
1212

1313
### 1. Installation
1414

15-
#### With Yarn
15+
#### Strapi v5 - Use latest version
16+
17+
##### With Yarn
18+
19+
```bash
20+
yarn add strapi-plugin-strapi-algolia@latest
21+
```
22+
23+
###### With NPM
24+
25+
```bash
26+
npm install --save strapi-plugin-strapi-algolia@latest
27+
```
28+
29+
#### Strapi v4 - Use version 1.x.x
30+
31+
##### With Yarn
1632

1733
```bash
18-
yarn add strapi-plugin-strapi-algolia
34+
yarn add strapi-plugin-strapi-algolia@1
1935
```
2036

21-
##### With NPM
37+
###### With NPM
2238

2339
```bash
24-
npm install --save strapi-plugin-strapi-algolia
40+
npm install --save strapi-plugin-strapi-algolia@1
2541
```
2642

2743
### 2. Setup environment variables

Diff for: admin/custom.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare module '@strapi/design-system/*';
2+
declare module '@strapi/design-system';
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
1-
import { Button } from '@strapi/design-system/Button';
2-
import {
3-
ConfirmDialog,
4-
useFetchClient,
5-
useNotification,
6-
} from '@strapi/helper-plugin';
7-
import Play from '@strapi/icons/Play';
1+
import { Button } from '@strapi/design-system';
2+
import { Play, WarningCircle } from '@strapi/icons';
3+
import { useNotification } from '@strapi/strapi/admin';
84
import { useEffect, useState } from 'react';
95
import { useIntl } from 'react-intl';
10-
import { useConfigContentTypes } from '../../hooks';
11-
import pluginId from '../../pluginId';
6+
import { useConfigContentTypes } from '../hooks';
7+
import pluginId from '../pluginId';
128

13-
const IndexAllButton = ({ contentType }: { contentType: string }) => {
9+
import { Dialog } from '@strapi/design-system';
10+
import { ConfirmDialog, useFetchClient } from '@strapi/strapi/admin';
11+
12+
export default ({ contentType }: { contentType?: string }) => {
1413
const { contentTypes } = useConfigContentTypes();
1514
const { post } = useFetchClient();
1615

1716
const [showConfirmModal, setShowConfirmModal] = useState(false);
18-
const [
19-
isModalConfirmButtonLoading,
20-
setIsModalConfirmButtonLoading,
21-
] = useState(false);
2217
const { formatMessage } = useIntl();
23-
const toggleNotification = useNotification();
18+
const { toggleNotification } = useNotification();
2419

2520
const abortController = new AbortController();
2621
const { signal } = abortController;
@@ -36,9 +31,6 @@ const IndexAllButton = ({ contentType }: { contentType: string }) => {
3631

3732
const handleConfirmDelete = async () => {
3833
try {
39-
// Show the loading state
40-
setIsModalConfirmButtonLoading(true);
41-
4234
await post(
4335
`/${pluginId}/index-all-articles`,
4436
{
@@ -49,33 +41,27 @@ const IndexAllButton = ({ contentType }: { contentType: string }) => {
4941

5042
toggleNotification({
5143
type: 'success',
52-
message: {
44+
message: formatMessage({
5345
id: 'cache.purge.success',
5446
defaultMessage: 'All items have been indexed',
55-
},
47+
}),
5648
});
57-
58-
setIsModalConfirmButtonLoading(false);
59-
60-
toggleConfirmModal();
6149
} catch (err) {
6250
const errorMessage = (err as any)?.response?.payload?.error
6351
?.message;
64-
setIsModalConfirmButtonLoading(false);
65-
toggleConfirmModal();
6652

6753
if (errorMessage) {
6854
toggleNotification({
6955
type: 'warning',
70-
message: {
56+
message: formatMessage({
7157
id: 'cache.purge.error',
7258
defaultMessage: errorMessage,
73-
},
59+
}),
7460
});
7561
} else {
7662
toggleNotification({
7763
type: 'warning',
78-
message: { id: 'notification.error' },
64+
message: formatMessage({ id: 'notification.error' }),
7965
});
8066
}
8167
}
@@ -96,35 +82,32 @@ const IndexAllButton = ({ contentType }: { contentType: string }) => {
9682
size="S"
9783
startIcon={<Play />}
9884
variant="default"
85+
type="button"
9986
>
10087
{formatMessage({
10188
id: 'cache.purge.delete-entry',
10289
defaultMessage: 'Index all items',
10390
})}
10491
</Button>
105-
<ConfirmDialog
106-
variantRightButton="default"
107-
isConfirmButtonLoading={isModalConfirmButtonLoading}
108-
isOpen={showConfirmModal}
109-
onConfirm={handleConfirmDelete}
110-
onToggleDialog={toggleConfirmModal}
111-
title={{
112-
id: 'cache.purge.confirm-modal-title',
113-
defaultMessage: 'Confirm indexing all items?',
114-
}}
115-
bodyText={{
116-
id: 'cache.purge.confirm-modal-body',
117-
defaultMessage:
118-
'Are you sure you want to index all items this content type?',
119-
}}
120-
iconRightButton={<Play />}
121-
rightButtonText={{
122-
id: 'cache.purge.confirm-modal-confirm',
123-
defaultMessage: 'Index all items',
124-
}}
125-
/>
92+
<Dialog.Root
93+
open={showConfirmModal}
94+
onOpenChange={toggleConfirmModal}
95+
>
96+
<ConfirmDialog
97+
onConfirm={handleConfirmDelete}
98+
title={formatMessage({
99+
id: 'cache.purge.confirm-modal-title',
100+
defaultMessage: 'Confirm indexing all items?',
101+
})}
102+
variant="default"
103+
icon={<WarningCircle fill="danger500" />}
104+
children={formatMessage({
105+
id: 'cache.purge.confirm-modal-body',
106+
defaultMessage:
107+
'Are you sure you want to index all items this content type?',
108+
})}
109+
/>
110+
</Dialog.Root>
126111
</>
127112
);
128113
};
129-
130-
export default IndexAllButton;

Diff for: admin/src/components/Initializer/index.tsx renamed to admin/src/components/Initializer.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useEffect, useRef } from 'react';
2-
import pluginId from '../../pluginId';
2+
import pluginId from '../pluginId';
33

4-
const Initializer = ({
4+
export default ({
55
setPlugin,
66
}: {
77
setPlugin: (id: string) => void;
@@ -14,5 +14,3 @@ const Initializer = ({
1414

1515
return null;
1616
};
17-
18-
export default Initializer;

Diff for: admin/src/components/ListViewInjectedComponent.tsx

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { useRBAC } from '@strapi/strapi/admin';
2+
import { useMatch } from 'react-router-dom';
3+
import strapiAlgoliaPermissions from '../permissions';
4+
import IndexAllButton from './IndexAllButton';
5+
6+
const ListViewInjectedComponent = () => {
7+
const routeMatch = useMatch('/content-manager/:kind/:slug?');
8+
const { allowedActions } = useRBAC(strapiAlgoliaPermissions);
9+
10+
if (!allowedActions.canIndexAll) {
11+
return null;
12+
}
13+
14+
return <IndexAllButton contentType={routeMatch?.params.slug} />;
15+
};
16+
17+
export default ListViewInjectedComponent;

Diff for: admin/src/components/ListViewInjectedComponent/index.tsx

-19
This file was deleted.

Diff for: admin/src/hooks/useConfigContentTypes/index.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
1-
/* eslint-disable @typescript-eslint/no-unused-vars */
2-
3-
import {
4-
useFetchClient,
5-
useNotification,
6-
} from '@strapi/helper-plugin';
1+
import { useNotification } from '@strapi/strapi/admin';
72
import { useEffect, useReducer, useRef } from 'react';
83
import pluginId from '../../pluginId';
94
import init from './init';
105
import reducer, { Actions, initialState } from './reducer';
116

7+
import { useFetchClient } from '@strapi/strapi/admin';
8+
129
const useConfigContentTypes = (shouldFetchData = true) => {
1310
const [{ contentTypes, isLoading }, dispatch] = useReducer(
1411
reducer,
1512
initialState,
1613
() => init(initialState, shouldFetchData)
1714
);
18-
const toggleNotification = useNotification();
15+
const { toggleNotification } = useNotification();
1916
const client = useFetchClient();
2017

2118
const isMounted = useRef(true);
@@ -42,7 +39,6 @@ const useConfigContentTypes = (shouldFetchData = true) => {
4239
const { data } = await client.get(
4340
`/${pluginId}/config/content-types`,
4441
{
45-
method: 'GET',
4642
signal,
4743
}
4844
);

Diff for: admin/src/index.tsx renamed to admin/src/index.ts

+25-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
1-
import { prefixPluginTranslations } from '@strapi/helper-plugin';
21
import pluginPkg from '../../package.json';
32
import Initializer from './components/Initializer';
43
import ListViewInjectedComponent from './components/ListViewInjectedComponent';
54
import pluginId from './pluginId';
65

76
const { name } = pluginPkg.strapi;
87

8+
type TradOptions = Record<string, string>;
9+
10+
const prefixPluginTranslations = (
11+
trad: TradOptions,
12+
pluginId: string
13+
): TradOptions => {
14+
if (!pluginId) {
15+
throw new TypeError("pluginId can't be empty");
16+
}
17+
return Object.keys(trad).reduce<TradOptions>(
18+
(acc, current) => ({
19+
...acc,
20+
[`${pluginId}.${current}`]: trad[current],
21+
}),
22+
{}
23+
);
24+
};
25+
926
export default {
1027
register(app: any) {
1128
app.registerPlugin({
@@ -16,10 +33,12 @@ export default {
1633
});
1734
},
1835
bootstrap(app: any) {
19-
app.injectContentManagerComponent('listView', 'actions', {
20-
name: 'ListViewInjectedComponent',
21-
Component: ListViewInjectedComponent,
22-
});
36+
app
37+
.getPlugin('content-manager')
38+
.injectComponent('listView', 'actions', {
39+
name: 'ListViewInjectedComponent',
40+
Component: ListViewInjectedComponent,
41+
});
2342
},
2443
async registerTrads({ locales }: any) {
2544
const importedTranslations = await Promise.all(
@@ -36,6 +55,6 @@ export default {
3655
)
3756
);
3857

39-
return Promise.resolve(importedTranslations);
58+
return importedTranslations;
4059
},
4160
};

Diff for: admin/tsconfig.build.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": "./tsconfig",
3+
"include": ["./src", "./custom.d.ts"],
4+
"exclude": ["**/*.test.ts", "**/*.test.tsx"],
5+
"compilerOptions": {
6+
"rootDir": "../",
7+
"baseUrl": ".",
8+
"outDir": "./dist",
9+
"skipLibCheck": true
10+
}
11+
}

Diff for: admin/tsconfig.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "@strapi/typescript-utils/tsconfigs/admin",
3+
"include": ["./src", "./custom.d.ts"],
4+
"compilerOptions": {
5+
"rootDir": "../",
6+
"baseUrl": ".",
7+
"skipLibCheck": true
8+
}
9+
}

Diff for: custom.d.ts

Whitespace-only changes.

0 commit comments

Comments
 (0)