From 5ae725a5d5bae35ad927bea9adc207c04850135b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Luiz=20de=20Castro?= Date: Mon, 27 Dec 2021 08:24:26 -0300 Subject: [PATCH 01/10] merging the quantity being added with the quantity already in the order form, instead of replacing the quantity --- react/AutocompleteBlock.tsx | 9 +++++++++ react/TextAreaBlock.tsx | 28 ++++++++++++++++++++++------ react/UploadBlock.tsx | 28 ++++++++++++++++++++++------ 3 files changed, 53 insertions(+), 12 deletions(-) diff --git a/react/AutocompleteBlock.tsx b/react/AutocompleteBlock.tsx index 7cb66c7b..cbf7e448 100644 --- a/react/AutocompleteBlock.tsx +++ b/react/AutocompleteBlock.tsx @@ -69,6 +69,7 @@ const AutocompleteBlock: StorefrontFunctionComponent { return intl.formatMessage(message) @@ -115,9 +116,17 @@ const AutocompleteBlock: StorefrontFunctionComponent { + let currentItemsInCart = orderForm.orderForm.items const mutationResult = await addToCart({ variables: { items: items.map((item: any) => { + let existsInCurrentOrder = currentItemsInCart.filter( + el => el.id === item.id.toString() + ) + if (existsInCurrentOrder.length > 0) { + item['quantity'] = + item['quantity'] + existsInCurrentOrder[0]['quantity'] + } return { ...item, } diff --git a/react/TextAreaBlock.tsx b/react/TextAreaBlock.tsx index 3597d1fa..94080d14 100644 --- a/react/TextAreaBlock.tsx +++ b/react/TextAreaBlock.tsx @@ -66,6 +66,7 @@ const TextAreaBlock: StorefrontFunctionComponent { @@ -97,9 +98,17 @@ const TextAreaBlock: StorefrontFunctionComponent { + let currentItemsInCart = orderForm.orderForm.items const mutationResult = await addToCart({ variables: { items: items.map((item: any) => { + let existsInCurrentOrder = currentItemsInCart.filter( + el => el.id === item.id.toString() + ) + if (existsInCurrentOrder.length > 0) { + item['quantity'] = + item['quantity'] + existsInCurrentOrder[0]['quantity'] + } return { ...item, } @@ -211,13 +220,20 @@ const TextAreaBlock: StorefrontFunctionComponent { + return internalItems.reduce((acc, val) => { + const { id, quantity } = val + const ind = acc.findIndex(el => el.id === id) + if (ind !== -1) { + acc[ind].quantity += quantity + } else { + acc.push(val) } - - callAddToCart(items) + return acc + }, []) + } + const mergedItems = merge(items) + callAddToCart(mergedItems) } const onRefidLoading = (data: boolean) => { setRefIdLoading(data) diff --git a/react/UploadBlock.tsx b/react/UploadBlock.tsx index 776bb495..dc1a4f9f 100644 --- a/react/UploadBlock.tsx +++ b/react/UploadBlock.tsx @@ -64,6 +64,7 @@ const UploadBlock: StorefrontFunctionComponent { @@ -216,9 +217,17 @@ const UploadBlock: StorefrontFunctionComponent { + let existsInCurrentOrder = currentItemsInCart.filter( + el => el.id === item.id.toString() + ) + if (existsInCurrentOrder.length > 0) { + item['quantity'] = + item['quantity'] + existsInCurrentOrder[0]['quantity'] + } return { ...item, } @@ -289,13 +298,20 @@ const UploadBlock: StorefrontFunctionComponent { + return internalItems.reduce((acc, val) => { + const { id, quantity } = val + const ind = acc.findIndex(el => el.id === id) + if (ind !== -1) { + acc[ind].quantity += quantity + } else { + acc.push(val) } - - callAddToCart(items) + return acc + }, []) + } + const mergedItems = merge(items) + callAddToCart(mergedItems) } const CSS_HANDLES = [ From 814136be40795247ffd0058aaf1404d19d0a014d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Luiz=20de=20Castro?= Date: Wed, 29 Dec 2021 00:44:40 -0300 Subject: [PATCH 02/10] [Code Enhancement] Adjusting the code to guarentee a better quality, changing lets to consts and using array destructuring --- react/AutocompleteBlock.tsx | 9 ++++----- react/TextAreaBlock.tsx | 7 +++---- react/UploadBlock.tsx | 7 +++---- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/react/AutocompleteBlock.tsx b/react/AutocompleteBlock.tsx index cbf7e448..2ca612af 100644 --- a/react/AutocompleteBlock.tsx +++ b/react/AutocompleteBlock.tsx @@ -116,16 +116,15 @@ const AutocompleteBlock: StorefrontFunctionComponent { - let currentItemsInCart = orderForm.orderForm.items + const currentItemsInCart = orderForm.orderForm.items const mutationResult = await addToCart({ variables: { items: items.map((item: any) => { - let existsInCurrentOrder = currentItemsInCart.filter( + const [existsInCurrentOrder] = currentItemsInCart.filter( el => el.id === item.id.toString() ) - if (existsInCurrentOrder.length > 0) { - item['quantity'] = - item['quantity'] + existsInCurrentOrder[0]['quantity'] + if (existsInCurrentOrder?.length > 0) { + item.quantity = item.quantity + existsInCurrentOrder.quantity } return { ...item, diff --git a/react/TextAreaBlock.tsx b/react/TextAreaBlock.tsx index 94080d14..863f5732 100644 --- a/react/TextAreaBlock.tsx +++ b/react/TextAreaBlock.tsx @@ -102,12 +102,11 @@ const TextAreaBlock: StorefrontFunctionComponent { - let existsInCurrentOrder = currentItemsInCart.filter( + const [existsInCurrentOrder] = currentItemsInCart.filter( el => el.id === item.id.toString() ) - if (existsInCurrentOrder.length > 0) { - item['quantity'] = - item['quantity'] + existsInCurrentOrder[0]['quantity'] + if (existsInCurrentOrder?.length > 0) { + item.quantity = item.quantity + existsInCurrentOrder.quantity } return { ...item, diff --git a/react/UploadBlock.tsx b/react/UploadBlock.tsx index dc1a4f9f..2b345d98 100644 --- a/react/UploadBlock.tsx +++ b/react/UploadBlock.tsx @@ -221,12 +221,11 @@ const UploadBlock: StorefrontFunctionComponent { - let existsInCurrentOrder = currentItemsInCart.filter( + const [existsInCurrentOrder] = currentItemsInCart.filter( el => el.id === item.id.toString() ) - if (existsInCurrentOrder.length > 0) { - item['quantity'] = - item['quantity'] + existsInCurrentOrder[0]['quantity'] + if (existsInCurrentOrder?.length > 0) { + item.quantity = item.quantity + existsInCurrentOrder.quantity } return { ...item, From 6b0abb7bf9b31a534f73efe7c678439412584dba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Luiz=20de=20Castro?= Date: Wed, 29 Dec 2021 01:11:55 -0300 Subject: [PATCH 03/10] [Code Enhancement] Changing lets to consts --- react/TextAreaBlock.tsx | 2 +- react/UploadBlock.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/react/TextAreaBlock.tsx b/react/TextAreaBlock.tsx index 863f5732..d0ef40b6 100644 --- a/react/TextAreaBlock.tsx +++ b/react/TextAreaBlock.tsx @@ -98,7 +98,7 @@ const TextAreaBlock: StorefrontFunctionComponent { - let currentItemsInCart = orderForm.orderForm.items + const currentItemsInCart = orderForm.orderForm.items const mutationResult = await addToCart({ variables: { items: items.map((item: any) => { diff --git a/react/UploadBlock.tsx b/react/UploadBlock.tsx index 2b345d98..e3f94ace 100644 --- a/react/UploadBlock.tsx +++ b/react/UploadBlock.tsx @@ -217,7 +217,7 @@ const UploadBlock: StorefrontFunctionComponent { From f5236f4a6c86cc14d1b33f8d5b0ed4b957aa7173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Luiz=20de=20Castro?= Date: Wed, 29 Dec 2021 01:41:06 -0300 Subject: [PATCH 04/10] [Code Enhancement] changing the condition where we check if the item exists --- react/AutocompleteBlock.tsx | 2 +- react/TextAreaBlock.tsx | 2 +- react/UploadBlock.tsx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/react/AutocompleteBlock.tsx b/react/AutocompleteBlock.tsx index 2ca612af..07f12ed2 100644 --- a/react/AutocompleteBlock.tsx +++ b/react/AutocompleteBlock.tsx @@ -123,7 +123,7 @@ const AutocompleteBlock: StorefrontFunctionComponent el.id === item.id.toString() ) - if (existsInCurrentOrder?.length > 0) { + if (existsInCurrentOrder) { item.quantity = item.quantity + existsInCurrentOrder.quantity } return { diff --git a/react/TextAreaBlock.tsx b/react/TextAreaBlock.tsx index d0ef40b6..3ed3dc2f 100644 --- a/react/TextAreaBlock.tsx +++ b/react/TextAreaBlock.tsx @@ -105,7 +105,7 @@ const TextAreaBlock: StorefrontFunctionComponent el.id === item.id.toString() ) - if (existsInCurrentOrder?.length > 0) { + if (existsInCurrentOrder) { item.quantity = item.quantity + existsInCurrentOrder.quantity } return { diff --git a/react/UploadBlock.tsx b/react/UploadBlock.tsx index e3f94ace..8dafc22d 100644 --- a/react/UploadBlock.tsx +++ b/react/UploadBlock.tsx @@ -224,7 +224,7 @@ const UploadBlock: StorefrontFunctionComponent el.id === item.id.toString() ) - if (existsInCurrentOrder?.length > 0) { + if (existsInCurrentOrder) { item.quantity = item.quantity + existsInCurrentOrder.quantity } return { From 0fffcd3e222027311d08510e016027f3b20bf89f Mon Sep 17 00:00:00 2001 From: wender <24723+wender@users.noreply.github.com> Date: Wed, 29 Dec 2021 15:37:47 +0000 Subject: [PATCH 05/10] Release v3.4.0 --- CHANGELOG.md | 2 ++ manifest.json | 2 +- node/package.json | 2 +- react/package.json | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27ce70a8..f3938a60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +## [3.4.0] - 2021-12-29 + ## [3.3.2] - 2021-12-21 ### Fixed diff --git a/manifest.json b/manifest.json index 60d1543d..c9557777 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "vendor": "vtex", "name": "quickorder", - "version": "3.3.2", + "version": "3.4.0", "title": "Quickorder", "description": "Allow users to add multiple products to the cart at once", "defaultLocale": "en-US", diff --git a/node/package.json b/node/package.json index 2fb3a5d7..e91b47ca 100644 --- a/node/package.json +++ b/node/package.json @@ -53,5 +53,5 @@ "vtex.store-resources": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-resources@0.73.0/public/_types/react", "vtex.styleguide": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.styleguide@9.132.1/public/@types/vtex.styleguide" }, - "version": "3.3.2" + "version": "3.4.0" } diff --git a/react/package.json b/react/package.json index 6e4c0ec9..7e1f5091 100644 --- a/react/package.json +++ b/react/package.json @@ -51,5 +51,5 @@ "vtex.store-resources": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-resources@0.73.0/public/_types/react", "vtex.styleguide": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.styleguide@9.132.1/public/@types/vtex.styleguide" }, - "version": "3.3.2" + "version": "3.4.0" } From dc17c43b7a105cb5d236332d482ac941e2299c4f Mon Sep 17 00:00:00 2001 From: Charles Santos Date: Fri, 7 Jan 2022 17:30:43 -0300 Subject: [PATCH 06/10] ADD Quality Engineering tasks --- .github/sonarcloud.yml | 49 ++++++++++++++++++++++++++++++++++++++ .github/workflows/lint.yml | 32 +++++++++++++++++++++++++ sonar-project.properties | 12 ++++++++++ 3 files changed, 93 insertions(+) create mode 100644 .github/sonarcloud.yml create mode 100644 .github/workflows/lint.yml create mode 100644 sonar-project.properties diff --git a/.github/sonarcloud.yml b/.github/sonarcloud.yml new file mode 100644 index 00000000..80db5a6a --- /dev/null +++ b/.github/sonarcloud.yml @@ -0,0 +1,49 @@ +name: "[QE] SonarCloud" + +on: + push: + branches: + - master + - main + - release/* + - feature/* + - fix/* + - chore/* + pull_request: + types: [opened, synchronize, reopened] + +jobs: + sonarcloud: + name: SonarCloud + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Cache for node_modules + uses: actions/cache@v2 + with: + path: "**/node_modules" + key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }} + + - name: Install base packages + run: yarn install --frozen-lockfile + if: steps.cache-node-modules.outputs.cache-hit != 'true' + + - name: Install node packages + run: yarn install --frozen-lockfile + working-directory: ./node + if: steps.cache-node-modules.outputs.cache-hit != 'true' + + - name: Install react packages + run: yarn install --frozen-lockfile + working-directory: ./react + if: steps.cache-node-modules.outputs.cache-hit != 'true' + + - name: SonarCloud Scan + uses: SonarSource/sonarcloud-github-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..71a67a4b --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,32 @@ +name: "[QE] Lint" + +on: + workflow_dispatch: + pull_request: + branches: + - master + - main + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - uses: actions/setup-node@master + with: + node-version: 12.x + env: + RUNNER_TEMP: /tmp + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: 'echo "::set-output name=dir::$(yarn cache dir)"' + - uses: actions/cache@v1 + id: yarn-cache + with: + path: "${{ steps.yarn-cache-dir-path.outputs.dir }}" + key: "${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}" + restore-keys: | + ${{ runner.os }}-yarn- + - name: Lint project + uses: vtex/action-lint@master \ No newline at end of file diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 00000000..9df466d2 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,12 @@ +sonar.projectKey=thyarles_quickorder +sonar.organization=thyarles + +# This is the name and version displayed in the SonarCloud UI. +#sonar.projectName=quickorder +#sonar.projectVersion=1.0 + +# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. +#sonar.sources=. + +# Encoding of the source code. Default is default system encoding +#sonar.sourceEncoding=UTF-8 From a560f83ad9e0cbbc72710d953f6ba949985f71e6 Mon Sep 17 00:00:00 2001 From: Charles Santos Date: Fri, 7 Jan 2022 17:32:07 -0300 Subject: [PATCH 07/10] FIX file location --- .github/workflows/sonarcloud.yml | 49 ++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 .github/workflows/sonarcloud.yml diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml new file mode 100644 index 00000000..80db5a6a --- /dev/null +++ b/.github/workflows/sonarcloud.yml @@ -0,0 +1,49 @@ +name: "[QE] SonarCloud" + +on: + push: + branches: + - master + - main + - release/* + - feature/* + - fix/* + - chore/* + pull_request: + types: [opened, synchronize, reopened] + +jobs: + sonarcloud: + name: SonarCloud + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Cache for node_modules + uses: actions/cache@v2 + with: + path: "**/node_modules" + key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }} + + - name: Install base packages + run: yarn install --frozen-lockfile + if: steps.cache-node-modules.outputs.cache-hit != 'true' + + - name: Install node packages + run: yarn install --frozen-lockfile + working-directory: ./node + if: steps.cache-node-modules.outputs.cache-hit != 'true' + + - name: Install react packages + run: yarn install --frozen-lockfile + working-directory: ./react + if: steps.cache-node-modules.outputs.cache-hit != 'true' + + - name: SonarCloud Scan + uses: SonarSource/sonarcloud-github-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} \ No newline at end of file From 920370b806cb63d0d887510432030f11db906117 Mon Sep 17 00:00:00 2001 From: Charles Santos Date: Fri, 7 Jan 2022 17:32:29 -0300 Subject: [PATCH 08/10] FIX File location --- .github/sonarcloud.yml | 49 ------------------------------------------ 1 file changed, 49 deletions(-) delete mode 100644 .github/sonarcloud.yml diff --git a/.github/sonarcloud.yml b/.github/sonarcloud.yml deleted file mode 100644 index 80db5a6a..00000000 --- a/.github/sonarcloud.yml +++ /dev/null @@ -1,49 +0,0 @@ -name: "[QE] SonarCloud" - -on: - push: - branches: - - master - - main - - release/* - - feature/* - - fix/* - - chore/* - pull_request: - types: [opened, synchronize, reopened] - -jobs: - sonarcloud: - name: SonarCloud - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - - name: Cache for node_modules - uses: actions/cache@v2 - with: - path: "**/node_modules" - key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }} - - - name: Install base packages - run: yarn install --frozen-lockfile - if: steps.cache-node-modules.outputs.cache-hit != 'true' - - - name: Install node packages - run: yarn install --frozen-lockfile - working-directory: ./node - if: steps.cache-node-modules.outputs.cache-hit != 'true' - - - name: Install react packages - run: yarn install --frozen-lockfile - working-directory: ./react - if: steps.cache-node-modules.outputs.cache-hit != 'true' - - - name: SonarCloud Scan - uses: SonarSource/sonarcloud-github-action@master - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} \ No newline at end of file From f790cf6c390e55a721e39d75e0583ba22891552f Mon Sep 17 00:00:00 2001 From: Charles Santos Date: Fri, 7 Jan 2022 17:35:03 -0300 Subject: [PATCH 09/10] FIX org name --- sonar-project.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sonar-project.properties b/sonar-project.properties index 9df466d2..4d8acd43 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,5 +1,5 @@ -sonar.projectKey=thyarles_quickorder -sonar.organization=thyarles +sonar.projectKey=vtex-apps_quickorder +sonar.organization=vtex-apps # This is the name and version displayed in the SonarCloud UI. #sonar.projectName=quickorder From 4dd06ea84dc26bd01a62db91e8bdf29f2dacde00 Mon Sep 17 00:00:00 2001 From: wender <24723+wender@users.noreply.github.com> Date: Fri, 7 Jan 2022 21:55:59 +0000 Subject: [PATCH 10/10] Release v3.4.1 --- CHANGELOG.md | 2 ++ manifest.json | 2 +- node/package.json | 2 +- react/package.json | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3938a60..3160bed5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +## [3.4.1] - 2022-01-07 + ## [3.4.0] - 2021-12-29 ## [3.3.2] - 2021-12-21 diff --git a/manifest.json b/manifest.json index c9557777..5a42ef5e 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "vendor": "vtex", "name": "quickorder", - "version": "3.4.0", + "version": "3.4.1", "title": "Quickorder", "description": "Allow users to add multiple products to the cart at once", "defaultLocale": "en-US", diff --git a/node/package.json b/node/package.json index e91b47ca..2201bc56 100644 --- a/node/package.json +++ b/node/package.json @@ -53,5 +53,5 @@ "vtex.store-resources": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-resources@0.73.0/public/_types/react", "vtex.styleguide": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.styleguide@9.132.1/public/@types/vtex.styleguide" }, - "version": "3.4.0" + "version": "3.4.1" } diff --git a/react/package.json b/react/package.json index 7e1f5091..5205c488 100644 --- a/react/package.json +++ b/react/package.json @@ -51,5 +51,5 @@ "vtex.store-resources": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-resources@0.73.0/public/_types/react", "vtex.styleguide": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.styleguide@9.132.1/public/@types/vtex.styleguide" }, - "version": "3.4.0" + "version": "3.4.1" }