@akemona-org/strapi-plugin-i18n 3.7.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 (147) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +19 -0
  3. package/admin/src/assets/images/logo.svg +1 -0
  4. package/admin/src/components/CMEditViewCopyLocale/index.js +183 -0
  5. package/admin/src/components/CMEditViewCopyLocale/utils/cleanData.js +36 -0
  6. package/admin/src/components/CMEditViewCopyLocale/utils/generateOptions.js +22 -0
  7. package/admin/src/components/CMEditViewCopyLocale/utils/index.js +2 -0
  8. package/admin/src/components/CMEditViewCopyLocale/utils/removePasswordAndRelationsFieldFromData.js +54 -0
  9. package/admin/src/components/CMEditViewCopyLocale/utils/tests/cleanData.test.js +83 -0
  10. package/admin/src/components/CMEditViewCopyLocale/utils/tests/data.js +219 -0
  11. package/admin/src/components/CMEditViewCopyLocale/utils/tests/generateOptions.test.js +79 -0
  12. package/admin/src/components/CMEditViewCopyLocale/utils/tests/removePasswordAndRelationsFieldFromData.test.js +40 -0
  13. package/admin/src/components/CMEditViewInjectedComponents/index.js +58 -0
  14. package/admin/src/components/CMEditViewLocalePicker/Option.js +66 -0
  15. package/admin/src/components/CMEditViewLocalePicker/Wrapper.js +8 -0
  16. package/admin/src/components/CMEditViewLocalePicker/index.js +160 -0
  17. package/admin/src/components/CMEditViewLocalePicker/utils/addStatusColorToLocale.js +24 -0
  18. package/admin/src/components/CMEditViewLocalePicker/utils/createLocalesOption.js +20 -0
  19. package/admin/src/components/CMEditViewLocalePicker/utils/index.js +2 -0
  20. package/admin/src/components/CheckboxConfirmation/Wrapper.js +12 -0
  21. package/admin/src/components/CheckboxConfirmation/index.js +70 -0
  22. package/admin/src/components/DeleteModalAdditionalInfos/index.js +25 -0
  23. package/admin/src/components/LocaleList/index.js +101 -0
  24. package/admin/src/components/LocaleListCell/LocaleListCell.js +90 -0
  25. package/admin/src/components/LocaleListCell/tests/LocaleListCell.test.js +128 -0
  26. package/admin/src/components/LocalePicker/index.js +126 -0
  27. package/admin/src/components/LocaleRow/index.js +77 -0
  28. package/admin/src/components/ModalCreate/AdvancedForm.js +45 -0
  29. package/admin/src/components/ModalCreate/BaseForm.js +103 -0
  30. package/admin/src/components/ModalCreate/index.js +136 -0
  31. package/admin/src/components/ModalDelete/index.js +49 -0
  32. package/admin/src/components/ModalEdit/AdvancedForm.js +51 -0
  33. package/admin/src/components/ModalEdit/BaseForm.js +91 -0
  34. package/admin/src/components/ModalEdit/index.js +122 -0
  35. package/admin/src/components/SettingsModal.js +66 -0
  36. package/admin/src/components/index.js +2 -0
  37. package/admin/src/containers/Initializer.js +31 -0
  38. package/admin/src/containers/SettingsPage/LocaleSettingsPage.js +69 -0
  39. package/admin/src/containers/SettingsPage/index.js +33 -0
  40. package/admin/src/containers/SettingsPage/tests/SettingsPage.test.js +744 -0
  41. package/admin/src/containers/SettingsPage/tests/__snapshots__/SettingsPage.test.js.snap +241 -0
  42. package/admin/src/hooks/constants.js +6 -0
  43. package/admin/src/hooks/reducers.js +63 -0
  44. package/admin/src/hooks/tests/reducers.test.js +203 -0
  45. package/admin/src/hooks/useAddLocale/index.js +60 -0
  46. package/admin/src/hooks/useContentTypePermissions/index.js +16 -0
  47. package/admin/src/hooks/useDefaultLocales/index.js +27 -0
  48. package/admin/src/hooks/useDeleteLocale/index.js +45 -0
  49. package/admin/src/hooks/useEditLocale/index.js +46 -0
  50. package/admin/src/hooks/useHasI18n/index.js +13 -0
  51. package/admin/src/hooks/useLocales/index.js +35 -0
  52. package/admin/src/index.js +169 -0
  53. package/admin/src/middlewares/addCommonFieldsToInitialDataMiddleware.js +83 -0
  54. package/admin/src/middlewares/addLocaleColumnToListViewMiddleware.js +32 -0
  55. package/admin/src/middlewares/addLocaleToCollectionTypesMiddleware.js +25 -0
  56. package/admin/src/middlewares/addLocaleToSingleTypesMiddleware.js +25 -0
  57. package/admin/src/middlewares/extendCMEditViewLayoutMiddleware.js +159 -0
  58. package/admin/src/middlewares/extendCTBAttributeInitialDataMiddleware.js +58 -0
  59. package/admin/src/middlewares/extendCTBInitialDataMiddleware.js +33 -0
  60. package/admin/src/middlewares/index.js +21 -0
  61. package/admin/src/middlewares/localePermissionMiddleware.js +39 -0
  62. package/admin/src/middlewares/tests/addCommonFieldsToInitialDataMiddleware.test.js +97 -0
  63. package/admin/src/middlewares/tests/addLocaleColumnToListViewMiddleware.test.js +68 -0
  64. package/admin/src/middlewares/tests/addLocaleToCollectionTypesMiddleware.test.js +200 -0
  65. package/admin/src/middlewares/tests/addLocaleToSingleTypesMiddleware.test.js +193 -0
  66. package/admin/src/middlewares/tests/extendCMEditViewLayoutMiddleware.test.js +556 -0
  67. package/admin/src/middlewares/tests/extendCTBAttrributeInitialDataMiddleware.test.js +124 -0
  68. package/admin/src/middlewares/tests/extendCTBInitialDataMiddleware.test.js +92 -0
  69. package/admin/src/middlewares/tests/localePermissionMiddleware.test.js +150 -0
  70. package/admin/src/middlewares/utils/addLocaleToLinksSearch.js +56 -0
  71. package/admin/src/middlewares/utils/tests/addLocaleToLinksSearch.test.js +137 -0
  72. package/admin/src/permissions.js +9 -0
  73. package/admin/src/pluginId.js +5 -0
  74. package/admin/src/schemas.js +7 -0
  75. package/admin/src/selectors/selectCollectionTypesRelatedPermissions.js +4 -0
  76. package/admin/src/selectors/selectI18nLocales.js +3 -0
  77. package/admin/src/translations/en.json +60 -0
  78. package/admin/src/translations/fr.json +9 -0
  79. package/admin/src/translations/index.js +11 -0
  80. package/admin/src/translations/zh-Hans.json +60 -0
  81. package/admin/src/utils/getDefaultLocale.js +60 -0
  82. package/admin/src/utils/getInitialLocale.js +14 -0
  83. package/admin/src/utils/getLocaleFromQuery.js +7 -0
  84. package/admin/src/utils/getTrad.js +5 -0
  85. package/admin/src/utils/index.js +2 -0
  86. package/admin/src/utils/localizedFields.js +23 -0
  87. package/admin/src/utils/mutateCTBContentTypeSchema.js +66 -0
  88. package/admin/src/utils/tests/getDefaultLocale.test.js +337 -0
  89. package/admin/src/utils/tests/getInitialLocale.test.js +106 -0
  90. package/admin/src/utils/tests/mutateCTBContentTypeSchema.test.js +205 -0
  91. package/config/functions/bootstrap.js +57 -0
  92. package/config/functions/migrations/__tests__/content-type.test.js +255 -0
  93. package/config/functions/migrations/__tests__/field.test.js +150 -0
  94. package/config/functions/migrations/content-type/disable/index.js +34 -0
  95. package/config/functions/migrations/content-type/disable/migrate-for-bookshelf.js +58 -0
  96. package/config/functions/migrations/content-type/disable/migrate-for-mongoose.js +39 -0
  97. package/config/functions/migrations/content-type/enable/index.js +40 -0
  98. package/config/functions/migrations/content-type/utils/index.js +27 -0
  99. package/config/functions/migrations/field/__tests__/utils.test.js +53 -0
  100. package/config/functions/migrations/field/index.js +37 -0
  101. package/config/functions/migrations/field/migrate-for-bookshelf.js +72 -0
  102. package/config/functions/migrations/field/migrate-for-mongoose.js +24 -0
  103. package/config/functions/migrations/field/migrate.js +55 -0
  104. package/config/functions/migrations/field/utils.js +58 -0
  105. package/config/functions/register.js +46 -0
  106. package/config/policies/validateLocaleCreation.js +68 -0
  107. package/config/routes.json +64 -0
  108. package/constants/__tests__/index.test.js +27 -0
  109. package/constants/index.js +36 -0
  110. package/constants/iso-locales.json +2002 -0
  111. package/controllers/__tests__/content-types.test.js +113 -0
  112. package/controllers/__tests__/iso-locales.test.js +26 -0
  113. package/controllers/__tests__/locales.test.js +308 -0
  114. package/controllers/content-types.js +64 -0
  115. package/controllers/iso-locales.js +11 -0
  116. package/controllers/locales.js +104 -0
  117. package/domain/locale.js +10 -0
  118. package/middlewares/i18n/defaults.json +5 -0
  119. package/middlewares/i18n/index.js +28 -0
  120. package/models/Locale.settings.json +31 -0
  121. package/oas.yml +195 -0
  122. package/package.json +31 -0
  123. package/services/__tests__/__snapshots__/iso-locales.test.js.snap +2006 -0
  124. package/services/__tests__/content-types.test.js +545 -0
  125. package/services/__tests__/core-api.test.js +106 -0
  126. package/services/__tests__/entity-service-decorator.test.js +280 -0
  127. package/services/__tests__/iso-locales.test.js +11 -0
  128. package/services/__tests__/locales.test.js +237 -0
  129. package/services/__tests__/localizations.test.js +187 -0
  130. package/services/__tests__/metrics.test.js +90 -0
  131. package/services/content-types.js +200 -0
  132. package/services/core-api.js +296 -0
  133. package/services/entity-service-decorator.js +155 -0
  134. package/services/iso-locales.js +9 -0
  135. package/services/locales.js +97 -0
  136. package/services/localizations.js +65 -0
  137. package/services/metrics.js +24 -0
  138. package/services/permissions/actions.js +124 -0
  139. package/services/permissions/engine.js +63 -0
  140. package/services/permissions/sections-builder.js +48 -0
  141. package/services/permissions.js +11 -0
  142. package/tests/content-manager/list-relation.test.e2e.js +122 -0
  143. package/tests/graphql.test.e2e.js +120 -0
  144. package/tests/locales.test.e2e.js +414 -0
  145. package/utils/index.js +20 -0
  146. package/validation/content-types.js +30 -0
  147. package/validation/locales.js +39 -0
@@ -0,0 +1,241 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`i18n settings page permissions shows nothing when the user doesn't have read permission 1`] = `
4
+ .c3 {
5
+ display: -webkit-inline-box;
6
+ display: -webkit-inline-flex;
7
+ display: -ms-inline-flexbox;
8
+ display: inline-flex;
9
+ -webkit-align-items: center;
10
+ -webkit-box-align: center;
11
+ -ms-flex-align: center;
12
+ align-items: center;
13
+ -webkit-box-pack: center;
14
+ -webkit-justify-content: center;
15
+ -ms-flex-pack: center;
16
+ justify-content: center;
17
+ height: 30px;
18
+ padding: 0 15px;
19
+ font-weight: 600;
20
+ font-size: 1.3rem;
21
+ border-radius: 2px;
22
+ cursor: pointer;
23
+ outline: 0;
24
+ background-color: #ffffff;
25
+ background-color: #007EFF;
26
+ border: 1px solid #007EFF;
27
+ color: #ffffff;
28
+ }
29
+
30
+ .c3:hover,
31
+ .c3:active {
32
+ -webkit-box-shadow: inset 0 0 30px rgba(0,0,0,0.1);
33
+ -moz-box-shadow: inset 0 0 30px rgba(0,0,0,0.1);
34
+ box-shadow: inset 0 0 30px [object Object];
35
+ }
36
+
37
+ .c3:focus {
38
+ outline: 0;
39
+ }
40
+
41
+ .c3 > span svg {
42
+ font-size: 10px;
43
+ }
44
+
45
+ .c3 > svg {
46
+ height: 10px;
47
+ width: auto;
48
+ margin-right: 10px;
49
+ }
50
+
51
+ .c0 {
52
+ margin-bottom: 30px;
53
+ position: relative;
54
+ width: 100%;
55
+ height: 50px;
56
+ }
57
+
58
+ .c0 .justify-content-end {
59
+ display: -webkit-box;
60
+ display: -webkit-flex;
61
+ display: -ms-flexbox;
62
+ display: flex;
63
+ }
64
+
65
+ .c0 .header-title p {
66
+ width: 100%;
67
+ margin: 0;
68
+ overflow: hidden;
69
+ text-overflow: ellipsis;
70
+ white-space: nowrap;
71
+ font-size: 1.3rem;
72
+ font-weight: 400;
73
+ line-height: normal;
74
+ color: #787e8f;
75
+ }
76
+
77
+ .c0 .sticky {
78
+ position: fixed;
79
+ top: 0;
80
+ left: 30.6rem;
81
+ z-index: 1050;
82
+ background-color: white;
83
+ width: calc(100vw - 30.6rem);
84
+ padding-right: 15px;
85
+ height: 60px;
86
+ display: -webkit-box;
87
+ display: -webkit-flex;
88
+ display: -ms-flexbox;
89
+ display: flex;
90
+ }
91
+
92
+ .c0 .sticky .row {
93
+ width: 100%;
94
+ margin: auto;
95
+ margin-top: 16px;
96
+ }
97
+
98
+ .c0 .sticky .row .header-title p {
99
+ display: none;
100
+ }
101
+
102
+ .c0 .sticky .row > div > div {
103
+ padding-top: 0;
104
+ }
105
+
106
+ .c0 .sticky .row > div > div h1 {
107
+ font-size: 2rem;
108
+ }
109
+
110
+ .c0 .sticky .row > div > div h1 svg {
111
+ margin-top: 8px;
112
+ }
113
+
114
+ .c0 .sticky .row > div > div button {
115
+ margin-top: auto;
116
+ margin-bottom: auto;
117
+ }
118
+
119
+ .c2 {
120
+ display: -webkit-box;
121
+ display: -webkit-flex;
122
+ display: -ms-flexbox;
123
+ display: flex;
124
+ -webkit-box-pack: end;
125
+ -webkit-justify-content: flex-end;
126
+ -ms-flex-pack: end;
127
+ justify-content: flex-end;
128
+ width: -webkit-fit-content;
129
+ width: -moz-fit-content;
130
+ width: fit-content;
131
+ max-width: 100%;
132
+ padding-top: 1rem;
133
+ }
134
+
135
+ .c2 > button {
136
+ margin-right: 0;
137
+ margin-left: 1rem;
138
+ max-width: 100%;
139
+ overflow: hidden;
140
+ text-overflow: ellipsis;
141
+ white-space: nowrap;
142
+ text-align: center;
143
+ outline: 0;
144
+ }
145
+
146
+ .c1 {
147
+ position: relative;
148
+ padding-top: 0.5rem;
149
+ }
150
+
151
+ .c1 h1 {
152
+ position: relative;
153
+ width: -webkit-fit-content;
154
+ width: -moz-fit-content;
155
+ width: fit-content;
156
+ max-width: 100%;
157
+ margin-bottom: 0;
158
+ padding-right: 18px;
159
+ font-size: 2.4rem;
160
+ line-height: normal;
161
+ font-weight: 600;
162
+ overflow: hidden;
163
+ text-overflow: ellipsis;
164
+ white-space: nowrap;
165
+ }
166
+
167
+ .c1 svg {
168
+ position: absolute;
169
+ right: 0;
170
+ top: 0;
171
+ margin-top: 12px;
172
+ font-size: 12px;
173
+ color: rgba(16,22,34,0.35);
174
+ cursor: pointer;
175
+ outline: 0;
176
+ }
177
+
178
+ <div>
179
+ <div
180
+ class="c0"
181
+ >
182
+ <div
183
+ class="sticky-wrapper"
184
+ >
185
+ <div
186
+ class="row"
187
+ >
188
+ <div
189
+ class="col-sm-6 header-title"
190
+ >
191
+ <div
192
+ class="c1"
193
+ >
194
+ <h1>
195
+ Plugin.name
196
+ </h1>
197
+ </div>
198
+ <p>
199
+ Settings.list.description
200
+ </p>
201
+ </div>
202
+ <div
203
+ class="col-sm-6 justify-content-end"
204
+ >
205
+ <div
206
+ class="c2"
207
+ >
208
+ <button
209
+ class="c3"
210
+ color="primary"
211
+ style="padding-left: 15px; padding-right: 15px;"
212
+ type="button"
213
+ >
214
+ <svg
215
+ fill="#ffffff"
216
+ height="11px"
217
+ viewBox="0 0 13 13"
218
+ width="11px"
219
+ xmlns="http://www.w3.org/2000/svg"
220
+ >
221
+ <g
222
+ data-name="Layer 2"
223
+ >
224
+ <path
225
+ d="M6.5.5v12m6-6H.5"
226
+ fill="none"
227
+ stroke="#ffffff"
228
+ stroke-linecap="round"
229
+ />
230
+ </g>
231
+ </svg>
232
+ Settings.list.actions.add
233
+ </button>
234
+ </div>
235
+ </div>
236
+ </div>
237
+ </div>
238
+ </div>
239
+ <div />
240
+ </div>
241
+ `;
@@ -0,0 +1,6 @@
1
+ import pluginId from '../pluginId';
2
+
3
+ export const RESOLVE_LOCALES = `${pluginId}/locales/resolve-locales`;
4
+ export const ADD_LOCALE = `${pluginId}/locales/add`;
5
+ export const DELETE_LOCALE = `${pluginId}/locales/delete`;
6
+ export const UPDATE_LOCALE = `${pluginId}/locales/update`;
@@ -0,0 +1,63 @@
1
+ import produce from 'immer';
2
+ import set from 'lodash/set';
3
+ import pluginId from '../pluginId';
4
+ import { RESOLVE_LOCALES, ADD_LOCALE, DELETE_LOCALE, UPDATE_LOCALE } from './constants';
5
+
6
+ export const initialState = {
7
+ isLoading: true,
8
+ locales: [],
9
+ };
10
+
11
+ const localeReducer = produce((draftState = initialState, action) => {
12
+ switch (action.type) {
13
+ case RESOLVE_LOCALES: {
14
+ draftState.isLoading = false;
15
+ draftState.locales = action.locales;
16
+ break;
17
+ }
18
+
19
+ case ADD_LOCALE: {
20
+ if (action.newLocale.isDefault) {
21
+ draftState.locales.forEach(locale => {
22
+ locale.isDefault = false;
23
+ });
24
+ }
25
+
26
+ draftState.locales.push(action.newLocale);
27
+ break;
28
+ }
29
+
30
+ case DELETE_LOCALE: {
31
+ const locales = draftState.locales.filter(locale => locale.id !== action.id);
32
+
33
+ set(draftState, 'locales', locales);
34
+ break;
35
+ }
36
+
37
+ case UPDATE_LOCALE: {
38
+ if (action.editedLocale.isDefault) {
39
+ draftState.locales.forEach(locale => {
40
+ locale.isDefault = false;
41
+ });
42
+ }
43
+
44
+ const indexToEdit = draftState.locales.findIndex(
45
+ locale => locale.id === action.editedLocale.id
46
+ );
47
+
48
+ set(draftState.locales, indexToEdit, action.editedLocale);
49
+ break;
50
+ }
51
+
52
+ default:
53
+ return draftState;
54
+ }
55
+
56
+ return draftState;
57
+ });
58
+
59
+ const reducers = {
60
+ [`${pluginId}_locales`]: localeReducer,
61
+ };
62
+
63
+ export default reducers;
@@ -0,0 +1,203 @@
1
+ import reducers, { initialState } from '../reducers';
2
+ import { RESOLVE_LOCALES, ADD_LOCALE, DELETE_LOCALE, UPDATE_LOCALE } from '../constants';
3
+
4
+ describe('i18n reducer', () => {
5
+ it('resolves the initial state when the action is not known', () => {
6
+ const action = {
7
+ type: 'UNKNWON_ACTION',
8
+ };
9
+
10
+ const actual = reducers.i18n_locales(initialState, action);
11
+ const expected = initialState;
12
+
13
+ expect(actual).toEqual(expected);
14
+ });
15
+
16
+ it('resolves a list of locales when triggering RESOLVE_LOCALES', () => {
17
+ const action = {
18
+ type: RESOLVE_LOCALES,
19
+ locales: [{ id: 1, displayName: 'French', isDefault: false }],
20
+ };
21
+
22
+ const actual = reducers.i18n_locales(initialState, action);
23
+ const expected = {
24
+ isLoading: false,
25
+ locales: [
26
+ {
27
+ displayName: 'French',
28
+ id: 1,
29
+ isDefault: false,
30
+ },
31
+ ],
32
+ };
33
+
34
+ expect(actual).toEqual(expected);
35
+ });
36
+
37
+ it('adds a locale when triggering ADD_LOCALE', () => {
38
+ const action = {
39
+ type: ADD_LOCALE,
40
+ newLocale: { id: 1, displayName: 'French', isDefault: false },
41
+ };
42
+
43
+ const actual = reducers.i18n_locales(initialState, action);
44
+ const expected = {
45
+ isLoading: true,
46
+ locales: [
47
+ {
48
+ displayName: 'French',
49
+ id: 1,
50
+ isDefault: false,
51
+ },
52
+ ],
53
+ };
54
+
55
+ expect(actual).toEqual(expected);
56
+ });
57
+
58
+ it('adds a locale when triggering ADD_LOCALE and set it to default', () => {
59
+ const action = {
60
+ type: ADD_LOCALE,
61
+ newLocale: { id: 1, displayName: 'French', isDefault: true },
62
+ };
63
+
64
+ const locales = [
65
+ {
66
+ displayName: 'English',
67
+ id: 2,
68
+ isDefault: true,
69
+ },
70
+ ];
71
+
72
+ const actual = reducers.i18n_locales({ ...initialState, locales }, action);
73
+ const expected = {
74
+ isLoading: true,
75
+ locales: [
76
+ {
77
+ displayName: 'English',
78
+ id: 2,
79
+ isDefault: false,
80
+ },
81
+ {
82
+ displayName: 'French',
83
+ id: 1,
84
+ isDefault: true,
85
+ },
86
+ ],
87
+ };
88
+
89
+ expect(actual).toEqual(expected);
90
+ });
91
+
92
+ it('removes a locale when triggering DELETE_LOCALE ', () => {
93
+ const action = {
94
+ type: DELETE_LOCALE,
95
+ id: 2,
96
+ };
97
+
98
+ const locales = [
99
+ {
100
+ displayName: 'French',
101
+ id: 1,
102
+ isDefault: true,
103
+ },
104
+ {
105
+ displayName: 'English',
106
+ id: 2,
107
+ isDefault: false,
108
+ },
109
+ ];
110
+
111
+ const actual = reducers.i18n_locales({ ...initialState, locales }, action);
112
+ const expected = {
113
+ isLoading: true,
114
+ locales: [
115
+ {
116
+ displayName: 'French',
117
+ id: 1,
118
+ isDefault: true,
119
+ },
120
+ ],
121
+ };
122
+
123
+ expect(actual).toEqual(expected);
124
+ });
125
+
126
+ it('updates a locale when triggering UPDATE_LOCALE', () => {
127
+ const action = {
128
+ type: UPDATE_LOCALE,
129
+ editedLocale: { id: 1, displayName: 'Frenchie', isDefault: false },
130
+ };
131
+
132
+ const locales = [
133
+ {
134
+ displayName: 'English',
135
+ id: 2,
136
+ isDefault: true,
137
+ },
138
+ {
139
+ displayName: 'French',
140
+ id: 1,
141
+ isDefault: false,
142
+ },
143
+ ];
144
+
145
+ const actual = reducers.i18n_locales({ ...initialState, locales }, action);
146
+ const expected = {
147
+ isLoading: true,
148
+ locales: [
149
+ {
150
+ displayName: 'English',
151
+ id: 2,
152
+ isDefault: true,
153
+ },
154
+ {
155
+ displayName: 'Frenchie',
156
+ id: 1,
157
+ isDefault: false,
158
+ },
159
+ ],
160
+ };
161
+
162
+ expect(actual).toEqual(expected);
163
+ });
164
+
165
+ it('updates a locale when triggering UPDATE_LOCALE and set it to default', () => {
166
+ const action = {
167
+ type: UPDATE_LOCALE,
168
+ editedLocale: { id: 1, displayName: 'Frenchie', isDefault: true },
169
+ };
170
+
171
+ const locales = [
172
+ {
173
+ displayName: 'English',
174
+ id: 2,
175
+ isDefault: true,
176
+ },
177
+ {
178
+ displayName: 'French',
179
+ id: 1,
180
+ isDefault: false,
181
+ },
182
+ ];
183
+
184
+ const actual = reducers.i18n_locales({ ...initialState, locales }, action);
185
+ const expected = {
186
+ isLoading: true,
187
+ locales: [
188
+ {
189
+ displayName: 'English',
190
+ id: 2,
191
+ isDefault: false,
192
+ },
193
+ {
194
+ displayName: 'Frenchie',
195
+ id: 1,
196
+ isDefault: true,
197
+ },
198
+ ],
199
+ };
200
+
201
+ expect(actual).toEqual(expected);
202
+ });
203
+ });
@@ -0,0 +1,60 @@
1
+ import { useState } from 'react';
2
+ import { request } from 'strapi-helper-plugin';
3
+ import { useDispatch } from 'react-redux';
4
+ import get from 'lodash/get';
5
+ import { getTrad } from '../../utils';
6
+ import { ADD_LOCALE } from '../constants';
7
+
8
+ const addLocale = async ({ code, name, isDefault }) => {
9
+ const data = await request(`/i18n/locales`, {
10
+ method: 'POST',
11
+ body: {
12
+ name,
13
+ code,
14
+ isDefault,
15
+ },
16
+ });
17
+
18
+ strapi.notification.toggle({
19
+ type: 'success',
20
+ message: { id: getTrad('Settings.locales.modal.create.success') },
21
+ });
22
+
23
+ return data;
24
+ };
25
+
26
+ const useAddLocale = () => {
27
+ const [isLoading, setLoading] = useState(false);
28
+ const dispatch = useDispatch();
29
+
30
+ const persistLocale = async locale => {
31
+ setLoading(true);
32
+
33
+ try {
34
+ const newLocale = await addLocale(locale);
35
+ dispatch({ type: ADD_LOCALE, newLocale });
36
+ } catch (e) {
37
+ const message = get(e, 'response.payload.message', null);
38
+
39
+ if (message && message.includes('already exists')) {
40
+ strapi.notification.toggle({
41
+ type: 'warning',
42
+ message: { id: getTrad('Settings.locales.modal.create.alreadyExist') },
43
+ });
44
+ } else {
45
+ strapi.notification.toggle({
46
+ type: 'warning',
47
+ message: { id: 'notification.error' },
48
+ });
49
+ }
50
+
51
+ throw e;
52
+ } finally {
53
+ setLoading(false);
54
+ }
55
+ };
56
+
57
+ return { isAdding: isLoading, addLocale: persistLocale };
58
+ };
59
+
60
+ export default useAddLocale;
@@ -0,0 +1,16 @@
1
+ import { useSelector } from 'react-redux';
2
+ import selectCollectionTypesRelatedPermissions from '../../selectors/selectCollectionTypesRelatedPermissions';
3
+
4
+ const useContentTypePermissions = slug => {
5
+ const collectionTypesRelatedPermissions = useSelector(selectCollectionTypesRelatedPermissions);
6
+
7
+ const currentCTRelatedPermissions = collectionTypesRelatedPermissions[slug];
8
+ const readPermissions =
9
+ currentCTRelatedPermissions['plugins::content-manager.explorer.read'] || [];
10
+ const createPermissions =
11
+ currentCTRelatedPermissions['plugins::content-manager.explorer.create'] || [];
12
+
13
+ return { createPermissions, readPermissions };
14
+ };
15
+
16
+ export default useContentTypePermissions;
@@ -0,0 +1,27 @@
1
+ import { useQuery } from 'react-query';
2
+ import { request } from 'strapi-helper-plugin';
3
+
4
+ const fetchDefaultLocalesList = async () => {
5
+ try {
6
+ const data = await request('/i18n/iso-locales', {
7
+ method: 'GET',
8
+ });
9
+
10
+ return data;
11
+ } catch (e) {
12
+ strapi.notification.toggle({
13
+ type: 'warning',
14
+ message: { id: 'notification.error' },
15
+ });
16
+
17
+ return [];
18
+ }
19
+ };
20
+
21
+ const useDefaultLocales = () => {
22
+ const { isLoading, data } = useQuery('default-locales', fetchDefaultLocalesList);
23
+
24
+ return { defaultLocales: data, isLoading };
25
+ };
26
+
27
+ export default useDefaultLocales;
@@ -0,0 +1,45 @@
1
+ import { useState } from 'react';
2
+ import { request } from 'strapi-helper-plugin';
3
+ import { useDispatch } from 'react-redux';
4
+ import { getTrad } from '../../utils';
5
+ import { DELETE_LOCALE } from '../constants';
6
+
7
+ const deleteLocale = async id => {
8
+ try {
9
+ const data = await request(`/i18n/locales/${id}`, {
10
+ method: 'DELETE',
11
+ });
12
+
13
+ strapi.notification.toggle({
14
+ type: 'success',
15
+ message: { id: getTrad('Settings.locales.modal.delete.success') },
16
+ });
17
+
18
+ return data;
19
+ } catch (e) {
20
+ strapi.notification.toggle({
21
+ type: 'warning',
22
+ message: { id: 'notification.error' },
23
+ });
24
+
25
+ return e;
26
+ }
27
+ };
28
+
29
+ const useDeleteLocale = () => {
30
+ const [isLoading, setLoading] = useState(false);
31
+ const dispatch = useDispatch();
32
+
33
+ const removeLocale = async id => {
34
+ setLoading(true);
35
+
36
+ await deleteLocale(id);
37
+
38
+ dispatch({ type: DELETE_LOCALE, id });
39
+ setLoading(false);
40
+ };
41
+
42
+ return { isDeleting: isLoading, deleteLocale: removeLocale };
43
+ };
44
+
45
+ export default useDeleteLocale;
@@ -0,0 +1,46 @@
1
+ import { useState } from 'react';
2
+ import { request } from 'strapi-helper-plugin';
3
+ import { useDispatch } from 'react-redux';
4
+ import { getTrad } from '../../utils';
5
+ import { UPDATE_LOCALE } from '../constants';
6
+
7
+ const editLocale = async (id, payload) => {
8
+ try {
9
+ const data = await request(`/i18n/locales/${id}`, {
10
+ method: 'PUT',
11
+ body: payload,
12
+ });
13
+
14
+ strapi.notification.toggle({
15
+ type: 'success',
16
+ message: { id: getTrad('Settings.locales.modal.edit.success') },
17
+ });
18
+
19
+ return data;
20
+ } catch {
21
+ strapi.notification.toggle({
22
+ type: 'warning',
23
+ message: { id: 'notification.error' },
24
+ });
25
+
26
+ return null;
27
+ }
28
+ };
29
+
30
+ const useEditLocale = () => {
31
+ const [isLoading, setLoading] = useState(false);
32
+ const dispatch = useDispatch();
33
+
34
+ const modifyLocale = async (id, payload) => {
35
+ setLoading(true);
36
+
37
+ const editedLocale = await editLocale(id, payload);
38
+
39
+ dispatch({ type: UPDATE_LOCALE, editedLocale });
40
+ setLoading(false);
41
+ };
42
+
43
+ return { isEditing: isLoading, editLocale: modifyLocale };
44
+ };
45
+
46
+ export default useEditLocale;