@strapi/admin 4.0.0-beta.0 → 4.0.0-beta.4
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.
- package/admin/src/content-manager/components/Inputs/index.js +1 -1
- package/admin/src/content-manager/components/Inputs/utils/getStep.js +3 -1
- package/admin/src/content-manager/components/RepeatableComponent/DragPreview.js +4 -4
- package/admin/src/content-manager/components/RepeatableComponent/DraggedItem/Preview.js +8 -3
- package/admin/src/content-manager/components/RepeatableComponent/DraggedItem/index.js +1 -0
- package/admin/src/content-manager/components/RepeatableComponent/index.js +4 -1
- package/admin/src/content-manager/pages/ListView/index.js +5 -3
- package/admin/src/content-manager/pages/ListView/utils/buildQueryString.js +1 -4
- package/admin/src/content-manager/pages/ListView/utils/createPluginsFilter.js +1 -10
- package/admin/src/content-manager/utils/index.js +0 -2
- package/admin/src/pages/AuthPage/components/ForgotPassword/index.js +1 -3
- package/admin/src/pages/AuthPage/components/ForgotPasswordSuccess/index.js +1 -1
- package/admin/src/pages/AuthPage/components/Oops/index.js +1 -1
- package/admin/src/pages/AuthPage/components/ResetPassword/index.js +1 -3
- package/admin/src/pages/SettingsPage/pages/ApplicationInfosPage/index.js +3 -3
- package/admin/src/pages/SettingsPage/pages/Roles/EditPage/index.js +1 -15
- package/admin/src/pages/SettingsPage/pages/Roles/ListPage/index.js +3 -3
- package/admin/src/pages/SettingsPage/pages/Webhooks/EditView/components/HeadersInput/index.js +8 -3
- package/admin/src/pages/SettingsPage/pages/Webhooks/EditView/components/WebhookForm/index.js +1 -7
- package/admin/src/translations/en.json +1 -1
- package/build/1920.b03b4847.chunk.js +1 -0
- package/build/2022.4be1cb62.chunk.js +1 -0
- package/build/2068.ae950560.chunk.js +1 -0
- package/build/2321.d29283ee.chunk.js +1 -0
- package/build/2321.d3de7f6d.chunk.js +1 -0
- package/build/2957.20b1ea7d.chunk.js +1 -0
- package/build/3632.aa815ec4.chunk.js +1 -0
- package/build/3632.d6c8a9e1.chunk.js +1 -0
- package/build/3736.120018c1.chunk.js +1 -0
- package/build/3742.8fccd1b5.chunk.js +1 -0
- package/build/4023.76e9e178.chunk.js +1 -0
- package/build/4045.fc816c07.chunk.js +1 -0
- package/build/4151.6b91db28.chunk.js +1 -0
- package/build/4151.d40cdd4f.chunk.js +1 -0
- package/build/4506.106c3ece.chunk.js +1 -0
- package/build/4506.b0b403d4.chunk.js +1 -0
- package/build/4922.0d01a3c9.chunk.js +1 -0
- package/build/4922.122f4821.chunk.js +1 -0
- package/build/5220.4b1142ae.chunk.js +1 -0
- package/build/5381.e6079de9.chunk.js +1 -0
- package/build/5381.fb3623a0.chunk.js +1 -0
- package/build/5437.6485754a.chunk.js +1 -0
- package/build/5437.ef54f6e9.chunk.js +1 -0
- package/build/5515.455bd84f.chunk.js +1 -0
- package/build/5768.a1d8ff37.chunk.js +1 -0
- package/build/6259.1bb0b4f7.chunk.js +1 -0
- package/build/6259.b485d83b.chunk.js +1 -0
- package/build/6505.c6291da8.chunk.js +1 -0
- package/build/7199.0052beea.chunk.js +1 -0
- package/build/7199.252d8528.chunk.js +1 -0
- package/build/7199.5f13d43c.chunk.js +1 -0
- package/build/8354.969e6be7.chunk.js +2 -0
- package/build/8354.969e6be7.chunk.js.LICENSE.txt +15 -0
- package/build/8354.e98f79fa.chunk.js +2 -0
- package/build/8354.e98f79fa.chunk.js.LICENSE.txt +15 -0
- package/build/9467.306d8123.chunk.js +2 -0
- package/build/9467.306d8123.chunk.js.LICENSE.txt +14 -0
- package/build/9467.ba799c20.chunk.js +2 -0
- package/build/9467.ba799c20.chunk.js.LICENSE.txt +14 -0
- package/build/9572.38876034.chunk.js +1 -0
- package/build/9572.51d54b5e.chunk.js +1 -0
- package/build/9662.eab41690.chunk.js +1 -0
- package/build/9733.0406406a.chunk.js +1 -0
- package/build/9761.ff59a465.chunk.js +1 -0
- package/build/Admin-authenticatedApp.0e0b7eda.chunk.js +1 -0
- package/build/Admin-authenticatedApp.1e2a9091.chunk.js +1 -0
- package/build/Admin-authenticatedApp.66ad69d3.chunk.js +1 -0
- package/build/Admin-authenticatedApp.93aedd80.chunk.js +1 -0
- package/build/Admin_homePage.69842ede.chunk.js +1 -0
- package/build/Admin_marketplace.76a7e5cf.chunk.js +1 -0
- package/build/Admin_marketplace.9eb4a5cc.chunk.js +1 -0
- package/build/Admin_pluginsPage.8a83dc26.chunk.js +1 -0
- package/build/Admin_pluginsPage.8c902c93.chunk.js +1 -0
- package/build/Admin_profilePage.1ffd2fba.chunk.js +1 -0
- package/build/Admin_settingsPage.31bfc41d.chunk.js +1 -0
- package/build/Admin_settingsPage.41834456.chunk.js +1 -0
- package/build/admin-edit-roles-page.9e6faaf0.chunk.js +1 -0
- package/build/admin-users.1e7df135.chunk.js +1 -0
- package/build/admin-users.802b7b32.chunk.js +1 -0
- package/build/content-manager.c6fe3a8c.chunk.js +1 -0
- package/build/content-manager.cb2f952c.chunk.js +1 -0
- package/build/content-type-builder.8804ef89.chunk.js +1 -0
- package/build/documentation-page.85806105.chunk.js +1 -0
- package/build/documentation-page.b469efca.chunk.js +1 -0
- package/build/email-settings-page.1bd68221.chunk.js +1 -0
- package/build/email-settings-page.fdb43c01.chunk.js +1 -0
- package/build/en-json.1bc78007.chunk.js +1 -0
- package/build/i18n-settings-page.656f08b4.chunk.js +1 -0
- package/build/index.html +1 -1
- package/build/main.4ee1cf3c.js +2 -0
- package/build/main.4ee1cf3c.js.LICENSE.txt +120 -0
- package/build/main.7c5ad390.js +2 -0
- package/build/main.7c5ad390.js.LICENSE.txt +120 -0
- package/build/main.ee2290ee.js +2 -0
- package/build/main.ee2290ee.js.LICENSE.txt +120 -0
- package/build/main.f55c84a4.js +2 -0
- package/build/main.f55c84a4.js.LICENSE.txt +120 -0
- package/build/runtime~main.1c25335a.js +1 -0
- package/build/runtime~main.a0799a2d.js +1 -0
- package/build/runtime~main.be47aa31.js +1 -0
- package/build/runtime~main.d645defb.js +1 -0
- package/build/upload-settings.6a1fac42.chunk.js +1 -0
- package/build/upload-settings.6c55d564.chunk.js +1 -0
- package/build/upload.668329be.chunk.js +1 -0
- package/build/upload.d74b7b76.chunk.js +1 -0
- package/build/users-advanced-settings-page.86360137.chunk.js +1 -0
- package/build/users-advanced-settings-page.c84be683.chunk.js +1 -0
- package/build/users-providers-settings-page.8703ab92.chunk.js +1 -0
- package/build/users-providers-settings-page.969ed311.chunk.js +1 -0
- package/build/webhook-edit-page.d7a61df1.chunk.js +1 -0
- package/build/webhook-list-page.0fb3597e.chunk.js +1 -0
- package/build/webhook-list-page.17c17912.chunk.js +1 -0
- package/ee/server/routes/features-routes.js +2 -2
- package/ee/server/routes/index.js +5 -3
- package/index.js +15 -2
- package/package.json +7 -7
- package/server/controllers/index.js +1 -1
- package/server/controllers/{Webhooks.js → webhooks.js} +0 -0
- package/server/policies/hasPermissions.js +3 -3
- package/server/policies/isAuthenticatedAdmin.js +1 -1
- package/server/routes/admin.js +3 -3
- package/server/routes/api-tokens.js +5 -5
- package/server/routes/roles.js +6 -6
- package/server/routes/users.js +6 -6
- package/server/routes/webhooks.js +13 -13
- package/server/strategies/api-token.js +4 -1
- package/server/utils/index.js +1 -3
- package/admin/src/content-manager/components/Inputs/GenericInput.js +0 -347
- package/admin/src/content-manager/utils/formatFiltersFromQuery.js +0 -55
- package/admin/src/content-manager/utils/formatFiltersToQuery.js +0 -27
package/server/routes/admin.js
CHANGED
|
@@ -28,7 +28,7 @@ module.exports = [
|
|
|
28
28
|
config: {
|
|
29
29
|
policies: [
|
|
30
30
|
'admin::isAuthenticatedAdmin',
|
|
31
|
-
{ name: 'admin::hasPermissions',
|
|
31
|
+
{ name: 'admin::hasPermissions', config: { actions: ['admin::marketplace.read'] } },
|
|
32
32
|
],
|
|
33
33
|
},
|
|
34
34
|
},
|
|
@@ -41,7 +41,7 @@ module.exports = [
|
|
|
41
41
|
'admin::isAuthenticatedAdmin',
|
|
42
42
|
{
|
|
43
43
|
name: 'admin::hasPermissions',
|
|
44
|
-
|
|
44
|
+
config: { actions: ['admin::marketplace.plugins.install'] },
|
|
45
45
|
},
|
|
46
46
|
],
|
|
47
47
|
},
|
|
@@ -55,7 +55,7 @@ module.exports = [
|
|
|
55
55
|
'admin::isAuthenticatedAdmin',
|
|
56
56
|
{
|
|
57
57
|
name: 'admin::hasPermissions',
|
|
58
|
-
|
|
58
|
+
config: { actions: ['admin::marketplace.plugins.uninstall'] },
|
|
59
59
|
},
|
|
60
60
|
],
|
|
61
61
|
},
|
|
@@ -8,7 +8,7 @@ module.exports = [
|
|
|
8
8
|
config: {
|
|
9
9
|
policies: [
|
|
10
10
|
'admin::isAuthenticatedAdmin',
|
|
11
|
-
{ name: 'admin::hasPermissions',
|
|
11
|
+
{ name: 'admin::hasPermissions', config: { actions: ['admin::api-tokens.create'] } },
|
|
12
12
|
],
|
|
13
13
|
},
|
|
14
14
|
},
|
|
@@ -19,7 +19,7 @@ module.exports = [
|
|
|
19
19
|
config: {
|
|
20
20
|
policies: [
|
|
21
21
|
'admin::isAuthenticatedAdmin',
|
|
22
|
-
{ name: 'admin::hasPermissions',
|
|
22
|
+
{ name: 'admin::hasPermissions', config: { actions: ['admin::api-tokens.read'] } },
|
|
23
23
|
],
|
|
24
24
|
},
|
|
25
25
|
},
|
|
@@ -30,7 +30,7 @@ module.exports = [
|
|
|
30
30
|
config: {
|
|
31
31
|
policies: [
|
|
32
32
|
'admin::isAuthenticatedAdmin',
|
|
33
|
-
{ name: 'admin::hasPermissions',
|
|
33
|
+
{ name: 'admin::hasPermissions', config: { actions: ['admin::api-tokens.delete'] } },
|
|
34
34
|
],
|
|
35
35
|
},
|
|
36
36
|
},
|
|
@@ -41,7 +41,7 @@ module.exports = [
|
|
|
41
41
|
config: {
|
|
42
42
|
policies: [
|
|
43
43
|
'admin::isAuthenticatedAdmin',
|
|
44
|
-
{ name: 'admin::hasPermissions',
|
|
44
|
+
{ name: 'admin::hasPermissions', config: { actions: ['admin::api-tokens.read'] } },
|
|
45
45
|
],
|
|
46
46
|
},
|
|
47
47
|
},
|
|
@@ -52,7 +52,7 @@ module.exports = [
|
|
|
52
52
|
config: {
|
|
53
53
|
policies: [
|
|
54
54
|
'admin::isAuthenticatedAdmin',
|
|
55
|
-
{ name: 'admin::hasPermissions',
|
|
55
|
+
{ name: 'admin::hasPermissions', config: { actions: ['admin::api-tokens.update'] } },
|
|
56
56
|
],
|
|
57
57
|
},
|
|
58
58
|
},
|
package/server/routes/roles.js
CHANGED
|
@@ -6,7 +6,7 @@ module.exports = [
|
|
|
6
6
|
path: '/users/batch-delete',
|
|
7
7
|
handler: 'user.deleteMany',
|
|
8
8
|
config: {
|
|
9
|
-
policies: [{ name: 'admin::hasPermissions',
|
|
9
|
+
policies: [{ name: 'admin::hasPermissions', config: { actions: ['admin::users.delete'] } }],
|
|
10
10
|
},
|
|
11
11
|
},
|
|
12
12
|
{
|
|
@@ -16,7 +16,7 @@ module.exports = [
|
|
|
16
16
|
config: {
|
|
17
17
|
policies: [
|
|
18
18
|
'admin::isAuthenticatedAdmin',
|
|
19
|
-
{ name: 'admin::hasPermissions',
|
|
19
|
+
{ name: 'admin::hasPermissions', config: { actions: ['admin::roles.read'] } },
|
|
20
20
|
],
|
|
21
21
|
},
|
|
22
22
|
},
|
|
@@ -27,7 +27,7 @@ module.exports = [
|
|
|
27
27
|
config: {
|
|
28
28
|
policies: [
|
|
29
29
|
'admin::isAuthenticatedAdmin',
|
|
30
|
-
{ name: 'admin::hasPermissions',
|
|
30
|
+
{ name: 'admin::hasPermissions', config: { actions: ['admin::roles.update'] } },
|
|
31
31
|
],
|
|
32
32
|
},
|
|
33
33
|
},
|
|
@@ -38,7 +38,7 @@ module.exports = [
|
|
|
38
38
|
config: {
|
|
39
39
|
policies: [
|
|
40
40
|
'admin::isAuthenticatedAdmin',
|
|
41
|
-
{ name: 'admin::hasPermissions',
|
|
41
|
+
{ name: 'admin::hasPermissions', config: { actions: ['admin::roles.read'] } },
|
|
42
42
|
],
|
|
43
43
|
},
|
|
44
44
|
},
|
|
@@ -49,7 +49,7 @@ module.exports = [
|
|
|
49
49
|
config: {
|
|
50
50
|
policies: [
|
|
51
51
|
'admin::isAuthenticatedAdmin',
|
|
52
|
-
{ name: 'admin::hasPermissions',
|
|
52
|
+
{ name: 'admin::hasPermissions', config: { actions: ['admin::roles.read'] } },
|
|
53
53
|
],
|
|
54
54
|
},
|
|
55
55
|
},
|
|
@@ -60,7 +60,7 @@ module.exports = [
|
|
|
60
60
|
config: {
|
|
61
61
|
policies: [
|
|
62
62
|
'admin::isAuthenticatedAdmin',
|
|
63
|
-
{ name: 'admin::hasPermissions',
|
|
63
|
+
{ name: 'admin::hasPermissions', config: { actions: ['admin::roles.update'] } },
|
|
64
64
|
],
|
|
65
65
|
},
|
|
66
66
|
},
|
package/server/routes/users.js
CHANGED
|
@@ -32,7 +32,7 @@ module.exports = [
|
|
|
32
32
|
config: {
|
|
33
33
|
policies: [
|
|
34
34
|
'admin::isAuthenticatedAdmin',
|
|
35
|
-
{ name: 'admin::hasPermissions',
|
|
35
|
+
{ name: 'admin::hasPermissions', config: { actions: ['admin::users.create'] } },
|
|
36
36
|
],
|
|
37
37
|
},
|
|
38
38
|
},
|
|
@@ -43,7 +43,7 @@ module.exports = [
|
|
|
43
43
|
config: {
|
|
44
44
|
policies: [
|
|
45
45
|
'admin::isAuthenticatedAdmin',
|
|
46
|
-
{ name: 'admin::hasPermissions',
|
|
46
|
+
{ name: 'admin::hasPermissions', config: { actions: ['admin::users.read'] } },
|
|
47
47
|
],
|
|
48
48
|
},
|
|
49
49
|
},
|
|
@@ -54,7 +54,7 @@ module.exports = [
|
|
|
54
54
|
config: {
|
|
55
55
|
policies: [
|
|
56
56
|
'admin::isAuthenticatedAdmin',
|
|
57
|
-
{ name: 'admin::hasPermissions',
|
|
57
|
+
{ name: 'admin::hasPermissions', config: { actions: ['admin::users.read'] } },
|
|
58
58
|
],
|
|
59
59
|
},
|
|
60
60
|
},
|
|
@@ -65,7 +65,7 @@ module.exports = [
|
|
|
65
65
|
config: {
|
|
66
66
|
policies: [
|
|
67
67
|
'admin::isAuthenticatedAdmin',
|
|
68
|
-
{ name: 'admin::hasPermissions',
|
|
68
|
+
{ name: 'admin::hasPermissions', config: { actions: ['admin::users.update'] } },
|
|
69
69
|
],
|
|
70
70
|
},
|
|
71
71
|
},
|
|
@@ -74,7 +74,7 @@ module.exports = [
|
|
|
74
74
|
path: '/users/:id',
|
|
75
75
|
handler: 'user.deleteOne',
|
|
76
76
|
config: {
|
|
77
|
-
policies: [{ name: 'admin::hasPermissions',
|
|
77
|
+
policies: [{ name: 'admin::hasPermissions', config: { actions: ['admin::users.delete'] } }],
|
|
78
78
|
},
|
|
79
79
|
},
|
|
80
80
|
{
|
|
@@ -82,7 +82,7 @@ module.exports = [
|
|
|
82
82
|
path: '/users/batch-delete',
|
|
83
83
|
handler: 'user.deleteMany',
|
|
84
84
|
config: {
|
|
85
|
-
policies: [{ name: 'admin::hasPermissions',
|
|
85
|
+
policies: [{ name: 'admin::hasPermissions', config: { actions: ['admin::users.delete'] } }],
|
|
86
86
|
},
|
|
87
87
|
},
|
|
88
88
|
];
|
|
@@ -4,73 +4,73 @@ module.exports = [
|
|
|
4
4
|
{
|
|
5
5
|
method: 'GET',
|
|
6
6
|
path: '/webhooks',
|
|
7
|
-
handler: '
|
|
7
|
+
handler: 'webhooks.listWebhooks',
|
|
8
8
|
config: {
|
|
9
9
|
policies: [
|
|
10
10
|
'admin::isAuthenticatedAdmin',
|
|
11
|
-
{ name: 'admin::hasPermissions',
|
|
11
|
+
{ name: 'admin::hasPermissions', config: { actions: ['admin::webhooks.read'] } },
|
|
12
12
|
],
|
|
13
13
|
},
|
|
14
14
|
},
|
|
15
15
|
{
|
|
16
16
|
method: 'POST',
|
|
17
17
|
path: '/webhooks',
|
|
18
|
-
handler: '
|
|
18
|
+
handler: 'webhooks.createWebhook',
|
|
19
19
|
config: {
|
|
20
20
|
policies: [
|
|
21
21
|
'admin::isAuthenticatedAdmin',
|
|
22
|
-
{ name: 'admin::hasPermissions',
|
|
22
|
+
{ name: 'admin::hasPermissions', config: { actions: ['admin::webhooks.create'] } },
|
|
23
23
|
],
|
|
24
24
|
},
|
|
25
25
|
},
|
|
26
26
|
{
|
|
27
27
|
method: 'GET',
|
|
28
28
|
path: '/webhooks/:id',
|
|
29
|
-
handler: '
|
|
29
|
+
handler: 'webhooks.getWebhook',
|
|
30
30
|
config: {
|
|
31
31
|
policies: [
|
|
32
32
|
'admin::isAuthenticatedAdmin',
|
|
33
|
-
{ name: 'admin::hasPermissions',
|
|
33
|
+
{ name: 'admin::hasPermissions', config: { actions: ['admin::webhooks.read'] } },
|
|
34
34
|
],
|
|
35
35
|
},
|
|
36
36
|
},
|
|
37
37
|
{
|
|
38
38
|
method: 'PUT',
|
|
39
39
|
path: '/webhooks/:id',
|
|
40
|
-
handler: '
|
|
40
|
+
handler: 'webhooks.updateWebhook',
|
|
41
41
|
config: {
|
|
42
42
|
policies: [
|
|
43
43
|
'admin::isAuthenticatedAdmin',
|
|
44
|
-
{ name: 'admin::hasPermissions',
|
|
44
|
+
{ name: 'admin::hasPermissions', config: { actions: ['admin::webhooks.update'] } },
|
|
45
45
|
],
|
|
46
46
|
},
|
|
47
47
|
},
|
|
48
48
|
{
|
|
49
49
|
method: 'DELETE',
|
|
50
50
|
path: '/webhooks/:id',
|
|
51
|
-
handler: '
|
|
51
|
+
handler: 'webhooks.deleteWebhook',
|
|
52
52
|
config: {
|
|
53
53
|
policies: [
|
|
54
54
|
'admin::isAuthenticatedAdmin',
|
|
55
|
-
{ name: 'admin::hasPermissions',
|
|
55
|
+
{ name: 'admin::hasPermissions', config: { actions: ['admin::webhooks.delete'] } },
|
|
56
56
|
],
|
|
57
57
|
},
|
|
58
58
|
},
|
|
59
59
|
{
|
|
60
60
|
method: 'POST',
|
|
61
61
|
path: '/webhooks/batch-delete',
|
|
62
|
-
handler: '
|
|
62
|
+
handler: 'webhooks.deleteWebhooks',
|
|
63
63
|
config: {
|
|
64
64
|
policies: [
|
|
65
65
|
'admin::isAuthenticatedAdmin',
|
|
66
|
-
{ name: 'admin::hasPermissions',
|
|
66
|
+
{ name: 'admin::hasPermissions', config: { actions: ['admin::webhooks.delete'] } },
|
|
67
67
|
],
|
|
68
68
|
},
|
|
69
69
|
},
|
|
70
70
|
{
|
|
71
71
|
method: 'POST',
|
|
72
72
|
path: '/webhooks/:id/trigger',
|
|
73
|
-
handler: '
|
|
73
|
+
handler: 'webhooks.triggerWebhook',
|
|
74
74
|
config: {
|
|
75
75
|
policies: [],
|
|
76
76
|
},
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
const constants = require('../services/constants');
|
|
4
4
|
const { getService } = require('../utils');
|
|
5
5
|
|
|
6
|
+
const isReadScope = scope => scope.endsWith('find') || scope.endsWith('findOne');
|
|
7
|
+
|
|
6
8
|
/** @type {import('.').AuthenticateFunction} */
|
|
7
9
|
const authenticate = async ctx => {
|
|
8
10
|
const apiTokenService = getService('api-token');
|
|
@@ -47,7 +49,8 @@ const verify = (auth, config) => {
|
|
|
47
49
|
* If you don't have `full-access` you can only access `find` and `findOne`
|
|
48
50
|
* scopes. If the route has no scope, then you can't get access to it.
|
|
49
51
|
*/
|
|
50
|
-
|
|
52
|
+
|
|
53
|
+
if (config.scope && config.scope.every(isReadScope)) {
|
|
51
54
|
return;
|
|
52
55
|
}
|
|
53
56
|
|
package/server/utils/index.js
CHANGED
|
@@ -1,347 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* GenericInput
|
|
4
|
-
* This is a temp file move it to the helper plugin when ready
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import React, { useState } from 'react';
|
|
8
|
-
import PropTypes from 'prop-types';
|
|
9
|
-
import { useIntl } from 'react-intl';
|
|
10
|
-
import cloneDeep from 'lodash/cloneDeep';
|
|
11
|
-
import { formatISO } from 'date-fns';
|
|
12
|
-
import { DatePicker } from '@strapi/parts/DatePicker';
|
|
13
|
-
import { NumberInput } from '@strapi/parts/NumberInput';
|
|
14
|
-
import { Select, Option } from '@strapi/parts/Select';
|
|
15
|
-
import { Textarea } from '@strapi/parts/Textarea';
|
|
16
|
-
import { TextInput } from '@strapi/parts/TextInput';
|
|
17
|
-
import { TimePicker } from '@strapi/parts/TimePicker';
|
|
18
|
-
import { ToggleInput } from '@strapi/parts/ToggleInput';
|
|
19
|
-
import Hide from '@strapi/icons/Hide';
|
|
20
|
-
import Show from '@strapi/icons/Show';
|
|
21
|
-
|
|
22
|
-
const GenericInput = ({
|
|
23
|
-
autoComplete,
|
|
24
|
-
customInputs,
|
|
25
|
-
description,
|
|
26
|
-
disabled,
|
|
27
|
-
intlLabel,
|
|
28
|
-
labelAction,
|
|
29
|
-
error,
|
|
30
|
-
name,
|
|
31
|
-
onChange,
|
|
32
|
-
options,
|
|
33
|
-
placeholder,
|
|
34
|
-
step,
|
|
35
|
-
type,
|
|
36
|
-
value,
|
|
37
|
-
...rest
|
|
38
|
-
}) => {
|
|
39
|
-
const { formatMessage } = useIntl();
|
|
40
|
-
const [showPassword, setShowPassword] = useState(false);
|
|
41
|
-
|
|
42
|
-
const CustomInput = customInputs ? customInputs[type] : null;
|
|
43
|
-
|
|
44
|
-
if (CustomInput) {
|
|
45
|
-
return (
|
|
46
|
-
<CustomInput
|
|
47
|
-
{...rest}
|
|
48
|
-
description={description}
|
|
49
|
-
disabled={disabled}
|
|
50
|
-
intlLabel={intlLabel}
|
|
51
|
-
labelAction={labelAction}
|
|
52
|
-
error={error}
|
|
53
|
-
name={name}
|
|
54
|
-
onChange={onChange}
|
|
55
|
-
placeholder={placeholder}
|
|
56
|
-
type={type}
|
|
57
|
-
value={value}
|
|
58
|
-
/>
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const label = intlLabel.id
|
|
63
|
-
? formatMessage(
|
|
64
|
-
{ id: intlLabel.id, defaultMessage: intlLabel.defaultMessage },
|
|
65
|
-
{ ...intlLabel.values }
|
|
66
|
-
)
|
|
67
|
-
: name;
|
|
68
|
-
|
|
69
|
-
const hint = description
|
|
70
|
-
? formatMessage(
|
|
71
|
-
{ id: description.id, defaultMessage: description.defaultMessage },
|
|
72
|
-
{ ...description.values }
|
|
73
|
-
)
|
|
74
|
-
: '';
|
|
75
|
-
|
|
76
|
-
const formattedPlaceholder = placeholder
|
|
77
|
-
? formatMessage(
|
|
78
|
-
{ id: placeholder.id, defaultMessage: placeholder.defaultMessage },
|
|
79
|
-
{ ...placeholder.values }
|
|
80
|
-
)
|
|
81
|
-
: '';
|
|
82
|
-
|
|
83
|
-
const errorMessage = error ? formatMessage({ id: error, defaultMessage: error }) : '';
|
|
84
|
-
|
|
85
|
-
switch (type) {
|
|
86
|
-
case 'bool': {
|
|
87
|
-
return (
|
|
88
|
-
<ToggleInput
|
|
89
|
-
checked={value || false}
|
|
90
|
-
disabled={disabled}
|
|
91
|
-
hint={hint}
|
|
92
|
-
label={label}
|
|
93
|
-
labelAction={labelAction}
|
|
94
|
-
name={name}
|
|
95
|
-
offLabel={formatMessage({
|
|
96
|
-
id: 'app.components.ToggleCheckbox.off-label',
|
|
97
|
-
defaultMessage: 'Off',
|
|
98
|
-
})}
|
|
99
|
-
onLabel={formatMessage({
|
|
100
|
-
id: 'app.components.ToggleCheckbox.on-label',
|
|
101
|
-
defaultMessage: 'On',
|
|
102
|
-
})}
|
|
103
|
-
onChange={e => {
|
|
104
|
-
onChange({ target: { name, value: e.target.checked } });
|
|
105
|
-
}}
|
|
106
|
-
/>
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
case 'date': {
|
|
110
|
-
return (
|
|
111
|
-
<DatePicker
|
|
112
|
-
clearLabel={formatMessage({ id: 'clearLabel', defaultMessage: 'Clear' })}
|
|
113
|
-
disabled={disabled}
|
|
114
|
-
error={errorMessage}
|
|
115
|
-
label={label}
|
|
116
|
-
labelAction={labelAction}
|
|
117
|
-
id={name}
|
|
118
|
-
hint={hint}
|
|
119
|
-
name={name}
|
|
120
|
-
onChange={date => {
|
|
121
|
-
const formattedDate = formatISO(cloneDeep(date), { representation: 'date' });
|
|
122
|
-
|
|
123
|
-
onChange({ target: { name, value: formattedDate, type } });
|
|
124
|
-
}}
|
|
125
|
-
onClear={() => onChange({ target: { name, value: '', type } })}
|
|
126
|
-
placeholder={formattedPlaceholder}
|
|
127
|
-
selectedDate={value ? new Date(value) : null}
|
|
128
|
-
selectedDateLabel={formattedDate => `Date picker, current is ${formattedDate}`}
|
|
129
|
-
/>
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
case 'number': {
|
|
133
|
-
return (
|
|
134
|
-
<NumberInput
|
|
135
|
-
disabled={disabled}
|
|
136
|
-
error={errorMessage}
|
|
137
|
-
label={label}
|
|
138
|
-
labelAction={labelAction}
|
|
139
|
-
id={name}
|
|
140
|
-
hint={hint}
|
|
141
|
-
name={name}
|
|
142
|
-
onValueChange={value => {
|
|
143
|
-
onChange({ target: { name, value, type } });
|
|
144
|
-
}}
|
|
145
|
-
placeholder={formattedPlaceholder}
|
|
146
|
-
step={step}
|
|
147
|
-
value={value || undefined}
|
|
148
|
-
/>
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
case 'email':
|
|
152
|
-
case 'text':
|
|
153
|
-
case 'string': {
|
|
154
|
-
return (
|
|
155
|
-
<TextInput
|
|
156
|
-
autoComplete={autoComplete}
|
|
157
|
-
disabled={disabled}
|
|
158
|
-
error={errorMessage}
|
|
159
|
-
label={label}
|
|
160
|
-
labelAction={labelAction}
|
|
161
|
-
id={name}
|
|
162
|
-
hint={hint}
|
|
163
|
-
name={name}
|
|
164
|
-
onChange={onChange}
|
|
165
|
-
placeholder={formattedPlaceholder}
|
|
166
|
-
type={type}
|
|
167
|
-
value={value || ''}
|
|
168
|
-
/>
|
|
169
|
-
);
|
|
170
|
-
}
|
|
171
|
-
case 'password': {
|
|
172
|
-
return (
|
|
173
|
-
<TextInput
|
|
174
|
-
autoComplete={autoComplete}
|
|
175
|
-
disabled={disabled}
|
|
176
|
-
error={errorMessage}
|
|
177
|
-
endAction={
|
|
178
|
-
<button
|
|
179
|
-
aria-label={formatMessage({
|
|
180
|
-
id: 'Auth.form.password.show-password',
|
|
181
|
-
defaultMessage: 'Show password',
|
|
182
|
-
})}
|
|
183
|
-
onClick={() => {
|
|
184
|
-
setShowPassword(prev => !prev);
|
|
185
|
-
}}
|
|
186
|
-
style={{
|
|
187
|
-
border: 'none',
|
|
188
|
-
padding: 0,
|
|
189
|
-
background: 'transparent',
|
|
190
|
-
}}
|
|
191
|
-
type="button"
|
|
192
|
-
>
|
|
193
|
-
{showPassword ? <Show /> : <Hide />}
|
|
194
|
-
</button>
|
|
195
|
-
}
|
|
196
|
-
label={label}
|
|
197
|
-
labelAction={labelAction}
|
|
198
|
-
id={name}
|
|
199
|
-
hint={hint}
|
|
200
|
-
name={name}
|
|
201
|
-
onChange={onChange}
|
|
202
|
-
placeholder={formattedPlaceholder}
|
|
203
|
-
type={showPassword ? 'text' : 'password'}
|
|
204
|
-
value={value || ''}
|
|
205
|
-
/>
|
|
206
|
-
);
|
|
207
|
-
}
|
|
208
|
-
case 'select': {
|
|
209
|
-
return (
|
|
210
|
-
<Select
|
|
211
|
-
disabled={disabled}
|
|
212
|
-
error={errorMessage}
|
|
213
|
-
label={label}
|
|
214
|
-
labelAction={labelAction}
|
|
215
|
-
id={name}
|
|
216
|
-
hint={hint}
|
|
217
|
-
name={name}
|
|
218
|
-
onChange={value => {
|
|
219
|
-
onChange({ target: { name, value: value === '' ? null : value, type: 'select' } });
|
|
220
|
-
}}
|
|
221
|
-
placeholder={formattedPlaceholder}
|
|
222
|
-
value={value || ''}
|
|
223
|
-
>
|
|
224
|
-
{options.map(({ metadatas: { intlLabel, disabled, hidden }, key, value }) => {
|
|
225
|
-
return (
|
|
226
|
-
<Option key={key} value={value} disabled={disabled} hidden={hidden}>
|
|
227
|
-
{formatMessage(intlLabel)}
|
|
228
|
-
</Option>
|
|
229
|
-
);
|
|
230
|
-
})}
|
|
231
|
-
</Select>
|
|
232
|
-
);
|
|
233
|
-
}
|
|
234
|
-
case 'textarea': {
|
|
235
|
-
return (
|
|
236
|
-
<Textarea
|
|
237
|
-
disabled={disabled}
|
|
238
|
-
error={errorMessage}
|
|
239
|
-
label={label}
|
|
240
|
-
labelAction={labelAction}
|
|
241
|
-
id={name}
|
|
242
|
-
hint={hint}
|
|
243
|
-
name={name}
|
|
244
|
-
onChange={onChange}
|
|
245
|
-
placeholder={formattedPlaceholder}
|
|
246
|
-
type={type}
|
|
247
|
-
value={value || ''}
|
|
248
|
-
>
|
|
249
|
-
{value}
|
|
250
|
-
</Textarea>
|
|
251
|
-
);
|
|
252
|
-
}
|
|
253
|
-
case 'time': {
|
|
254
|
-
let time = value;
|
|
255
|
-
|
|
256
|
-
// The backend send a value which has the following format: '00:45:00.000'
|
|
257
|
-
// or the time picker only supports hours & minutes so we need to mutate the value
|
|
258
|
-
if (value && value.split(':').length > 2) {
|
|
259
|
-
time = time.split(':');
|
|
260
|
-
time.pop();
|
|
261
|
-
time = time.join(':');
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
return (
|
|
265
|
-
<TimePicker
|
|
266
|
-
clearLabel={formatMessage({ id: 'clearLabel', defaultMessage: 'Clear' })}
|
|
267
|
-
disabled={disabled}
|
|
268
|
-
error={errorMessage}
|
|
269
|
-
label={label}
|
|
270
|
-
labelAction={labelAction}
|
|
271
|
-
id={name}
|
|
272
|
-
hint={hint}
|
|
273
|
-
name={name}
|
|
274
|
-
onChange={time => {
|
|
275
|
-
onChange({ target: { name, value: `${time}`, type } });
|
|
276
|
-
}}
|
|
277
|
-
onClear={() => {
|
|
278
|
-
onChange({ target: { name, value: null, type } });
|
|
279
|
-
}}
|
|
280
|
-
placeholder={formattedPlaceholder}
|
|
281
|
-
step={step}
|
|
282
|
-
value={time}
|
|
283
|
-
/>
|
|
284
|
-
);
|
|
285
|
-
}
|
|
286
|
-
default: {
|
|
287
|
-
return <div>{type} is not supported</div>;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
GenericInput.defaultProps = {
|
|
293
|
-
autoComplete: undefined,
|
|
294
|
-
customInputs: null,
|
|
295
|
-
description: null,
|
|
296
|
-
disabled: false,
|
|
297
|
-
error: '',
|
|
298
|
-
labelAction: undefined,
|
|
299
|
-
placeholder: null,
|
|
300
|
-
options: [],
|
|
301
|
-
step: 1,
|
|
302
|
-
value: '',
|
|
303
|
-
};
|
|
304
|
-
|
|
305
|
-
GenericInput.propTypes = {
|
|
306
|
-
autoComplete: PropTypes.string,
|
|
307
|
-
customInputs: PropTypes.object,
|
|
308
|
-
description: PropTypes.shape({
|
|
309
|
-
id: PropTypes.string.isRequired,
|
|
310
|
-
defaultMessage: PropTypes.string.isRequired,
|
|
311
|
-
values: PropTypes.object,
|
|
312
|
-
}),
|
|
313
|
-
disabled: PropTypes.bool,
|
|
314
|
-
error: PropTypes.string,
|
|
315
|
-
intlLabel: PropTypes.shape({
|
|
316
|
-
id: PropTypes.string.isRequired,
|
|
317
|
-
defaultMessage: PropTypes.string.isRequired,
|
|
318
|
-
values: PropTypes.object,
|
|
319
|
-
}).isRequired,
|
|
320
|
-
labelAction: PropTypes.element,
|
|
321
|
-
name: PropTypes.string.isRequired,
|
|
322
|
-
onChange: PropTypes.func.isRequired,
|
|
323
|
-
options: PropTypes.arrayOf(
|
|
324
|
-
PropTypes.shape({
|
|
325
|
-
metadatas: PropTypes.shape({
|
|
326
|
-
intlLabel: PropTypes.shape({
|
|
327
|
-
id: PropTypes.string.isRequired,
|
|
328
|
-
defaultMessage: PropTypes.string.isRequired,
|
|
329
|
-
}).isRequired,
|
|
330
|
-
disabled: PropTypes.bool,
|
|
331
|
-
hidden: PropTypes.bool,
|
|
332
|
-
}).isRequired,
|
|
333
|
-
key: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
|
|
334
|
-
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
|
|
335
|
-
}).isRequired
|
|
336
|
-
),
|
|
337
|
-
placeholder: PropTypes.shape({
|
|
338
|
-
id: PropTypes.string.isRequired,
|
|
339
|
-
defaultMessage: PropTypes.string.isRequired,
|
|
340
|
-
values: PropTypes.object,
|
|
341
|
-
}),
|
|
342
|
-
step: PropTypes.number,
|
|
343
|
-
type: PropTypes.string.isRequired,
|
|
344
|
-
value: PropTypes.any,
|
|
345
|
-
};
|
|
346
|
-
|
|
347
|
-
export default GenericInput;
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
// List of all the possible filters
|
|
2
|
-
const VALID_REST_OPERATORS = [
|
|
3
|
-
'eq',
|
|
4
|
-
'ne',
|
|
5
|
-
'in',
|
|
6
|
-
'nin',
|
|
7
|
-
'contains',
|
|
8
|
-
'ncontains',
|
|
9
|
-
'containss',
|
|
10
|
-
'ncontainss',
|
|
11
|
-
'lt',
|
|
12
|
-
'lte',
|
|
13
|
-
'gt',
|
|
14
|
-
'gte',
|
|
15
|
-
'null',
|
|
16
|
-
];
|
|
17
|
-
|
|
18
|
-
// from strapi-utils/convert-rest-query-params
|
|
19
|
-
const findAppliedFilter = whereClause => {
|
|
20
|
-
// Useful to remove the mainField of relation fields.
|
|
21
|
-
const formattedWhereClause = whereClause.split('.')[0];
|
|
22
|
-
const separatorIndex = whereClause.lastIndexOf('_');
|
|
23
|
-
|
|
24
|
-
if (separatorIndex === -1) {
|
|
25
|
-
return { operator: '=', field: formattedWhereClause };
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const fieldName = formattedWhereClause.substring(0, separatorIndex);
|
|
29
|
-
const operator = whereClause.slice(separatorIndex + 1);
|
|
30
|
-
|
|
31
|
-
// the field as underscores
|
|
32
|
-
if (!VALID_REST_OPERATORS.includes(operator)) {
|
|
33
|
-
return { operator: '=', field: formattedWhereClause };
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return { operator: `_${operator}`, field: fieldName };
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const formatFiltersFromQuery = ({ _where }) => {
|
|
40
|
-
if (!_where) {
|
|
41
|
-
return [];
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return _where.map(obj => {
|
|
45
|
-
const [key] = Object.keys(obj);
|
|
46
|
-
const { field, operator } = findAppliedFilter(key);
|
|
47
|
-
|
|
48
|
-
const value = obj[key];
|
|
49
|
-
|
|
50
|
-
return { name: field, filter: operator, value };
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export default formatFiltersFromQuery;
|
|
55
|
-
export { findAppliedFilter };
|