Skip to content

Commit

Permalink
feat(FOROME-1632): change a request for included/excluded variants (#946
Browse files Browse the repository at this point in the history
)

* feat(FOROME-1632): disable modal buttons on dashboard

* feat(FOROME-1632): change step index for request

* feat(FOROME-1632): move condition to store
  • Loading branch information
EvgeniySobolev authored Sep 16, 2022
1 parent e4e2877 commit 5679295
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ReactElement, useCallback } from 'react'
import { observer } from 'mobx-react-lite'

import dtreeStore from '@store/dtree'
import { Dialog } from '@ui/dialog'
import { CompoundHetCondition } from '@components/conditions/compound-het-condition'
import { AttributeKinds } from '@service-providers/common'
Expand All @@ -20,6 +21,8 @@ export const CompoundHetDialog = observer(
attributeSubKind,
} = funcStore

const { isOnDashboard } = dtreeStore

const { currentStepGroups } = modalsControlStore

const handleModals = () => {
Expand Down Expand Up @@ -75,7 +78,7 @@ export const CompoundHetDialog = observer(
currentStepGroups,
onClose: modalsVisibilityStore.closeCompoundHetDialog,
handleModals,
disabled: hasErrors,
disabled: hasErrors || isOnDashboard,
saveAttribute: () => handleSaveChanges(mode, param),
addAttribute: action => handleAddAttribute(action, mode, param),
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ReactElement, useCallback } from 'react'
import { observer } from 'mobx-react-lite'

import dtreeStore from '@store/dtree'
import { Dialog } from '@ui/dialog'
import { CompoundRequestCondition } from '@components/conditions/compound-request/compound-request-condition'
import { AttributeKinds } from '@service-providers/common'
Expand All @@ -24,6 +25,7 @@ export const CompoundRequestDialog = observer(
} = funcStore

const { currentStepGroups } = modalsControlStore
const { isOnDashboard } = dtreeStore

const handleModals = () => {
modalsVisibilityStore.closeCompoundRequestDialog()
Expand Down Expand Up @@ -82,7 +84,7 @@ export const CompoundRequestDialog = observer(
currentStepGroups,
onClose: modalsVisibilityStore.closeCompoundRequestDialog,
handleModals,
disabled: hasErrors,
disabled: hasErrors || isOnDashboard,
saveAttribute: () => handleSaveChanges(mode, param),
addAttribute: action => handleAddAttribute(action, mode, param),
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ReactElement, useCallback } from 'react'
import { observer } from 'mobx-react-lite'

import dtreeStore from '@store/dtree'
import { Dialog } from '@ui/dialog'
import { CustomInheritanceModeCondition } from '@components/conditions/custom-inheritance-mode'
import { AttributeKinds } from '@service-providers/common'
Expand All @@ -23,6 +24,7 @@ export const CustomInheritanceModeDialog = observer(
} = funcStore

const { currentStepGroups } = modalsControlStore
const { isOnDashboard } = dtreeStore

const handleModals = () => {
modalsVisibilityStore.closeCustomInheritanceModeDialog()
Expand Down Expand Up @@ -79,7 +81,7 @@ export const CustomInheritanceModeDialog = observer(
currentStepGroups,
onClose: modalsVisibilityStore.closeCustomInheritanceModeDialog,
handleModals,
disabled: hasErrors,
disabled: hasErrors || isOnDashboard,
saveAttribute: () => handleSaveChanges(mode, param),
addAttribute: action => handleAddAttribute(action, mode, param),
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ReactElement, useCallback } from 'react'
import { observer } from 'mobx-react-lite'

import dtreeStore from '@store/dtree'
import { Dialog } from '@ui/dialog'
import { DEFAULT_COUNT, EnumCondition } from '@components/conditions/enum'
import dashboardStore from '@pages/filter/common/dashboard'
Expand All @@ -27,6 +28,8 @@ export const EnumDialog = observer(
initialCondition,
} = attributeStore

const { isOnDashboard } = dtreeStore

const { currentStepGroups } = modalsControlStore
const { selectedEnumVariants } = dashboardStore
const initialVariants = initialEnumVariants || selectedEnumVariants
Expand Down Expand Up @@ -100,7 +103,7 @@ export const EnumDialog = observer(
currentStepGroups,
onClose: modalsVisibilityStore.closeEnumDialog,
handleModals,
disabled: value.length === 0,
disabled: value.length === 0 || isOnDashboard,
saveAttribute: () => handleSaveChanges(mode, value),
addAttribute: action => handleAddAttribute(action, mode, value),
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ReactElement, useCallback } from 'react'
import { observer } from 'mobx-react-lite'

import dtreeStore from '@store/dtree'
import { Dialog } from '@ui/dialog'
import { GeneRegionCondition } from '@components/conditions/gene-region-condition/gene-region-condition'
import { AttributeKinds } from '@service-providers/common'
Expand All @@ -20,6 +21,8 @@ export const GeneRegionDialog = observer(
attributeSubKind,
} = funcStore

const { isOnDashboard } = dtreeStore

const { currentStepGroups } = modalsControlStore

const handleModals = () => {
Expand Down Expand Up @@ -75,7 +78,7 @@ export const GeneRegionDialog = observer(
currentStepGroups,
onClose: modalsVisibilityStore.closeGeneRegionDialog,
handleModals,
disabled: hasErrors,
disabled: hasErrors || isOnDashboard,
saveAttribute: () => handleSaveChanges(mode, param),
addAttribute: action => handleAddAttribute(action, mode, param),
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ReactElement, useCallback } from 'react'
import { observer } from 'mobx-react-lite'

import dtreeStore from '@store/dtree'
import { Dialog } from '@ui/dialog'
import { InheritanceModeCondition } from '@components/conditions/inheritance-mode'
import { AttributeKinds } from '@service-providers/common'
Expand All @@ -22,6 +23,8 @@ export const InheritanceModeDialog = observer(
attributeSubKind,
} = funcStore

const { isOnDashboard } = dtreeStore

const { currentStepGroups } = modalsControlStore

const handleModals = () => {
Expand Down Expand Up @@ -79,7 +82,7 @@ export const InheritanceModeDialog = observer(
currentStepGroups,
onClose: modalsVisibilityStore.closeInheritanceModeDialog,
handleModals,
disabled: hasErrors,
disabled: hasErrors || isOnDashboard,
saveAttribute: () => handleSaveChanges(values, mode, param),
addAttribute: action =>
handleAddAttribute(action, values, mode, param),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ReactElement } from 'react'
import { observer } from 'mobx-react-lite'

import { ActionType } from '@declarations'
import dtreeStore from '@store/dtree'
import { Dialog } from '@ui/dialog'
import { NumericCondition } from '@components/conditions/numeric'
import {
Expand All @@ -26,6 +27,8 @@ export const NumericDialog = observer(
attributeName,
} = attributeStore

const { isOnDashboard } = dtreeStore

const { currentStepGroups } = modalsControlStore

if (!attributeStatus || attributeStatus.kind !== 'numeric') {
Expand Down Expand Up @@ -75,6 +78,7 @@ export const NumericDialog = observer(
initialValue={initialNumericValue}
controls={({ value, hasErrors }) => {
const disabled =
isOnDashboard ||
hasErrors ||
(value[0] == null && value[2] == null) ||
(typeof attributeStatus.min !== 'number' &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export const FinalStep = observer(
const shouldMakeActive = classList.includes('step-content-area')

if (shouldMakeActive) {
stepStore.makeStepActive(stepNo, ActiveStepOptions.StartedVariants)
stepStore.makeStepActive({
index: stepNo,
option: ActiveStepOptions.StartedVariants,
})
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ interface IInactiveFieldProps {
export const InactiveFieldLabel = observer(
({ stepNo, groupIndex }: IInactiveFieldProps) => {
const handleDeleteAttribute = () => {
stepStore.makeStepActive(stepNo - 1, ActiveStepOptions.StartedVariants)
stepStore.makeStepActive({
index: stepNo - 1,
option: ActiveStepOptions.StartedVariants,
})

deleteAttribute(groupIndex)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ export const ContentItemHeader = observer(
!stepType

const handleModals = () => {
stepStore.makeStepActive(stepNo - 1, ActiveStepOptions.StartedVariants)
stepStore.makeStepActive({
index: stepNo - 1,
option: ActiveStepOptions.StartedVariants,
})

stepType === AttributeKinds.ENUM &&
modalsVisibilityStore.openEnumDialog(groupName, groupNo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ export const NextStepContent = observer(

const openModal = () => {
if (groups.length) {
stepStore.makeStepActive(stepNo - 1, ActiveStepOptions.StartedVariants)
stepStore.makeStepActive({
index: stepNo - 1,
option: ActiveStepOptions.StartedVariants,
})
}

modalsVisibilityStore.openSelectAttributeDialog()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,11 @@ export const NextStepRoute = observer(
styles.nextStepRoute__excludeAmount_included,
)}
onClick={() =>
stepStore.makeStepActive(
stepNo - 1,
ActiveStepOptions.ReturnedVariants,
)
stepStore.makeStepActive({
index: stepNo - 1,
option: ActiveStepOptions.ReturnedVariants,
isIncreasedStepIndex: true,
})
}
data-testid={DecisionTreesResultsDataCy.excludeInfo}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ export const NextStep = observer(
const shouldMakeActive = classList.includes('step-content-area')

if (shouldMakeActive) {
stepStore.makeStepActive(stepNo - 1, ActiveStepOptions.StartedVariants)
stepStore.makeStepActive({
index: stepNo - 1,
option: ActiveStepOptions.StartedVariants,
})
}
}

Expand Down
19 changes: 18 additions & 1 deletion src/store/dtree/dtree.store.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { makeAutoObservable, reaction, runInAction, toJS } from 'mobx'

import { ViewTypeDashboard } from '@core/enum/view-type-dashboard-enum'
import { t } from '@i18n'
import { ActionsHistoryStore } from '@store/actions-history'
import filterDtrees from '@store/filter-dtrees'
import dashboardStore from '@pages/filter/common/dashboard'
import { IDsListArguments } from '@service-providers/dataset-level'
import {
dtreeProvider,
Expand Down Expand Up @@ -44,6 +46,7 @@ export class DtreeStore {
readonly stat = new DtreeStatStore()
private _dtreeModifiedState: DtreeModifiedState = DtreeModifiedState.NotDtree
private _previousDtreeCode = ''
private _viewType: ViewTypeDashboard = ViewTypeDashboard.List
private _XlPointCounts: PointCount[] = []

public startDtreeCode = ''
Expand Down Expand Up @@ -105,6 +108,10 @@ export class DtreeStore {
return this._dtreeModifiedState === DtreeModifiedState.NotDtree
}

public get isOnDashboard(): boolean {
return this._viewType === ViewTypeDashboard.Tile
}

constructor() {
reaction(
() => this.dtreeSetData,
Expand All @@ -127,7 +134,10 @@ export class DtreeStore {

const index = shouldUseFinalIndex ? finalStepIndex : activeStepIndex

stepStore.makeStepActive(index, ActiveStepOptions.StartedVariants)
stepStore.makeStepActive({
index,
option: ActiveStepOptions.StartedVariants,
})
}
if (response?.kind === 'xl') {
dtreeProvider
Expand Down Expand Up @@ -181,6 +191,13 @@ export class DtreeStore {
this._previousDtreeCode = code
},
)

reaction(
() => dashboardStore.viewType,
viewType => {
this._viewType = viewType
},
)
}

public get totalCounts() {
Expand Down
36 changes: 30 additions & 6 deletions src/store/dtree/step.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ export enum CreateEmptyStepPositions {
FINAL = 'FINAL',
}

interface IActiveStep {
index: number
option: ActiveStepOptions
isIncreasedStepIndex?: boolean
}

class StepStore {
activeStepIndex: number = 0
activeStepOption: ActiveStepOptions = ActiveStepOptions.StartedVariants
Expand Down Expand Up @@ -97,9 +103,15 @@ class StepStore {
})
}

makeStepActive(index: number, option: ActiveStepOptions) {
makeStepActive({ index, option, isIncreasedStepIndex = false }: IActiveStep) {
this.setActiveStep(index, option)
this.changeStepDataActiveStep(index, option, this.stepIndexForApi)
this.changeStepDataActiveStep(
index,
option,
isIncreasedStepIndex
? `${+this.stepIndexForApi + 1}`
: this.stepIndexForApi,
)
}

insertEmptyStep(position: CreateEmptyStepPositions, index: number) {
Expand Down Expand Up @@ -142,19 +154,28 @@ class StepStore {
case CreateEmptyStepPositions.FINAL:
this.insertEmptyStep(position, previousStepIndex)

this.makeStepActive(stepIndex, ActiveStepOptions.StartedVariants)
this.makeStepActive({
index: stepIndex,
option: ActiveStepOptions.StartedVariants,
})
break

case CreateEmptyStepPositions.BEFORE:
this.insertEmptyStep(position, stepIndex)

this.makeStepActive(stepIndex, ActiveStepOptions.StartedVariants)
this.makeStepActive({
index: stepIndex,
option: ActiveStepOptions.StartedVariants,
})
break

case CreateEmptyStepPositions.AFTER:
this.insertEmptyStep(position, stepIndex)

this.makeStepActive(nextStepIndex, ActiveStepOptions.StartedVariants)
this.makeStepActive({
index: nextStepIndex,
option: ActiveStepOptions.StartedVariants,
})
break

default:
Expand All @@ -175,7 +196,10 @@ class StepStore {
item.step = currNo + 1
})

this.makeStepActive(stepData.length - 1, ActiveStepOptions.StartedVariants)
this.makeStepActive({
index: stepData.length - 1,
option: ActiveStepOptions.StartedVariants,
})
}
}

Expand Down

0 comments on commit 5679295

Please sign in to comment.