Skip to content

Commit da83f0c

Browse files
authored
fix(admin): make sure code is working in TS (#1501)
1 parent 45dc2b8 commit da83f0c

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

.github/linters/.textlintrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"rules": {
3+
"terminology": {
4+
"exclude": [
5+
"Node(?:js)?"
6+
]
7+
}
8+
}
9+
}

admin/authentication-support.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@ API Platform Admin delegates the authentication support to React Admin.
44
Refer to [the chapter dedicated to authentication in the React Admin documentation](https://marmelab.com/react-admin/Authentication.html)
55
for more information.
66

7-
In short, you have to tweak the data provider and the api documentation parser like this:
7+
In short, you have to tweak the data provider and the API documentation parser like this:
88

99
```typescript
1010
// pwa/pages/admin/index.tsx
1111

1212
import Head from "next/head";
1313
import { Redirect, Route } from "react-router-dom";
14-
import { hydraDataProvider as baseHydraDataProvider, fetchHydra as baseFetchHydra, useIntrospection } from "@api-platform/admin";
15-
import parseHydraDocumentation from "@api-platform/api-doc-parser/lib/hydra/parseHydraDocumentation";
14+
import {
15+
fetchHydra as baseFetchHydra,
16+
hydraDataProvider as baseHydraDataProvider,
17+
useIntrospection,
18+
} from "@api-platform/admin";
19+
import { parseHydraDocumentation } from "@api-platform/api-doc-parser";
1620
import authProvider from "utils/authProvider";
1721
import { ENTRYPOINT } from "config/entrypoint";
1822

@@ -35,18 +39,20 @@ const RedirectToLogin = () => {
3539
};
3640
const apiDocumentationParser = async () => {
3741
try {
38-
const { api } = await parseHydraDocumentation(ENTRYPOINT, { headers: getHeaders });
39-
return { api };
42+
return await parseHydraDocumentation(ENTRYPOINT, { headers: getHeaders });
4043
} catch (result) {
41-
if (result.status !== 401) {
44+
const { api, response, status } = result;
45+
if (status !== 401 || !response) {
4246
throw result;
4347
}
4448

4549
// Prevent infinite loop if the token is expired
4650
localStorage.removeItem("token");
4751

4852
return {
49-
api: result.api,
53+
api,
54+
response,
55+
status,
5056
customRoutes: [
5157
<Route key="/" path="/" component={RedirectToLogin} />
5258
],

admin/components.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ const App = () => (
2121
dataProvider={dataProvider}
2222
authProvider={authProvider}>
2323
<ResourceGuesser
24-
name"books"
24+
name="books"
2525
list={BooksList}
2626
show={BooksShow}
2727
edit={BooksEdit}
2828
create={BooksCreate} />
29-
<ResourceGuesser name"authors" />
29+
<ResourceGuesser name="authors" />
3030
</AdminGuesser>
3131
)
3232

admin/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ for any API supporting [the Hydra Core Vocabulary](http://www.hydra-cg.com/) or
88
API Platform Admin is the perfect companion of APIs created
99
using [the API Platform framework](https://api-platform.com), but also supports APIs written with any other programming language or framework as long as they expose a standard Hydra API documentation.
1010

11-
API Platform Admin is a 100% standalone Single-Page-Application with no coupling to the server part,
11+
API Platform Admin is a 100% standalone Single-Page-Application written in TypeScript with no coupling to the server part,
1212
according to the API-first paradigm.
1313

1414
API Platform Admin parses the API documentation then uses the awesome [React Admin](https://marmelab.com/react-admin/)

0 commit comments

Comments
 (0)