@commercetools-frontend-extensions/export-resources-modal
v4.7.2
Published
Shared export modal for exporting resources
Downloads
3,150
Readme
@commercetools-frontend-extensions/export-resources-modal
Package for exporting resources from Merchant Center Applications.
This library takes into account that you are building a Merchant Center Applications which documentation you can find here. The components follow the same principles of the UIKit components.
Getting started
$ npm install --save @commercetools-frontend-extensions/export-resources-modal
// or
$ yarn add @commercetools-frontend-extensions/export-resources-modal
Description
Export Resources Modal is an internal component used to export resources into csv or json files, it's using Exporter Services to create async export Job.
Usage
import ExportResourcesModal from '@commercetools-frontend-extensions/export-resources-modal';
// Use case: Exporting all resources
<ExportResourcesModal
isOpen={true}
outputFormat="csv"
resourceType="category"
totalResourcesCount={143}
fieldGroups={[
{
groupLabel: 'All general fields',
groupName: 'general-fields',
fields: [
{
name: 'key',
label: 'Category key',
isRequired: true,
},
{
name: 'externalId',
label: 'External id',
},
{
name: 'createdAt',
label: 'Created at',
isSelectedByDefault: true,
},
{
name: 'lastModifiedAt',
label: 'Last modified at',
isSelectedByDefault: true,
},
{ name: 'name', label: 'Name', isSelectedByDefault: true },
{
name: 'parent',
label: 'parent',
isSelectedByDefault: true,
fields: [
{
name: 'parent.name',
label: 'Parent name',
},
{
name: 'parent.key',
label: 'Parent key',
},
],
},
{
name: 'id',
label: 'Id',
isSelectedByDefault: true,
},
],
},
{
groupLabel: 'All custom fields',
groupName: 'custom-fields',
fields: [
{
name: 'custom-type-key-and-type-id',
label: 'Custom type key and type id',
},
{
name: 'general-category-attributes',
label: 'General category attributes',
fields: [
{
name: 'custom.fields.season',
label: 'Season',
},
{
name: 'custom.fields.target-audience',
label: 'Target audience',
},
],
},
{
name: 'book-category-attributes',
label: 'Book category attributes',
fields: [
{
name: 'custom.fields.genre',
label: 'Genre',
},
{
name: 'custom.fields.age-group',
label: 'Age group',
},
],
},
],
},
]}
fieldOrder={['*', 'custom']}
onClose={() => {
...
}}
/>
// Use case: Exporting filtered resources
<ExportResourcesModal
isOpen={true}
outputFormat="csv"
resourceType="category"
filters={{
queryPredicate: 'key = "category-key"',
total: 20
}}
totalResourcesCount={143}
fieldGroups={[
{
groupLabel: 'All general fields',
groupName: 'general-fields',
fields: [
{
name: 'key',
label: 'Category key',
isRequired: true,
},
{
name: 'externalId',
label: 'External id',
},
{
name: 'createdAt',
label: 'Created at',
isSelectedByDefault: true,
},
{
name: 'lastModifiedAt',
label: 'Last modified at',
isSelectedByDefault: true,
},
{ name: 'name', label: 'Name', isSelectedByDefault: true },
{
name: 'parent',
label: 'parent',
isSelectedByDefault: true,
fields: [
{
name: 'parent.name',
label: 'Parent name',
},
{
name: 'parent.key',
label: 'Parent key',
},
],
},
{
name: 'id',
label: 'Id',
isSelectedByDefault: true,
},
],
},
{
groupLabel: 'All custom fields',
groupName: 'custom-fields',
fields: [
{
name: 'custom-type-key-and-type-id',
label: 'Custom type key and type id',
},
{
name: 'general-category-attributes',
label: 'General category attributes',
fields: [
{
name: 'custom.fields.season',
label: 'Season',
},
{
name: 'custom.fields.target-audience',
label: 'Target audience',
},
],
},
{
name: 'book-category-attributes',
label: 'Book category attributes',
fields: [
{
name: 'custom.fields.genre',
label: 'Genre',
},
{
name: 'custom.fields.age-group',
label: 'Age group',
},
],
},
],
},
]}
fieldOrder={['*', 'custom']}
onClose={() => {
...
}}
/>
// Use case: Exporting only selected resources by their IDs
<ExportResourcesModal
isOpen={true}
outputFormat="csv"
resourceType="category"
selectedResourceIds={['02ed9a7d-7c1f-40da-b2b7-4cca6752bf29', '04051276-1641-4e01-a03e-d4de16b7e4eb', 'ac7d9f7b-5c7d-4dd3-b82b-8555ab4a2a6e']}
fields={[
{
groupLabel: 'All General fields',
groupName: 'general-fields',
fields:[
{
name: 'key',
label: 'Category key',
isRequired: true,
isSelectedByDefault: true,
},
{
name: 'externalId',
label: 'External id',
},
{ name: 'createdAt', label: 'Created at', isSelectedByDefault: true, },
{ name: 'lastModifiedAt', label: 'Last modified at', isSelectedByDefault: true, },
{ name: 'name', label: 'Name', isSelectedByDefault: true, },
{
name: 'parent',
isSelectedByDefault: true,
fields: [
{
name: 'parent.name',
label: 'Parent name',
},
{
name: 'parent.key',
label: 'Parent key',
},
],
},
{
name: 'id',
label: 'Id',
},
]
},
{
groupLabel: 'All custom fields',
groupName: 'custom-fields',
fields: [
{
name: 'custom-type-key-and-typeid',
label: 'Custom type key and type id',
isSelectedByDefault: false,
},
{
name: 'general-category-attributes',
label: 'General category attributes',
isSelectedByDefault: false,
fields: [
{
name: 'season',
label: 'Season',
},
{
name: 'target-audience',
label: 'Target audience',
},
],
},
{
name: 'book-category-attributes',
label: 'Book category attributes',
isSelectedByDefault: false,
fields: [
{
name: 'genre',
label: 'Genre',
},
{
name: 'age-group',
label: 'Age group',
},
],
},
]
}
]}
onClose={() => {
...
}}
/>
Properties
| Props | Type | Required | Default | Description |
| -------------------------------------------- | ------------------------------------------------------- | :--------------------------------------------------: | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| isOpen
| boolean
| | false
| Controls whether the export modal is open or closed |
| outputFormat
| string
Possible values: csv
, json
| | csv
| The file format to export |
| onExportSuccess
| function
| | | Callback function that is called when the export operation is successful |
| 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 |
| resourceType
| string
| ✅ | | The type of the resource, example: category
, product
...
| filters
| Filters
| | | Filters can be set as simple string for query predicates or as a search query
object for Search API filters, such as the Product Search API.
| totalResourcesCount
| number
| ✅ | | The count of all resources of identified resourceType
|
| selectedResourceIds
| array
| | | Array of Ids of the selected resources |
| fieldGroups
| array
| ✅ | | Array of the grouped fields
to export. |
| fieldGroups[].groupLabel
| string
| ✅ | | The label of the field group to be shown in the export modal |
| fieldGroups[].groupName
| string
| ✅ | | The name of the field group used to determine the state of expanded groups |
| fieldGroups[].isExpanded
| string
| | false
| This property used to control the default state of each expandable group section in the UI. If isExpanded
is set to true
, then the corresponding group will be expanded when the component loads. The default value is false
which means unless explicitly set to true
, the group will be collapsed on initial load |
| fieldGroups[].fields
| array
| ✅ | | Array of the fields to export. The fields must align with the commercetools API schema. Field can have nested fields
array. |
| fieldGroups[].fields[].name
| string
| ✅ | | A string that represents the unique identifier for each field. The leaf fields must align with the commercetools HTTP API fields, while parent fields can be developer-specific and created for grouping purposes. |
| fieldGroups[].fields[].label
| string
| ✅ | | The label of the field to be shown in the export modal |
| 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 |
| fieldGroups[].fields[].extendedFieldNames
| array
| | | An array of additional field names that should be included along with the main field name when exporting data. |
| fieldGroups[].fields[].dependentGroupNames
| array
| | | The array of group names provided determines the state of the checkbox. If any of the groups mentioned in the dependentGroupNames
has at least one checkbox selected, then the field is automatically selected. Optionally, dependentFieldNames
can be used to specify particular fields within the group. Note: The field will be readonly if it has dependencies. |
| fieldGroups[].fields[].dependentFieldNames
| array
| | | The array of field names of specific fields within the group to determine the state of the checkbox. If any of the specified fields in the dependentFieldNames
are checked, the field is automatically selected. |
| fieldGroups[].fields[].isSelectedByDefault
| boolean
| | false
| 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. |
| fieldGroups[].fields[].isExpandable
| boolean
| | false
| isExpandable
property indicates if the field can be expanded/collapsed on the UI. If the isExpandable
is passed as true, then a expand/collapse button is displayed on the UI to control |
| fieldGroups[].fields[].isExpanded
| boolean
| | false
| This property is used along with fieldGroups[].fields[].isExpandable
to control the default state of each expandable fields in the UI. If fieldGroups[].fields[].isExpanded
is set to true
, then the corresponding field will be expanded when the component loads. The default value is false
which means unless explicitly set to true
, the field will be collapsed on initial load |
| 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 |
Releasing
This package uses changesets
in order to do releases to NPM.
In case you want to publish a new version with the latest changes you need to:
- Add a changeset with
pnpm changeset
and select@commercetools-frontend-extensions/export-resources-modal
as the modified package. - Some options would be appear in order to do the release:
patch
: use this release for fixes or small changesminor
: use this release for depenency upgrades or medium changesmajor
: use this release for breaking changes
- 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.
- e.g:
feat(utils): add utils for dates
- e.g:
- Push the
changeset
to your branch and GitHub actions will detect that the PR contains changes that affect the published library. - 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. - Make sure that everything is correct and then merge
Version Packages
PR. - Wait until the new version is available in NPM and then deploy the custom in CircleCI.
Canary releases
Canary releases are automatically published to the distribution channel via CI following a successful build and merge to the main branch.
i18n
The repo is configured with an integration with Transifex. The process for i18n is the same as the Merchant Center uses.
pnpm i18n:build
for adding the new keys to transifex.
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).
Whenever the translators finish translations and mark them as done, the repo will receive a PR (per language) for adding translated messages.
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)