@commercetools-frontend-extensions/export-resources-modal 0.0.0-canary-20240507102123
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/LICENSE +29 -0
- package/README.md +283 -0
- package/dist/commercetools-frontend-extensions-export-resources-modal.cjs.dev.js +1258 -0
- package/dist/commercetools-frontend-extensions-export-resources-modal.cjs.js +7 -0
- package/dist/commercetools-frontend-extensions-export-resources-modal.cjs.prod.js +1241 -0
- package/dist/commercetools-frontend-extensions-export-resources-modal.esm.js +1219 -0
- package/package.json +71 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) commercetools GmbH
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
|
8
|
+
|
|
9
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
10
|
+
list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
|
14
|
+
and/or other materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
17
|
+
contributors may be used to endorse or promote products derived from
|
|
18
|
+
this software without specific prior written permission.
|
|
19
|
+
|
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
24
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
25
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
26
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
27
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
28
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
# @commercetools-frontend-extensions/export-resources-modal
|
|
2
|
+
|
|
3
|
+
Package for exporting resources from Merchant Center Applications.
|
|
4
|
+
|
|
5
|
+
> This library takes into account that you are building a Merchant Center Applications which documentation you can find [here](https://docs.commercetools.com/custom-applications/).
|
|
6
|
+
> The components follow the same principles of the [UIKit](https://github.com/commercetools/ui-kit) components.
|
|
7
|
+
|
|
8
|
+
## Getting started
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
$ npm install --save @commercetools-frontend-extensions/export-resources-modal
|
|
12
|
+
|
|
13
|
+
// or
|
|
14
|
+
|
|
15
|
+
$ yarn add @commercetools-frontend-extensions/export-resources-modal
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Description
|
|
19
|
+
|
|
20
|
+
Export Resources Modal is an internal component used to export resources into csv or json files, it's using [Exporter Services](https://github.com/commercetools/commercetools-exporter) to create async export Job.
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
import { ExportResourcesModal } from '@commercetools-frontend-extensions/export-resources-modal';
|
|
26
|
+
|
|
27
|
+
// Use case: Exporting all resources
|
|
28
|
+
<ExportResourcesModal
|
|
29
|
+
isOpen={true}
|
|
30
|
+
exportType="all"
|
|
31
|
+
outputFormat="csv"
|
|
32
|
+
resourceType="category"
|
|
33
|
+
totalResourcesCount={143}
|
|
34
|
+
fieldGroups={[
|
|
35
|
+
{
|
|
36
|
+
groupLabel: 'All general fields',
|
|
37
|
+
fields: [
|
|
38
|
+
{
|
|
39
|
+
name: 'key',
|
|
40
|
+
label: 'Category key',
|
|
41
|
+
isRequired: true,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: 'externalId',
|
|
45
|
+
label: 'External id',
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: 'createdAt',
|
|
49
|
+
label: 'Created at',
|
|
50
|
+
isSelectedByDefault: true,
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: 'lastModifiedAt',
|
|
54
|
+
label: 'Last modified at',
|
|
55
|
+
isSelectedByDefault: true,
|
|
56
|
+
},
|
|
57
|
+
{ name: 'name', label: 'Name', isSelectedByDefault: true },
|
|
58
|
+
{
|
|
59
|
+
name: 'parent',
|
|
60
|
+
label: 'parent',
|
|
61
|
+
isSelectedByDefault: true,
|
|
62
|
+
fields: [
|
|
63
|
+
{
|
|
64
|
+
name: 'parent.name',
|
|
65
|
+
label: 'Parent name',
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: 'parent.key',
|
|
69
|
+
label: 'Parent key',
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: 'id',
|
|
75
|
+
label: 'Id',
|
|
76
|
+
isSelectedByDefault: true,
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
groupLabel: 'All custom fields',
|
|
82
|
+
fields: [
|
|
83
|
+
{
|
|
84
|
+
name: 'custom-type-key-and-type-id',
|
|
85
|
+
label: 'Custom type key and typeId',
|
|
86
|
+
isReadOnly: true,
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: 'general-category-attributes',
|
|
90
|
+
label: 'General category attributes',
|
|
91
|
+
fields: [
|
|
92
|
+
{
|
|
93
|
+
name: 'custom.fields.season',
|
|
94
|
+
label: 'Season',
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: 'custom.fields.target-audience',
|
|
98
|
+
label: 'Target audience',
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
name: 'book-category-attributes',
|
|
104
|
+
label: 'Book category attributes',
|
|
105
|
+
fields: [
|
|
106
|
+
{
|
|
107
|
+
name: 'custom.fields.genre',
|
|
108
|
+
label: 'Genre',
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
name: 'custom.fields.age-group',
|
|
112
|
+
label: 'Age group',
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
},
|
|
118
|
+
]}
|
|
119
|
+
fieldOrder={['*', 'custom']}
|
|
120
|
+
renderProperties={()=>(
|
|
121
|
+
<>
|
|
122
|
+
- The category parent is referenced by externalId or key.
|
|
123
|
+
</>
|
|
124
|
+
)}
|
|
125
|
+
onClose={() => {
|
|
126
|
+
...
|
|
127
|
+
}}
|
|
128
|
+
/>
|
|
129
|
+
|
|
130
|
+
// Use case: Exporting only selected resources by their IDs
|
|
131
|
+
<ExportResourcesModal
|
|
132
|
+
isOpen={true}
|
|
133
|
+
exportType="selected"
|
|
134
|
+
outputFormat="csv"
|
|
135
|
+
resourceType="category"
|
|
136
|
+
selectedResourceIds={['02ed9a7d-7c1f-40da-b2b7-4cca6752bf29', '04051276-1641-4e01-a03e-d4de16b7e4eb', 'ac7d9f7b-5c7d-4dd3-b82b-8555ab4a2a6e']}
|
|
137
|
+
fields={[
|
|
138
|
+
{
|
|
139
|
+
groupLabel: 'All General fields',
|
|
140
|
+
fields:[
|
|
141
|
+
{
|
|
142
|
+
name: 'key',
|
|
143
|
+
label: 'Category key',
|
|
144
|
+
isRequired: true,
|
|
145
|
+
isSelectedByDefault: true,
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
name: 'externalId',
|
|
149
|
+
label: 'External id',
|
|
150
|
+
},
|
|
151
|
+
{ name: 'createdAt', label: 'Created at', isSelectedByDefault: true, },
|
|
152
|
+
{ name: 'lastModifiedAt', label: 'Last modified at', isSelectedByDefault: true, },
|
|
153
|
+
{ name: 'name', label: 'Name', isSelectedByDefault: true, },
|
|
154
|
+
{
|
|
155
|
+
name: 'parent',
|
|
156
|
+
isSelectedByDefault: true,
|
|
157
|
+
fields: [
|
|
158
|
+
{
|
|
159
|
+
name: 'parent.name',
|
|
160
|
+
label: 'Parent name',
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
name: 'parent.key',
|
|
164
|
+
label: 'Parent key',
|
|
165
|
+
},
|
|
166
|
+
],
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
name: 'id',
|
|
170
|
+
label: 'Id',
|
|
171
|
+
},
|
|
172
|
+
]
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
groupLabel: 'All custom fields',
|
|
176
|
+
fields: [
|
|
177
|
+
{
|
|
178
|
+
name: 'custom-type-key-and-typeid',
|
|
179
|
+
label: 'Custom type key and typeId',
|
|
180
|
+
isReadOnly: true,
|
|
181
|
+
isSelectedByDefault: false,
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
name: 'general-category-attributes',
|
|
185
|
+
label: 'General category attributes',
|
|
186
|
+
resourceTypeIds: ['category'],
|
|
187
|
+
isSelectedByDefault: false,
|
|
188
|
+
fields: [
|
|
189
|
+
{
|
|
190
|
+
name: 'season',
|
|
191
|
+
label: 'Season',
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
name: 'target-audience',
|
|
195
|
+
label: 'Target audience',
|
|
196
|
+
},
|
|
197
|
+
],
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
name: 'book-category-attributes',
|
|
201
|
+
label: 'Book category attributes',
|
|
202
|
+
resourceTypeIds: ['category', 'asset'],
|
|
203
|
+
isSelectedByDefault: false,
|
|
204
|
+
fields: [
|
|
205
|
+
{
|
|
206
|
+
name: 'genre',
|
|
207
|
+
label: 'Genre',
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
name: 'age-group',
|
|
211
|
+
label: 'Age group',
|
|
212
|
+
},
|
|
213
|
+
],
|
|
214
|
+
},
|
|
215
|
+
]
|
|
216
|
+
}
|
|
217
|
+
]}
|
|
218
|
+
renderProperties={()=>(
|
|
219
|
+
<>
|
|
220
|
+
- The category parent is referenced by externalId or key.
|
|
221
|
+
</>
|
|
222
|
+
)}
|
|
223
|
+
onClose={() => {
|
|
224
|
+
...
|
|
225
|
+
}}
|
|
226
|
+
/>
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## Properties
|
|
230
|
+
|
|
231
|
+
| Props | Type | Required | Default | Description |
|
|
232
|
+
| -------------------------------------------- | ------------------------------------------------------- | :--------------------------------------------------: | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
233
|
+
| `isOpen` | `boolean` | | `false` | Controls whether the export modal is open or closed |
|
|
234
|
+
| `outputFormat` | `string`<br/>Possible values: `csv`, `json` | | `csv` | The file format to export |
|
|
235
|
+
| `onExportSuccess` | `function` | | | Callback function that is called when the export operation is successful |
|
|
236
|
+
| `onClose` | `function` | | | Callback function invoked when the modal is requested to close (on overlay click, close button click or `ESC` press). This function is also called after an export operation regardless of its success or failure |
|
|
237
|
+
| `resourceType` | `string` | ✅ | | The type of the resource, example: `category`, `product`... |
|
|
238
|
+
| `totalResourcesCount` | `number` | (✅) Required only if the `exportType` is `all` | | The count of all resources of identified `resourceType` |
|
|
239
|
+
| `exportType` | `string` <br/>Possible values:<br/>`all` and `selected` | | `all` | The type of export, so either export `all` resources or export only `selected` resources |
|
|
240
|
+
| `selectedResourceIds` | `array` | (✅) Required only if the `exportType` is `selected` | | Array of Ids of the selected resources |
|
|
241
|
+
| `fieldGroups` | `array` | ✅ | | Array of the grouped `fields` to export. |
|
|
242
|
+
| `fieldGroups[].groupLabel` | `array` | ✅ | | Array of the grouped `fields` to export. |
|
|
243
|
+
| `fieldGroups[].fields` | `array` | ✅ | | Array of the fields to export. The fields must align with the [commercetools API schema](https://docs.commercetools.com/api/). Field can have nested `fields` array. |
|
|
244
|
+
| `fieldGroups[].fields[].name` | `string` | ✅ | | A string that represents the unique identifier for each field |
|
|
245
|
+
| `fieldGroups[].fields[].label` | `string` | ✅ | | The label of the field to be shown in the export modal |
|
|
246
|
+
| `fieldGroups[].fields[].isRequired` | `boolean` | | `false` | `isRequired` field indicates whether a field is required for the export process. If `true` the field will be selected by default and cannot be deselected by the user. This is useful for fields that are essential for the export process. Fields marked as required will have a `*` appended to their label in the UI |
|
|
247
|
+
| `fieldGroups[].fields[].isSelectedByDefault` | `boolean` | | `true` | This field is a part of the `fields` array is used to control the default state of the corresponding checkbox in the UI. If `isSelectedByDefault` is set to true, the checkbox for that particular field will be checked by default when the component loads. The default value of this attribute is `true` which means unless explicitly set to `false`, the checkbox for the field will be checked on initial load. |
|
|
248
|
+
| `renderProperties` | `function` | | | A prop to render properties that are resource-specific |
|
|
249
|
+
| `fieldOrder` | `string[]` | | | The field names are sorted based on the order passed. The value `*` can be passed to denote any fields and for example fieldOrder=['*', 'custom'] will push all the fields that starts with custom to the last in the list and any other fields will be at the beginning of the list |
|
|
250
|
+
|
|
251
|
+
## Releasing
|
|
252
|
+
|
|
253
|
+
This package uses [`changesets`](https://github.com/atlassian/changesets) in order to do releases to NPM.
|
|
254
|
+
|
|
255
|
+
In case you want to publish a new version with the latest changes you need to:
|
|
256
|
+
|
|
257
|
+
1. Add a changeset with `pnpm changeset` and select `@commercetools-frontend-extensions/export-resources-modal` as the modified package.
|
|
258
|
+
2. Some options would be appear in order to do the release:
|
|
259
|
+
- `patch`: use this release for fixes or small changes
|
|
260
|
+
- `minor`: use this release for depenency upgrades or medium changes
|
|
261
|
+
- `major`: use this release for breaking changes
|
|
262
|
+
3. After selecting the option you will need to add a comment for the release notes. We recommend to use the same format as for the commits.
|
|
263
|
+
- e.g: `feat(utils): add utils for dates`
|
|
264
|
+
4. Push the `changeset` to your branch and GitHub actions will detect that the PR contains changes that affect the published library.
|
|
265
|
+
5. After the PR gets merged, another PR will be created called `Version Packages` which is the one that will be detected, again by GitHub Actions, to do a release to NPM.
|
|
266
|
+
6. Make sure that everything is correct and then merge `Version Packages` PR.
|
|
267
|
+
7. Wait until the new version is available in NPM and then deploy the custom in CircleCI.
|
|
268
|
+
|
|
269
|
+
### Canary releases
|
|
270
|
+
|
|
271
|
+
Canary releases are automatically published to the distribution channel via CI following a successful build and merge to the **main** branch.
|
|
272
|
+
|
|
273
|
+
## i18n
|
|
274
|
+
|
|
275
|
+
The repo is configured with an integration with Transifex. The process for i18n is the same as the Merchant Center uses.
|
|
276
|
+
|
|
277
|
+
`pnpm i18n:build` for adding the new keys to transifex.
|
|
278
|
+
|
|
279
|
+
Once the PR gets merged to `main` transifex will receive a notification with new keys that need to be translated (that's why is important that `description` and `defaultMessage` are descriptive enough).
|
|
280
|
+
|
|
281
|
+
Whenever the translators finish translations and mark them as done, the repo will receive a PR (per language) for adding translated messages.
|
|
282
|
+
|
|
283
|
+
Once we review that translated keys are correct and add a `changeset` we can merge the PR. (Don't forget to deploy the custom app)
|