Skip to content

Commit 3d01c66

Browse files
authored
Merge pull request #262 from os2display/feature/redux-toolkit-upgrade
Redux toolkit upgrade and fixed RTK Query caching setup
2 parents aff9768 + c81af4e commit 3d01c66

File tree

156 files changed

+3887
-20743
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+3887
-20743
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ All notable changes to this project will be documented in this file.
1111
* Updated PHP dependencies.
1212
* Added Playwright github action.
1313
* Changed how templates are imported.
14+
* Removed propTypes.
15+
* Upgraded redux-toolkit and how api slices are generated.
16+
* Fixed redux-toolkit cache handling.
1417

1518
### NB! Prior to 3.x the project was split into separate repositories
1619

README.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Development
44

55
```bash
6-
docker compose pull
6+
docker compose pull
77
docker compose up --detach
88
docker compose exec phpfpm composer install
99
docker compose run --rm node npm install
@@ -25,15 +25,46 @@ The fixtures have the image-text template, and two screen layouts: full screen a
2525

2626
TODO
2727

28-
## Documentation
28+
## API specification and generated code
29+
30+
When the API is changed a new OpenAPI specification should be generated that reflects the changes to the API.
31+
32+
To generate the updated API specification, run the following command:
33+
34+
```shell
35+
docker compose exec phpfpm composer update-api-spec
36+
```
37+
38+
This will generate `public/api-spec-v2.json` and `public/api-spec-v2.yaml`.
39+
40+
This generated API specification is used to generate
41+
[Redux Toolkit RTK Query](https://redux-toolkit.js.org/rtk-query/overview) code for interacting with the API.
42+
43+
To generate the Redux Toolkit RTK Query code, run the following command:
44+
45+
```shell
46+
docker compose exec node npx @rtk-query/codegen-openapi /app/assets/shared/redux/openapi-config.js
47+
```
48+
49+
This will generate `assets/shared/redux/generated-api.ts`. This generated code is enhanced by the custom file
50+
`assets/shared/redux/enhanced-api.ts`.
51+
52+
### Important
53+
54+
If new endpoints are added to the API, `assets/shared/redux/enhanced-api.ts` should be modified to reflect changes in
55+
Redux-Toolkit cache invalidation and new hooks should be added.
56+
57+
See
58+
[https://redux-toolkit.js.org/rtk-query/usage/code-generation](https://redux-toolkit.js.org/rtk-query/usage/code-generation)
59+
for information about the code generation.
2960

3061
## Tests
3162

3263
### API tests
3364

3465
TODO
3566

36-
### Admin / Client tests
67+
### Admin and Client tests
3768

3869
To run tests, use the script:
3970

assets/admin/components/activation-code/activation-code-activate.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useTranslation } from "react-i18next";
33
import { useNavigate } from "react-router-dom";
44
import Form from "react-bootstrap/Form";
55
import { Button } from "react-bootstrap";
6-
import { usePostV2UserActivationCodesActivateMutation } from "../../redux/api/api.generated.ts";
6+
import { usePostV2UserActivationCodesActivateMutation } from "../../../shared/redux/enhanced-api.ts";
77
import {
88
displaySuccess,
99
displayError,

assets/admin/components/activation-code/activation-code-create.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { React, useState, useEffect } from "react";
22
import { useTranslation } from "react-i18next";
33
import { useNavigate } from "react-router-dom";
4-
import { usePostV2UserActivationCodesMutation } from "../../redux/api/api.generated.ts";
4+
import { usePostV2UserActivationCodesMutation } from "../../../shared/redux/enhanced-api.ts";
55
import ActivationCodeForm from "./activation-code-form";
66
import {
77
displaySuccess,
@@ -64,7 +64,7 @@ function ActivationCodeCreate() {
6464
};
6565

6666
PostV2UserActivationCode({
67-
userActivationCodeUserActivationCodeInput: JSON.stringify(saveData),
67+
userActivationCodeUserActivationCodeInputJsonld: JSON.stringify(saveData),
6868
});
6969
};
7070

assets/admin/components/activation-code/activation-code-form.jsx

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { React } from "react";
22
import { useNavigate } from "react-router-dom";
33
import { Button, Col, Row } from "react-bootstrap";
44
import { useTranslation } from "react-i18next";
5-
import PropTypes from "prop-types";
65
import Form from "react-bootstrap/Form";
76
import LoadingComponent from "../util/loading-component/loading-component";
87
import ContentBody from "../util/content-body/content-body";
@@ -107,16 +106,4 @@ function ActivationCodeForm({
107106
);
108107
}
109108

110-
ActivationCodeForm.propTypes = {
111-
activationCode: PropTypes.shape({
112-
displayName: PropTypes.string.isRequired,
113-
role: PropTypes.string.isRequired,
114-
}).isRequired,
115-
handleInput: PropTypes.func.isRequired,
116-
handleSubmit: PropTypes.func.isRequired,
117-
headerText: PropTypes.string.isRequired,
118-
isLoading: PropTypes.bool,
119-
loadingMessage: PropTypes.string,
120-
};
121-
122109
export default ActivationCodeForm;

assets/admin/components/activation-code/activation-code-list.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ import {
1515
displayError,
1616
} from "../util/list/toast-component/display-toast";
1717
import {
18-
api,
18+
enhancedApi,
1919
useDeleteV2UserActivationCodesByIdMutation,
2020
useGetV2UserActivationCodesQuery,
21-
} from "../../redux/api/api.generated.ts";
21+
} from "../../../shared/redux/enhanced-api.ts";
2222

2323
/**
2424
* The Activation Code list component.
@@ -135,7 +135,7 @@ function ActivationCodeList() {
135135
}
136136

137137
dispatch(
138-
api.endpoints.postV2UserActivationCodesRefresh.initiate({
138+
enhancedApi.endpoints.postV2UserActivationCodesRefresh.initiate({
139139
userActivationCodeActivationCode: JSON.stringify({
140140
activationCode: item[0].code,
141141
}),

assets/admin/components/auth-handler.jsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { React, useContext } from "react";
2-
import PropTypes from "prop-types";
32
import Login from "./user/login";
43
import UserContext from "../context/user-context";
54

@@ -20,8 +19,4 @@ function AuthHandler({ children }) {
2019
return children;
2120
}
2221

23-
AuthHandler.propTypes = {
24-
children: PropTypes.node.isRequired,
25-
};
26-
2722
export default AuthHandler;

assets/admin/components/error-boundary.jsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { Component } from "react";
2-
import PropTypes from "prop-types";
32
import "./error-boundary.scss";
43

54
class ErrorBoundary extends Component {
@@ -38,10 +37,4 @@ class ErrorBoundary extends Component {
3837
}
3938
}
4039

41-
ErrorBoundary.propTypes = {
42-
children: PropTypes.node.isRequired,
43-
errorText: PropTypes.string.isRequired,
44-
errorHandler: PropTypes.func,
45-
};
46-
4740
export default ErrorBoundary;

assets/admin/components/feed-sources/feed-source-edit.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { React } from "react";
22
import { useParams } from "react-router-dom";
3-
import { useGetV2FeedSourcesByIdQuery } from "../../redux/api/api.generated.ts";
3+
import { useGetV2FeedSourcesByIdQuery } from "../../../shared/redux/enhanced-api.ts";
44
import FeedSourceManager from "./feed-source-manager";
55

66
/**

assets/admin/components/feed-sources/feed-source-form.jsx

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { React } from "react";
22
import { Alert, Button, Row, Col } from "react-bootstrap";
33
import { useTranslation } from "react-i18next";
44
import { useNavigate } from "react-router-dom";
5-
import PropTypes from "prop-types";
65
import Form from "react-bootstrap/Form";
76
import LoadingComponent from "../util/loading-component/loading-component";
87
import FormInputArea from "../util/forms/form-input-area";
@@ -185,30 +184,4 @@ function FeedSourceForm({
185184
);
186185
}
187186

188-
FeedSourceForm.propTypes = {
189-
feedSource: PropTypes.shape({
190-
title: PropTypes.string,
191-
description: PropTypes.string,
192-
feedType: PropTypes.string,
193-
supportedFeedOutputType: PropTypes.string,
194-
}),
195-
handleInput: PropTypes.func.isRequired,
196-
handleSubmit: PropTypes.func.isRequired,
197-
handleSaveNoClose: PropTypes.func.isRequired,
198-
handleSecretInput: PropTypes.func.isRequired,
199-
onFeedTypeChange: PropTypes.func.isRequired,
200-
headerText: PropTypes.string.isRequired,
201-
isLoading: PropTypes.bool,
202-
loadingMessage: PropTypes.string,
203-
feedSourceTypeOptions: PropTypes.arrayOf(
204-
PropTypes.shape({
205-
value: PropTypes.string.isRequired,
206-
title: PropTypes.string,
207-
key: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
208-
template: PropTypes.element,
209-
})
210-
).isRequired,
211-
mode: PropTypes.string,
212-
};
213-
214187
export default FeedSourceForm;

0 commit comments

Comments
 (0)