Skip to content

Commit 9cabc40

Browse files
committed
fix(js): Apply fixes for CoPilot suggestions.
1 parent ec0c815 commit 9cabc40

File tree

3 files changed

+50
-33
lines changed

3 files changed

+50
-33
lines changed

assets/js/components/doc-search.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* DocSearch component for InfluxData documentation
33
* Handles asynchronous loading and initialization of Algolia DocSearch
44
*/
5+
const debug = false; // Set to true for debugging output
56

67
export default function DocSearch({ component }) {
78
// Store configuration from component data attributes
@@ -26,7 +27,9 @@ export default function DocSearch({ component }) {
2627

2728
// Load DocSearch asynchronously
2829
function loadDocSearch() {
29-
console.log('Loading DocSearch script...');
30+
if (debug) {
31+
console.log('Loading DocSearch script...');
32+
}
3033
const script = document.createElement('script');
3134
script.src =
3235
'https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js';
@@ -37,7 +40,9 @@ export default function DocSearch({ component }) {
3740

3841
// Initialize DocSearch after script loads
3942
function initializeDocSearch() {
40-
console.log('Initializing DocSearch...');
43+
if (debug) {
44+
console.log('Initializing DocSearch...');
45+
}
4146
const multiVersion = ['influxdb'];
4247

4348
// Use object-based lookups instead of conditionals for version and product names
@@ -168,6 +173,8 @@ export default function DocSearch({ component }) {
168173
// Return cleanup function
169174
return function cleanup() {
170175
// Clean up any event listeners if needed
171-
console.log('DocSearch component cleanup');
176+
if (debug) {
177+
console.log('DocSearch component cleanup');
178+
}
172179
};
173180
}

assets/js/flux-group-keys.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export default function FluxGroupKeysDemo({ component }) {
116116
toggleCheckbox($(this));
117117
groupKey = getChecked(component);
118118
groupData();
119-
buildGroupExample();
119+
buildGroupExample(component);
120120
});
121121

122122
// Group and render tables on load
@@ -240,8 +240,8 @@ function toggleCheckbox(element) {
240240
}
241241

242242
// Build example group function
243-
function buildGroupExample($component) {
244-
var columnCollection = getChecked($component)
243+
function buildGroupExample(component) {
244+
var columnCollection = getChecked(component)
245245
.map((i) => '<span class=\"s2\">"' + i + '"</span>')
246246
.join(', ');
247247
$('pre#group-by-example')[0].innerHTML =

assets/js/utils/search-interactions.js

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ export default function SearchInteractions({ searchInput }) {
77
let observer = null;
88
let dropdownObserver = null;
99
let dropdownMenu = null;
10-
10+
const debug = false; // Set to true for debugging logs
11+
1112
// Fade content wrapper when focusing on search input
1213
function handleFocus() {
1314
contentWrapper.style.opacity = '0.35';
@@ -18,53 +19,62 @@ export default function SearchInteractions({ searchInput }) {
1819
function handleBlur(event) {
1920
// Only process blur if not clicking within dropdown
2021
const relatedTarget = event.relatedTarget;
21-
if (relatedTarget && (
22-
relatedTarget.closest('.algolia-autocomplete') ||
23-
relatedTarget.closest('.ds-dropdown-menu'))) {
22+
if (
23+
relatedTarget &&
24+
(relatedTarget.closest('.algolia-autocomplete') ||
25+
relatedTarget.closest('.ds-dropdown-menu'))
26+
) {
2427
return;
2528
}
26-
29+
2730
contentWrapper.style.opacity = '1';
2831
contentWrapper.style.transition = 'opacity 200ms';
29-
32+
3033
// Hide dropdown if it exists
3134
if (dropdownMenu) {
3235
dropdownMenu.style.display = 'none';
3336
}
3437
}
35-
38+
3639
// Add event listeners
3740
searchInput.addEventListener('focus', handleFocus);
3841
searchInput.addEventListener('blur', handleBlur);
39-
42+
4043
// Use MutationObserver to detect when dropdown is added to the DOM
4144
observer = new MutationObserver((mutations) => {
4245
for (const mutation of mutations) {
4346
if (mutation.type === 'childList') {
44-
const newDropdown = document.querySelector('.ds-dropdown-menu:not([data-monitored])');
47+
const newDropdown = document.querySelector(
48+
'.ds-dropdown-menu:not([data-monitored])'
49+
);
4550
if (newDropdown) {
46-
console.log('DocSearch dropdown detected');
47-
4851
// Save reference to dropdown
4952
dropdownMenu = newDropdown;
5053
newDropdown.setAttribute('data-monitored', 'true');
51-
54+
5255
// Monitor dropdown removal/display changes
5356
dropdownObserver = new MutationObserver((dropdownMutations) => {
5457
for (const dropdownMutation of dropdownMutations) {
55-
if (dropdownMutation.type === 'attributes' &&
56-
dropdownMutation.attributeName === 'style') {
57-
console.log('Dropdown style changed:', dropdownMenu.style.display);
58+
if (debug) {
59+
if (
60+
dropdownMutation.type === 'attributes' &&
61+
dropdownMutation.attributeName === 'style'
62+
) {
63+
console.log(
64+
'Dropdown style changed:',
65+
dropdownMenu.style.display
66+
);
67+
}
5868
}
5969
}
6070
});
61-
71+
6272
// Observe changes to dropdown attributes (like style)
63-
dropdownObserver.observe(dropdownMenu, {
73+
dropdownObserver.observe(dropdownMenu, {
6474
attributes: true,
65-
attributeFilter: ['style']
75+
attributeFilter: ['style'],
6676
});
67-
77+
6878
// Add event listeners to keep dropdown open when interacted with
6979
dropdownMenu.addEventListener('mousedown', (e) => {
7080
// Prevent blur on searchInput when clicking in dropdown
@@ -74,24 +84,24 @@ export default function SearchInteractions({ searchInput }) {
7484
}
7585
}
7686
});
77-
87+
7888
// Start observing the document body for dropdown creation
79-
observer.observe(document.body, {
80-
childList: true,
81-
subtree: true
89+
observer.observe(document.body, {
90+
childList: true,
91+
subtree: true,
8292
});
83-
93+
8494
// Return cleanup function
8595
return function cleanup() {
8696
searchInput.removeEventListener('focus', handleFocus);
8797
searchInput.removeEventListener('blur', handleBlur);
88-
98+
8999
if (observer) {
90100
observer.disconnect();
91101
}
92-
102+
93103
if (dropdownObserver) {
94104
dropdownObserver.disconnect();
95105
}
96106
};
97-
}
107+
}

0 commit comments

Comments
 (0)