Skip to content

Commit 7574b9b

Browse files
committed
code cleanup and add stepper to advanced tutorial
1 parent de07256 commit 7574b9b

File tree

4 files changed

+26
-90
lines changed

4 files changed

+26
-90
lines changed

docs/quick-start.mdx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -251,18 +251,18 @@ technologies that integrate with ClickHouse.
251251

252252
Query id: 8ca9b2f9-65a2-4982-954a-890de710a336
253253

254-
┌─name──────┬─type────────────────────┬─default_type─┬─default_expression─┬─comment─┬─codec_expression─┬─ttl_expression─
255-
│ id │ Nullable(Int64) │ │ │ │ │ │
256-
│ type │ Nullable(String) │ │ │ │ │ │
257-
│ author │ Nullable(String) │ │ │ │ │ │
258-
timestamp │ Nullable(DateTime64(9)) │ │ │ │ │ │
259-
│ comment │ Nullable(String) │ │ │ │ │ │
260-
│ children │ Array(Nullable(Int64)) │ │ │ │ │ │
261-
└───────────┴─────────────────────────┴──────────────┴────────────────────┴─────────┴──────────────────┴────────────────
254+
┌─name──────┬─type────────────────────┐
255+
│ id │ Nullable(Int64) │
256+
│ type │ Nullable(String) │
257+
│ author │ Nullable(String) │
258+
timestamp │ Nullable(DateTime64(9)) │
259+
│ comment │ Nullable(String) │
260+
│ children │ Array(Nullable(Int64)) │
261+
└───────────┴─────────────────────────┘
262262
```
263263

264264
Notice ClickHouse infers the names and data types of your columns by analyzing a
265-
large batch of rows. If ClickHouse can not determine the storage type from the
265+
large batch of rows. If ClickHouse can not determine the file format from the
266266
filename, you can specify it as the second argument:
267267

268268
```sql

docs/tutorial.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Learn how to ingest and query data in ClickHouse using a New York City taxi exam
1717

1818
You need access to a running ClickHouse service to complete this tutorial. For instructions, see the [Quick Start](./quick-start.mdx) guide.
1919

20+
<VerticalStepper>
21+
2022
## Create a new table {#create-a-new-table}
2123

2224
The New York City taxi dataset contains details about millions of taxi rides, with columns including tip amount, tolls, payment type, and more. Create a table to store this data.
@@ -508,6 +510,7 @@ Write some queries that join the `taxi_zone_dictionary` with your `trips` table.
508510
Generally, we avoid using `SELECT *` often in ClickHouse. You should only retrieve the columns you actually need. However, this query is slower for the purposes of the example.
509511
:::
510512
513+
</VerticalStepper>
511514
512515
## Next steps {#next-steps}
513516
@@ -517,3 +520,4 @@ Learn more about ClickHouse with the following documentation:
517520
- [Integrate an external data source](/integrations/index.mdx): Review data source integration options, including files, Kafka, PostgreSQL, data pipelines, and many others.
518521
- [Visualize data in ClickHouse](./integrations/data-visualization/index.md): Connect your favorite UI/BI tool to ClickHouse.
519522
- [SQL Reference](./sql-reference/index.md): Browse the SQL functions available in ClickHouse for transforming, processing and analyzing data.
523+

plugins/remark-custom-blocks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const plugin = (options) => {
2020

2121
// Target JSX elements in the AST
2222
visit(tree, 'mdxJsxFlowElement', (node, index, parent) => {
23-
// Look specifically for the <VerticlStepper> tag used in the markdown file
23+
// Look specifically for the <VerticalStepper> tag used in the markdown file
2424
if (node.name === 'VerticalStepper') {
2525
try {
2626
// --- 1. Parse <VerticalStepper> Attributes ---

src/components/Stepper/Stepper.tsx

Lines changed: 12 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect } from 'react';
1+
import React from 'react';
22
import { VerticalStepper as OriginalVerticalStepper } from '@clickhouse/click-ui/bundled';
33

44
// --- Step Component ---
@@ -8,7 +8,6 @@ interface StepProps {
88
label?: React.ReactNode;
99
forceExpanded?: string; // From parent 'expanded' state
1010
isFirstStep?: boolean; // Prop calculated by parent
11-
isActiveStep?: boolean; // Prop calculated by parent (based on state/scroll)
1211
[key: string]: any;
1312
}
1413

@@ -18,21 +17,18 @@ const Step = ({
1817
label,
1918
forceExpanded,
2019
isFirstStep = false,
21-
isActiveStep = false,
2220
...restProps
2321
}: StepProps) => {
2422

2523
// Determine 'active' status based on props passed from parent
26-
const shouldBeActive = isFirstStep || isActiveStep || forceExpanded === 'true';
24+
const shouldBeActive = isFirstStep || forceExpanded === 'true';
2725
const status: 'active' | 'complete' | 'incomplete' = shouldBeActive ? 'active' : 'incomplete';
2826

2927
// Let underlying component handle expansion based on status='active'
30-
// We pass collapsed=true, relying on status='active' to override it.
3128
const collapsed = true;
3229

33-
// Swap out the Click-UI Stepper label (shown next to the numbered circle) for the
34-
// H2 header so that Docusaurus doesn't fail on broken anchor checks
35-
useEffect(() => {
30+
// Swap out the Click-UI Stepper label for the H2 header
31+
React.useEffect(() => {
3632
try {
3733
const button = document.querySelectorAll(`button[id^=${id}]`)[0];
3834
const divChildren = Array.from(button.children).filter(el => el.tagName === 'DIV');
@@ -45,13 +41,12 @@ const Step = ({
4541
} catch (e) {
4642
console.log('Error occurred in Stepper.tsx while swapping H2 for Click-UI label')
4743
}
48-
}, []);
44+
}, [id]);
4945

5046
// Filter out props specific to this wrapper logic
5147
const {
5248
forceExpanded: _,
5349
isFirstStep: __,
54-
isActiveStep: ___,
5550
...domSafeProps // Pass the rest to the underlying component
5651
} = restProps;
5752

@@ -79,15 +74,12 @@ interface StepperProps {
7974

8075
// Using VerticalStepper name based on MDXComponents.js
8176
const VStepper = ({
82-
children,
83-
type = 'numbered',
84-
className,
85-
expanded, // 'true' if allExpanded was set
86-
...props
87-
}: StepperProps) => {
88-
89-
// State for tracking active steps via scroll/click
90-
const [activeStepIds, setActiveStepIds] = useState<Set<string>>(new Set());
77+
children,
78+
type = 'numbered',
79+
className,
80+
expanded, // 'true' if allExpanded was set
81+
...props
82+
}: StepperProps) => {
9183

9284
// Determine if all steps should be expanded from the start
9385
const isExpandedMode = expanded === 'true';
@@ -96,69 +88,22 @@ const VStepper = ({
9688
const childSteps = React.Children.toArray(children)
9789
.filter(child => React.isValidElement(child));
9890

99-
// Extract step-X IDs (used for state tracking and keys)
91+
// Extract step-X IDs (used for keys)
10092
const stepIds = childSteps.map((child, index) => {
10193
const childElement = child as React.ReactElement;
10294
return childElement.props.id || `step-${index + 1}`;
10395
});
10496

105-
// --- Scroll Listener Effect ---
106-
// This is currently not used, but we may want to include it at a later stage
107-
useEffect(() => {
108-
if (isExpandedMode) return;
109-
110-
const handleScroll = () => {
111-
const headers = document.querySelectorAll('button[id^="step-"]');
112-
if (headers.length === 0) {
113-
console.log('No step headers found using CORRECT selectors');
114-
return;
115-
}
116-
117-
headers.forEach((header, index) => {
118-
if (index >= stepIds.length) return;
119-
const rect = header.getBoundingClientRect();
120-
const isVisible = rect.top < window.innerHeight * 0.7 && rect.bottom > 0;
121-
if (isVisible) {
122-
const stepId = stepIds[index];
123-
setActiveStepIds(prev => {
124-
if (prev.has(stepId)) return prev;
125-
// console.log(`Activating step ${stepId} from scroll`);
126-
return new Set([...prev, stepId]);
127-
});
128-
}
129-
});
130-
};
131-
132-
const timeoutId = setTimeout(handleScroll, 500);
133-
window.addEventListener('scroll', handleScroll);
134-
const intervals = [1000, 2000, 3000].map(delay => setTimeout(handleScroll, delay));
135-
136-
return () => {
137-
window.removeEventListener('scroll', handleScroll);
138-
clearTimeout(timeoutId);
139-
intervals.forEach(id => clearTimeout(id));
140-
};
141-
}, [isExpandedMode, stepIds]);
142-
143-
// Click handler (used within onClick prop below)
144-
const handleStepClick = (stepId: string) => {
145-
if (isExpandedMode) return;
146-
// console.log(`Clicked on step ${stepId}`);
147-
setActiveStepIds(prev => new Set([...prev, stepId]));
148-
};
149-
15097
// Prepare children, passing down calculated state
15198
const enhancedChildren = childSteps.map((child, index) => {
15299
const childElement = child as React.ReactElement;
153100
const stepId = childElement.props.id || `step-${index + 1}`;
154-
const isActiveStep = activeStepIds.has(stepId); // Is this step activated by scroll/click?
155101
const isFirstStep = index === 0; // Is this the first step?
156102

157103
return React.cloneElement(childElement, {
158104
key: stepId,
159105
id: stepId,
160106
isFirstStep, // Pass down flag for first step logic
161-
isActiveStep, // Pass down flag for active state logic
162107
forceExpanded: isExpandedMode ? 'true' : undefined // Pass down expanded mode
163108
});
164109
});
@@ -171,19 +116,6 @@ const VStepper = ({
171116
type={type}
172117
className={className}
173118
{...domProps}
174-
onClick={(e) => {
175-
if (isExpandedMode) return;
176-
const target = e.target as HTMLElement;
177-
const header = target.closest('button[id^="step-"]');
178-
if (header) {
179-
const allHeaders = document.querySelectorAll('button[id^="step-"]');
180-
const index = Array.from(allHeaders).indexOf(header as Element);
181-
if (index !== -1 && index < stepIds.length) {
182-
const stepId = stepIds[index];
183-
handleStepClick(stepId);
184-
}
185-
}
186-
}}
187119
>
188120
{enhancedChildren}
189121
</OriginalVerticalStepper>

0 commit comments

Comments
 (0)