-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: movesrc/ui/store/reducers/groups/table to typescript [#634]
- Loading branch information
Showing
3 changed files
with
110 additions
and
60 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,11 +1,9 @@ | ||
import createActionTypes, {createPrefix} from '../constants/utils'; | ||
import createActionTypes from '../constants/utils'; | ||
|
||
const PREFIX = createPrefix('GROUPS'); | ||
|
||
export const GROUPS_TABLE = createActionTypes(PREFIX + 'GROUPS_TABLE'); | ||
export const GROUPS_TABLE_DATA_FIELDS = PREFIX + 'GROUPS_TABLE_DATA_FIELDS'; | ||
export const GROUPS_TABLE = createActionTypes('GROUPS:GROUPS_TABLE'); | ||
export const GROUPS_TABLE_DATA_FIELDS = 'GROUPS:GROUPS_TABLE_DATA_FIELDS'; | ||
|
||
export const ROOT_GROUP_NAME = '<Root>'; | ||
|
||
export const GROUP_EDITOR_ACTION = createActionTypes(PREFIX + 'GROUP_EDITOR_ACTION'); | ||
export const GROUP_EDITOR_ACTION_DATA_FIELDS = PREFIX + 'GROUP_EDITOR_ACTION_DATA_FIELDS'; | ||
export const GROUP_EDITOR_ACTION = createActionTypes('GROUPS:GROUP_EDITOR_ACTION'); | ||
export const GROUP_EDITOR_ACTION_DATA_FIELDS = 'GROUPS:GROUP_EDITOR_ACTION_DATA_FIELDS'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import {GROUPS_TABLE, GROUPS_TABLE_DATA_FIELDS} from '../../../constants/groups'; | ||
import {mergeStateOnClusterChange} from '../../../store/reducers/utils'; | ||
import type {Action} from 'redux'; | ||
import type {ActionD, YTError} from '../../../types'; | ||
|
||
type Group = { | ||
name: string; | ||
members: string[]; | ||
memberOf: string[]; | ||
idm: boolean; | ||
}; | ||
|
||
type EphemeralStateType = { | ||
loaded: boolean; | ||
loading: boolean; | ||
error: YTError | null; | ||
groups: Group[]; | ||
sort: { | ||
column: string; | ||
order: string; | ||
}; | ||
expanded: Record<string, boolean>; | ||
}; | ||
|
||
const ephemeralState: EphemeralStateType = { | ||
loaded: false, | ||
loading: false, | ||
error: null, | ||
groups: [], | ||
sort: { | ||
column: 'name', | ||
order: 'asc', | ||
}, | ||
expanded: {}, | ||
}; | ||
|
||
type PersistantStateType = { | ||
nameFilter: string; | ||
}; | ||
|
||
const persistantState = { | ||
nameFilter: '', | ||
}; | ||
|
||
type GroupsTableStateType = EphemeralStateType & PersistantStateType; | ||
|
||
export const groupsTableState: GroupsTableStateType = { | ||
...ephemeralState, | ||
...persistantState, | ||
}; | ||
|
||
function reducer(state: GroupsTableStateType = groupsTableState, action: GroupsTableAction) { | ||
switch (action.type) { | ||
case GROUPS_TABLE.REQUEST: { | ||
return {...state, loading: true}; | ||
} | ||
case GROUPS_TABLE.SUCCESS: { | ||
return { | ||
...state, | ||
loading: false, | ||
loaded: true, | ||
error: null, | ||
...action.data, | ||
}; | ||
} | ||
case GROUPS_TABLE.FAILURE: { | ||
return {...state, loading: false, loaded: false}; | ||
} | ||
case GROUPS_TABLE.CANCELLED: { | ||
return {...state, loading: false, loaded: false, error: null}; | ||
} | ||
case GROUPS_TABLE_DATA_FIELDS: { | ||
return {...state, ...action.data}; | ||
} | ||
default: | ||
return state; | ||
} | ||
} | ||
|
||
export type GroupsTableAction = | ||
| Action<typeof GROUPS_TABLE.REQUEST> | ||
| ActionD< | ||
typeof GROUPS_TABLE.SUCCESS, | ||
{ | ||
data: { | ||
groups: Group[]; | ||
}; | ||
} | ||
> | ||
| ActionD<typeof GROUPS_TABLE.FAILURE, {error: YTError}> | ||
| Action<typeof GROUPS_TABLE.CANCELLED> | ||
| ActionD< | ||
typeof GROUPS_TABLE_DATA_FIELDS, | ||
{ | ||
data: { | ||
sort?: { | ||
column: string; | ||
order: string; | ||
}; | ||
expanded?: Record<string, boolean>; | ||
}; | ||
} | ||
>; | ||
|
||
export default mergeStateOnClusterChange(ephemeralState, persistantState, reducer); |