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

chore(headless, atomic, quantic)!: remove deprecated functions/properties #4350

Merged
merged 17 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
17 changes: 0 additions & 17 deletions packages/atomic/cypress/e2e/search-interface.cypress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,22 +358,5 @@ describe('Search Interface Component', () => {
);
});
});

describe('with doNotTrack', () => {
beforeEach(() => {
fixture.withDoNotTrack().init();
});

it('should not call the analytics server', () => {
cy.wait(TestFixture.interceptAliases.Search);
cy.shouldBeCalled(TestFixture.interceptAliases.UA, 0);
});

it('should not include analytics in the search request', () => {
cy.wait(TestFixture.interceptAliases.Search).should((firstSearch) =>
expect(firstSearch.request.body).not.to.have.property('analytics')
);
});
});
});
});
15 changes: 1 addition & 14 deletions packages/atomic/cypress/fixtures/test-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export class TestFixture {
private language?: string;
private localizationCompatibilityVersion: i18nCompatibilityVersion = 'v4';
private disabledAnalytics = false;
private doNotTrack = false;
private fieldCaptions: {field: string; captions: Record<string, string>}[] =
[];
private translations: Record<string, string> = {};
Expand Down Expand Up @@ -136,11 +135,6 @@ export class TestFixture {
return this;
}

public withDoNotTrack() {
this.doNotTrack = true;
return this;
}

public withRedirection() {
this.redirected = true;
return this;
Expand Down Expand Up @@ -210,13 +204,6 @@ export class TestFixture {
setupIntercept();
spyConsole();

cy.window().then((win) => {
Object.defineProperty(win.navigator, 'doNotTrack', {
get: () => (this.doNotTrack ? '1' : '0'),
configurable: true,
});
});

cy.document().then((doc) => {
doc.head.appendChild(this.style);
doc.body.appendChild(this.searchInterface);
Expand Down Expand Up @@ -273,7 +260,7 @@ export class TestFixture {

if (this.execFirstSearch && this.firstIntercept) {
cy.wait(TestFixture.interceptAliases.Search);
if (!(this.disabledAnalytics || this.doNotTrack)) {
if (!this.disabledAnalytics) {
cy.wait(TestFixture.interceptAliases.UA);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ export class AtomicCategoryFacet implements InitializableComponent {
this.bindings.store.registerFacet('categoryFacets', facetInfo);
initializePopover(this.host, {
...facetInfo,
hasValues: () => !!this.facet.state.values.length,
hasValues: () => !!this.facet.state.valuesAsTrees.length,
numberOfActiveValues: () => (this.facetState.hasActiveValues ? 1 : 0),
});
this.initializeDependenciesManager();
Expand Down Expand Up @@ -344,7 +344,8 @@ export class AtomicCategoryFacet implements InitializableComponent {
return (
this.searchStatusState.hasError ||
!this.facet.state.enabled ||
(!this.facet.state.values.length && !this.facet.state.parents.length)
(!this.facet.state.selectedValueAncestry.length &&
!this.facet.state.valuesAsTrees.length)
);
}

Expand Down Expand Up @@ -381,7 +382,7 @@ export class AtomicCategoryFacet implements InitializableComponent {
}

private get hasParents() {
return !!this.facetState.parents.length;
return !!this.facetState.selectedValueAncestry.length;
}

private initializeDependenciesManager() {
Expand Down Expand Up @@ -447,7 +448,10 @@ export class AtomicCategoryFacet implements InitializableComponent {
);
}

private renderValuesTree(parents: CategoryFacetValue[], isRoot: boolean) {
private renderValuesTree(
valuesAsTrees: CategoryFacetValue[],
isRoot: boolean
) {
if (!this.hasParents) {
return this.renderChildren();
}
Expand All @@ -463,14 +467,14 @@ export class AtomicCategoryFacet implements InitializableComponent {
}}
/>
<CategoryFacetParentAsTreeContainer isTopLevel={false}>
{this.renderValuesTree(parents, false)}
{this.renderValuesTree(valuesAsTrees, false)}
</CategoryFacetParentAsTreeContainer>
</CategoryFacetTreeValueContainer>
);
}

if (parents.length > 1) {
const parentValue = parents[0];
if (valuesAsTrees.length > 1) {
const parentValue = valuesAsTrees[0];

return (
<CategoryFacetTreeValueContainer>
Expand All @@ -484,13 +488,13 @@ export class AtomicCategoryFacet implements InitializableComponent {
}}
/>
<CategoryFacetParentAsTreeContainer isTopLevel={false}>
{this.renderValuesTree(parents.slice(1), false)}
{this.renderValuesTree(valuesAsTrees.slice(1), false)}
</CategoryFacetParentAsTreeContainer>
</CategoryFacetTreeValueContainer>
);
}

const activeParent = parents[0];
const activeParent = valuesAsTrees[0];
const activeParentDisplayValue = getFieldValueCaption(
this.field,
activeParent.value,
Expand Down Expand Up @@ -551,11 +555,22 @@ export class AtomicCategoryFacet implements InitializableComponent {
}

private renderChildren() {
if (!this.facetState.values.length) {
if (!this.facetState.valuesAsTrees.length) {
return;
}
if (this.facetState.selectedValueAncestry.length > 0) {
return this.facetState.selectedValueAncestry
.find((value) => value.state === 'selected')
?.children.map((value, i) =>
this.renderChild(
value,
i === 0,
i === this.resultIndexToFocusOnShowMore
)
);
}

return this.facetState.values.map((value, i) =>
return this.facetState.valuesAsTrees.map((value, i) =>
this.renderChild(value, i === 0, i === this.resultIndexToFocusOnShowMore)
);
}
Expand Down Expand Up @@ -598,7 +613,8 @@ export class AtomicCategoryFacet implements InitializableComponent {
label={this.label}
i18n={this.bindings.i18n}
onShowMore={() => {
this.resultIndexToFocusOnShowMore = this.facetState.values.length;
this.resultIndexToFocusOnShowMore =
this.facetState.valuesAsTrees[0].children.length;
this.focusTargets.showMoreFocus.focusAfterSearch();
this.facet.showMoreValues();
}}
Expand Down Expand Up @@ -627,7 +643,7 @@ export class AtomicCategoryFacet implements InitializableComponent {
const {
bindings: {i18n},
label,
facetState: {facetSearch, enabled, valuesAsTrees, parents},
facetState: {facetSearch, enabled, valuesAsTrees, selectedValueAncestry},
searchStatusState: {hasError, firstSearchExecuted},
} = this;

Expand Down Expand Up @@ -666,7 +682,7 @@ export class AtomicCategoryFacet implements InitializableComponent {
isTopLevel={true}
className="mt-3"
>
{this.renderValuesTree(parents, true)}
{this.renderValuesTree(selectedValueAncestry, true)}
</CategoryFacetParentAsTreeContainer>
) : (
<CategoryFacetChildrenAsTreeContainer className="mt-3">
Expand Down
16 changes: 2 additions & 14 deletions packages/headless/src/app/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {versionReducer as version} from '../features/debug/version-slice';
import {SearchParametersState} from '../state/search-app-state';
import {isBrowser} from '../utils/runtime';
import {matchCoveoOrganizationEndpointUrlAnyOrganization} from '../utils/url-utils';
import {doNotTrack} from '../utils/utils';
import {analyticsMiddleware} from './analytics-middleware';
import {configuration} from './common-reducers';
import {EngineConfiguration} from './engine-configuration';
Expand Down Expand Up @@ -185,8 +184,7 @@ export interface ExternalEngineOptions<State extends object> {
}

function getUpdateAnalyticsConfigurationPayload(
configuration: EngineConfiguration,
logger: Logger
configuration: EngineConfiguration
): UpdateAnalyticsConfigurationActionCreatorPayload | null {
const apiBaseUrl =
configuration.organizationEndpoints?.analytics || undefined;
Expand All @@ -199,15 +197,6 @@ function getUpdateAnalyticsConfigurationPayload(
apiBaseUrl,
};

// TODO KIT-2844
if (payloadWithURL.analyticsMode !== 'next' && doNotTrack()) {
logger.info('Analytics disabled since doNotTrack is active.');
return {
...payloadWithURL,
enabled: false,
};
}

alexprudhomme marked this conversation as resolved.
Show resolved Hide resolved
if (payloadWithURL.analyticsMode === 'next' && !payload.trackingId) {
throw new InvalidEngineConfiguration(
'analytics.trackingId is required when analytics.analyticsMode="next"'
Expand Down Expand Up @@ -263,8 +252,7 @@ export function buildEngine<
);

const analyticsPayload = getUpdateAnalyticsConfigurationPayload(
options.configuration,
engine.logger
options.configuration
);
if (analyticsPayload) {
engine.dispatch(updateAnalyticsConfiguration(analyticsPayload));
Expand Down
8 changes: 1 addition & 7 deletions packages/headless/src/app/logger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pino, {LevelWithSilent, LogEvent} from 'pino';
import pino, {LevelWithSilent} from 'pino';

export type LogLevel = LevelWithSilent;

Expand All @@ -12,12 +12,6 @@ export interface LoggerOptions {
* All arguments passed to the log method, except the message, will be pass to this function. By default it does not change the shape of the log object.
*/
logFormatter?: (object: {}) => {};
/**
* Function which will be called after writing the log message in the browser.
*
* @deprecated This option is deprecated and will be removed in a future version.
*/
browserPostLogHook?: (level: LogLevel, logEvent: LogEvent) => void;
}

export function buildLogger(options: LoggerOptions | undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,10 @@ describe('category facet', () => {
});

describe('when the search response is empty', () => {
it('#state.values is an empty array', () => {
expect(state.search.response.facets).toEqual([]);
expect(categoryFacet.state.values).toEqual([]);
it('#state.selectedValueAncestry is an empty array', () => {
expect(categoryFacet.state.selectedValueAncestry).toEqual([]);
});

it('#state.parents is an empty array', () => {
expect(categoryFacet.state.parents).toEqual([]);
});

it('#state.valuesAsTrees', () => {
it('#state.valuesAsTrees is an empty array', () => {
expect(categoryFacet.state.valuesAsTrees).toEqual([]);
});
});
Expand All @@ -174,10 +168,6 @@ describe('category facet', () => {
state.search.response.facets = [response];
});

it('#state.values contains the same values', () => {
expect(categoryFacet.state.values).toBe(values);
});

it('#state.valuesAsTrees contains the same values', () => {
expect(categoryFacet.state.valuesAsTrees).toBe(values);
});
Expand Down Expand Up @@ -212,18 +202,6 @@ describe('category facet', () => {
state.search.response.facets = [response];
});

it('#state.parents contains the outer and middle values', () => {
expect(categoryFacet.state.parents).toEqual([outerValue, middleValue]);
});

it('#state.values contains the innermost values', () => {
expect(categoryFacet.state.values).toBe(innerValues);
});

it('#state.parents contains the outer and middle values', () => {
expect(categoryFacet.state.parents).toEqual([outerValue, middleValue]);
});

it('#state.valueAsTree contains the outer value', () => {
expect(categoryFacet.state.valuesAsTrees).toEqual([outerValue]);
});
Expand Down Expand Up @@ -283,18 +261,14 @@ describe('category facet', () => {
state.search.response.facets = [response];
});

it('#state.parents contains the selected leaf value', () => {
expect(categoryFacet.state.parents).toEqual([selectedValue]);
});

it('#state.selectedValueAncestry contains the selected leaf value', () => {
expect(categoryFacet.state.selectedValueAncestry).toEqual([
selectedValue,
]);
});

it('#state.values is an empty array', () => {
expect(categoryFacet.state.values).toEqual([]);
it('#state.activeValue.children an empty array', () => {
expect(categoryFacet.state.activeValue?.children).toEqual([]);
});

it('#state.activeValue is the selected leaf value', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,19 +163,6 @@ export interface CoreCategoryFacetState {
*/
isHierarchical: boolean;

/**
* The facet's parent values.
* @deprecated uses `valuesAsTrees` instead.
*
*/
parents: CategoryFacetValue[];

/**
* The facet's values.
* @deprecated use `selectedValueAncestry` instead.
*/
values: CategoryFacetValue[];

/**
* The selected facet values ancestry.
* The first element is the "root" of the selected value ancestry tree.
Expand Down
Loading
Loading