mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 16:45:43 -06:00
* Configuration: Always display expired API keys * Use exclamation-triangle instead * Reintroduce toggle, move logic into store and call both endpoints * Handle apiKeys without TTL * Remove backend changes and make checks in frontend instead
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
import { createSlice } from '@reduxjs/toolkit';
|
|
|
|
import { ApiKeysState } from 'app/types';
|
|
|
|
export const initialApiKeysState: ApiKeysState = {
|
|
hasFetched: false,
|
|
includeExpired: false,
|
|
keys: [],
|
|
keysIncludingExpired: [],
|
|
searchQuery: '',
|
|
};
|
|
|
|
const apiKeysSlice = createSlice({
|
|
name: 'apiKeys',
|
|
initialState: initialApiKeysState,
|
|
reducers: {
|
|
apiKeysLoaded: (state, action): ApiKeysState => {
|
|
const { keys, keysIncludingExpired } = action.payload;
|
|
const includeExpired =
|
|
action.payload.keys.length === 0 && action.payload.keysIncludingExpired.length > 0
|
|
? true
|
|
: state.includeExpired;
|
|
return { ...state, hasFetched: true, keys, keysIncludingExpired, includeExpired };
|
|
},
|
|
setSearchQuery: (state, action): ApiKeysState => {
|
|
return { ...state, searchQuery: action.payload };
|
|
},
|
|
includeExpiredToggled: (state): ApiKeysState => {
|
|
return { ...state, includeExpired: !state.includeExpired };
|
|
},
|
|
isFetching: (state): ApiKeysState => {
|
|
return { ...state, hasFetched: false };
|
|
},
|
|
},
|
|
});
|
|
|
|
export const { apiKeysLoaded, includeExpiredToggled, isFetching, setSearchQuery } = apiKeysSlice.actions;
|
|
|
|
export const apiKeysReducer = apiKeysSlice.reducer;
|
|
|
|
export default {
|
|
apiKeys: apiKeysReducer,
|
|
};
|