Merge branch '14393-vocabulary'
[arvados-workbench2.git] / src / store / vocabulary / vocabulary-actions.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { Dispatch } from 'redux';
6 import { ServiceRepository } from '~/services/services';
7 import { propertiesActions } from '~/store/properties/properties-actions';
8 import { VOCABULARY_PROPERTY_NAME, DEFAULT_VOCABULARY } from './vocabulary-selctors';
9 import { isVocabulary } from '~/models/vocabulary';
10
11 export const loadVocabulary = async (dispatch: Dispatch, _: {}, { vocabularyService }: ServiceRepository) => {
12     const vocabulary = await vocabularyService.getVocabulary();
13
14     dispatch(propertiesActions.SET_PROPERTY({
15         key: VOCABULARY_PROPERTY_NAME,
16         value: isVocabulary(vocabulary)
17             ? vocabulary
18             : DEFAULT_VOCABULARY,
19     }));
20 };