mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
* Refactor: Adds Redux Toolkit package * Refactor: Uses configureStore from Redux Toolkit * Refactor: Migrates applicationReducer * Refactor: Migrates appNotificationsReducer * Refactor: Migrates locationReducer * Refactor: Migrates navModelReducer * Refactor: Migrates teamsReducer and teamReducer * Refactor: Migrates cleanUpAction * Refactor: Migrates alertRulesReducer * Refactor: Cleans up recursiveCleanState * Refactor: Switched to Angular compatible reducers * Refactor: Migrates folderReducer * Refactor: Migrates dashboardReducer * Migrates panelEditorReducer * Refactor: Migrates dataSourcesReducer * Refactor: Migrates usersReducer * Refactor: Migrates organizationReducer * Refactor: Migrates pluginsReducer * Refactor: Migrates ldapReducer and ldapUserReducer * Refactor: Migrates apiKeysReducer * Refactor: Migrates exploreReducer and itemReducer * Refactor: Removes actionCreatorFactory and reducerFactory * Refactor: Moves mocks to test section * Docs: Removes sections about home grown framework * Update contribute/style-guides/redux.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Refactor: Cleans up some code * Refactor: Adds state typings * Refactor: Cleans up typings * Refactor: Adds comment about ImmerJs autoFreeze Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
|
|
|
import { Invitee, OrgUser, UsersState } from 'app/types';
|
|
import config from 'app/core/config';
|
|
|
|
export const initialState: UsersState = {
|
|
invitees: [] as Invitee[],
|
|
users: [] as OrgUser[],
|
|
searchQuery: '',
|
|
canInvite: !config.externalUserMngLinkName,
|
|
externalUserMngInfo: config.externalUserMngInfo,
|
|
externalUserMngLinkName: config.externalUserMngLinkName,
|
|
externalUserMngLinkUrl: config.externalUserMngLinkUrl,
|
|
hasFetched: false,
|
|
};
|
|
|
|
const usersSlice = createSlice({
|
|
name: 'users',
|
|
initialState,
|
|
reducers: {
|
|
usersLoaded: (state, action: PayloadAction<OrgUser[]>): UsersState => {
|
|
return { ...state, hasFetched: true, users: action.payload };
|
|
},
|
|
inviteesLoaded: (state, action: PayloadAction<Invitee[]>): UsersState => {
|
|
return { ...state, hasFetched: true, invitees: action.payload };
|
|
},
|
|
setUsersSearchQuery: (state, action: PayloadAction<string>): UsersState => {
|
|
return { ...state, searchQuery: action.payload };
|
|
},
|
|
},
|
|
});
|
|
|
|
export const { inviteesLoaded, setUsersSearchQuery, usersLoaded } = usersSlice.actions;
|
|
|
|
export const usersReducer = usersSlice.reducer;
|
|
|
|
export default {
|
|
users: usersReducer,
|
|
};
|