Skip to content

Commit

Permalink
feat(FOROME-1417): Adding a rubric select for solution create dialog
Browse files Browse the repository at this point in the history
* feat(FOROME-1417): Adding a rubric select for solution create dialog

Co-authored-by: Vladislav <Lapk1n@yandex.ru>
  • Loading branch information
AndreyUstyumenko and Lapk1n authored Aug 23, 2022
1 parent 97f486e commit dcd13b2
Show file tree
Hide file tree
Showing 17 changed files with 138 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { ReactElement, useEffect, useState } from 'react'

import {
ExploreGenomeTypesDictionary,
genomeTypesOptions,
TGenomeOptionsKeys,
} from '@core/enum/explore-genome-types-enum'
import { t } from '@i18n'
import { Dialog } from '@ui/dialog'
import { Input } from '@ui/input'
import { Select } from '@ui/select'
import { ISolutionEntryDescription } from '@service-providers/common'
import { validatePresetName } from '@utils/validation/validatePresetName'

Expand All @@ -11,7 +17,7 @@ interface ISolutionCreateDialogProps {
isOpen?: boolean
controlName: string
onClose: () => void
onCreate: (solutionName: string) => void
onCreate: (solutionName: string, rubric?: TGenomeOptionsKeys) => void
}

export const SolutionCreateDialog = ({
Expand All @@ -22,6 +28,9 @@ export const SolutionCreateDialog = ({
onCreate,
}: ISolutionCreateDialogProps): ReactElement => {
const [solutionName, setSolutionName] = useState('')
const [rubric, setRubric] =
useState<TGenomeOptionsKeys | undefined>(undefined)
const [selectValue, setSelectValue] = useState<string | undefined>(undefined)
const [isValidationError, setIsValidationError] = useState(false)
const [isSameNameError, setIsSameNameError] = useState(false)

Expand All @@ -45,14 +54,30 @@ export const SolutionCreateDialog = ({
)
}, [solutionName, solutions])

const onChangeRubric = (e: React.ChangeEvent<HTMLSelectElement>) => {
const { value } = e.target
setSelectValue(value)

if (value === 'empty') {
setRubric(undefined)
return
}

const rubricKey = Object.entries(ExploreGenomeTypesDictionary).find(
([, val]) => val === value,
)?.[0]

setRubric(rubricKey as TGenomeOptionsKeys)
}

return (
<Dialog
isOpen={isOpen}
onClose={onClose}
title={t('solutionControl.createDialog.title', { controlName })}
applyText={t('general.create')}
isApplyDisabled={hasError || !solutionName}
onApply={() => onCreate(solutionName)}
onApply={() => onCreate(solutionName, rubric)}
>
<Input
value={solutionName}
Expand All @@ -62,6 +87,19 @@ export const SolutionCreateDialog = ({
})}
onChange={event => setSolutionName(event.target.value)}
/>

<div className="flex flex-col mt-[16px] text-12">
<label>{t('solutionControl.createDialog.assignSolutionPack')}</label>
<Select
options={genomeTypesOptions}
className="py-[5px] px-[4px]"
value={selectValue}
onChange={onChangeRubric}
reset
resetText="Choose the type"
/>
</div>

{hasError && (
<div className="text-red-secondary text-12">{errorText}</div>
)}
Expand Down
18 changes: 18 additions & 0 deletions src/core/enum/explore-genome-types-enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,21 @@ export const ExploreGenomeTypesDictionary = {
} as const

export type TExploreGenomeKeys = keyof typeof ExploreGenomeKeys

export type TGenomeOptionsKeys = Exclude<
TExploreGenomeKeys,
'BuildInclusionExclusion' | 'ExploreData'
>

export type TGenomeOptionsValues =
typeof ExploreGenomeTypesDictionary[TGenomeOptionsKeys]

export const genomeTypesOptions = Object.entries(ExploreGenomeTypesDictionary)
.filter(([key]) =>
[
ExploreGenomeKeys.ACMGSecondary,
ExploreGenomeKeys.PhenotypeBased,
ExploreGenomeKeys.GeneticFirst,
].includes(key as any),
)
.map(([, value]) => value) as TGenomeOptionsValues[]
3 changes: 2 additions & 1 deletion src/i18n/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export const en = {
controlNamePlaceholder: 'Enter {controlName} Name',
solutionNameAlreadyExists:
'{controlName} "{solutionName}" already exists',
assignSolutionPack: 'Assign Solution Pack',
},
deleteDialog: {
title: 'Delete {controlName}',
Expand Down Expand Up @@ -219,7 +220,7 @@ export const en = {
createDerivedDS: 'Create Derived DS',
datasetCreation: 'Dataset Creation',
addDatasetTitle: 'Add new dataset',
label: 'Dataset Name:',
label: 'Dataset Name',
attention:
'Attention: Zone filters (Gene, Gene List, Sample, Tags) do not participate in dataset creation',
addDataset: 'Add dataset',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,51 @@
import { ReactElement } from 'react'
import { ReactElement, useCallback } from 'react'

import { TGenomeOptionsKeys } from '@core/enum/explore-genome-types-enum'
import { useModal } from '@core/hooks/use-modal'
import { t } from '@i18n'
import filterStore from '@store/filter'
import filterDtreesStore from '@store/filter-dtrees'
import filterPresetsStore from '@store/filter-presets'
import { Button } from '@ui/button'
import { SolutionCreateDialog } from '@components/solution-control/solution-create-dialog'
import presetsCardStore from '@pages/main/components/selected-dataset/build-flow/components/cards/presets-card/presets-card.store'
import { ISolutionEntryDescription } from '@service-providers/common'

import { FilterControlOptionsNames } from '../filter-control.const'
interface ICreateEntryProps {
solutionName: string
pageName: FilterControlOptionsNames
availableSolutionEntries: ISolutionEntryDescription[] | undefined
createSolutionEntry: (entryName: string) => void
}

export const CreateEntryButton = ({
solutionName,
pageName,
availableSolutionEntries,
createSolutionEntry,
}: ICreateEntryProps): ReactElement => {
const [createDialog, openCreateDialog, closeCreateDialog] = useModal()

const solutionName =
pageName === FilterControlOptionsNames.dtree ? pageName : 'Preset'

const onCreateSolution = useCallback(
(entryName: string, rubric?: TGenomeOptionsKeys) => {
closeCreateDialog()

if (pageName === FilterControlOptionsNames.dtree) {
filterDtreesStore.createDtree(entryName, rubric)
} else if (pageName === FilterControlOptionsNames.refiner) {
filterPresetsStore.createPreset(
entryName,
filterStore.conditions,
rubric,
)
}

pageName === FilterControlOptionsNames.dtree
? presetsCardStore.refreshDtrees()
: presetsCardStore.refreshPresets()
},
[closeCreateDialog, pageName],
)

return (
<>
<Button
Expand All @@ -32,10 +59,7 @@ export const CreateEntryButton = ({
solutions={availableSolutionEntries}
onClose={closeCreateDialog}
controlName={solutionName}
onCreate={entryName => {
closeCreateDialog()
createSolutionEntry(entryName)
}}
onCreate={onCreateSolution}
/>
</>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { FilterControlOptionsNames } from './filter-control.const'
export interface IFilterControlProps {
SolutionControl: React.ElementType
TextEditorButton?: React.ElementType
createSolutionEntry: (entryName: string) => void
availableSolutionEntries: ISolutionEntryDescription[] | undefined
isForwardAllowed: boolean
isBackwardAllowed: boolean
Expand Down
8 changes: 1 addition & 7 deletions src/pages/filter/common/filter-control/filter-control.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export const FilterControl = observer(
({
SolutionControl,
TextEditorButton,
createSolutionEntry,
availableSolutionEntries,
className,
isForwardAllowed,
Expand Down Expand Up @@ -104,12 +103,7 @@ export const FilterControl = observer(
<Divider orientation="vertical" className="h-[75%]" />

<CreateEntryButton
solutionName={
pageName === FilterControlOptionsNames.dtree
? pageName
: 'Preset'
}
createSolutionEntry={createSolutionEntry}
pageName={pageName}
availableSolutionEntries={availableSolutionEntries}
/>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,10 @@ export const CreateDatasetDialog = observer(
>
<div className="flex flex-col">
<div>
<span className="text-14">{t('dsCreation.label')}</span>

<Input
disabled={!operations.isCreationOver}
value={value}
label={t('dsCreation.label')}
onChange={e => handleChange(e.target.value)}
className="mt-1"
data-testid={DecisionTreesMenuDataCy.datasetNameInput}
Expand Down
5 changes: 0 additions & 5 deletions src/pages/filter/dtree/dtree.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ export const DtreePage = observer((): ReactElement => {

const { availableDtrees: availableSolutionEntries } = filterDtreesStore

const createDtree = (treeName: string): void => {
filterDtreesStore.createDtree(treeName)
}

const modifiedDtree = dtreeStore.isDtreeModified
? dtreeStore.currentDtreeName
: undefined
Expand Down Expand Up @@ -123,7 +119,6 @@ export const DtreePage = observer((): ReactElement => {
}
pageName={FilterControlOptionsNames[GlbPagesNames.Dtree]}
SolutionControl={SolutionControlDtree}
createSolutionEntry={createDtree}
availableSolutionEntries={availableSolutionEntries}
isEntryCreationAllowed={isEntryCreationAllowed}
isBackwardAllowed={dtreeStore.actionHistory.isBackwardAllowed}
Expand Down
5 changes: 0 additions & 5 deletions src/pages/filter/refiner/refiner.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ export const RefinerPage = observer((): ReactElement => {
const { availablePresets: availableSolutionEntries, activePreset } =
filterPresetsStore

const createPreset = (presetName: string): void => {
filterPresetsStore.createPreset(presetName, filterStore.conditions)
}

const filterCounts = filterStore.stat.filteredCounts

const modifiedPreset = filterStore.isPresetModified
Expand Down Expand Up @@ -102,7 +98,6 @@ export const RefinerPage = observer((): ReactElement => {
<FilterControl
pageName={FilterControlOptionsNames[GlbPagesNames.Refiner]}
SolutionControl={SolutionControlRefiner}
createSolutionEntry={createPreset}
availableSolutionEntries={availableSolutionEntries}
isBackwardAllowed={filterStore.actionHistory.isBackwardAllowed}
isForwardAllowed={filterStore.actionHistory.isForwardAllowed}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ class PresetsCardStore {
this.loadDTrees()
}

public refreshDtrees() {
this._dtrees.invalidate()
}

public refreshPresets() {
this._presets.invalidate()
}

public getSolutionsByRubric(rubric?: TExploreGenomeKeys) {
if (rubric) {
return this.solutions.filter(solution => solution.rubric === rubric)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
TPropertyStatus,
} from '../common'
import { TGetFullStatUnitsOptions } from '../filtering-regime'
import { TGenomeOptionsKeys } from './../../core/enum/explore-genome-types-enum'

// dtree_set

Expand All @@ -28,6 +29,7 @@ export type TDtreeModifyingActions = [
actionType: ActionTypes.DTREE,
actionName: DtreeModifyingActions,
decisionTreeName: string,
rubric?: TGenomeOptionsKeys,
]

export enum InstrModifyingActionNames {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// ds_stat

import {
DatasetKinds,
IFuncPropertyStatus,
Expand All @@ -10,6 +9,8 @@ import {
TPropertyStatus,
} from 'service-providers/common'

import { TGenomeOptionsKeys } from '@core/enum/explore-genome-types-enum'

export enum DsStatArgumentsOptions {
UPDATE = 'UPDATE',
DELETE = 'DELETE',
Expand All @@ -21,7 +22,11 @@ export interface IDsStatArguments {
tm?: number
filter?: string
conditions?: ReadonlyArray<TCondition>
instr?: [option: DsStatArgumentsOptions, filterName: string]
instr?: [
option: DsStatArgumentsOptions,
filterName: string,
rubric?: TGenomeOptionsKeys,
]
}

export interface IDsStatCondSeq {
Expand Down Expand Up @@ -106,6 +111,7 @@ export type TUpdateFilterPresetParams = {
ds: string
presetName: string
conditions?: ReadonlyArray<TCondition>
rubric?: TGenomeOptionsKeys
}

export type TJoinFilterPresetParams = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ export class FilteringRegimeProvider extends ServiceProviderBase {
{
ds: params.ds,
conditions: params.conditions,
instr: [DsStatArgumentsOptions.UPDATE, params.presetName],
instr: [
DsStatArgumentsOptions.UPDATE,
params.presetName,
params.rubric,
],
},
options,
)
Expand Down
13 changes: 11 additions & 2 deletions src/store/filter-dtrees/filter-dtrees.store.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { makeAutoObservable, reaction, toJS } from 'mobx'

import { TGenomeOptionsKeys } from '@core/enum/explore-genome-types-enum'
import { pushQueryParams } from '@core/history'
import { t } from '@i18n'
import { createHistoryObserver } from '@store/common'
Expand Down Expand Up @@ -85,7 +86,10 @@ export class FilterDtreesStore {
this.setActiveDtree('')
}

public createDtree = (dtreeName: string): void => {
public createDtree = (
dtreeName: string,
rubric?: TGenomeOptionsKeys,
): void => {
if (!validatePresetName(dtreeName)) {
showToast(t('filter.notValidName'), 'error')

Expand All @@ -95,7 +99,12 @@ export class FilterDtreesStore {
.updateDtree({
ds: datasetStore.datasetName,
code: dtreeStore.dtreeCode,
instr: [ActionTypes.DTREE, DtreeModifyingActions.UPDATE, dtreeName],
instr: [
ActionTypes.DTREE,
DtreeModifyingActions.UPDATE,
dtreeName,
rubric,
],
})
.then(() => {
this.dtrees.invalidate()
Expand Down
Loading

0 comments on commit dcd13b2

Please sign in to comment.