Skip to content

Commit 730325a

Browse files
authored
feat: enhance SourceSchemaPreview button integration in select components (#1223)
1 parent fb1b035 commit 730325a

File tree

8 files changed

+99
-34
lines changed

8 files changed

+99
-34
lines changed

.changeset/itchy-peas-pull.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hyperdx/app": minor
3+
---
4+
5+
Improve SourceSchemaPreview button integration in SourceSelect and DBTableSelect components.

packages/app/src/DBSearchPage.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,13 +1215,10 @@ function DBSearchPage() {
12151215
onCreate={openNewSourceModal}
12161216
allowedSourceKinds={[SourceKind.Log, SourceKind.Trace]}
12171217
data-testid="source-selector"
1218+
sourceSchemaPreview={
1219+
<SourceSchemaPreview source={inputSourceObj} variant="text" />
1220+
}
12181221
/>
1219-
<span className="ms-1">
1220-
<SourceSchemaPreview
1221-
source={inputSourceObj}
1222-
iconStyles={{ size: 'xs', color: 'dark.2' }}
1223-
/>
1224-
</span>
12251222
<Menu withArrow position="bottom-start">
12261223
<Menu.Target>
12271224
<ActionIcon

packages/app/src/DashboardFiltersEditModal.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,9 @@ const DashboardFilterEditForm = ({
8989
data-testid="source-selector"
9090
rules={{ required: true }}
9191
comboboxProps={{ withinPortal: true }}
92-
/>
93-
</span>
94-
<span className="me-2">
95-
<SourceSchemaPreview
96-
source={source}
97-
iconStyles={{ color: 'dark.2' }}
92+
sourceSchemaPreview={
93+
<SourceSchemaPreview source={source} variant="text" />
94+
}
9895
/>
9996
</span>
10097
</Group>

packages/app/src/components/DBEditTimeChartForm.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -686,10 +686,9 @@ export default function EditTimeChartForm({
686686
control={control}
687687
name="source"
688688
data-testid="source-selector"
689-
/>
690-
<SourceSchemaPreview
691-
source={tableSource}
692-
iconStyles={{ color: 'dark.2' }}
689+
sourceSchemaPreview={
690+
<SourceSchemaPreview source={tableSource} variant="text" />
691+
}
693692
/>
694693
</Flex>
695694

packages/app/src/components/DBTableSelect.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Flex, Select } from '@mantine/core';
44
import { useTablesDirect } from '@/clickhouse';
55

66
import SourceSchemaPreview from './SourceSchemaPreview';
7+
import { SourceSelectRightSection } from './SourceSelect';
78

89
export default function DBTableSelect({
910
database,
@@ -36,6 +37,19 @@ export default function DBTableSelect({
3637
label: db.name,
3738
}));
3839

40+
const rightSectionProps = SourceSelectRightSection({
41+
sourceSchemaPreview:
42+
connectionId && database && table ? (
43+
<SourceSchemaPreview
44+
source={{
45+
connection: connectionId,
46+
from: { databaseName: database, tableName: table },
47+
}}
48+
variant="text"
49+
/>
50+
) : undefined,
51+
});
52+
3953
return (
4054
<Flex align="center" gap={8}>
4155
<Select
@@ -53,17 +67,7 @@ export default function DBTableSelect({
5367
ref={inputRef}
5468
size={size}
5569
className="flex-grow-1"
56-
/>
57-
<SourceSchemaPreview
58-
source={
59-
connectionId && database && table
60-
? {
61-
connection: connectionId,
62-
from: { databaseName: database, tableName: table },
63-
}
64-
: undefined
65-
}
66-
iconStyles={{ color: 'gray.4' }}
70+
{...rightSectionProps}
6771
/>
6872
</Flex>
6973
);

packages/app/src/components/SourceSchemaPreview.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useState } from 'react';
22
import { MetricsDataType, TSource } from '@hyperdx/common-utils/dist/types';
3-
import { Modal, Paper, Tabs, Text, TextProps, Tooltip } from '@mantine/core';
3+
import { Modal, Paper, Tabs, TextProps, Tooltip } from '@mantine/core';
4+
import { IconCode } from '@tabler/icons-react';
45

56
import { useTableMetadata } from '@/hooks/useMetadata';
67

@@ -11,13 +12,15 @@ interface SourceSchemaInfoIconProps {
1112
isEnabled: boolean;
1213
tableCount: number;
1314
iconStyles?: Pick<TextProps, 'size' | 'color'>;
15+
variant?: 'icon' | 'text';
1416
}
1517

1618
const SourceSchemaInfoIcon = ({
1719
onClick,
1820
isEnabled,
1921
tableCount,
2022
iconStyles,
23+
variant = 'icon',
2124
}: SourceSchemaInfoIconProps) => {
2225
const tooltipText = isEnabled
2326
? tableCount > 1
@@ -33,11 +36,15 @@ const SourceSchemaInfoIcon = ({
3336
position="right"
3437
onClick={() => isEnabled && onClick()}
3538
>
36-
<Text {...iconStyles}>
37-
<i
38-
className={`bi bi-code-square ${isEnabled ? 'cursor-pointer' : ''}`}
39-
/>
40-
</Text>
39+
{variant === 'text' ? (
40+
<span
41+
style={{ cursor: isEnabled ? 'pointer' : 'default', ...iconStyles }}
42+
>
43+
Schema
44+
</span>
45+
) : (
46+
<IconCode size={16} />
47+
)}
4148
</Tooltip>
4249
);
4350
};
@@ -79,6 +86,7 @@ export interface SourceSchemaPreviewProps {
7986
source?: Pick<TSource, 'connection' | 'from' | 'metricTables'> &
8087
Partial<Pick<TSource, 'kind' | 'name'>>;
8188
iconStyles?: Pick<TextProps, 'size' | 'color'>;
89+
variant?: 'icon' | 'text';
8290
}
8391

8492
const METRIC_TYPE_NAMES: Record<MetricsDataType, string> = {
@@ -92,6 +100,7 @@ const METRIC_TYPE_NAMES: Record<MetricsDataType, string> = {
92100
const SourceSchemaPreview = ({
93101
source,
94102
iconStyles,
103+
variant = 'icon',
95104
}: SourceSchemaPreviewProps) => {
96105
const [isModalOpen, setIsModalOpen] = useState(false);
97106

@@ -130,6 +139,7 @@ const SourceSchemaPreview = ({
130139
onClick={() => setIsModalOpen(true)}
131140
iconStyles={iconStyles}
132141
tableCount={tables.length}
142+
variant={variant}
133143
/>
134144
{isEnabled && (
135145
<Modal

packages/app/src/components/SourceSelect.tsx

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,59 @@
11
import { memo, useMemo } from 'react';
22
import { UseControllerProps } from 'react-hook-form';
33
import { SourceKind } from '@hyperdx/common-utils/dist/types';
4-
import { SelectProps } from '@mantine/core';
4+
import { SelectProps, UnstyledButton } from '@mantine/core';
5+
import { ComboboxChevron } from '@mantine/core';
56

67
import SelectControlled from '@/components/SelectControlled';
78
import { HDX_LOCAL_DEFAULT_SOURCES } from '@/config';
89
import { useSources } from '@/source';
910

11+
import styles from '../../styles/SourceSelectControlled.module.scss';
12+
13+
interface SourceSelectRightSectionProps {
14+
sourceSchemaPreview?: React.ReactNode;
15+
}
16+
17+
export const SourceSelectRightSection = ({
18+
sourceSchemaPreview,
19+
}: SourceSelectRightSectionProps) => {
20+
if (!sourceSchemaPreview) {
21+
return {
22+
rightSection: <ComboboxChevron />,
23+
};
24+
}
25+
26+
return {
27+
rightSection: (
28+
<>
29+
<UnstyledButton
30+
onClick={e => {
31+
e.stopPropagation();
32+
e.preventDefault();
33+
}}
34+
className={styles.sourceSchemaPreviewButton}
35+
>
36+
{sourceSchemaPreview}
37+
</UnstyledButton>
38+
<ComboboxChevron />
39+
</>
40+
),
41+
rightSectionWidth: 70,
42+
};
43+
};
44+
1045
function SourceSelectControlledComponent({
1146
size,
1247
onCreate,
1348
allowedSourceKinds,
1449
comboboxProps,
50+
sourceSchemaPreview,
1551
...props
1652
}: {
1753
size?: string;
1854
onCreate?: () => void;
1955
allowedSourceKinds?: SourceKind[];
56+
sourceSchemaPreview?: React.ReactNode;
2057
} & UseControllerProps<any> &
2158
SelectProps) {
2259
const { data } = useSources();
@@ -45,6 +82,8 @@ function SourceSelectControlledComponent({
4582
[data, onCreate, allowedSourceKinds, hasLocalDefaultSources],
4683
);
4784

85+
const rightSectionProps = SourceSelectRightSection({ sourceSchemaPreview });
86+
4887
return (
4988
<SelectControlled
5089
{...props}
@@ -57,6 +96,7 @@ function SourceSelectControlledComponent({
5796
maxDropdownHeight={280}
5897
size={size}
5998
onCreate={onCreate}
99+
{...rightSectionProps}
60100
/>
61101
);
62102
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.sourceSchemaPreviewButton {
2+
pointer-events: all;
3+
font-size: var(--mantine-font-size-xxs);
4+
background-color: var(--mantine-color-gray-9);
5+
color: var(--mantine-color-gray-2);
6+
padding-inline: var(--mantine-spacing-xxxs);
7+
border-radius: var(--mantine-radius-xs);
8+
9+
&:hover {
10+
color: var(--mantine-color-gray-1);
11+
cursor: pointer;
12+
}
13+
}

0 commit comments

Comments
 (0)