-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app-general): add flow to recover dynamicData
- Loading branch information
1 parent
c49dfa4
commit 7e8c122
Showing
8 changed files
with
147 additions
and
1 deletion.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
packages/game-app/src/_shared/dynamicData/apis/retrieveDynamicData.ts
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,38 @@ | ||
import firebase from 'firebase/app'; | ||
import { DevOpsMaturitiesDoc, FirebaseCollections, GameRolesDoc } from '@pipeline/common'; | ||
import { SelectOption } from '@pipeline/models'; | ||
|
||
import 'firebase/firestore'; | ||
|
||
const retrieveSelectOptions = (source: { [key: string]: { [key: string]: string } }, lang: string): SelectOption[] => { | ||
return Object.keys(source).map(k => { | ||
return { | ||
value: k, | ||
label: source[k][lang], | ||
} as SelectOption; | ||
}); | ||
}; | ||
|
||
export async function executeRetrieveGameRoles(lang = 'en'): Promise<SelectOption[]> { | ||
const gameRolesDoc = await firebase | ||
.firestore() | ||
.doc(`${FirebaseCollections.DynamicData}/${FirebaseCollections.GameRoles}`) | ||
.get(); | ||
if (!gameRolesDoc.exists) { | ||
//TODO handle this | ||
} | ||
const gameRoles = gameRolesDoc.data() as GameRolesDoc; | ||
return retrieveSelectOptions(gameRoles.labels, lang); | ||
} | ||
|
||
export async function executeRetrieveDevOpsMaturities(lang = 'en'): Promise<SelectOption[]> { | ||
const devOpsMaturitiesDoc = await firebase | ||
.firestore() | ||
.doc(`${FirebaseCollections.DynamicData}/${FirebaseCollections.DevOpsMaturities}`) | ||
.get(); | ||
if (!devOpsMaturitiesDoc.exists) { | ||
//TODO handle this | ||
} | ||
const devOpsMaturities = devOpsMaturitiesDoc.data() as DevOpsMaturitiesDoc; | ||
return retrieveSelectOptions(devOpsMaturities.labels, lang); | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/game-app/src/_shared/dynamicData/hooks/useRetrieveDynamicData.ts
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,12 @@ | ||
import { createRequestHook } from '@pipeline/requests-status'; | ||
import { actions } from '@pipeline/dynamicData'; | ||
|
||
const useRetrieveGameRoles = createRequestHook('gameRoles', actions.retrieveGameRoles, { | ||
errorMessagesScope: '', //TODO | ||
}); | ||
|
||
const useRetrieveDevOpsMaturities = createRequestHook('devOpsMaturities', actions.retrieveDevOpsMaturities, { | ||
errorMessagesScope: '', //TODO | ||
}); | ||
|
||
export { useRetrieveGameRoles, useRetrieveDevOpsMaturities }; |
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,4 @@ | ||
import { reducer, actions, name, selectors } from './slice'; | ||
import { runRetrieveDevOpsMaturities, runRetrieveGameRoles } from './saga'; | ||
|
||
export { reducer, actions, name, runRetrieveDevOpsMaturities, runRetrieveGameRoles, selectors }; |
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,34 @@ | ||
import { call, put, takeEvery } from 'redux-saga/effects'; | ||
import { addRequestStatusManagement } from '@pipeline/requests-status'; | ||
import { executeRetrieveDevOpsMaturities, executeRetrieveGameRoles } from './apis/retrieveDynamicData'; | ||
import { actions } from './slice'; | ||
import { SelectOption } from '@pipeline/models'; | ||
|
||
function* retrieveGameRolesSaga() { | ||
try { | ||
const gameRoles: SelectOption[] = yield call(executeRetrieveGameRoles); | ||
yield put(actions.setGameRoles(gameRoles)); | ||
} catch (e) { | ||
throw e; | ||
} | ||
} | ||
|
||
function* retrieveDevOpsMaturitiesSaga() { | ||
try { | ||
const devOpsMaturities: SelectOption[] = yield call(executeRetrieveDevOpsMaturities); | ||
yield put(actions.setDevOpsMaturities(devOpsMaturities)); | ||
} catch (e) { | ||
throw e; | ||
} | ||
} | ||
|
||
export function* runRetrieveGameRoles() { | ||
yield takeEvery(actions.retrieveGameRoles, addRequestStatusManagement(retrieveGameRolesSaga, 'gameRoles')); | ||
} | ||
|
||
export function* runRetrieveDevOpsMaturities() { | ||
yield takeEvery( | ||
actions.retrieveGameRoles, | ||
addRequestStatusManagement(retrieveDevOpsMaturitiesSaga, 'devOpsMaturities'), | ||
); | ||
} |
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,50 @@ | ||
import { createAction, createSelector, createSlice, PayloadAction } from '@reduxjs/toolkit'; | ||
import { SelectOption } from '@pipeline/models'; | ||
|
||
export interface State { | ||
gameRoles: SelectOption[]; | ||
devOpsMaturities: SelectOption[]; | ||
} | ||
|
||
const initialState = { | ||
devOpsMaturities: [], | ||
gameRoles: [], | ||
} as State; | ||
|
||
const slice = createSlice({ | ||
name: 'dynamicData', | ||
initialState: initialState, | ||
reducers: { | ||
setGameRoles(state, action: PayloadAction<SelectOption[]>) { | ||
state.gameRoles = action.payload; | ||
}, | ||
setDevOpsMaturities(state, action: PayloadAction<SelectOption[]>) { | ||
state.devOpsMaturities = action.payload; | ||
}, | ||
}, | ||
}); | ||
|
||
export const retrieveGameRoles = createAction('dynamicData/retrieveGameRoles'); | ||
export const retrieveDevOpsMaturities = createAction('dynamicData/retrieveDevOpsMaturities'); | ||
|
||
const getGameRoles = createSelector( | ||
(state: { [name]: State }) => state[name], | ||
dynamicDataState => dynamicDataState.gameRoles, | ||
); | ||
|
||
const getDevOpsMaturities = createSelector( | ||
(state: { [name]: State }) => state[name], | ||
dynamicDataState => dynamicDataState.devOpsMaturities, | ||
); | ||
|
||
export const reducer = slice.reducer; | ||
export const actions = { | ||
...slice.actions, | ||
retrieveGameRoles, | ||
retrieveDevOpsMaturities, | ||
}; | ||
export const name = slice.name; | ||
export const selectors = { | ||
getGameRoles, | ||
getDevOpsMaturities, | ||
}; |
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,4 +4,6 @@ | |
|
||
export interface RequestsKeys { | ||
signup: null; | ||
gameRoles: null; | ||
devOpsMaturities: null; | ||
} |
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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import { name as i18nName, reducer as i18nReducer } from '@pipeline/i18n'; | ||
import { name as authName, reducer as authReducer } from '@pipeline/auth'; | ||
import { name as requestsStatusName, reducer as requestsStatusReducer } from '@pipeline/requests-status'; | ||
import { name as dynamicDataName, reducer as dynamicDataReducer } from '@pipeline/dynamicData'; | ||
|
||
const reducers = { | ||
[i18nName]: i18nReducer, | ||
[authName]: authReducer, | ||
[requestsStatusName]: requestsStatusReducer, | ||
[dynamicDataName]: dynamicDataReducer, | ||
}; | ||
|
||
export default reducers; |
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