forked from grafana.jool/grafana-jool
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.3 KiB
39 lines
1.3 KiB
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
|
|
|
import { OrgServiceAccount, ServiceAccountsState } from 'app/types';
|
|
|
|
export const initialState: ServiceAccountsState = {
|
|
serviceAccounts: [] as OrgServiceAccount[],
|
|
searchQuery: '',
|
|
searchPage: 1,
|
|
isLoading: true,
|
|
};
|
|
|
|
const serviceAccountsSlice = createSlice({
|
|
name: 'serviceaccounts',
|
|
initialState,
|
|
reducers: {
|
|
serviceAccountsLoaded: (state, action: PayloadAction<OrgServiceAccount[]>): ServiceAccountsState => {
|
|
return { ...state, isLoading: true, serviceAccounts: action.payload };
|
|
},
|
|
setServiceAccountsSearchQuery: (state, action: PayloadAction<string>): ServiceAccountsState => {
|
|
// reset searchPage otherwise search results won't appear
|
|
return { ...state, searchQuery: action.payload, searchPage: initialState.searchPage };
|
|
},
|
|
setServiceAccountsSearchPage: (state, action: PayloadAction<number>): ServiceAccountsState => {
|
|
return { ...state, searchPage: action.payload };
|
|
},
|
|
},
|
|
});
|
|
|
|
export const {
|
|
setServiceAccountsSearchQuery,
|
|
setServiceAccountsSearchPage,
|
|
serviceAccountsLoaded,
|
|
} = serviceAccountsSlice.actions;
|
|
|
|
export const serviceAccountsReducer = serviceAccountsSlice.reducer;
|
|
|
|
export default {
|
|
serviceAccounts: serviceAccountsReducer,
|
|
};
|
|
|