@salesforcedevs/dx-components 0.18.9 → 0.19.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/modules/dx/header/__tests__/mockProps.ts +4 -10
- package/src/modules/dx/headerSearch/headerSearch.html +0 -1
- package/src/modules/dx/headerSearch/headerSearch.ts +23 -19
- package/src/modules/dx/sidebarSearch/sidebarSearch.ts +7 -10
- package/src/modules/dx/sidebarSearchResult/__tests__/sidebarSearchResult.test.ts +47 -6
- package/src/modules/dx/sidebarSearchResult/sidebarSearchResult.ts +18 -4
- package/src/modules/utils/coveo/coveo.ts +4 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforcedevs/dx-components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.3",
|
|
4
4
|
"description": "DX Lightning web components",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"@types/debounce": "^1.2.0",
|
|
30
30
|
"@types/lodash.get": "^4.4.6"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "3e316062ee2d79d71aebcbc69d327f24ebefa8fc"
|
|
33
33
|
}
|
|
@@ -13,13 +13,7 @@ import {
|
|
|
13
13
|
mockNavAnalytics
|
|
14
14
|
} from "./mockNavs";
|
|
15
15
|
import mockNavDevelopers from "./mockNavDevelopers";
|
|
16
|
-
|
|
17
|
-
export const coveoConfig = {
|
|
18
|
-
coveoOrganizationId: "coveosalesforcetestakshatha",
|
|
19
|
-
coveoPublicAccessToken: "xx114e9d50-bc6b-40f1-b25b-fa5a06c7e168",
|
|
20
|
-
coveoSearchPipeline: "salesforcedevdoc",
|
|
21
|
-
coveoSearchHub: "salesforcedevdoc2"
|
|
22
|
-
};
|
|
16
|
+
import { coveoHeaderConfig } from "../../../utils/coveo/coveo";
|
|
23
17
|
|
|
24
18
|
const versions = JSON.stringify([
|
|
25
19
|
{
|
|
@@ -44,18 +38,18 @@ export const mockPropsDevelopers = {
|
|
|
44
38
|
navItems: JSON.stringify(mockNavDevelopers),
|
|
45
39
|
subtitle: "Developers",
|
|
46
40
|
signupLink: "/sign-up",
|
|
47
|
-
...
|
|
41
|
+
...coveoHeaderConfig
|
|
48
42
|
};
|
|
49
43
|
|
|
50
44
|
export const mockPropsNoNavigation = {
|
|
51
45
|
subtitle: "Developers",
|
|
52
|
-
...
|
|
46
|
+
...coveoHeaderConfig
|
|
53
47
|
};
|
|
54
48
|
|
|
55
49
|
export const mockPropsDevWebsite = {
|
|
56
50
|
version: "1",
|
|
57
51
|
versions,
|
|
58
|
-
...
|
|
52
|
+
...coveoHeaderConfig,
|
|
59
53
|
signupLink: "/sign-up",
|
|
60
54
|
bannerMarkup:
|
|
61
55
|
'<span><a href="https://forms.gle/TdSyKFPHXoBx7seM9" target="blank">Share your feedback</a>about our new site.</span>'
|
|
@@ -77,25 +77,29 @@ export default class HeaderSearch extends LightningElement {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
private instantiateSearchbox() {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
80
|
+
try {
|
|
81
|
+
const options: StandaloneSearchBoxOptions = {
|
|
82
|
+
numberOfSuggestions: 3,
|
|
83
|
+
redirectionUrl: "https://developer.salesforce.com"
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const engine = buildSearchEngine({
|
|
87
|
+
organizationId: this.coveoOrganizationId,
|
|
88
|
+
publicAccessToken: this.coveoPublicAccessToken,
|
|
89
|
+
searchPipeline: this.coveoSearchPipeline,
|
|
90
|
+
searchHub: this.coveoSearchHub
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
this.searchBox = buildStandaloneSearchBox(engine, { options });
|
|
94
|
+
|
|
95
|
+
this.searchBox?.subscribe(() => {
|
|
96
|
+
if (this.searchBox) {
|
|
97
|
+
this.searchState = this.searchBox.state;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
} catch (e) {
|
|
101
|
+
console.error(`Coveo searchbox failed to initialize (${e})`);
|
|
102
|
+
}
|
|
99
103
|
}
|
|
100
104
|
|
|
101
105
|
private createSearchHref = (value: string | null = "") => {
|
|
@@ -285,23 +285,20 @@ export default class SidebarSearch extends LightningElement {
|
|
|
285
285
|
}: Result): SidebarSearchResult => {
|
|
286
286
|
// discussion about this normalization here: https://salesforce-internal.slack.com/archives/C020S6784JX/p1639506238376600
|
|
287
287
|
|
|
288
|
-
const isNestedGuide = clickUri.includes("/guide/");
|
|
289
|
-
const isGuide = clickUri.endsWith("/guide") || isNestedGuide;
|
|
290
|
-
const isReference = clickUri.endsWith("/references");
|
|
291
|
-
const isApex = !!sfhtml_url__c;
|
|
292
|
-
|
|
293
288
|
let pathname;
|
|
294
|
-
if (
|
|
289
|
+
if (sfhtml_url__c) {
|
|
295
290
|
pathname = `/docs/${sfhtml_url__c}`;
|
|
296
291
|
} else {
|
|
292
|
+
const isNestedGuide = clickUri.includes("/guide/");
|
|
297
293
|
const url = new URL(clickUri);
|
|
298
|
-
const extension =
|
|
294
|
+
const extension =
|
|
295
|
+
isNestedGuide && !url.pathname?.endsWith(".html")
|
|
296
|
+
? ".html"
|
|
297
|
+
: "";
|
|
299
298
|
pathname = `${url.pathname}${extension}`;
|
|
300
299
|
}
|
|
301
300
|
|
|
302
|
-
const
|
|
303
|
-
isGuide || isReference || isApex ? `?q=${this.value}` : "";
|
|
304
|
-
const href = `${pathname}${query}`;
|
|
301
|
+
const href = `${pathname}?q=${this.value}`;
|
|
305
302
|
|
|
306
303
|
return {
|
|
307
304
|
title,
|
|
@@ -4,7 +4,7 @@ import { createRenderComponent } from "utils/tests";
|
|
|
4
4
|
const TAG = "dx-sidebar-search-result";
|
|
5
5
|
const render = createRenderComponent(TAG, SidebarSearchResult);
|
|
6
6
|
|
|
7
|
-
const
|
|
7
|
+
const MOCK_RESULT = {
|
|
8
8
|
description: "test description here",
|
|
9
9
|
descriptionHighlights: [{ length: 5, offset: 5 }],
|
|
10
10
|
href: "/test",
|
|
@@ -13,24 +13,65 @@ const PROPS = {
|
|
|
13
13
|
titleHighlights: [{ length: 5, offset: 5 }]
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
+
const MOCK_RESULT_2 = {
|
|
17
|
+
description:
|
|
18
|
+
"Auth.MyDomainLoginDiscoveryHandler to show a custom error message on the My Domain login page ... Auth.LoginDiscoveryHandler to show an error message on the Experience Cloud site login page",
|
|
19
|
+
descriptionHighlights: [
|
|
20
|
+
{ length: 4, offset: 0 },
|
|
21
|
+
{ length: 4, offset: 98 }
|
|
22
|
+
],
|
|
23
|
+
href: "/test",
|
|
24
|
+
selected: false,
|
|
25
|
+
title: "Auth Exceptions | Apex Reference Guide | Salesforce Developers",
|
|
26
|
+
titleHighlights: [{ length: 4, offset: 0 }]
|
|
27
|
+
};
|
|
28
|
+
|
|
16
29
|
describe(TAG, () => {
|
|
17
30
|
it("renders a result with the correct highlighted content", () => {
|
|
18
|
-
const element = render(
|
|
31
|
+
const element = render(MOCK_RESULT);
|
|
19
32
|
|
|
33
|
+
const title = element.shadowRoot.querySelector(".title");
|
|
20
34
|
const titleBolds = element.shadowRoot.querySelectorAll(".title .bold");
|
|
21
|
-
expect(
|
|
35
|
+
expect(title.textContent).toEqual(MOCK_RESULT.title);
|
|
36
|
+
expect(titleBolds.length).toEqual(MOCK_RESULT.titleHighlights.length);
|
|
22
37
|
expect(titleBolds[0].textContent).toEqual("title");
|
|
23
38
|
|
|
39
|
+
const description = element.shadowRoot.querySelector(".description");
|
|
24
40
|
const descriptionBolds =
|
|
25
41
|
element.shadowRoot.querySelectorAll(".description .bold");
|
|
26
|
-
expect(
|
|
42
|
+
expect(description.textContent).toEqual(MOCK_RESULT.description);
|
|
43
|
+
expect(descriptionBolds.length).toEqual(
|
|
44
|
+
MOCK_RESULT.descriptionHighlights.length
|
|
45
|
+
);
|
|
27
46
|
expect(descriptionBolds[0].textContent).toEqual("descr");
|
|
28
47
|
|
|
29
48
|
return expect(element).toBeAccessible();
|
|
30
49
|
});
|
|
31
50
|
|
|
51
|
+
it("renders another result variant with the correct highlighted content", () => {
|
|
52
|
+
const element = render(MOCK_RESULT_2);
|
|
53
|
+
|
|
54
|
+
const title = element.shadowRoot.querySelector(".title");
|
|
55
|
+
const titleBolds = element.shadowRoot.querySelectorAll(".title .bold");
|
|
56
|
+
expect(title.textContent).toEqual(MOCK_RESULT_2.title);
|
|
57
|
+
expect(titleBolds.length).toEqual(MOCK_RESULT_2.titleHighlights.length);
|
|
58
|
+
expect(titleBolds[0].textContent).toEqual("Auth");
|
|
59
|
+
|
|
60
|
+
const description = element.shadowRoot.querySelector(".description");
|
|
61
|
+
const descriptionBolds =
|
|
62
|
+
element.shadowRoot.querySelectorAll(".description .bold");
|
|
63
|
+
expect(description.textContent).toEqual(MOCK_RESULT_2.description);
|
|
64
|
+
expect(descriptionBolds.length).toEqual(
|
|
65
|
+
MOCK_RESULT_2.descriptionHighlights.length
|
|
66
|
+
);
|
|
67
|
+
expect(descriptionBolds[0].textContent).toEqual("Auth");
|
|
68
|
+
expect(descriptionBolds[1].textContent).toEqual("Auth");
|
|
69
|
+
|
|
70
|
+
return expect(element).toBeAccessible();
|
|
71
|
+
});
|
|
72
|
+
|
|
32
73
|
it("renders a result as selected when specified", () => {
|
|
33
|
-
const element = render({ ...
|
|
74
|
+
const element = render({ ...MOCK_RESULT, selected: true });
|
|
34
75
|
|
|
35
76
|
const selected = element.shadowRoot.querySelector(
|
|
36
77
|
".sidebar-item-selected"
|
|
@@ -42,7 +83,7 @@ describe(TAG, () => {
|
|
|
42
83
|
|
|
43
84
|
it("doesn't add bold class when there is no highlighted term", () => {
|
|
44
85
|
const element = render({
|
|
45
|
-
...
|
|
86
|
+
...MOCK_RESULT,
|
|
46
87
|
descriptionHighlights: [],
|
|
47
88
|
titleHighlights: []
|
|
48
89
|
});
|
|
@@ -13,7 +13,7 @@ const toChunks = (value: string, highlights: CoveoHighlights) => {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
let endIndex = 0;
|
|
16
|
-
return highlights.reduce((acc, { length, offset }) => {
|
|
16
|
+
return highlights.reduce((acc, { length, offset }, i) => {
|
|
17
17
|
const plainValue = value.slice(endIndex, offset);
|
|
18
18
|
const plainChunk = {
|
|
19
19
|
value: plainValue,
|
|
@@ -28,9 +28,23 @@ const toChunks = (value: string, highlights: CoveoHighlights) => {
|
|
|
28
28
|
id: offset
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
let chunks =
|
|
32
|
+
plainValue.length > 0
|
|
33
|
+
? [...acc, plainChunk, boldChunk]
|
|
34
|
+
: [...acc, boldChunk];
|
|
35
|
+
|
|
36
|
+
const remaining = value.slice(endIndex);
|
|
37
|
+
if (remaining.length > 0 && highlights.length - 1 === i) {
|
|
38
|
+
chunks = [
|
|
39
|
+
...chunks,
|
|
40
|
+
{
|
|
41
|
+
value: remaining,
|
|
42
|
+
id: value.length
|
|
43
|
+
}
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return chunks;
|
|
34
48
|
}, []);
|
|
35
49
|
};
|
|
36
50
|
|
|
@@ -38,17 +38,18 @@ export const getSidebarSearchParams = () =>
|
|
|
38
38
|
new URLSearchParams(window.location.search).get("q");
|
|
39
39
|
|
|
40
40
|
const coveoOrganizationId = "coveosalesforcetestakshatha";
|
|
41
|
+
const coveoPublicAccessToken = "xxfeb39525-e402-4e41-a870-7132441f7875";
|
|
41
42
|
|
|
42
43
|
export const coveoHeaderConfig = {
|
|
43
44
|
coveoOrganizationId,
|
|
44
|
-
coveoPublicAccessToken
|
|
45
|
+
coveoPublicAccessToken,
|
|
45
46
|
coveoSearchPipeline: "salesforcedevdoc",
|
|
46
47
|
coveoSearchHub: "salesforcedevdoc"
|
|
47
48
|
};
|
|
48
49
|
|
|
49
50
|
export const coveoXMLDocsConfig = {
|
|
50
51
|
coveoOrganizationId,
|
|
51
|
-
coveoPublicAccessToken
|
|
52
|
+
coveoPublicAccessToken,
|
|
52
53
|
coveoSearchHub: "Developer_Docs_SS",
|
|
53
54
|
coveoAdvancedQueryConfig: JSON.stringify({
|
|
54
55
|
objecttype: "HTDeveloperDocumentsC",
|
|
@@ -60,7 +61,7 @@ export const coveoXMLDocsConfig = {
|
|
|
60
61
|
|
|
61
62
|
export const coveoSFDocsConfig = {
|
|
62
63
|
coveoOrganizationId,
|
|
63
|
-
coveoPublicAccessToken
|
|
64
|
+
coveoPublicAccessToken,
|
|
64
65
|
coveoSearchHub: "Developer_MdDocs_SS",
|
|
65
66
|
coveoAdvancedQueryConfig: JSON.stringify({
|
|
66
67
|
source: "Sitemap - Developer Docs",
|