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(experience-controls): experience controls module and adapter #1307

Merged
merged 23 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9017a64
feat(xcontrols): add skeleton (#1278)
mgg709 Sep 13, 2023
02f6f2d
feat(xcontrols): add store module (#1285)
AnaOstio Sep 15, 2023
6534e8f
feat(xcontrols): add actions (#1288)
mgg709 Sep 20, 2023
b52ff8c
feat(xcontrols): add emitter (#1290)
mgg709 Sep 20, 2023
3844630
feat(xcontrols): add experience-controls component (#1297)
AnaOstio Sep 22, 2023
4ebbaab
feat(xcontrols): add request mapper (#1300)
mgg709 Sep 27, 2023
ce7af6f
feat(xcontrols): create response mapper (#1305)
AnaOstio Sep 28, 2023
347a135
feat(xcontrols): update the xperience-controls module with adapter (#…
AnaOstio Oct 3, 2023
068146f
Merge remote-tracking branch 'origin/main' into feature/EMP-1939-crea…
CachedaCodes Oct 3, 2023
53c0a4f
install missing deps for `x-types`
diegopf Oct 3, 2023
d9ceae5
export `PlatformExperienceControlsRequest`
diegopf Oct 3, 2023
13b9d67
remove unnecessary eslint-disable comment
diegopf Oct 3, 2023
2278faf
refactor `ExperienceControlsRequestMapper` comment
diegopf Oct 3, 2023
5189842
use `ExperienceControlsResponse` type for experienceControlsEndpointA…
diegopf Oct 3, 2023
408c798
change default endpoint for experienceControlsEndpointAdapter
diegopf Oct 3, 2023
9703847
add test for experienceControlsEndpointAdapter
diegopf Oct 3, 2023
173cf6d
extend experienceControlsAdapter to point to test
diegopf Oct 3, 2023
168dd72
skip test
diegopf Oct 3, 2023
566e1f8
enable test again
diegopf Oct 3, 2023
966d21f
chore: change object assign to vue set
CachedaCodes Oct 3, 2023
e574c4f
skip test again
CachedaCodes Oct 4, 2023
ef75c33
restore test
CachedaCodes Oct 4, 2023
6d4246f
remove tests from svg package scripts
CachedaCodes Oct 4, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { PlatformPopularSearchesResponse } from '../types/responses/popular-sear
import { PlatformRelatedTagsResponse } from '../types/responses/related-tags-response.model';
import { PlatformNextQueriesResponse } from '../types/responses/next-queries-response.model';
import { PlatformSemanticQueriesResponse } from '../types/responses/semantic-queries-response.model';
import { PlatformExperienceControlsResponse } from '../types';
import { getFetchMock } from './__mocks__/fetch.mock';
import { platformIdentifierResultsResponse } from './__fixtures__/identifier-results.response';
import { platformRecommendationsResponse } from './__fixtures__/recommendations.response';
Expand Down Expand Up @@ -636,4 +637,37 @@ describe('platformAdapter tests', () => {
]
});
});

it('should call the experiences control adapter', async () => {
const platformResponse: PlatformExperienceControlsResponse = {
grid: {
columns: 2
}
};

const fetchMock = jest.fn(getFetchMock(platformResponse));
window.fetch = fetchMock as any;

const response = await platformAdapter.experienceControls({
extraParams: {
instance: 'empathy',
env: 'staging'
}
});

expect(fetchMock).toHaveBeenCalledTimes(1);
expect(fetchMock).toHaveBeenCalledWith(
// eslint-disable-next-line max-len
'https://api.staging.empathy.co/config/v1/public/configs?service=xcontrols&instance=empathy&env=staging',
{ signal: expect.anything() }
);
expect(response).toStrictEqual({
controls: {
grid: {
columns: 2
}
},
events: {}
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* eslint-disable max-len */
import { endpointAdapterFactory } from '@empathyco/x-adapter';
import { ExperienceControlsRequest, ExperienceControlsResponse } from '@empathyco/x-types';
import { experienceControlsRequestMapper } from '../mappers/requests/experience-controls-request.mapper';
import { experienceControlsResponseMapper } from '../mappers/responses/experience-controls-response.mapper';
/* eslint-enable max-len */

/**.
* Default adapter for the experience controls endpoint.
*
* @public
*/
export const experienceControlsEndpointAdapter = endpointAdapterFactory<
ExperienceControlsRequest,
ExperienceControlsResponse
>({
endpoint: 'https://api.{extraParams.env(.)}empathy.co/config/v1/public/configs',
requestMapper: experienceControlsRequestMapper,
responseMapper: experienceControlsResponseMapper,
defaultRequestOptions: {
id: 'experience-controls',
parameters: {
service: 'xcontrols'
}
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export * from './related-tags.endpoint-adapter';
export * from './search.endpoint-adapter';
export * from './semantic-queries.endpoint-adapter';
export * from './tagging.endpoint-adapter';
export * from './experience-controls.endpoint-adapter';
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* eslint-disable max-len */
import { schemaMapperFactory } from '@empathyco/x-adapter';
import { ExperienceControlsRequest } from '@empathyco/x-types';
import { PlatformExperienceControlsRequest } from '../../types/requests/experience-controls-request.model';
import { experienceControlsRequestSchema } from '../../schemas/requests/experience-controls-request.schema';
/* eslint-enable max-len */

/**
* Default implementation for the ExperienceControlsRequestMapper.
*
* @public
*/
export const experienceControlsRequestMapper = schemaMapperFactory<
ExperienceControlsRequest,
PlatformExperienceControlsRequest
>(experienceControlsRequestSchema);
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export * from './related-tags-request.mapper';
export * from './search-request.mapper';
export * from './semantic-queries-request.mapper';
export * from './tagging-request.mapper';
export * from './experience-controls-request.mapper';
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { schemaMapperFactory } from '@empathyco/x-adapter';
import { ExperienceControlsResponse } from '@empathyco/x-types';
import { PlatformExperienceControlsResponse } from '../../types';
// eslint-disable-next-line max-len
import { experienceControlsResponseSchema } from '../../schemas/responses/experience-controls-response.schema';

/**
* Default implementation for the ExperienceControlsResponseMapper.
*
* @public
*/
export const experienceControlsResponseMapper = schemaMapperFactory<
PlatformExperienceControlsResponse,
ExperienceControlsResponse
>(experienceControlsResponseSchema);
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export * from './recommendations-response.mapper';
export * from './related-tags-response.mapper';
export * from './search-response.mapper';
export * from './semantic-queries-response.mapper';
export * from './experience-controls-response.mapper';
4 changes: 3 additions & 1 deletion packages/x-adapter-platform/src/platform.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { identifierResultsEndpointAdapter } from './endpoint-adapters/identifier
import { taggingEndpointAdapter } from './endpoint-adapters/tagging.endpoint-adapter';
import { querySuggestionsEndpointAdapter } from './endpoint-adapters/query-suggestions.endpoint-adapter';
import { semanticQueriesEndpointAdapter } from './endpoint-adapters/semantic-queries.endpoint-adapter';
import { experienceControlsEndpointAdapter } from './endpoint-adapters/experience-controls.endpoint-adapter';
/* eslint-enable max-len */

/**
Expand All @@ -25,5 +26,6 @@ export const platformAdapter: PlatformAdapter = {
relatedTags: relatedTagsEndpointAdapter,
identifierResults: identifierResultsEndpointAdapter,
tagging: taggingEndpointAdapter,
semanticQueries: semanticQueriesEndpointAdapter
semanticQueries: semanticQueriesEndpointAdapter,
experienceControls: experienceControlsEndpointAdapter
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { createMutableSchema } from '@empathyco/x-adapter';
import { ExperienceControlsRequest } from '@empathyco/x-types';
// eslint-disable-next-line max-len
import { PlatformExperienceControlsRequest } from '../../types/requests/experience-controls-request.model';

/**
* Default implementation for the ExperienceControlsRequestSchema.
*
* @public
*/
export const experienceControlsRequestSchema = createMutableSchema<
ExperienceControlsRequest,
PlatformExperienceControlsRequest
>({
extraParams: 'extraParams'
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export * from './related-tags-request.schema';
export * from './recommendations-request.schema';
export * from './search-request.schema';
export * from './semantic-queries-request.schema';
export * from './experience-controls-request.schema';
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { createMutableSchema } from '@empathyco/x-adapter';
import { ExperienceControlsResponse } from '@empathyco/x-types';
import { PlatformExperienceControlsResponse } from '../../types';

/**
* Default implementation for the ExperienceControlsResponseSchema.
*
* @public
*/
export const experienceControlsResponseSchema = createMutableSchema<
PlatformExperienceControlsResponse,
ExperienceControlsResponse
>({
controls: response => response,
events: {}
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export * from './related-tags-response.schema';
export * from './recommendations-response.schema';
export * from './semantic-queries-response.schema';
export * from './search-response.schema';
export * from './experience-controls-response.schema';
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
SemanticQueriesRequest,
SemanticQueriesResponse,
TaggingRequest,
ExperienceControlsRequest,
ExperienceControlsResponse,
XComponentsAdapter
} from '@empathyco/x-types';
import { ExtendableEndpointAdapter } from '@empathyco/x-adapter';
Expand All @@ -35,4 +37,8 @@ export interface PlatformAdapter extends XComponentsAdapter {
identifierResults: ExtendableEndpointAdapter<IdentifierResultsRequest, IdentifierResultsResponse>;
semanticQueries: ExtendableEndpointAdapter<SemanticQueriesRequest, SemanticQueriesResponse>;
tagging: ExtendableEndpointAdapter<TaggingRequest, void>;
experienceControls: ExtendableEndpointAdapter<
ExperienceControlsRequest,
ExperienceControlsResponse
>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { PlatformExtraParamsRequest } from './request.types';

/**
* Request for the `experience controls` endpoint.
*
* @public
*/
export interface PlatformExperienceControlsRequest extends PlatformExtraParamsRequest {}
1 change: 1 addition & 0 deletions packages/x-adapter-platform/src/types/requests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export * from './recommendations-request.model';
export * from './related-tags-request.model';
export * from './search-request.model';
export * from './semantic-queries-request.model';
export * from './experience-controls-request.model';
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Dictionary } from '@empathyco/x-utils';

/**
* Response for the `experience controls` endpoint.
*
* @public
*/
export interface PlatformExperienceControlsResponse extends Dictionary<unknown> {}
1 change: 1 addition & 0 deletions packages/x-adapter-platform/src/types/responses/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export * from './related-tags-response.model';
export * from './recommendations-response.model';
export * from './search-response.model';
export * from './semantic-queries-response.model';
export * from './experience-controls-response.model';
3 changes: 2 additions & 1 deletion packages/x-components/src/__tests__/adapter.dummy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ export const XComponentsAdapterDummy: XComponentsAdapter = {
relatedTags: jest.fn(),
search: jest.fn(),
semanticQueries: jest.fn(),
tagging: jest.fn()
tagging: jest.fn(),
experienceControls: jest.fn()
};
7 changes: 5 additions & 2 deletions packages/x-components/src/__tests__/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
QuerySuggestionsResponse,
RelatedTagsResponse,
SearchResponse,
SemanticQueriesResponse
SemanticQueriesResponse,
ExperienceControlsResponse
} from '@empathyco/x-types';
import { XPluginOptions } from '../plugins';
import { XPlugin } from '../plugins/x-plugin';
Expand Down Expand Up @@ -45,6 +46,7 @@ interface MockedAdapterFeatures {
search: SearchResponse;
semanticQueries: SemanticQueriesResponse;
tagging: void;
experienceControls: ExperienceControlsResponse;
}

/**
Expand Down Expand Up @@ -158,7 +160,8 @@ export function getMockedAdapter(
relatedTags: getMockedAdapterFunction(responseFeatures?.relatedTags!),
search: getMockedAdapterFunction(responseFeatures?.search!),
semanticQueries: getMockedAdapterFunction(responseFeatures?.semanticQueries!),
tagging: getMockedAdapterFunction(undefined)
tagging: getMockedAdapterFunction(undefined),
experienceControls: getMockedAdapterFunction(responseFeatures?.experienceControls!)
/* eslint-enable @typescript-eslint/no-non-null-asserted-optional-chain */
};
}
Expand Down
3 changes: 2 additions & 1 deletion packages/x-components/src/adapter/e2e-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@ export const e2eAdapter: XComponentsAdapter = {
defaultRequestOptions: {
properties: { keepalive: true }
}
})
}),
experienceControls: mockEndpointAdapter('experience-controls')
};
3 changes: 2 additions & 1 deletion packages/x-components/src/store/x.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export const RootXStoreModule: Module<XModuleState, any> = {
searchBox: null,
semanticQueries: null,
tagging: null,
url: null
url: null,
experienceControls: null
}),
namespaced: true
};
6 changes: 6 additions & 0 deletions packages/x-components/src/views/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ export const adapterConfig = {
e2e: 'Cypress' in window ? true : false
};

const experienceControlsAdapter = platformAdapter.experienceControls.extends({
endpoint: 'https://config-service.internal.test.empathy.co/public/configs'
});

platformAdapter.experienceControls = experienceControlsAdapter;

export const adapter = new Proxy(platformAdapter, {
get: (obj: PlatformAdapter, prop: keyof PlatformAdapter) =>
adapterConfig.e2e ? e2eAdapter[prop] : obj[prop]
Expand Down
3 changes: 3 additions & 0 deletions packages/x-components/src/views/home/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<PreselectedFilters />
<UrlHandler query="q" store="store" />
<SnippetCallbacks />
<ExperienceControls />
<OpenMainModal>Start</OpenMainModal>
<h1 class="x-text-primary-50 x-text-4xl x-font-bold x-leading-[1.5]">Test controls</h1>
<ul class="x-test-controls x-flex x-flex-col x-gap-16">
Expand Down Expand Up @@ -452,6 +453,7 @@
import ChevronTinyRight from '../../components/icons/chevron-tiny-right.vue';
import ChevronUp from '../../components/icons/chevron-up.vue';
import CrossIcon from '../../components/icons/cross.vue';
import ExperienceControls from '../../x-modules/experience-controls/components/experience-controls.vue';
import Grid2Col from '../../components/icons/grid-2-col.vue';
import Grid4Col from '../../components/icons/grid-4-col.vue';
import LightBulbOn from '../../components/icons/light-bulb-on.vue';
Expand Down Expand Up @@ -539,6 +541,7 @@
ClearSearchInput,
CloseMainModal,
CrossIcon,
ExperienceControls,
Grid2Col,
Grid4Col,
LightBulbOn,
Expand Down
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<script lang="ts">
import Vue from 'vue';
import { Component } from 'vue-property-decorator';
import { XOn } from '../../../components/decorators/bus.decorators';
import { XEvent, XEventsTypes } from '../../../wiring/events.types';
import { xComponentMixin } from '../../../components/x-component.mixin';
import { experienceControlsXModule } from '../x-module';

/**
* This component subscribes to changes in the ExperienceControls module to fire the events that
* propagate the configuration.
*
* @public
*/
@Component({
mixins: [xComponentMixin(experienceControlsXModule)]
})
export default class ExperienceControls extends Vue {
/**.
* Iterates the list of XEvents received and emits them
*
* @param {Partial<XEventsTypes>} events events to be emitted
*/
@XOn('ExperienceControlsEventsChanged')
onEventsChanged(events: Partial<XEventsTypes>): void {
Object.entries(events).forEach(([eventName, eventPayload]) => {
this.$x.emit(eventName as XEvent, eventPayload);
});
}

// eslint-disable-next-line @typescript-eslint/no-empty-function
render(): void {}
}
</script>

<docs lang="mdx">
## Examples

This component will fire the events received in the `ExperienceControlsEventsChanged` event.

```vue
<template>
<ExperienceControls />
</template>
<script>
import { ExperienceControls } from '@empathyco/x-components/experience-controls';

export default {
name: 'ExperienceControlsDemo',
components: {
ExperienceControls
}
};
</script>
```
</docs>
Loading