@salesforcedevs/dx-components 0.10.1-alpha.116 → 0.10.1-alpha.117
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/LICENSE +12 -0
- package/package.json +3 -2
- package/src/modules/dx/lazy/lazy.ts +0 -7
- package/src/modules/dx/sidebar/__tests__/mockDocContent.ts +48 -0
- package/src/modules/dx/sidebar/__tests__/mockPageReference.ts +8 -0
- package/src/modules/dx/sidebar/sidebar.ts +7 -0
- package/src/modules/dx/sidebarSearch/__tests__/{preloadedState.ts → mockPreloadedState.ts} +0 -0
- package/src/modules/dx/sidebarSearch/__tests__/sidebarSearch.test.ts +91 -14
- package/src/modules/dx/sidebarSearch/sidebarSearch.ts +71 -75
- package/src/modules/utils/highlight/__tests__/highlight.test.ts +154 -0
- package/src/modules/utils/highlight/highlight.ts +2 -1
- package/src/modules/utils/jest/jest.ts +35 -0
- package/src/modules/utils/tests/tests.ts +18 -11
- package/src/.DS_Store +0 -0
- package/src/modules/.DS_Store +0 -0
- package/src/modules/dx/.DS_Store +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Copyright (c) 2020, Salesforce.com, Inc.
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
5
|
+
|
|
6
|
+
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
7
|
+
|
|
8
|
+
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
9
|
+
|
|
10
|
+
* Neither the name of Salesforce.com nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
11
|
+
|
|
12
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforcedevs/dx-components",
|
|
3
|
-
"version": "0.10.1-alpha.
|
|
3
|
+
"version": "0.10.1-alpha.117",
|
|
4
4
|
"description": "DX Lightning web components",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
@@ -28,5 +28,6 @@
|
|
|
28
28
|
"@types/classnames": "^2.2.10",
|
|
29
29
|
"@types/debounce": "^1.2.0",
|
|
30
30
|
"@types/lodash.get": "^4.4.6"
|
|
31
|
-
}
|
|
31
|
+
},
|
|
32
|
+
"gitHead": "d2289f6fae864f4763bc892ecd78b6454eae44d6"
|
|
32
33
|
}
|
|
@@ -2,13 +2,6 @@ import { LightningElement, api } from "lwc";
|
|
|
2
2
|
|
|
3
3
|
import { LazyMode } from "typings/custom";
|
|
4
4
|
|
|
5
|
-
declare global {
|
|
6
|
-
interface Window {
|
|
7
|
-
requestIdleCallback: any;
|
|
8
|
-
cancelIdleCallback: any;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
5
|
/**
|
|
13
6
|
* Defines a fallback for BackgroundTasksAPI for browsers that doesn't support it.
|
|
14
7
|
* Currently BackgroundTasksAPI is supported by all major browsers
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const noteWithOrderedList = `<div class='box message info'>
|
|
2
|
+
<h4 class='mbs'>Note with ordered list</h4>
|
|
3
|
+
<ol class='ol enumList'>
|
|
4
|
+
<li class='li'>From Setup, enter <kbd class='ph userinput'>Apex Classes</kbd> in the <span
|
|
5
|
+
class='keyword parmname'>Quick
|
|
6
|
+
Find</span> box, then select <strong class='ph uicontrol'>Apex Classes</strong>.</li>
|
|
7
|
+
|
|
8
|
+
<li class='li'>Click <strong class='ph uicontrol'>Edit</strong> next to SiteRegisterController.</li>
|
|
9
|
+
|
|
10
|
+
<li class='li'>Find the <samp class='codeph apex_code'><span class='keyword'>private</span> <span
|
|
11
|
+
class='keyword'>static</span> Id PORTAL_ACCOUNT_ID =
|
|
12
|
+
<span class='string'>'<Account_ID>'</span>;</samp> line and insert the ID for the account that
|
|
13
|
+
you want
|
|
14
|
+
to
|
|
15
|
+
associate with new users. The line should look similar to
|
|
16
|
+
this:
|
|
17
|
+
</li>
|
|
18
|
+
|
|
19
|
+
<li class='li'>Click <strong class='ph uicontrol'>Save</strong>.</li>
|
|
20
|
+
</ol>
|
|
21
|
+
</div>`;
|
|
22
|
+
|
|
23
|
+
export const sampleCodeBlockAndNote = `
|
|
24
|
+
<h1 class='helpHead1'>Using the instanceof Keyword</h1>
|
|
25
|
+
<p class="p">If you need to verify at run time whether an object is actually an instance of a particular class, use the
|
|
26
|
+
<samp class="codeph apex_code"><span class="statement">instanceof</span></samp> keyword.
|
|
27
|
+
The <samp class="codeph apex_code"><span class="statement">instanceof</span></samp> keyword can only be used to
|
|
28
|
+
verify if the target type in the expression on the right of the keyword is a viable
|
|
29
|
+
alternative for the declared type of the expression on the left.
|
|
30
|
+
</p>
|
|
31
|
+
<div class="p">You could add the following check to the <samp class="codeph apex_code">Report</samp>class in the <a class="xref" href="atlas.en-us.apexcode.meta/apexcode/apex_classes_casting.htm" title="In general, all type information is available at run time. This means that Apex enables casting, that is, a data type of one class can be assigned to a data type of another class, but only if one class is a subclass of the other class. Use casting when you want to convert an object from one data type to another.">classes and casting example</a> before you cast the item back into a <samp class="codeph apex_code">CustomReport</samp> object.
|
|
32
|
+
<div class="codeSection apex_code">
|
|
33
|
+
<pre class="codeblock brush:apex">If (Reports.get(0) <span class="statement">instanceof</span> CustomReport) {\n <span class="onelineComment">// Can safely cast it back to a custom report object</span>\n CustomReport c = (CustomReport) Reports.get(0);\n} Else {\n <span class="onelineComment">// Do something with the non-custom-report.</span>\n}</pre>
|
|
34
|
+
</div>
|
|
35
|
+
</div>
|
|
36
|
+
${noteWithOrderedList}
|
|
37
|
+
<div class="p">
|
|
38
|
+
Follow these steps:
|
|
39
|
+
<ol class="ol enumList">
|
|
40
|
+
<li class="li">Add the data in a .csv file.</li>
|
|
41
|
+
<li class="li">Create a static resource for this file.</li>
|
|
42
|
+
<li class="li">
|
|
43
|
+
Call <samp class="codeph apex_code">Test.loadData</samp> within your test
|
|
44
|
+
method and passing it the sObject type token and the static resource name.
|
|
45
|
+
</li>
|
|
46
|
+
</ol>
|
|
47
|
+
</div>
|
|
48
|
+
`;
|
|
@@ -44,6 +44,13 @@ export default class Sidebar extends LightningElement {
|
|
|
44
44
|
}));
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
@api
|
|
48
|
+
setInputValue(searchTerm: string) {
|
|
49
|
+
this.template
|
|
50
|
+
.querySelector("dx-sidebar-search")
|
|
51
|
+
.setInputValue(searchTerm);
|
|
52
|
+
}
|
|
53
|
+
|
|
47
54
|
private expanded: boolean = true;
|
|
48
55
|
private _toggleHovered: boolean = false;
|
|
49
56
|
private _value?: string = undefined;
|
|
File without changes
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { createElement } from "lwc";
|
|
1
2
|
import SidebarSearch from "dx/sidebarSearch";
|
|
2
|
-
import { createRenderComponent } from "utils/tests";
|
|
3
|
-
import { coveoXMLDocsConfig } from "utils/coveo";
|
|
3
|
+
import { createRenderComponent, renderLightningElement } from "utils/tests";
|
|
4
|
+
import { coveoXMLDocsConfig } from "utils/coveo";
|
|
5
|
+
import { mockQueryParameter, unmockQueryParameter } from "utils/jest";
|
|
6
|
+
import mockPreloadedState from "./mockPreloadedState";
|
|
7
|
+
import { SESSION_KEY } from "../sidebarSearch";
|
|
4
8
|
|
|
5
9
|
const TAG = "dx-sidebar-search";
|
|
6
10
|
const render = createRenderComponent(TAG, SidebarSearch);
|
|
@@ -8,18 +12,9 @@ const render = createRenderComponent(TAG, SidebarSearch);
|
|
|
8
12
|
const PROPS = coveoXMLDocsConfig;
|
|
9
13
|
const QUERY = "test";
|
|
10
14
|
|
|
11
|
-
const mockQuery = (q: string): void => {
|
|
12
|
-
global.window = Object.create(window);
|
|
13
|
-
const url = `http://dummy.com?q="${q}"`;
|
|
14
|
-
Object.defineProperty(window, "location", {
|
|
15
|
-
value: {
|
|
16
|
-
href: url,
|
|
17
|
-
search: `?q=${q}`
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
|
|
22
15
|
describe(TAG, () => {
|
|
16
|
+
afterEach(unmockQueryParameter);
|
|
17
|
+
|
|
23
18
|
it("renders with the correct initial empty query", () => {
|
|
24
19
|
const element = render(PROPS);
|
|
25
20
|
|
|
@@ -31,7 +26,7 @@ describe(TAG, () => {
|
|
|
31
26
|
});
|
|
32
27
|
|
|
33
28
|
it("renders with the correct initial query", () => {
|
|
34
|
-
|
|
29
|
+
mockQueryParameter(QUERY);
|
|
35
30
|
|
|
36
31
|
const element = render(PROPS);
|
|
37
32
|
|
|
@@ -41,4 +36,86 @@ describe(TAG, () => {
|
|
|
41
36
|
|
|
42
37
|
return expect(element).toBeAccessible();
|
|
43
38
|
});
|
|
39
|
+
|
|
40
|
+
it("correctly consumes a valid session storage object", () => {
|
|
41
|
+
mockQueryParameter(mockPreloadedState.query.q);
|
|
42
|
+
|
|
43
|
+
window.sessionStorage.setItem(
|
|
44
|
+
SESSION_KEY,
|
|
45
|
+
JSON.stringify(mockPreloadedState)
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const mockOnChange = jest.fn();
|
|
49
|
+
|
|
50
|
+
const element = render(PROPS);
|
|
51
|
+
element.addEventListener("change", mockOnChange);
|
|
52
|
+
|
|
53
|
+
return Promise.resolve().then(() => {
|
|
54
|
+
expect(mockOnChange).toHaveBeenCalledTimes(1);
|
|
55
|
+
|
|
56
|
+
expect(element).toBeAccessible();
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe("highlighting", () => {
|
|
61
|
+
afterEach(unmockQueryParameter);
|
|
62
|
+
|
|
63
|
+
it("triggers on initial render when a search value exists", () => {
|
|
64
|
+
mockQueryParameter(QUERY);
|
|
65
|
+
const element = createElement(TAG, { is: SidebarSearch });
|
|
66
|
+
const dispatchEventSpy = jest.spyOn(element, "dispatchEvent");
|
|
67
|
+
renderLightningElement(element, PROPS);
|
|
68
|
+
expect(dispatchEventSpy).toHaveBeenCalledWith(
|
|
69
|
+
expect.objectContaining({
|
|
70
|
+
type: "highlightedtermchange",
|
|
71
|
+
detail: QUERY
|
|
72
|
+
})
|
|
73
|
+
);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("does not trigger on initial render when a search value does not exist", () => {
|
|
77
|
+
const element = createElement(TAG, { is: SidebarSearch });
|
|
78
|
+
const dispatchEventSpy = jest.spyOn(element, "dispatchEvent");
|
|
79
|
+
renderLightningElement(element, PROPS);
|
|
80
|
+
expect(dispatchEventSpy).not.toHaveBeenCalledWith(
|
|
81
|
+
expect.objectContaining({ type: "highlightedtermchange" })
|
|
82
|
+
);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("triggers on input change with non-empty value", () => {
|
|
86
|
+
const element = render(PROPS);
|
|
87
|
+
const dxInput = element.shadowRoot.querySelector("dx-input");
|
|
88
|
+
const inputEl = dxInput.shadowRoot.querySelector("input");
|
|
89
|
+
const dispatchEventSpy = jest.spyOn(element, "dispatchEvent");
|
|
90
|
+
|
|
91
|
+
inputEl.focus();
|
|
92
|
+
inputEl.value = QUERY;
|
|
93
|
+
inputEl.dispatchEvent(new KeyboardEvent("input"));
|
|
94
|
+
|
|
95
|
+
expect(dispatchEventSpy).toHaveBeenCalledWith(
|
|
96
|
+
expect.objectContaining({
|
|
97
|
+
type: "highlightedtermchange",
|
|
98
|
+
detail: QUERY
|
|
99
|
+
})
|
|
100
|
+
);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("triggers on input change with empty value", () => {
|
|
104
|
+
const element = render(PROPS);
|
|
105
|
+
const dxInput = element.shadowRoot.querySelector("dx-input");
|
|
106
|
+
const inputEl = dxInput.shadowRoot.querySelector("input");
|
|
107
|
+
const dispatchEventSpy = jest.spyOn(element, "dispatchEvent");
|
|
108
|
+
|
|
109
|
+
inputEl.focus();
|
|
110
|
+
inputEl.value = "";
|
|
111
|
+
inputEl.dispatchEvent(new KeyboardEvent("input"));
|
|
112
|
+
|
|
113
|
+
expect(dispatchEventSpy).toHaveBeenCalledWith(
|
|
114
|
+
expect.objectContaining({
|
|
115
|
+
type: "highlightedtermchange",
|
|
116
|
+
detail: ""
|
|
117
|
+
})
|
|
118
|
+
);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
44
121
|
});
|
|
@@ -18,7 +18,7 @@ import { RecentSearches } from "utils/recentSearches";
|
|
|
18
18
|
import { toJson } from "utils/normalizers";
|
|
19
19
|
import { Option, PopoverRequestCloseType } from "typings/custom";
|
|
20
20
|
|
|
21
|
-
const SESSION_KEY = "dx-sidebar-search-state";
|
|
21
|
+
export const SESSION_KEY = "dx-sidebar-search-state";
|
|
22
22
|
|
|
23
23
|
const DEFAULT_RESULT_COUNT = 20;
|
|
24
24
|
const SEARCH_DEBOUNCE_DELAY = 780;
|
|
@@ -42,13 +42,17 @@ export default class SidebarSearch extends LightningElement {
|
|
|
42
42
|
|
|
43
43
|
@api
|
|
44
44
|
public fetchMoreResults() {
|
|
45
|
-
console.log('fetch more results (resultList)', this.resultList)
|
|
46
45
|
if (this.resultList?.state?.moreResultsAvailable) {
|
|
47
46
|
this.fetchingMoreResults = true;
|
|
48
47
|
this.resultList.fetchMoreResults();
|
|
49
48
|
}
|
|
50
49
|
}
|
|
51
50
|
|
|
51
|
+
@api
|
|
52
|
+
setInputValue(searchTerm: string) {
|
|
53
|
+
this.value = searchTerm || "";
|
|
54
|
+
}
|
|
55
|
+
|
|
52
56
|
private _coveoAdvancedQueryConfig!: object;
|
|
53
57
|
private dropdownRequestedOpen: boolean = false;
|
|
54
58
|
private recentSearches: Option[] = [];
|
|
@@ -59,6 +63,7 @@ export default class SidebarSearch extends LightningElement {
|
|
|
59
63
|
private value?: string = "";
|
|
60
64
|
private engine: SearchEngine | null = null;
|
|
61
65
|
private fetchingMoreResults: boolean = false;
|
|
66
|
+
private didRender = false;
|
|
62
67
|
|
|
63
68
|
private get hasCorrectCoveoConfig(): boolean {
|
|
64
69
|
const coveoConfigurations = [
|
|
@@ -79,14 +84,10 @@ export default class SidebarSearch extends LightningElement {
|
|
|
79
84
|
this.dropdownRequestedOpen &&
|
|
80
85
|
this.recentSearches &&
|
|
81
86
|
this.recentSearches.length > 0 &&
|
|
82
|
-
this.
|
|
87
|
+
!this.value
|
|
83
88
|
);
|
|
84
89
|
}
|
|
85
90
|
|
|
86
|
-
private get isValueEmpty(): boolean {
|
|
87
|
-
return !this.value || this.value === "";
|
|
88
|
-
}
|
|
89
|
-
|
|
90
91
|
constructor() {
|
|
91
92
|
super();
|
|
92
93
|
|
|
@@ -96,7 +97,9 @@ export default class SidebarSearch extends LightningElement {
|
|
|
96
97
|
}
|
|
97
98
|
|
|
98
99
|
renderedCallback() {
|
|
100
|
+
// in prod some of the attributes seem to arrive later, so I put this coveo startup flow here
|
|
99
101
|
if (this.hasCorrectCoveoConfig && !this.engine) {
|
|
102
|
+
console.log("coveo config is good");
|
|
100
103
|
this.initializeCoveo();
|
|
101
104
|
} else if (!this.hasCorrectCoveoConfig) {
|
|
102
105
|
console.error(
|
|
@@ -109,6 +112,14 @@ export default class SidebarSearch extends LightningElement {
|
|
|
109
112
|
}
|
|
110
113
|
);
|
|
111
114
|
}
|
|
115
|
+
|
|
116
|
+
// If this is the first render and there is a search value, trigger
|
|
117
|
+
// term highlighting
|
|
118
|
+
if (!this.didRender && this.value) {
|
|
119
|
+
this.dispatchHighlightedTermChange();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
this.didRender = true;
|
|
112
123
|
}
|
|
113
124
|
|
|
114
125
|
private initializeUserSession() {
|
|
@@ -116,41 +127,44 @@ export default class SidebarSearch extends LightningElement {
|
|
|
116
127
|
if (!stringified) {
|
|
117
128
|
return;
|
|
118
129
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
this.
|
|
130
|
+
|
|
131
|
+
try {
|
|
132
|
+
const state = JSON.parse(stringified);
|
|
133
|
+
if (state?.query?.q === this.value) {
|
|
134
|
+
console.log(
|
|
135
|
+
"valid session storage found for value =",
|
|
136
|
+
this.value
|
|
137
|
+
);
|
|
138
|
+
this.preloadedState = state;
|
|
139
|
+
}
|
|
140
|
+
} catch (_) {
|
|
141
|
+
// Swallow error; no parseable preloaded state
|
|
142
|
+
// TODO: might want to clear sessionStorage, alert user(?), etc.
|
|
123
143
|
}
|
|
124
144
|
}
|
|
125
145
|
|
|
126
|
-
private initializeCoveo =
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
146
|
+
private initializeCoveo = () => {
|
|
147
|
+
try {
|
|
148
|
+
this.engine = buildSearchEngine({
|
|
149
|
+
organizationId: this.coveoOrganizationId,
|
|
150
|
+
publicAccessToken: this.coveoPublicAccessToken,
|
|
151
|
+
searchHub: this.coveoSearchHub,
|
|
152
|
+
preloadedState: this.preloadedState
|
|
153
|
+
});
|
|
154
|
+
} catch (ex) {
|
|
155
|
+
console.error(`Coveo engine failed to initialize (${ex})`);
|
|
156
|
+
}
|
|
133
157
|
|
|
134
|
-
|
|
135
|
-
"
|
|
136
|
-
|
|
137
|
-
|
|
158
|
+
if (!this.engine) {
|
|
159
|
+
console.error("Coveo engine failed to initialize!");
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
138
162
|
|
|
139
163
|
if (this.preloadedState) {
|
|
140
164
|
const actions = loadQueryActions(this.engine);
|
|
141
165
|
this.engine.dispatch(actions.updateQuery({ q: this.value || "" }));
|
|
142
166
|
}
|
|
143
167
|
|
|
144
|
-
console.log(
|
|
145
|
-
"initialized engine directly after query dispatch",
|
|
146
|
-
this.engine,
|
|
147
|
-
this.engine?.state?.query?.q
|
|
148
|
-
);
|
|
149
|
-
|
|
150
|
-
if (!this.engine) {
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
168
|
this.resultList = buildResultList(this.engine, {
|
|
155
169
|
options: { fieldsToInclude: ["sfhtml_url__c"] }
|
|
156
170
|
});
|
|
@@ -169,21 +183,16 @@ export default class SidebarSearch extends LightningElement {
|
|
|
169
183
|
|
|
170
184
|
this.resultList?.subscribe(this.onResultListChange);
|
|
171
185
|
|
|
172
|
-
|
|
173
|
-
"initialized engine after sub classes created",
|
|
174
|
-
this.engine
|
|
175
|
-
);
|
|
176
|
-
|
|
177
|
-
if (!this.isValueEmpty) {
|
|
186
|
+
if (this.value) {
|
|
178
187
|
this.dispatchHighlightedTermChange();
|
|
179
188
|
}
|
|
180
189
|
|
|
181
|
-
if (!this.preloadedState
|
|
182
|
-
this.
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
190
|
+
if (!this.preloadedState) {
|
|
191
|
+
if (this.value) {
|
|
192
|
+
this.submitSearch();
|
|
193
|
+
} else {
|
|
194
|
+
this.dispatchOnLoading(false);
|
|
195
|
+
}
|
|
187
196
|
}
|
|
188
197
|
};
|
|
189
198
|
|
|
@@ -195,28 +204,21 @@ export default class SidebarSearch extends LightningElement {
|
|
|
195
204
|
const { isLoading, firstSearchExecuted, results } =
|
|
196
205
|
this.resultList.state;
|
|
197
206
|
|
|
198
|
-
|
|
199
|
-
isLoading,
|
|
200
|
-
firstSearchExecuted,
|
|
201
|
-
results
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
if ((!firstSearchExecuted && !isLoading) || this.isValueEmpty) {
|
|
207
|
+
if ((!firstSearchExecuted && !isLoading) || !this.value) {
|
|
205
208
|
// coveo search is firing off some unwanted payloads on startup
|
|
206
209
|
console.log(
|
|
207
210
|
"returning in results list change",
|
|
208
211
|
this.value,
|
|
209
|
-
this.isValueEmpty,
|
|
210
212
|
!firstSearchExecuted && !isLoading
|
|
211
213
|
);
|
|
212
214
|
return;
|
|
213
215
|
}
|
|
214
216
|
|
|
215
217
|
if (!isLoading) {
|
|
218
|
+
console.log("dispatching on change event");
|
|
216
219
|
this.dispatchOnChangeEvent(results);
|
|
217
220
|
}
|
|
218
221
|
|
|
219
|
-
console.log("is fetching more results", this.fetchingMoreResults);
|
|
220
222
|
if (!this.fetchingMoreResults) {
|
|
221
223
|
this.dispatchOnLoading(isLoading);
|
|
222
224
|
}
|
|
@@ -270,7 +272,7 @@ export default class SidebarSearch extends LightningElement {
|
|
|
270
272
|
};
|
|
271
273
|
|
|
272
274
|
private updateSessionStorage() {
|
|
273
|
-
console.log("updating session storage"
|
|
275
|
+
console.log("updating session storage");
|
|
274
276
|
window.sessionStorage.setItem(
|
|
275
277
|
SESSION_KEY,
|
|
276
278
|
JSON.stringify(this.engine?.state)
|
|
@@ -290,6 +292,7 @@ export default class SidebarSearch extends LightningElement {
|
|
|
290
292
|
}
|
|
291
293
|
|
|
292
294
|
private dispatchOnLoading(loading: boolean) {
|
|
295
|
+
console.log("dispatching onloading", loading);
|
|
293
296
|
this.dispatchEvent(new CustomEvent("loading", { detail: loading }));
|
|
294
297
|
}
|
|
295
298
|
|
|
@@ -311,18 +314,14 @@ export default class SidebarSearch extends LightningElement {
|
|
|
311
314
|
})
|
|
312
315
|
));
|
|
313
316
|
|
|
314
|
-
private
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
if (this.value) {
|
|
323
|
-
queryParams.set("q", this.value);
|
|
324
|
-
}
|
|
325
|
-
window.history.pushState({}, "", `?${queryParams.toString()}${hash}`);
|
|
317
|
+
private dispatchSidebarSearchChange(searchTerm: string | undefined): void {
|
|
318
|
+
this.dispatchEvent(
|
|
319
|
+
new CustomEvent("sidebarsearchchange", {
|
|
320
|
+
detail: searchTerm ?? "",
|
|
321
|
+
bubbles: true,
|
|
322
|
+
composed: true
|
|
323
|
+
})
|
|
324
|
+
);
|
|
326
325
|
}
|
|
327
326
|
|
|
328
327
|
private submitSearch = debounce(() => {
|
|
@@ -354,15 +353,12 @@ export default class SidebarSearch extends LightningElement {
|
|
|
354
353
|
private onInputChange(e: CustomEvent) {
|
|
355
354
|
this.value = e.detail;
|
|
356
355
|
|
|
357
|
-
if (
|
|
356
|
+
if (this.value) {
|
|
358
357
|
this.dispatchOnLoading(true);
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
if (this.isValueEmpty) {
|
|
358
|
+
if (this.searchBox) {
|
|
359
|
+
this.submitSearch();
|
|
360
|
+
}
|
|
361
|
+
} else {
|
|
366
362
|
// coveo's reaction to an empty value triggers a return of results
|
|
367
363
|
// bootlegging our own ux here`
|
|
368
364
|
this.dispatchOnLoading(false);
|
|
@@ -370,7 +366,7 @@ export default class SidebarSearch extends LightningElement {
|
|
|
370
366
|
}
|
|
371
367
|
|
|
372
368
|
this.dispatchHighlightedTermChange();
|
|
373
|
-
this.
|
|
369
|
+
this.dispatchSidebarSearchChange(this.value);
|
|
374
370
|
}
|
|
375
371
|
|
|
376
372
|
private onInputFocus() {
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { createElement } from "lwc";
|
|
2
|
+
import CodeBlock from "dx/codeBlock";
|
|
3
|
+
import { highlightTerms } from "utils/highlight";
|
|
4
|
+
|
|
5
|
+
const mockContent = `<div><a name='apex_dev_guide'><!-- --></a><h1 class='helpHead1'>Apex Developer Guide</h1><div class='shortdesc'>Salesforce has changed the way organizations do business by moving enterprise
|
|
6
|
+
applications that were traditionally client-server-based into the Lightning Platform, an
|
|
7
|
+
on-demand, multitenant Web environment. This environment enables you to run and customize
|
|
8
|
+
applications, such as Salesforce Automation and Service & Support, and build new custom
|
|
9
|
+
applications based on particular business needs. </div><div id='sfdc:seealso' class='related-links'>
|
|
10
|
+
<ul class='ullinks'>
|
|
11
|
+
<li class='link ulchildlink'>
|
|
12
|
+
<strong><a href='atlas.en-us.apexcode.meta/apexcode/apex_intro_get_started.htm'>Getting Started with Apex</a></strong><br>
|
|
13
|
+
Apex is a strongly typed, object-oriented programming language that allows developers to execute flow and transaction control statements on the Lightning Platform server, in conjunction with calls to the API.</li>
|
|
14
|
+
<li class='link ulchildlink'>
|
|
15
|
+
<strong><a href='atlas.en-us.apexcode.meta/apexcode/apex_writing.htm'>Writing Apex</a></strong><br>
|
|
16
|
+
Apex is like Java for Salesforce. It enables you to add and interact with data in the Lightning Platform persistence layer. It uses classes, data types, variables, and if-else statements. You can make it execute based on a condition, or have a block of code execute repeatedly.</li>
|
|
17
|
+
<li class='link ulchildlink'>
|
|
18
|
+
<strong><a href='atlas.en-us.apexcode.meta/apexcode/apex_running.htm'>Running Apex</a></strong><br>
|
|
19
|
+
You can access many features of the Salesforce user interface programmatically in Apex, and you can integrate with external SOAP and REST Web services. You can run Apex code using a variety of mechanisms. Apex code runs in atomic transactions. </li>
|
|
20
|
+
<li class='link ulchildlink'>
|
|
21
|
+
<strong><a href='atlas.en-us.apexcode.meta/apexcode/apex_debug_test_deploy.htm'>Debugging, Testing, and Deploying Apex</a></strong><br>
|
|
22
|
+
Develop your Apex code in a sandbox and debug it with the Developer Console and debug logs. Unit-test your code, then distribute it to customers using packages.</li>
|
|
23
|
+
<li class='link ulchildlink'>
|
|
24
|
+
<strong><a href='atlas.en-us.apexcode.meta/apexcode/apex_reference.htm'>Apex Language Reference</a></strong><br>
|
|
25
|
+
This Apex reference goes into detail about DML statements and the built-in Apex classes and interfaces.</li>
|
|
26
|
+
<li class='link ulchildlink'>
|
|
27
|
+
<strong><a href='atlas.en-us.apexcode.meta/apexcode/apex_appendices.htm'>Appendices</a></strong><br>
|
|
28
|
+
</li>
|
|
29
|
+
<li class='link ulchildlink'>
|
|
30
|
+
<strong><a href='atlas.en-us.apexcode.meta/apexcode/glossary_apex.htm'>Glossary</a></strong><br>
|
|
31
|
+
</li>
|
|
32
|
+
</ul>
|
|
33
|
+
</div><!--DRC 228.7--></div>`;
|
|
34
|
+
|
|
35
|
+
const allowedTags = [
|
|
36
|
+
"p",
|
|
37
|
+
".p",
|
|
38
|
+
".shortdesc",
|
|
39
|
+
"h1",
|
|
40
|
+
"h2",
|
|
41
|
+
"h3",
|
|
42
|
+
"h4",
|
|
43
|
+
"h5",
|
|
44
|
+
"h6",
|
|
45
|
+
"li",
|
|
46
|
+
"dl",
|
|
47
|
+
"th",
|
|
48
|
+
"td"
|
|
49
|
+
];
|
|
50
|
+
const container = document.createElement("div");
|
|
51
|
+
|
|
52
|
+
describe("highlight utility", () => {
|
|
53
|
+
afterEach(() => (container.innerHTML = ""));
|
|
54
|
+
|
|
55
|
+
it("highlights text that matches search criteria", () => {
|
|
56
|
+
container.innerHTML = mockContent;
|
|
57
|
+
highlightTerms(
|
|
58
|
+
container.querySelectorAll(allowedTags.join(",")),
|
|
59
|
+
"apex"
|
|
60
|
+
);
|
|
61
|
+
expect(container.querySelectorAll("mark")).toHaveLength(14);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("doesn't highlight elements that contains dx/docs components", () => {
|
|
65
|
+
const searchTerm = "customreport";
|
|
66
|
+
const codeBlock = createElement("dx-code-block", { is: CodeBlock });
|
|
67
|
+
Object.assign(codeBlock, {
|
|
68
|
+
codeBlock: searchTerm,
|
|
69
|
+
language: "text"
|
|
70
|
+
// title: "",
|
|
71
|
+
// variant: "card"
|
|
72
|
+
});
|
|
73
|
+
container.appendChild(document.createElement("p"));
|
|
74
|
+
container.firstElementChild?.appendChild(codeBlock);
|
|
75
|
+
highlightTerms(
|
|
76
|
+
container.querySelectorAll(allowedTags.join(",")),
|
|
77
|
+
searchTerm
|
|
78
|
+
);
|
|
79
|
+
expect(container.querySelectorAll("mark")).toHaveLength(0);
|
|
80
|
+
expect(codeBlock.shadowRoot.innerHTML).toMatch(searchTerm); // sanity check
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("doesn't highlight terms separated by html tags", () => {
|
|
84
|
+
container.innerHTML = "<p>loadData<span>within</span></p>";
|
|
85
|
+
highlightTerms(
|
|
86
|
+
container.querySelectorAll(allowedTags.join(",")),
|
|
87
|
+
"loadDatawithin"
|
|
88
|
+
);
|
|
89
|
+
expect(container.querySelectorAll("mark")).toHaveLength(0);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("escapes regex especial characters", () => {
|
|
93
|
+
container.innerHTML = mockContent;
|
|
94
|
+
highlightTerms(
|
|
95
|
+
container.querySelectorAll(allowedTags.join(",")),
|
|
96
|
+
"apex.+"
|
|
97
|
+
);
|
|
98
|
+
expect(container.querySelectorAll("mark")).toHaveLength(0);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("cleans previous search result before searching for a new term", () => {
|
|
102
|
+
const firstSearch = "apex";
|
|
103
|
+
const secondSearch = "salesforce";
|
|
104
|
+
|
|
105
|
+
container.innerHTML = mockContent;
|
|
106
|
+
|
|
107
|
+
highlightTerms(
|
|
108
|
+
container.querySelectorAll(allowedTags.join(",")),
|
|
109
|
+
firstSearch
|
|
110
|
+
);
|
|
111
|
+
const firstMarks = container.querySelectorAll("mark");
|
|
112
|
+
expect(firstMarks).toHaveLength(14);
|
|
113
|
+
firstMarks.forEach(({ textContent }) =>
|
|
114
|
+
expect(textContent?.toLowerCase()).toBe(firstSearch)
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
highlightTerms(
|
|
118
|
+
container.querySelectorAll(allowedTags.join(",")),
|
|
119
|
+
secondSearch
|
|
120
|
+
);
|
|
121
|
+
const secondMarks = container.querySelectorAll("mark");
|
|
122
|
+
expect(secondMarks).toHaveLength(4);
|
|
123
|
+
secondMarks.forEach(({ textContent }) =>
|
|
124
|
+
expect(textContent?.toLowerCase()).toBe(secondSearch)
|
|
125
|
+
);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it("cleans all marks if the search term is empty string", () => {
|
|
129
|
+
const firstSearch = "apex";
|
|
130
|
+
const secondSearch = "";
|
|
131
|
+
|
|
132
|
+
container.innerHTML = mockContent;
|
|
133
|
+
|
|
134
|
+
highlightTerms(
|
|
135
|
+
container.querySelectorAll(allowedTags.join(",")),
|
|
136
|
+
firstSearch
|
|
137
|
+
);
|
|
138
|
+
const firstMarks = container.querySelectorAll("mark");
|
|
139
|
+
expect(firstMarks).toHaveLength(14);
|
|
140
|
+
firstMarks.forEach(({ textContent }) =>
|
|
141
|
+
expect(textContent?.toLowerCase()).toBe(firstSearch)
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
highlightTerms(
|
|
145
|
+
container.querySelectorAll(allowedTags.join(",")),
|
|
146
|
+
secondSearch
|
|
147
|
+
);
|
|
148
|
+
const secondMarks = container.querySelectorAll("mark");
|
|
149
|
+
expect(secondMarks).toHaveLength(0);
|
|
150
|
+
secondMarks.forEach(({ textContent }) =>
|
|
151
|
+
expect(textContent?.toLowerCase()).toBe(secondSearch)
|
|
152
|
+
);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
@@ -3,7 +3,8 @@ import { createSearchRegExp } from "utils/regexps";
|
|
|
3
3
|
const MARK_TAGS = /<\/?mark>/gi;
|
|
4
4
|
|
|
5
5
|
export const highlightTerms = (
|
|
6
|
-
|
|
6
|
+
// eslint-disable-next-line no-undef
|
|
7
|
+
elements: NodeListOf<Element>,
|
|
7
8
|
searchTerm: string
|
|
8
9
|
): void => {
|
|
9
10
|
searchTerm = searchTerm.trim();
|
|
@@ -21,3 +21,38 @@ export const createMediaMock = (
|
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
export const matchMediaMock = createMediaMock();
|
|
24
|
+
|
|
25
|
+
export const mockLocalStorage = function () {
|
|
26
|
+
let store: { [key: string]: string } = {};
|
|
27
|
+
return {
|
|
28
|
+
getItem: function (key: string) {
|
|
29
|
+
return store[key] || null;
|
|
30
|
+
},
|
|
31
|
+
setItem: function (key: string, value: string) {
|
|
32
|
+
store[key] = value.toString();
|
|
33
|
+
},
|
|
34
|
+
removeItem: function (key: string) {
|
|
35
|
+
delete store[key];
|
|
36
|
+
},
|
|
37
|
+
clear: function () {
|
|
38
|
+
store = {};
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const mockQueryParameter = (q: string): void => {
|
|
44
|
+
global.window = Object.create(window);
|
|
45
|
+
const search = q ? `?q=${q}` : "";
|
|
46
|
+
const href = `http://dummy.com${search}`;
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
delete window.location.value;
|
|
49
|
+
Object.defineProperty(window, "location", {
|
|
50
|
+
value: {
|
|
51
|
+
href,
|
|
52
|
+
search
|
|
53
|
+
},
|
|
54
|
+
writable: true
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const unmockQueryParameter = () => mockQueryParameter("");
|
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
import { createElement, LightningElement } from "lwc";
|
|
2
2
|
|
|
3
|
-
export const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
) =>
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Object.assign(component, properties);
|
|
12
|
-
document.body.appendChild(component);
|
|
13
|
-
return component;
|
|
3
|
+
export const renderLightningElement = (
|
|
4
|
+
element: LightningElement,
|
|
5
|
+
properties = {}
|
|
6
|
+
) => {
|
|
7
|
+
Object.assign(element, properties);
|
|
8
|
+
document.body.appendChild(element as unknown as Node);
|
|
9
|
+
return element;
|
|
14
10
|
};
|
|
15
11
|
|
|
12
|
+
export const createRenderComponent =
|
|
13
|
+
(tag: string, LWC: new () => LightningElement) =>
|
|
14
|
+
(properties = {}) => {
|
|
15
|
+
const component = createElement(tag, {
|
|
16
|
+
is: LWC
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
renderLightningElement(component, properties);
|
|
20
|
+
return component;
|
|
21
|
+
};
|
|
22
|
+
|
|
16
23
|
export const mockSlottedElement = <T extends HTMLElement>(
|
|
17
24
|
element: any,
|
|
18
25
|
elementType = "button",
|
package/src/.DS_Store
DELETED
|
Binary file
|
package/src/modules/.DS_Store
DELETED
|
Binary file
|
package/src/modules/dx/.DS_Store
DELETED
|
Binary file
|