-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(FOROME-299): load preset on dropdown change
* fix(FOROME-299): load preset on dropdown change
- Loading branch information
Showing
20 changed files
with
1,551 additions
and
1,207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
export enum ActionFilterEnum { | ||
Load = 'Load', | ||
Create = 'Create', | ||
Modify = 'Modify', | ||
Join = 'Join', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
src/pages/filter/ui/filter-control/filter-control-refiner/filter-control-refiner.store.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { get } from 'lodash' | ||
import { makeAutoObservable } from 'mobx' | ||
|
||
import { FilterList } from '@declarations' | ||
import { ActionFilterEnum } from '@core/enum/action-filter.enum' | ||
import { t } from '@i18n' | ||
import datasetStore from '@store/dataset' | ||
import filterStore from '@store/filter' | ||
import presetStore from '@store/filterPreset' | ||
import { compareConditions } from '@utils/filter-refiner/compareConditions' | ||
import { showToast } from '@utils/notifications/showToast' | ||
import { validatePresetName } from '@utils/validation/validatePresetName' | ||
|
||
class FilterControlRefinerStore { | ||
constructor() { | ||
makeAutoObservable(this) | ||
} | ||
|
||
get activePreset(): string { | ||
return datasetStore.activePreset | ||
} | ||
|
||
get presets(): string[] { | ||
return get(datasetStore, 'dsStat.filter-list', []) | ||
.filter(this.isPresetAbleToBeModified) | ||
.map((preset: FilterList) => preset.name) | ||
} | ||
|
||
public isPresetAbleToBeModified(preset: FilterList): boolean { | ||
return filterStore.actionName === ActionFilterEnum.Delete || | ||
filterStore.actionName === ActionFilterEnum.Modify | ||
? !preset.standard | ||
: true | ||
} | ||
|
||
public applyAction = ( | ||
createPresetName: string, | ||
isSelectedFiltersEmpty: boolean, | ||
): void => { | ||
if (filterStore.actionName === ActionFilterEnum.Delete) { | ||
presetStore.deletePreset() | ||
} | ||
|
||
if (filterStore.actionName === ActionFilterEnum.Join) { | ||
if (!datasetStore.activePreset) { | ||
showToast(t('error.choosePresetFirst'), 'error') | ||
|
||
return | ||
} | ||
|
||
const isConditionsAbleToJoin = compareConditions({ | ||
currentConditions: datasetStore.conditions, | ||
startConditions: datasetStore.startPresetConditions, | ||
currentPreset: datasetStore.activePreset, | ||
prevPreset: datasetStore.prevPreset, | ||
}) | ||
|
||
if (!isConditionsAbleToJoin) { | ||
showToast(t('error.cantJoinTheSamePreset'), 'error') | ||
|
||
return | ||
} | ||
|
||
presetStore.joinPreset(datasetStore.activePreset) | ||
} | ||
|
||
if (filterStore.actionName === ActionFilterEnum.Create) { | ||
const isPresetNameValid = validatePresetName(createPresetName) | ||
|
||
if (!isPresetNameValid) { | ||
showToast(t('filter.notValidName'), 'error') | ||
|
||
return | ||
} | ||
|
||
if (isSelectedFiltersEmpty) { | ||
showToast(t('error.chooseFiltersFirst'), 'error') | ||
|
||
return | ||
} | ||
|
||
presetStore.createPreset(createPresetName) | ||
} | ||
|
||
if (filterStore.actionName === ActionFilterEnum.Modify) { | ||
if (!datasetStore.activePreset) { | ||
showToast(t('error.choosePresetFirst'), 'error') | ||
|
||
return | ||
} | ||
|
||
const isConditionsAbleToModify = compareConditions({ | ||
currentConditions: datasetStore.conditions, | ||
startConditions: datasetStore.startPresetConditions, | ||
currentPreset: datasetStore.activePreset, | ||
prevPreset: datasetStore.prevPreset, | ||
}) | ||
|
||
if (!isConditionsAbleToModify) { | ||
showToast(t('error.noChangesToModify'), 'error') | ||
|
||
return | ||
} | ||
|
||
presetStore.modifyPreset(datasetStore.activePreset) | ||
} | ||
} | ||
} | ||
|
||
export default new FilterControlRefinerStore() |
Oops, something went wrong.