mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 08:35:43 -06:00
* ServiceAccounts: able to get upgrade status * Banner with API keys migration info * Show API keys migration info on Service accounts page * Migrate individual API keys * Use transaction for key migration * Migrate all api keys to service accounts * Hide api keys after migration * Migrate API keys separately for each org * Revert API key * Revert key API method * Rename migration actions and reducers * Fix linter errors * Tests for migrating single API key * Tests for migrating all api keys * More tests * Fix reverting tokens * API: rename convert to migrate * Add api route descriptions to methods * rearrange methods in api.go * Refactor: rename and move some methods * Prevent assigning tokens to non-existing service accounts * Refactor: ID TO Id * Refactor: fix error message * Delete service account if migration failed * Fix linter errors
49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
import { createSlice } from '@reduxjs/toolkit';
|
|
|
|
import { ApiKeysState } from 'app/types';
|
|
|
|
export const initialApiKeysState: ApiKeysState = {
|
|
hasFetched: false,
|
|
includeExpired: false,
|
|
keys: [],
|
|
keysIncludingExpired: [],
|
|
searchQuery: '',
|
|
apiKeysMigrated: false,
|
|
};
|
|
|
|
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 };
|
|
},
|
|
apiKeysMigrationStatusLoaded: (state, action): ApiKeysState => {
|
|
return { ...state, apiKeysMigrated: action.payload };
|
|
},
|
|
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, apiKeysMigrationStatusLoaded } =
|
|
apiKeysSlice.actions;
|
|
|
|
export const apiKeysReducer = apiKeysSlice.reducer;
|
|
|
|
export default {
|
|
apiKeys: apiKeysReducer,
|
|
};
|