Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(xcontrols): add actions #1288

Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/x-components/src/wiring/events.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { TaggingXEvents } from '../x-modules/tagging/events.types';
import { UrlXEvents } from '../x-modules/url/events.types';
import { XModuleName } from '../x-modules/x-modules.types';
import { SemanticQueriesXEvents } from '../x-modules/semantic-queries/events.types';
import { ExperienceControlsXEvents } from '../x-modules/experience-controls/events.types';
import { WireMetadata } from './wiring.types';
/* eslint-disable max-len */
/**.
Expand Down Expand Up @@ -70,6 +71,7 @@ export interface XEventsTypes
SearchXEvents,
SemanticQueriesXEvents,
TaggingXEvents,
ExperienceControlsXEvents,
UrlXEvents {
/**
* The provided number of columns of a grid has changed.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { XEventsTypes } from '../../wiring';

/**
* Dictionary of the events of Experience Controls XModule.
*
* @public
*/
export interface ExperienceControlsXEvents {
/**
* The experience-controls-events closed following its events configuration.
* * Payload: none.
*/
ExperienceControlsClosed: Partial<XEventsTypes>;
CachedaCodes marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { createFetchAndSaveActions } from '../../../../store/utils/fetch-and-save-action.utils';
import { ExperienceControlsActionContext } from '../types';

const { fetchAndSave, cancelPrevious } = createFetchAndSaveActions<
ExperienceControlsActionContext,
any,
any
CachedaCodes marked this conversation as resolved.
Show resolved Hide resolved
>({
fetch({ dispatch }, request) {
return dispatch('fetchControls', request);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you have the full adapter here you won't just receive the controls but also the events to emit. This should be called fetchExperienceControlsResponse

},
onSuccess({ commit }, controls) {
commit('setControls', controls);
CachedaCodes marked this conversation as resolved.
Show resolved Hide resolved
}
});

/**
* Default implementation for {@link ExperienceControlsActions.fetchAndSaveControls} action.
*
* @public
*/
export const fetchAndSaveControls = fetchAndSave;

/**
* Default implementation for {@link ExperienceControlsActions.cancelFetchAndSaveControls} action.
*
* @public
*/
export const cancelFetchAndSaveControls = cancelPrevious;
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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.
* @param request - To be done.
* @returns To be done.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a TODO to change with the adapter.

*
* @public
*/

export const fetchControls: ExperienceControlsXStoreModule['actions']['fetchControls'] = () => {
return fetch(
// eslint-disable-next-line max-len
'https://config-service.internal.test.empathy.co/public/configs?service=xcontrols&instance=empathy'
).then(response => response.json());
CachedaCodes marked this conversation as resolved.
Show resolved Hide resolved

//return XPlugin.adapter.experienceControls(request).then(({ controls }) => controls);
};
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, {});
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { fetchAndSaveControls } from './actions/fetch-and-save-controls.action';
import { fetchControls } from './actions/fetch-controls.action';
import { ExperienceControlsXStoreModule } from './types';

/**.
Expand All @@ -20,5 +22,8 @@ export const experienceControlsXStoreModule: ExperienceControlsXStoreModule = {
Object.assign(state.events, events);
}
},
actions: {}
actions: {
fetchControls,
fetchAndSaveControls
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,20 @@ export interface ExperienceControlsMutations {
setEvents(events: Partial<XEventsTypes>): void;
}

export interface ExperienceControlsActions {}
export interface ExperienceControlsActions {
/**
* Fetches the {@link ExperienceControlsState.controls} property.
*
* @param request - The request to fetch the {@link ExperienceControlsState.controls}.
* @returns A promise of the {@link ExperienceControlsState.controls}.
*/
fetchControls(request: any): Promise<{ [key: string]: unknown }>;
CachedaCodes marked this conversation as resolved.
Show resolved Hide resolved

/**
* Fetches and saves the {@link ExperienceControlsState.controls} property.
*/
fetchAndSaveControls(request: any): void;
CachedaCodes marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Experience Controls type safe store module.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import { wireCommit } from '../../wiring';
import { createWiring } from '../../wiring/wiring.utils';

/**
* WireCommit for {@link ExperienceControlsXModule}.
*
* @internal
*/
export const controlEvents = wireCommit('setControls');
CachedaCodes marked this conversation as resolved.
Show resolved Hide resolved

/**
* Wiring configuration for the {@link ExperienceControlsXModule | experience-controls module}.
*
* @internal
*/
export const experienceControlsWiring = createWiring({});
export const experienceControlsWiring = createWiring({
ExperienceControlsClosed: {
controlEvents
}
});