-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(xcontrols): add actions (#1288)
EMP-2056 --------- Co-authored-by: Ana Fernández Ostio <[email protected]> Co-authored-by: Ana Fernández Ostio <[email protected]> Co-authored-by: Ana Fernández Ostio <[email protected]>
- Loading branch information
1 parent
02f6f2d
commit 6534e8f
Showing
9 changed files
with
140 additions
and
10 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
File renamed without changes.
31 changes: 31 additions & 0 deletions
31
...ponents/src/x-modules/experience-controls/store/actions/fetch-and-save-controls.action.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,31 @@ | ||
import { createFetchAndSaveActions } from '../../../../store/utils/fetch-and-save-action.utils'; | ||
import { ExperienceControlsActionContext } from '../types'; | ||
|
||
const { fetchAndSave, cancelPrevious } = createFetchAndSaveActions< | ||
ExperienceControlsActionContext, | ||
//TODO: change types when the adapter is updated | ||
any, | ||
any | ||
>({ | ||
fetch({ dispatch }, request) { | ||
return dispatch('fetchExperienceControlsResponse', request); | ||
}, | ||
onSuccess({ commit }, experienceControlsResponse) { | ||
commit('setControls', experienceControlsResponse.controls); | ||
commit('setEvents', experienceControlsResponse.events); | ||
} | ||
}); | ||
|
||
/** | ||
* Default implementation for {@link ExperienceControlsActions.fetchAndSaveControls} action. | ||
* | ||
* @public | ||
*/ | ||
export const fetchAndSaveExperienceControlsResponse = fetchAndSave; | ||
|
||
/** | ||
* Default implementation for {@link ExperienceControlsActions.cancelFetchAndSaveControls} action. | ||
* | ||
* @public | ||
*/ | ||
export const cancelFetchAndSaveControls = cancelPrevious; |
37 changes: 37 additions & 0 deletions
37
...ges/x-components/src/x-modules/experience-controls/store/actions/fetch-controls.action.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,37 @@ | ||
import { ExperienceControlsXStoreModule } from '../types'; | ||
|
||
/** | ||
* Default implementation for the {@link ExperienceControlsActions.fetchControls}. | ||
* | ||
* @param _context - The {@link https://vuex.vuejs.org/guide/actions.html | context} of the actions, | ||
* provided by Vuex. | ||
* TODO: update when adapter is updateds. | ||
* @param request | ||
* @returns | ||
* | ||
* @public | ||
*/ | ||
|
||
// eslint-disable-next-line max-len | ||
export const fetchExperienceControlsResponse: ExperienceControlsXStoreModule['actions']['fetchExperienceControlsResponse'] = | ||
async () => { | ||
const response = await fetch( | ||
// eslint-disable-next-line max-len | ||
'https://config-service.internal.test.empathy.co/public/configs?service=xcontrols&instance=empathy' | ||
); | ||
|
||
if (response.ok) { | ||
const controls = await response.json(); | ||
|
||
const aux = { | ||
controls, | ||
events: {} | ||
}; | ||
|
||
return aux; | ||
} else { | ||
throw new Error('Failed to fetch data'); | ||
} | ||
|
||
//return XPlugin.adapter.experienceControls(request).then(({ controls }) => controls); | ||
}; |
7 changes: 5 additions & 2 deletions
7
packages/x-components/src/x-modules/experience-controls/store/emitters.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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
import { createStoreEmitters } from '../../../store'; | ||
import { experienceControlsXStoreModule } from './module'; | ||
|
||
/** | ||
* {@link StoreEmitters} For the experience-controls module. | ||
* {@link StoreEmitters} For the {@link ExperienceControlsXModule}. | ||
* | ||
* @internal | ||
*/ | ||
export const experienceControlsEmitters = {}; | ||
export const experienceControlsEmitters = createStoreEmitters(experienceControlsXStoreModule, {}); |
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
23 changes: 22 additions & 1 deletion
23
packages/x-components/src/x-modules/experience-controls/wiring.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 |
---|---|---|
@@ -1,8 +1,29 @@ | ||
import { namespacedWireCommit } from '../../wiring'; | ||
import { createWiring } from '../../wiring/wiring.utils'; | ||
|
||
const moduleName = 'experienceControls'; | ||
|
||
/** | ||
* WireCommit for {@link SemanticQueriesXModule}. | ||
* | ||
* @internal | ||
*/ | ||
const wireCommit = namespacedWireCommit(moduleName); | ||
|
||
/** | ||
* WireCommit for {@link ExperienceControlsXModule}. | ||
* | ||
* @internal | ||
*/ | ||
export const setParamsWire = wireCommit('setParams'); | ||
|
||
/** | ||
* Wiring configuration for the {@link ExperienceControlsXModule | experience-controls module}. | ||
* | ||
* @internal | ||
*/ | ||
export const experienceControlsWiring = createWiring({}); | ||
export const experienceControlsWiring = createWiring({ | ||
ExtraParamsChanged: { | ||
setParamsWire | ||
} | ||
}); |
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