4.6.23 • Published 8 months ago

@commercetools-frontend-extensions/export-resources-modal v4.6.23

Weekly downloads
-
License
BSD-3-Clause
Repository
-
Last release
8 months ago

@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

PropsTypeRequiredDefaultDescription
isOpenbooleanfalseControls whether the export modal is open or closed
outputFormatstringPossible values: csv, jsoncsvThe file format to export
onExportSuccessfunctionCallback function that is called when the export operation is successful
onClosefunctionCallback 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
resourceTypestringThe type of the resource, example: category, product...
filtersFiltersFilters 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.
totalResourcesCountnumberThe count of all resources of identified resourceType
selectedResourceIdsarrayArray of Ids of the selected resources
fieldGroupsarrayArray of the grouped fields to export.
fieldGroups[].groupLabelstringThe label of the field group to be shown in the export modal
fieldGroups[].groupNamestringThe name of the field group used to determine the state of expanded groups
fieldGroups[].isExpandedstringfalseThis 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[].fieldsarrayArray of the fields to export. The fields must align with the commercetools API schema. Field can have nested fields array.
fieldGroups[].fields[].namestringA 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[].labelstringThe label of the field to be shown in the export modal
fieldGroups[].fields[].isRequiredbooleanfalseisRequired 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[].extendedFieldNamesarrayAn array of additional field names that should be included along with the main field name when exporting data.
fieldGroups[].fields[].dependentGroupNamesarrayThe 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[].dependentFieldNamesarrayThe 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[].isSelectedByDefaultbooleanfalseThis 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[].isExpandablebooleanfalseisExpandable 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[].isExpandedbooleanfalseThis 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
fieldOrderstring[]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:

  1. Add a changeset with pnpm changeset and select @commercetools-frontend-extensions/export-resources-modal as the modified package.
  2. Some options would be appear in order to do the release:
    • patch: use this release for fixes or small changes
    • minor: use this release for depenency upgrades or medium changes
    • major: use this release for breaking changes
  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.
    • e.g: feat(utils): add utils for dates
  4. Push the changeset to your branch and GitHub actions will detect that the PR contains changes that affect the published library.
  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.
  6. Make sure that everything is correct and then merge Version Packages PR.
  7. 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)

4.6.23

8 months ago

4.6.22

8 months ago

4.6.20

8 months ago

4.6.21

8 months ago

4.6.15

8 months ago

4.6.16

8 months ago

4.6.13

9 months ago

4.6.14

9 months ago

4.6.19

8 months ago

4.6.17

8 months ago

4.6.18

8 months ago

4.6.12

9 months ago

4.6.7

9 months ago

4.6.6

9 months ago

4.6.9

9 months ago

4.6.8

9 months ago

4.6.3

10 months ago

4.6.2

10 months ago

4.6.5

9 months ago

4.6.4

9 months ago

4.6.11

9 months ago

4.6.10

9 months ago

4.5.4

10 months ago

4.5.3

10 months ago

4.5.6

10 months ago

4.5.5

10 months ago

4.4.1

11 months ago

4.0.5

1 year ago

4.4.0

11 months ago

4.0.4

1 year ago

4.4.3

10 months ago

4.4.2

11 months ago

4.4.5

10 months ago

4.4.4

10 months ago

4.4.6

10 months ago

4.3.2

11 months ago

4.3.1

11 months ago

4.3.4

11 months ago

4.3.3

11 months ago

4.3.0

11 months ago

4.3.5

11 months ago

4.6.1

10 months ago

4.6.0

10 months ago

4.2.1

11 months ago

4.2.0

11 months ago

4.5.0

10 months ago

4.1.3

12 months ago

4.5.2

10 months ago

4.5.1

10 months ago

4.1.0

1 year ago

4.1.2

12 months ago

4.1.1

1 year ago

4.0.3

1 year ago

4.0.2

1 year ago

4.0.1

1 year ago

4.0.0

1 year ago

3.7.0

1 year ago

3.6.0

1 year ago

3.5.1

1 year ago

3.5.0

1 year ago

3.5.0-next.4

1 year ago

3.5.0-next.3

1 year ago

3.4.3-next.2

1 year ago

3.4.3-next.0

1 year ago

3.4.3-next.1

1 year ago

3.4.0

1 year ago

3.4.2

1 year ago

3.4.1

1 year ago

3.3.0

1 year ago

3.2.1

1 year ago

3.2.0

1 year ago

3.1.0

1 year ago

3.0.0

1 year ago

1.5.3

1 year ago

1.5.2

1 year ago

1.5.1

1 year ago

1.5.0

1 year ago

1.4.1

1 year ago

1.4.0

1 year ago

1.3.7

2 years ago

1.3.6

2 years ago

1.3.5

2 years ago

1.3.4

2 years ago

1.3.3

2 years ago

1.3.2

2 years ago

1.3.8

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.8

2 years ago

1.0.2

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

2.0.0

2 years ago

0.1.0

3 years ago