Skip to content

Commit 54fb539

Browse files
committed
Refactor code for improved readability and consistency
- Updated formatting in various components to enhance code clarity. - Adjusted function signatures and parameters for better alignment. - Simplified return statements and conditional checks for cleaner code. - Consolidated multiline statements for improved readability. - Enhanced error handling messages for better debugging. docker-false
1 parent 02827f1 commit 54fb539

30 files changed

+219
-122
lines changed

src/components/charts/ChartVisualizationPro.tsx

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ function PieChart({
8383
legendShow?: boolean;
8484
}) {
8585
const total = data.reduce((sum, row) => sum + (Number(row[yKey]) || 0), 0);
86-
if (total === 0) return <div className="flex items-center justify-center h-full text-muted-foreground">No data</div>;
86+
if (total === 0)
87+
return (
88+
<div className="flex items-center justify-center h-full text-muted-foreground">No data</div>
89+
);
8790

8891
const slices: { label: string; value: number; pct: number; color: string }[] = [];
8992
let cumAngle = -Math.PI / 2;
@@ -149,7 +152,10 @@ function PieChart({
149152
<div className="flex flex-wrap gap-x-4 gap-y-1 justify-center text-xs">
150153
{slices.map((s, i) => (
151154
<div key={i} className="flex items-center gap-1.5">
152-
<span className="w-2.5 h-2.5 rounded-full inline-block flex-shrink-0" style={{ backgroundColor: s.color }} />
155+
<span
156+
className="w-2.5 h-2.5 rounded-full inline-block flex-shrink-0"
157+
style={{ backgroundColor: s.color }}
158+
/>
153159
<span className="text-muted-foreground truncate max-w-[120px]">{s.label}</span>
154160
<span className="font-medium">{formatNumber(s.value)}</span>
155161
</div>
@@ -188,7 +194,12 @@ export const ChartVisualizationPro: React.FC<ChartVisualizationProProps> = ({
188194

189195
// Transform data based on configuration
190196
const transformedData = useMemo(() => {
191-
return transformData(result, localConfig.transform, localConfig.xAxis, localConfig.yAxis || localConfig.series);
197+
return transformData(
198+
result,
199+
localConfig.transform,
200+
localConfig.xAxis,
201+
localConfig.yAxis || localConfig.series
202+
);
192203
}, [result, localConfig.transform, localConfig.xAxis, localConfig.yAxis, localConfig.series]);
193204

194205
const handleConfigChange = (updates: Partial<ChartConfig>) => {
@@ -238,7 +249,9 @@ export const ChartVisualizationPro: React.FC<ChartVisualizationProProps> = ({
238249
await exportChartAsPNG(chartRef.current, fileName, bg);
239250
toast.success("Chart exported as PNG");
240251
} catch (error) {
241-
toast.error(`Failed to export chart: ${error instanceof Error ? error.message : "Unknown error"}`);
252+
toast.error(
253+
`Failed to export chart: ${error instanceof Error ? error.message : "Unknown error"}`
254+
);
242255
}
243256
};
244257

@@ -274,13 +287,16 @@ export const ChartVisualizationPro: React.FC<ChartVisualizationProProps> = ({
274287
});
275288

276289
// Determine Y keys
277-
const yKeys: string[] = chartConfig.series?.map((s) => s.column) ?? (chartConfig.yAxis ? [chartConfig.yAxis] : []);
290+
const yKeys: string[] =
291+
chartConfig.series?.map((s) => s.column) ?? (chartConfig.yAxis ? [chartConfig.yAxis] : []);
278292
const colors = chartConfig.colors || DEFAULT_COLORS;
279293
const isDark = theme === "dark";
280294

281295
// Convert to uPlot columnar data: [xs, ...series]
282296
const xs = chartData.map((_, i) => i);
283-
const seriesData = yKeys.map((key) => chartData.map((row) => (Number(row[key]) || 0) as number));
297+
const seriesData = yKeys.map((key) =>
298+
chartData.map((row) => (Number(row[key]) || 0) as number)
299+
);
284300

285301
// For stacked charts, compute stacked values
286302
const isStacked = chartConfig.type === "stacked_bar" || chartConfig.type === "stacked_area";
@@ -361,7 +377,11 @@ export const ChartVisualizationPro: React.FC<ChartVisualizationProProps> = ({
361377
{
362378
stroke: isDark ? "#888" : "#666",
363379
grid: chartConfig.showGrid
364-
? { stroke: isDark ? "rgba(255,255,255,0.08)" : "rgba(0,0,0,0.08)", width: 1, dash: [4, 4] }
380+
? {
381+
stroke: isDark ? "rgba(255,255,255,0.08)" : "rgba(0,0,0,0.08)",
382+
width: 1,
383+
dash: [4, 4],
384+
}
365385
: { show: false },
366386
ticks: { stroke: isDark ? "rgba(255,255,255,0.15)" : "rgba(0,0,0,0.15)", width: 1 },
367387
values: (_u: uPlot, vals: number[]) => vals.map((v) => formatNumber(v)),
@@ -397,8 +417,8 @@ export const ChartVisualizationPro: React.FC<ChartVisualizationProProps> = ({
397417

398418
// Stacked: render in reverse order so first series is on top visually
399419
const data: uPlot.AlignedData = isStacked
400-
? [xs, ...finalSeriesData.reverse()] as uPlot.AlignedData
401-
: [xs, ...finalSeriesData] as uPlot.AlignedData;
420+
? ([xs, ...finalSeriesData.reverse()] as uPlot.AlignedData)
421+
: ([xs, ...finalSeriesData] as uPlot.AlignedData);
402422

403423
return { uPlotOptions: opts, uPlotData: data };
404424
}, [chartConfig, transformedData, theme]);
@@ -417,8 +437,8 @@ export const ChartVisualizationPro: React.FC<ChartVisualizationProProps> = ({
417437
<div className="text-center space-y-2 max-w-md">
418438
<h3 className="text-lg font-semibold">Create Your Chart</h3>
419439
<p className="text-muted-foreground text-sm">
420-
Configure chart settings above to visualize your data. Choose a chart type, select your axes, and
421-
customize to your needs.
440+
Configure chart settings above to visualize your data. Choose a chart type, select
441+
your axes, and customize to your needs.
422442
</p>
423443
{suggestedTypes.length > 0 && (
424444
<div className="pt-4">
@@ -515,7 +535,10 @@ export const ChartVisualizationPro: React.FC<ChartVisualizationProProps> = ({
515535
{/* X-Axis */}
516536
<div className="space-y-2">
517537
<label className="text-xs font-medium">X-Axis</label>
518-
<Select value={localConfig.xAxis || ""} onValueChange={(value) => handleConfigChange({ xAxis: value })}>
538+
<Select
539+
value={localConfig.xAxis || ""}
540+
onValueChange={(value) => handleConfigChange({ xAxis: value })}
541+
>
519542
<SelectTrigger>
520543
<SelectValue placeholder="Select column" />
521544
</SelectTrigger>

src/components/charts/tooltipPlugin.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ export function tooltipPlugin(xLabels: string[]): uPlot.Plugin {
4444
const s = u.series[i];
4545
if (!s.show) continue;
4646
const val = u.data[i][idx];
47-
const color = typeof s.stroke === "function" ? (s.stroke as (self: uPlot, seriesIdx: number) => string)(u, i) : s.stroke;
47+
const color =
48+
typeof s.stroke === "function"
49+
? (s.stroke as (self: uPlot, seriesIdx: number) => string)(u, i)
50+
: s.stroke;
4851
html += `<div class="uplot-tooltip-row">
4952
<span class="uplot-tooltip-dot" style="background:${color}"></span>
5053
<span class="uplot-tooltip-label">${s.label}</span>

src/components/editor/SqlEditor.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,15 @@ const SqlEditor: React.FC<SqlEditorProps> = ({ tabId, title, className }) => {
2323
const editorRef = useRef<HTMLDivElement>(null);
2424
const editorInstanceRef = useRef<EditorInstance | null>(null);
2525
const { theme } = useTheme();
26-
const { tabs, executeQuery, isExecuting, updateTabTitle, toggleBrainPanel, duckBrain, currentProfileId } =
27-
useDuckStore();
26+
const {
27+
tabs,
28+
executeQuery,
29+
isExecuting,
30+
updateTabTitle,
31+
toggleBrainPanel,
32+
duckBrain,
33+
currentProfileId,
34+
} = useDuckStore();
2835
const monacoConfig = useMonacoConfig(theme);
2936

3037
const currentTab = tabs.find((tab) => tab.id === tabId);

src/components/editor/monacoConfig.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,10 @@ monaco.languages.registerDocumentFormattingEditProvider("sql", {
209209
interface AutocompleteItem {
210210
suggestion: string;
211211
}
212-
const queryNative = async <T>(connection: { query: (sql: string) => Promise<{ toArray: () => unknown[] }> }, query: string): Promise<T[]> => {
212+
const queryNative = async <T>(
213+
connection: { query: (sql: string) => Promise<{ toArray: () => unknown[] }> },
214+
query: string
215+
): Promise<T[]> => {
213216
const results = await connection.query(query);
214217
return results.toArray().map((row: unknown) => row as T);
215218
};

src/components/explorer/FileImporter.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,10 @@ const FileDetails: React.FC<FileDetailsProps> = ({
265265
}, [tableName]);
266266

267267
// Handle CSV option changes
268-
const handleCsvOptionChange = (key: keyof CsvImportOptions, value: string | boolean | number | undefined) => {
268+
const handleCsvOptionChange = (
269+
key: keyof CsvImportOptions,
270+
value: string | boolean | number | undefined
271+
) => {
269272
if (onCsvOptionsChange && csvOptions) {
270273
onCsvOptionsChange({
271274
...csvOptions,

src/components/layout/Sidebar.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,7 @@ export default function Sidebar({ isExplorerOpen, onToggleExplorer }: SidebarPro
166166
</button>
167167
</DropdownMenuTrigger>
168168
</TooltipTrigger>
169-
<TooltipContent side="right">
170-
{currentProfile?.name || "Duck-UI"}
171-
</TooltipContent>
169+
<TooltipContent side="right">{currentProfile?.name || "Duck-UI"}</TooltipContent>
172170
</Tooltip>
173171
</TooltipProvider>
174172
<DropdownMenuContent side="right" align="start">

src/components/profile/PasswordDialog.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ interface PasswordDialogProps {
2121
onSubmit: (password: string) => Promise<void>;
2222
}
2323

24-
export default function PasswordDialog({ open, onOpenChange, profile, onSubmit }: PasswordDialogProps) {
24+
export default function PasswordDialog({
25+
open,
26+
onOpenChange,
27+
profile,
28+
onSubmit,
29+
}: PasswordDialogProps) {
2530
const [password, setPassword] = useState("");
2631
const [error, setError] = useState<string | null>(null);
2732
const [isLoading, setIsLoading] = useState(false);

src/components/profile/ProfileEditor.tsx

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,26 @@ import ProfileAvatar from "./ProfileAvatar";
88

99
const AVATAR_OPTIONS = [
1010
"logo",
11-
"\u{1F986}", "\u{1F424}", "\u{1F985}", "\u{1F427}", "\u{1F989}", "\u{1F426}", "\u{1F99C}", "\u{1F438}", "\u{1F43B}", "\u{1F98A}",
12-
"\u{1F431}", "\u{1F436}", "\u{1F43C}", "\u{1F981}", "\u{1F428}", "\u{1F42F}", "\u{1F430}", "\u{1F419}", "\u{1F98B}", "\u{1F31F}",
11+
"\u{1F986}",
12+
"\u{1F424}",
13+
"\u{1F985}",
14+
"\u{1F427}",
15+
"\u{1F989}",
16+
"\u{1F426}",
17+
"\u{1F99C}",
18+
"\u{1F438}",
19+
"\u{1F43B}",
20+
"\u{1F98A}",
21+
"\u{1F431}",
22+
"\u{1F436}",
23+
"\u{1F43C}",
24+
"\u{1F981}",
25+
"\u{1F428}",
26+
"\u{1F42F}",
27+
"\u{1F430}",
28+
"\u{1F419}",
29+
"\u{1F98B}",
30+
"\u{1F31F}",
1331
];
1432

1533
interface ProfileEditorProps {
@@ -19,15 +37,21 @@ interface ProfileEditorProps {
1937
onCancel: () => void;
2038
}
2139

22-
export default function ProfileEditor({ mode, initialValues, onSave, onCancel }: ProfileEditorProps) {
40+
export default function ProfileEditor({
41+
mode,
42+
initialValues,
43+
onSave,
44+
onCancel,
45+
}: ProfileEditorProps) {
2346
const [name, setName] = useState(initialValues?.name ?? "");
2447
const [avatarEmoji, setAvatarEmoji] = useState(initialValues?.avatarEmoji ?? "logo");
2548
const [passwordEnabled, setPasswordEnabled] = useState(false);
2649
const [password, setPassword] = useState("");
2750
const [confirmPassword, setConfirmPassword] = useState("");
2851
const [emojiOpen, setEmojiOpen] = useState(false);
2952

30-
const passwordMismatch = passwordEnabled && password !== confirmPassword && confirmPassword.length > 0;
53+
const passwordMismatch =
54+
passwordEnabled && password !== confirmPassword && confirmPassword.length > 0;
3155
const passwordTooShort = passwordEnabled && password.length > 0 && password.length < 4;
3256

3357
const isValid =

src/components/profile/ProfilePicker.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ export default function ProfilePicker({
110110
</Button>
111111
<p className="text-xs text-muted-foreground">
112112
Your profiles are stored locally on your device. Creating a profile does not share any
113-
data... This application is 100% offline and private by design, it's runs on the client side and does not send any data to any server.
113+
data... This application is 100% offline and private by design, it's runs on the client
114+
side and does not send any data to any server.
114115
</p>
115116
</div>
116117

src/components/saved-queries/SavedQueriesPanel.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ export default function SavedQueriesPanel({ onClose }: SavedQueriesPanelProps) {
6666
}
6767
try {
6868
await updateSavedQuery(id, { name: editName.trim() });
69-
setQueries((prev) =>
70-
prev.map((q) => (q.id === id ? { ...q, name: editName.trim() } : q))
71-
);
69+
setQueries((prev) => prev.map((q) => (q.id === id ? { ...q, name: editName.trim() } : q)));
7270
bumpSavedQueriesVersion();
7371
} catch {
7472
toast.error("Failed to rename query");
@@ -138,9 +136,7 @@ export default function SavedQueriesPanel({ onClose }: SavedQueriesPanelProps) {
138136
className="h-6 text-sm font-medium px-1"
139137
/>
140138
) : (
141-
<span className="font-medium text-sm truncate block">
142-
{query.name}
143-
</span>
139+
<span className="font-medium text-sm truncate block">{query.name}</span>
144140
)}
145141
<pre className="text-xs font-mono text-muted-foreground truncate">
146142
{query.sql_text.length > 100

0 commit comments

Comments
 (0)