-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add redux thunk fns; add cat indices API (#37)
* Add redux thunk fns; add cat indices API Signed-off-by: Tyler Ohlsen <[email protected]> * Remove unnecessary setIndices() Signed-off-by: Tyler Ohlsen <[email protected]> --------- Signed-off-by: Tyler Ohlsen <[email protected]> (cherry picked from commit 8a171f7)
- Loading branch information
1 parent
af582a6
commit e474349
Showing
9 changed files
with
139 additions
and
14 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
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 |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
*/ | ||
|
||
export * from './constants'; | ||
export * from './interfaces'; |
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,14 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/** | ||
* Interfaces here are primarily used for standardizing the data across | ||
* server & client side | ||
*/ | ||
|
||
export interface IIndex { | ||
name: string; | ||
health: 'green' | 'yellow' | 'red'; | ||
} |
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
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 |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
*/ | ||
|
||
export * from './workspace_reducer'; | ||
export * from './opensearch_reducer'; |
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,53 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { createAsyncThunk, createSlice } from '@reduxjs/toolkit'; | ||
import { getRouteService } from '../../services'; | ||
import { IIndex } from '../../../common'; | ||
|
||
const initialState = { | ||
loading: false, | ||
errorMessage: '', | ||
indices: {} as { [key: string]: IIndex }, | ||
}; | ||
|
||
const OPENSEARCH_PREFIX = 'opensearch'; | ||
const FETCH_INDICES_ACTION = `${OPENSEARCH_PREFIX}/fetchIndices`; | ||
|
||
export const fetchIndices = createAsyncThunk( | ||
FETCH_INDICES_ACTION, | ||
async (pattern?: string) => { | ||
// defaulting to fetch everything except system indices (starting with '.') | ||
const patternString = pattern || '*,-.*'; | ||
const response = getRouteService().fetchIndices(patternString); | ||
return response; | ||
} | ||
); | ||
|
||
const opensearchSlice = createSlice({ | ||
name: OPENSEARCH_PREFIX, | ||
initialState, | ||
reducers: {}, | ||
extraReducers: (builder) => { | ||
builder | ||
.addCase(fetchIndices.pending, (state, action) => { | ||
state.loading = true; | ||
}) | ||
.addCase(fetchIndices.fulfilled, (state, action) => { | ||
const indicesMap = new Map<string, IIndex>(); | ||
action.payload.forEach((index: IIndex) => { | ||
indicesMap.set(index.name, index); | ||
}); | ||
state.indices = Object.fromEntries(indicesMap.entries()); | ||
state.loading = false; | ||
}) | ||
.addCase(fetchIndices.rejected, (state, action) => { | ||
state.errorMessage = action.payload as string; | ||
state.loading = false; | ||
}); | ||
}, | ||
}); | ||
|
||
export const opensearchReducer = opensearchSlice.reducer; |
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
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,18 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
// OSD does not provide an interface for this response, but this is following the suggested | ||
// implementations. To prevent typescript complaining, leaving as loosely-typed 'any' | ||
export function generateCustomError(res: any, err: any) { | ||
return res.customError({ | ||
statusCode: err.statusCode || 500, | ||
body: { | ||
message: err.message, | ||
attributes: { | ||
error: err.body?.error || err.message, | ||
}, | ||
}, | ||
}); | ||
} |
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