12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- import Reflux from 'reflux';
- import FormSearchActions from 'app/actions/formSearchActions';
- import {FieldObject} from 'app/views/settings/components/forms/type';
- /**
- * Processed form field metadata.
- */
- export type FormSearchField = {
- route: string;
- title: React.ReactNode;
- description: React.ReactNode;
- field: FieldObject;
- };
- type StoreInterface = {
- reset: () => void;
- get: () => Internals['searchMap'];
- };
- type Internals = {
- searchMap: null | FormSearchField[];
- onLoadSearchMap: (searchMap: null | FormSearchField[]) => void;
- };
- /**
- * Store for "form" searches, but probably will include more
- */
- const formSearchStoreConfig: Reflux.StoreDefinition & Internals & StoreInterface = {
- searchMap: null,
- init() {
- this.reset();
- this.listenTo(FormSearchActions.loadSearchMap, this.onLoadSearchMap);
- },
- get() {
- return this.searchMap;
- },
- reset() {
- // `null` means it hasn't been loaded yet
- this.searchMap = null;
- },
- /**
- * Adds to search map
- */
- onLoadSearchMap(searchMap) {
- // Only load once
- if (this.searchMap !== null) {
- return;
- }
- this.searchMap = searchMap;
- this.trigger(this.searchMap);
- },
- };
- type FormSearchStore = Reflux.Store & StoreInterface;
- const FormSearchStore = Reflux.createStore(formSearchStoreConfig) as FormSearchStore;
- export default FormSearchStore;
|