1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- import { SchemaSubject } from 'generated-sources';
- import ActionType from 'redux/actionType';
- import { Action, SchemasState } from 'redux/interfaces';
- export const initialState: SchemasState = {
- byName: {},
- allNames: [],
- };
- const updateSchemaList = (
- state: SchemasState,
- payload: SchemaSubject[]
- ): SchemasState => {
- const initialMemo: SchemasState = {
- ...state,
- allNames: [],
- };
- return payload.reduce((memo: SchemasState, schema) => {
- if (!schema.subject) return memo;
- return {
- ...memo,
- byName: {
- ...memo.byName,
- [schema.subject]: {
- ...memo.byName[schema.subject],
- ...schema,
- },
- },
- allNames: [...memo.allNames, schema.subject],
- };
- }, initialMemo);
- };
- const reducer = (state = initialState, action: Action): SchemasState => {
- switch (action.type) {
- case ActionType.GET_CLUSTER_SCHEMAS__SUCCESS:
- return updateSchemaList(state, action.payload);
- default:
- return state;
- }
- };
- export default reducer;
|