@strapi/plugin-documentation 4.0.0-next.6 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/admin/src/components/FieldActionWrapper/index.js +14 -0
  2. package/admin/src/components/PluginIcon/index.js +12 -0
  3. package/admin/src/index.js +27 -12
  4. package/admin/src/pages/PluginPage/index.js +199 -0
  5. package/admin/src/pages/PluginPage/tests/index.test.js +873 -0
  6. package/admin/src/pages/PluginPage/tests/server.js +23 -0
  7. package/admin/src/pages/SettingsPage/index.js +181 -0
  8. package/admin/src/pages/SettingsPage/tests/index.test.js +612 -0
  9. package/admin/src/pages/SettingsPage/tests/server.js +18 -0
  10. package/admin/src/pages/{HomePage/utils → utils}/api.js +5 -4
  11. package/admin/src/pages/{HomePage/utils → utils}/schema.js +0 -0
  12. package/admin/src/pages/utils/useReactQuery.js +46 -0
  13. package/admin/src/permissions.js +7 -7
  14. package/admin/src/translations/ar.json +0 -3
  15. package/admin/src/translations/cs.json +0 -3
  16. package/admin/src/translations/de.json +0 -3
  17. package/admin/src/translations/en.json +14 -3
  18. package/admin/src/translations/es.json +0 -3
  19. package/admin/src/translations/fr.json +0 -3
  20. package/admin/src/translations/id.json +0 -3
  21. package/admin/src/translations/it.json +0 -3
  22. package/admin/src/translations/ko.json +0 -3
  23. package/admin/src/translations/ms.json +0 -3
  24. package/admin/src/translations/nl.json +0 -3
  25. package/admin/src/translations/pl.json +0 -3
  26. package/admin/src/translations/pt-BR.json +0 -3
  27. package/admin/src/translations/pt.json +0 -3
  28. package/admin/src/translations/ru.json +0 -3
  29. package/admin/src/translations/sk.json +0 -3
  30. package/admin/src/translations/th.json +0 -3
  31. package/admin/src/translations/tr.json +0 -3
  32. package/admin/src/translations/uk.json +0 -3
  33. package/admin/src/translations/vi.json +0 -3
  34. package/admin/src/translations/zh-Hans.json +3 -6
  35. package/admin/src/translations/zh.json +0 -3
  36. package/package.json +32 -45
  37. package/server/bootstrap.js +56 -0
  38. package/server/config/default-config.js +45 -0
  39. package/server/config/index.js +16 -0
  40. package/server/controllers/documentation.js +240 -0
  41. package/server/controllers/index.js +7 -0
  42. package/server/index.js +17 -0
  43. package/server/middlewares/documentation.js +30 -0
  44. package/server/middlewares/index.js +7 -0
  45. package/server/middlewares/restrict-access.js +24 -0
  46. package/{public → server/public}/index.html +0 -0
  47. package/{public → server/public}/login.html +0 -0
  48. package/server/register.js +11 -0
  49. package/server/routes/index.js +83 -0
  50. package/server/services/documentation.js +155 -0
  51. package/server/services/index.js +7 -0
  52. package/{services → server/services}/utils/components.json +0 -0
  53. package/{services → server/services}/utils/parametersOptions.json +0 -0
  54. package/{services → server/services}/utils/unknownComponent.json +0 -0
  55. package/server/utils/builders/build-api-endpoint-path.js +174 -0
  56. package/server/utils/builders/build-api-requests.js +41 -0
  57. package/server/utils/builders/build-api-responses.js +108 -0
  58. package/server/utils/builders/index.js +11 -0
  59. package/server/utils/clean-schema-attributes.js +205 -0
  60. package/server/utils/error-response.js +22 -0
  61. package/server/utils/get-schema-data.js +32 -0
  62. package/server/utils/query-params.js +84 -0
  63. package/strapi-admin.js +3 -0
  64. package/strapi-server.js +3 -0
  65. package/admin/src/assets/images/logo.svg +0 -1
  66. package/admin/src/components/Block/components.js +0 -26
  67. package/admin/src/components/Block/index.js +0 -39
  68. package/admin/src/components/Copy/index.js +0 -36
  69. package/admin/src/components/Header/index.js +0 -72
  70. package/admin/src/components/Row/ButtonContainer.js +0 -67
  71. package/admin/src/components/Row/components.js +0 -83
  72. package/admin/src/components/Row/index.js +0 -51
  73. package/admin/src/pages/App/index.js +0 -21
  74. package/admin/src/pages/HomePage/components.js +0 -59
  75. package/admin/src/pages/HomePage/index.js +0 -168
  76. package/admin/src/pages/HomePage/useHomePage.js +0 -56
  77. package/config/functions/bootstrap.js +0 -142
  78. package/config/policies/index.js +0 -33
  79. package/config/routes.json +0 -74
  80. package/config/settings.json +0 -46
  81. package/controllers/Documentation.js +0 -302
  82. package/middlewares/documentation/defaults.json +0 -5
  83. package/middlewares/documentation/index.js +0 -59
  84. package/services/Documentation.js +0 -1863
  85. package/services/utils/forms.json +0 -29
@@ -0,0 +1,23 @@
1
+ import { setupServer } from 'msw/node';
2
+ import { rest } from 'msw';
3
+
4
+ const handlers = [
5
+ rest.get('*/getInfos', (req, res, ctx) => {
6
+ return res(
7
+ ctx.delay(1000),
8
+ ctx.status(200),
9
+ ctx.json({
10
+ currentVersion: '1.0.0',
11
+ docVersions: [
12
+ { version: '1.0.0', generatedDoc: '10/05/2021 2:52:44 PM' },
13
+ { version: '1.2.0', generatedDoc: '11/05/2021 3:00:00 PM' },
14
+ ],
15
+ prefix: '/documentation',
16
+ })
17
+ );
18
+ }),
19
+ ];
20
+
21
+ const server = setupServer(...handlers);
22
+
23
+ export default server;
@@ -0,0 +1,181 @@
1
+ import React, { useState } from 'react';
2
+ import { useIntl } from 'react-intl';
3
+ import { Formik } from 'formik';
4
+ import {
5
+ CheckPermissions,
6
+ Form,
7
+ LoadingIndicatorPage,
8
+ useFocusWhenNavigate,
9
+ } from '@strapi/helper-plugin';
10
+
11
+ // Strapi Parts
12
+ import { ContentLayout, HeaderLayout } from '@strapi/design-system/Layout';
13
+ import { Main } from '@strapi/design-system/Main';
14
+ import { Button } from '@strapi/design-system/Button';
15
+ import { Box } from '@strapi/design-system/Box';
16
+ import { Stack } from '@strapi/design-system/Stack';
17
+ import { Typography } from '@strapi/design-system/Typography';
18
+ import { ToggleInput } from '@strapi/design-system/ToggleInput';
19
+ import { TextInput } from '@strapi/design-system/TextInput';
20
+ import { Grid, GridItem } from '@strapi/design-system/Grid';
21
+
22
+ // Strapi Icons
23
+ import Show from '@strapi/icons/Eye';
24
+ import Hide from '@strapi/icons/EyeStriked';
25
+ import Check from '@strapi/icons/Check';
26
+
27
+ import permissions from '../../permissions';
28
+ import { getTrad } from '../../utils';
29
+ import useReactQuery from '../utils/useReactQuery';
30
+ import FieldActionWrapper from '../../components/FieldActionWrapper';
31
+ import schema from '../utils/schema';
32
+
33
+ const SettingsPage = () => {
34
+ useFocusWhenNavigate();
35
+ const { formatMessage } = useIntl();
36
+ const { submitMutation, data, isLoading } = useReactQuery();
37
+ const [passwordShown, setPasswordShown] = useState(false);
38
+
39
+ const handleUpdateSettingsSubmit = body => {
40
+ submitMutation.mutate({
41
+ prefix: data?.prefix,
42
+ body,
43
+ });
44
+ };
45
+
46
+ return (
47
+ <Main>
48
+ {isLoading ? (
49
+ <LoadingIndicatorPage>Plugin settings are loading</LoadingIndicatorPage>
50
+ ) : (
51
+ <Formik
52
+ initialValues={{
53
+ restrictedAccess: data?.documentationAccess.restrictedAccess || false,
54
+ password: '',
55
+ }}
56
+ onSubmit={handleUpdateSettingsSubmit}
57
+ validationSchema={schema}
58
+ >
59
+ {({ handleSubmit, values, handleChange, errors, setFieldTouched, setFieldValue }) => {
60
+ return (
61
+ <Form noValidate onSubmit={handleSubmit}>
62
+ <HeaderLayout
63
+ title={formatMessage({
64
+ id: getTrad('plugin.name'),
65
+ defaultMessage: 'Documentation',
66
+ })}
67
+ subtitle={formatMessage({
68
+ id: getTrad('pages.SettingsPage.header.description'),
69
+ defaultMessage: 'Configure the documentation plugin',
70
+ })}
71
+ primaryAction={
72
+ <CheckPermissions permissions={permissions.update}>
73
+ <Button type="submit" startIcon={<Check />}>
74
+ {formatMessage({
75
+ id: getTrad('pages.SettingsPage.Button.save'),
76
+ defaultMessage: 'Save',
77
+ })}
78
+ </Button>
79
+ </CheckPermissions>
80
+ }
81
+ />
82
+ <ContentLayout>
83
+ <Box
84
+ background="neutral0"
85
+ hasRadius
86
+ shadow="filterShadow"
87
+ paddingTop={6}
88
+ paddingBottom={6}
89
+ paddingLeft={7}
90
+ paddingRight={7}
91
+ >
92
+ <Stack size={4}>
93
+ <Typography variant="delta" as="h2">
94
+ {formatMessage({
95
+ id: getTrad('pages.SettingsPage.title'),
96
+ defaultMessage: 'Settings',
97
+ })}
98
+ </Typography>
99
+ <Grid gap={4}>
100
+ <GridItem col={6} s={12}>
101
+ <ToggleInput
102
+ name="restrictedAccess"
103
+ label={formatMessage({
104
+ id: getTrad('pages.SettingsPage.toggle.label'),
105
+ defaultMessage: 'Restricted Access',
106
+ })}
107
+ hint={formatMessage({
108
+ id: getTrad('pages.SettingsPage.toggle.hint'),
109
+ defaultMessage: 'Make the documentation endpoint private',
110
+ })}
111
+ checked={values.restrictedAccess}
112
+ onChange={() => {
113
+ if (values.restrictedAccess === true) {
114
+ setFieldValue('password', '', false);
115
+ setFieldTouched('password', false, false);
116
+ }
117
+
118
+ setFieldValue('restrictedAccess', !values.restrictedAccess, false);
119
+ }}
120
+ onLabel="On"
121
+ offLabel="Off"
122
+ />
123
+ </GridItem>
124
+ {values.restrictedAccess && (
125
+ <GridItem col={6} s={12}>
126
+ <TextInput
127
+ label={formatMessage({
128
+ id: getTrad('pages.SettingsPage.password.label'),
129
+ defaultMessage: 'Password',
130
+ })}
131
+ name="password"
132
+ placeholder="**********"
133
+ type={passwordShown ? 'text' : 'password'}
134
+ value={values.password}
135
+ onChange={handleChange}
136
+ error={
137
+ errors.password
138
+ ? formatMessage({
139
+ id: errors.password,
140
+ defaultMessage: 'Invalid value',
141
+ })
142
+ : null
143
+ }
144
+ endAction={
145
+ <FieldActionWrapper
146
+ onClick={e => {
147
+ e.stopPropagation();
148
+ setPasswordShown(prev => !prev);
149
+ }}
150
+ label={formatMessage(
151
+ passwordShown
152
+ ? {
153
+ id: 'Auth.form.password.show-password',
154
+ defaultMessage: 'Show password',
155
+ }
156
+ : {
157
+ id: 'Auth.form.password.hide-password',
158
+ defaultMessage: 'Hide password',
159
+ }
160
+ )}
161
+ >
162
+ {passwordShown ? <Show /> : <Hide />}
163
+ </FieldActionWrapper>
164
+ }
165
+ />
166
+ </GridItem>
167
+ )}
168
+ </Grid>
169
+ </Stack>
170
+ </Box>
171
+ </ContentLayout>
172
+ </Form>
173
+ );
174
+ }}
175
+ </Formik>
176
+ )}
177
+ </Main>
178
+ );
179
+ };
180
+
181
+ export default SettingsPage;