Skip to content

Commit

Permalink
fix(FOROME-311): show accepted & rejected variants and include/exclud…
Browse files Browse the repository at this point in the history
…e final step

fix(FOROME-311): show accepted & rejected variants and include/exclud…
  • Loading branch information
YaroslavTrefilovBraveDevelopers authored Feb 8, 2022
2 parents 21a8fff + 2221d0f commit 2f6312d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/pages/filter/ui/query-builder/ui/final-step.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const FinalStep = observer(({ index }: IProps): ReactElement => {
const shouldMakeActive = classList.includes('step-content-area')

if (shouldMakeActive) {
makeStepActive(stepIndex)
makeStepActive(stepIndex, 'isActive', true)
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/store/dtree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,12 @@ class DtreeStore {

getStepIndexForApi = (index: number) => {
const indexes = toJS(this.dtreeStepIndices)
const currentIndex = Number(indexes[index])
const shouldGetAnotherIndex = index === indexes.length

const currentIndex = shouldGetAnotherIndex
? +indexes[index - 1] + 1
: +indexes[index]

const stepIndex = indexes.length === 0 ? 0 : currentIndex

const pointsIndexes = Object.keys(this.dtree?.points)
Expand Down
19 changes: 16 additions & 3 deletions src/utils/makeStepActive.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { toJS } from 'mobx'

import dtreeStore from '@store/dtree'

export const makeStepActive = (
index: number,
option: 'isActive' | 'isReturnedVariantsActive' = 'isActive',
isFinalStep = false,
) => {
const currentActiveIndex = dtreeStore.stepData.findIndex(
element => element[option] === true,
Expand All @@ -18,11 +21,21 @@ export const makeStepActive = (

dtreeStore.setStepActive(index, option)

const localStepData = toJS(dtreeStore.stepData)
const emptyStepList = localStepData.filter(
element => element.groups.length === 0 && !element.isFinalStep,
)

const calculatedIndex = index - emptyStepList.length

const indexForApi = isReturnedVariants
? dtreeStore.getStepIndexForApi(index) + 1
: dtreeStore.getStepIndexForApi(index)
? dtreeStore.getStepIndexForApi(calculatedIndex) + 1
: dtreeStore.getStepIndexForApi(calculatedIndex)

const finalStepIndexForApi = dtreeStore.getStepIndexForApi(-1)
const currentIndexForApi = isFinalStep ? finalStepIndexForApi : indexForApi

const code = dtreeStore.dtreeCode

dtreeStore.fetchDtreeStatAsync(code, String(indexForApi))
dtreeStore.fetchDtreeStatAsync(code, String(currentIndexForApi))
}

0 comments on commit 2f6312d

Please sign in to comment.