3.7.0 • Published 8 days ago

@commercetools-frontend-extensions/export-resources-modal v3.7.0

Weekly downloads
-
License
BSD-3-Clause
Repository
-
Last release
8 days 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}
    exportType="all"
    outputFormat="csv"
    resourceType="category"
    totalResourcesCount={143}
    fields={[
      {
        name: 'key',
        label: 'Category key',
        isRequired: true
      },
      {
        name: 'externalId',
        label: 'External id',
        isSelectedByDefault: false,
      },
      { name: 'createdAt', label: 'Created at' },
      { name: 'lastModifiedAt', label: 'Last modified at' },
      { name: 'name', label: 'Name' },
      {
        name: 'parent',
        fields: [
          {
            name: 'name',
            label: 'Parent name',
          },
          {
            name: 'key',
            label: 'Parent key',
          },
        ],
      },
      {
        name: 'id',
        label: 'Id',
        isSelectedByDefault: false,
      },
    ]}
    customFields={[
      {
        type:{
          key: 'general-category-attributes',
          label: 'General category attributes',
          resourceTypeIds: ['category'],
        },
        fields: [
          {
            name: 'season',
            label: 'Season',
          },
          {
            name: 'target-audience',
            label: 'Target audience',
          },
        ],
      },
      {
        type:{
          key: 'book-category-attributes',
          label: 'Book category attributes',
          resourceTypeIds: ['category', 'asset'],
        },
        fields: [
          {
            name: 'genre',
            label: 'Genre',
          },
          {
            name: 'age-group',
            label: 'Age group',
          },
        ],
      }
    ]}
    renderProperties={()=>(
      <>
        - The category parent is referenced by externalId or key.
      </>
    )}
    onClose={() => {
      ...
    }}
/>

// Use case: Exporting only selected resources by their IDs
<ExportResourcesModal
    isOpen={true}
    exportType="selected"
    outputFormat="csv"
    resourceType="category"
    selectedResourceIds={['02ed9a7d-7c1f-40da-b2b7-4cca6752bf29', '04051276-1641-4e01-a03e-d4de16b7e4eb', 'ac7d9f7b-5c7d-4dd3-b82b-8555ab4a2a6e']}
    fields={[
      {
        name: 'key',
        label: 'Category key',
        isRequired: true,
      },
      {
        name: 'externalId',
        label: 'External id',
        isSelectedByDefault: false,
      },
      { name: 'createdAt', label: 'Created at' },
      { name: 'lastModifiedAt', label: 'Last modified at' },
      { name: 'name', label: 'Name' },
      {
        name: 'parent',
        fields: [
          {
            name: 'name',
            label: 'Parent name',
          },
          {
            name: 'key',
            label: 'Parent key',
          },
        ],
      },
      {
        name: 'id',
        label: 'Id',
        isSelectedByDefault: false,
      },
    ]}
    customFields={[
      {
        type:{
          key: 'general-category-attributes',
          label: 'General category attributes',
          resourceTypeIds: ['category'],
        },
        fields: [
          {
            name: 'season',
            label: 'Season',
          },
          {
            name: 'target-audience',
            label: 'Target audience',
          },
        ],
      },
      {
        type:{
          key: 'book-category-attributes',
          label: 'Book category attributes',
          resourceTypeIds: ['category', 'asset'],
        },
        fields: [
          {
            name: 'genre',
            label: 'Genre',
          },
          {
            name: 'age-group',
            label: 'Age group',
          },
        ],
      }
    ]}
    renderProperties={()=>(
      <>
         - The category parent is referenced by externalId or key.
      </>
    )}
    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...
totalResourcesCountnumber(✅) Required only if the exportType is allThe count of all resources of identified resourceType
exportTypestring Possible values:all and selectedallThe type of export, so either export all resources or export only selected resources
selectedResourceIdsarray(✅) Required only if the exportType is selectedArray of Ids of the selected resources
fieldsarrayArray of the fields to export. The fields must align with the commercetools API schema
fields[].namestringA string that represents the unique identifier for each field
fields[].labelstringThe label of the field to be shown in the export modal
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
fields[].isSelectedByDefaultbooleantrueThis 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.
customFieldsarrayArray of objects, each representing a group of custom fields defined under a specific type.
customFields[].typestringThe type object.
customFields[].type.keystringThe unique identifier for the type.
customFields[].type.labelstringThe label of the type to be shown in the export modal.
customFields[].type.resourceTypeIdsstring[]An array of resource type IDs for which the type is defined.
customFields[].fieldsarrayAn array of objects with custom fields defined under the type represented by type.key.
customFields[].fields[].namestringThe name of the custom field.
customFields[].fields[].labelstringThe label of the custom field to be shown in the export modal. This should match the label of the custom field in the selected locale.
renderPropertiesfunctionA prop to render properties that are resource-specific

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.

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)

3.7.0

8 days ago

3.6.0

14 days ago

3.5.1

16 days ago

3.5.0

27 days ago

3.5.0-next.4

28 days ago

3.5.0-next.3

29 days ago

3.4.3-next.2

1 month ago

3.4.3-next.0

2 months ago

3.4.3-next.1

2 months ago

3.4.0

2 months ago

3.4.2

2 months ago

3.4.1

2 months ago

3.3.0

2 months ago

3.2.1

3 months ago

3.2.0

3 months ago

3.1.0

3 months ago

3.0.0

3 months ago

1.5.3

3 months ago

1.5.2

3 months ago

1.5.1

3 months ago

1.5.0

3 months ago

1.4.1

4 months ago

1.4.0

4 months ago

1.3.7

6 months ago

1.3.6

7 months ago

1.3.5

7 months ago

1.3.4

8 months ago

1.3.3

9 months ago

1.3.2

9 months ago

1.3.8

5 months ago

1.3.1

1 year ago

1.3.0

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.2.0

1 year ago

1.1.0

1 year ago

1.0.8

1 year ago

1.0.2

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

2.0.0

1 year ago

0.1.0

2 years ago