Skip to content

Commit 20ba871

Browse files
committed
fix(docs) hide integrations when empty
1 parent 9355a3e commit 20ba871

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed

src/components/docPage/type.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@
206206
margin-top: 0;
207207
}
208208

209-
[data-onboarding-option].hidden {
209+
[data-onboarding-option].hidden,
210+
[data-integrations-wrapper].hidden {
210211
display: none;
211212
}
212213
// force hide markers (___PRODUCT_OPTION_START___ and ___PRODUCT_OPTION_END___)

src/components/onboarding/index.tsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,46 @@ export function updateElementsVisibilityForOptions(
229229
});
230230
}
231231
});
232+
233+
// Handle integrations wrapper: hide opening/closing brackets if no integrations are visible
234+
const openWrappers = document.querySelectorAll<HTMLElement>('[data-integrations-wrapper="open"]');
235+
236+
openWrappers.forEach(openLine => {
237+
const codeBlock = openLine.closest('code.code-highlight');
238+
if (!codeBlock) return;
239+
240+
const allLines = Array.from(codeBlock.children) as HTMLElement[];
241+
const openIndex = allLines.indexOf(openLine);
242+
243+
// Find the matching close line in the same code block
244+
let closeIndex = -1;
245+
for (let i = openIndex + 1; i < allLines.length; i++) {
246+
if (allLines[i].dataset.integrationsWrapper === 'close') {
247+
closeIndex = i;
248+
break;
249+
}
250+
}
251+
252+
if (closeIndex === -1) return;
253+
254+
// Check if any lines between open and close are visible option lines
255+
let hasVisibleIntegrations = false;
256+
for (let i = openIndex + 1; i < closeIndex; i++) {
257+
const line = allLines[i];
258+
const isOption = line.dataset.onboardingOption;
259+
const isHidden = line.classList.contains('hidden');
260+
const isMarker = line.dataset.onboardingOptionHidden;
261+
262+
if (isOption && !isMarker && !isHidden) {
263+
hasVisibleIntegrations = true;
264+
break;
265+
}
266+
}
267+
268+
// Toggle visibility of both open and close lines
269+
openLine.classList.toggle('hidden', !hasVisibleIntegrations);
270+
allLines[closeIndex].classList.toggle('hidden', !hasVisibleIntegrations);
271+
});
232272
}
233273

234274
export function OnboardingOptionButtons({

src/rehype-onboarding-lines.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ function handle_inline_options(node) {
4242
// ___PRODUCT_OPTION_END___ session-replay
4343
const PRODUCT_OPTION_START = '___PRODUCT_OPTION_START___';
4444
const PRODUCT_OPTION_END = '___PRODUCT_OPTION_END___';
45+
46+
// First pass: mark lines with options
4547
node.children?.forEach(line => {
4648
const lineStr = toString(line);
4749
if (lineStr.includes(PRODUCT_OPTION_START)) {
@@ -55,4 +57,35 @@ function handle_inline_options(node) {
5557
line.properties['data-onboarding-option'] = currentOption;
5658
}
5759
});
60+
61+
// Second pass: Mark integrations array opening/closing lines
62+
// These should be hidden if all content inside is from options that are disabled
63+
for (let i = 0; i < (node.children?.length ?? 0); i++) {
64+
const line = node.children[i];
65+
const lineStr = toString(line).trim();
66+
67+
// Found "integrations: ["
68+
if (lineStr.match(/integrations:\s*\[/)) {
69+
console.log('🎯 Found integrations opening at line', i, ':', lineStr);
70+
// Mark the opening line and hide it by default
71+
line.properties['data-integrations-wrapper'] = 'open';
72+
line.properties.className = [...(line.properties.className || []), 'hidden'];
73+
74+
// Find the closing "],"
75+
for (let j = i + 1; j < node.children.length; j++) {
76+
const closeStr = toString(node.children[j]).trim();
77+
if (closeStr.includes('],')) {
78+
console.log('🎯 Found integrations closing at line', j, ':', closeStr);
79+
// Mark the closing line and hide it by default
80+
node.children[j].properties['data-integrations-wrapper'] = 'close';
81+
node.children[j].properties.className = [
82+
...(node.children[j].properties.className || []),
83+
'hidden',
84+
];
85+
break;
86+
}
87+
}
88+
break; // Only handle first integrations array
89+
}
90+
}
5891
}

0 commit comments

Comments
 (0)