Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/upload-only-xlsx-and-xls
Browse files Browse the repository at this point in the history
  • Loading branch information
JooLuiz authored Jan 10, 2022
2 parents 84583f5 + 4dd06ea commit cc53799
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 15 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -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
49 changes: 49 additions & 0 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
@@ -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 }}
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed

- Restricting the Quick Order Upload to accept only .xls and .xlsx files

## [3.4.1] - 2022-01-07

## [3.4.0] - 2021-12-29

## [3.3.2] - 2021-12-21

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"vendor": "vtex",
"name": "quickorder",
"version": "3.3.2",
"version": "3.4.1",
"title": "Quickorder",
"description": "Allow users to add multiple products to the cart at once",
"defaultLocale": "en-US",
Expand Down
2 changes: 1 addition & 1 deletion node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@
"vtex.store-resources": "http://vtex.vtexassets.com/_v/public/typings/v1/[email protected]/public/_types/react",
"vtex.styleguide": "http://vtex.vtexassets.com/_v/public/typings/v1/[email protected]/public/@types/vtex.styleguide"
},
"version": "3.3.2"
"version": "3.4.1"
}
8 changes: 8 additions & 0 deletions react/AutocompleteBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const AutocompleteBlock: StorefrontFunctionComponent<any &
const { promptOnCustomEvent } = settings

const { setOrderForm }: OrderFormContext = OrderForm.useOrderForm()
const orderForm = OrderForm.useOrderForm()

const translateMessage = (message: MessageDescriptor) => {
return intl.formatMessage(message)
Expand Down Expand Up @@ -115,9 +116,16 @@ const AutocompleteBlock: StorefrontFunctionComponent<any &

const { selectedItem, quantitySelected, unitMultiplier } = state
const callAddToCart = async (items: any) => {
const currentItemsInCart = orderForm.orderForm.items
const mutationResult = await addToCart({
variables: {
items: items.map((item: any) => {
const [existsInCurrentOrder] = currentItemsInCart.filter(
el => el.id === item.id.toString()
)
if (existsInCurrentOrder) {
item.quantity = item.quantity + existsInCurrentOrder.quantity
}
return {
...item,
}
Expand Down
27 changes: 21 additions & 6 deletions react/TextAreaBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const TextAreaBlock: StorefrontFunctionComponent<TextAreaBlockInterface &
const { promptOnCustomEvent } = settings

const { setOrderForm }: OrderFormContext = OrderForm.useOrderForm()
const orderForm = OrderForm.useOrderForm()
const { showToast } = useContext(ToastContext)

const translateMessage = (message: MessageDescriptor) => {
Expand Down Expand Up @@ -97,9 +98,16 @@ const TextAreaBlock: StorefrontFunctionComponent<TextAreaBlockInterface &
}

const callAddToCart = async (items: any) => {
const currentItemsInCart = orderForm.orderForm.items
const mutationResult = await addToCart({
variables: {
items: items.map((item: any) => {
const [existsInCurrentOrder] = currentItemsInCart.filter(
el => el.id === item.id.toString()
)
if (existsInCurrentOrder) {
item.quantity = item.quantity + existsInCurrentOrder.quantity
}
return {
...item,
}
Expand Down Expand Up @@ -211,13 +219,20 @@ const TextAreaBlock: StorefrontFunctionComponent<TextAreaBlockInterface &
seller,
}
})

if (items.length === 0) {
toastMessage({ success: false, isNewItem: false })
return
const merge = internalItems => {
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)
Expand Down
27 changes: 21 additions & 6 deletions react/UploadBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const UploadBlock: StorefrontFunctionComponent<UploadBlockInterface &
const { promptOnCustomEvent } = settings

const { setOrderForm }: OrderFormContext = OrderForm.useOrderForm()
const orderForm = OrderForm.useOrderForm()
const { showToast } = useContext(ToastContext)

const translateMessage = (message: MessageDescriptor) => {
Expand Down Expand Up @@ -216,9 +217,16 @@ const UploadBlock: StorefrontFunctionComponent<UploadBlockInterface &
for (let i = 0; i < loopCount; i++) {
const chunk = tempItems.splice(0, splitBy)
if (chunk.length) {
const currentItemsInCart = orderForm.orderForm.items
const mutationChunk = await addToCart({
variables: {
items: chunk.map((item: any) => {
const [existsInCurrentOrder] = currentItemsInCart.filter(
el => el.id === item.id.toString()
)
if (existsInCurrentOrder) {
item.quantity = item.quantity + existsInCurrentOrder.quantity
}
return {
...item,
}
Expand Down Expand Up @@ -289,13 +297,20 @@ const UploadBlock: StorefrontFunctionComponent<UploadBlockInterface &
seller,
}
})

if (items.length === 0) {
toastMessage({ success: false, isNewItem: false })
return
const merge = internalItems => {
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 = [
Expand Down
2 changes: 1 addition & 1 deletion react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
"vtex.store-resources": "http://vtex.vtexassets.com/_v/public/typings/v1/[email protected]/public/_types/react",
"vtex.styleguide": "http://vtex.vtexassets.com/_v/public/typings/v1/[email protected]/public/@types/vtex.styleguide"
},
"version": "3.3.2"
"version": "3.4.1"
}
12 changes: 12 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
sonar.projectKey=vtex-apps_quickorder
sonar.organization=vtex-apps

# 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

0 comments on commit cc53799

Please sign in to comment.