Skip to content

Commit 2d32555

Browse files
committedMar 20, 2025
introduce icons for column types
1 parent 67b3415 commit 2d32555

File tree

1 file changed

+89
-19
lines changed
  • packages/web-console/src/scenes/Schema/Row

1 file changed

+89
-19
lines changed
 

‎packages/web-console/src/scenes/Schema/Row/index.tsx

+89-19
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,18 @@
2525
import React, { MouseEvent, useContext, useState, useEffect, useRef } from "react"
2626
import styled from "styled-components"
2727
import { Rocket } from "@styled-icons/boxicons-regular"
28-
import { SortDown } from "@styled-icons/boxicons-regular"
28+
import { SortDown, Font } from "@styled-icons/boxicons-regular"
2929
import { ChevronRight } from "@styled-icons/boxicons-solid"
3030
import { Error as ErrorIcon } from "@styled-icons/boxicons-regular"
3131
import { CheckboxBlankCircle, Loader4 } from "@styled-icons/remix-line"
32+
import type { StyledIcon } from '@styled-icons/styled-icon'
33+
import { OneHundredTwentyThree, CalendarMinus, Globe, GeoAlt, Type as CharIcon } from '@styled-icons/bootstrap'
3234
import type { TreeNodeKind } from "../../../components/Tree"
3335
import * as QuestDB from "../../../utils/questdb"
3436
import Highlighter from "react-highlight-words"
3537
import { TableIcon } from "../table-icon"
3638
import { Box } from "@questdb/react-components"
3739
import { Text, TransitionDuration, IconWithTooltip, spinAnimation } from "../../../components"
38-
import type { TextProps } from "../../../components"
3940
import { color } from "../../../utils"
4041
import { SchemaContext } from "../SchemaContext"
4142
import { Checkbox } from "../checkbox"
@@ -186,6 +187,87 @@ const ErrorItem = styled.div`
186187
gap: 0.5rem;
187188
`
188189

190+
const TypeIcon = styled.div`
191+
margin-right: 0.8rem;
192+
display: flex;
193+
align-items: center;
194+
`
195+
196+
const TYPE_ICONS = {
197+
number: {
198+
types: ["boolean", "byte", "short", "int", "long", "long256", "double", "float", "binary", "uuid"],
199+
icon: OneHundredTwentyThree
200+
},
201+
date: {
202+
types: ["date"],
203+
icon: CalendarMinus
204+
},
205+
text: {
206+
types: ["char", "symbol", "varchar", "string"],
207+
icon: CharIcon
208+
},
209+
time: {
210+
types: ["timestamp", "interval"],
211+
icon: SortDown
212+
},
213+
network: {
214+
types: ["ipv4"],
215+
icon: Globe
216+
},
217+
geo: {
218+
types: ["geohash"],
219+
icon: GeoAlt
220+
}
221+
} as const
222+
223+
const IconWrapper = ({ icon: Icon, size = "14px" }: { icon: StyledIcon; size?: string }) => (
224+
<TypeIcon>
225+
<Icon size={size} />
226+
</TypeIcon>
227+
)
228+
229+
const getIcon = (type: string) => {
230+
const iconConfig = Object.values(TYPE_ICONS).find(
231+
({ types }) => types.some((t) => t === type.toLowerCase())
232+
)
233+
234+
return <IconWrapper icon={iconConfig?.icon ?? DotIcon} />
235+
}
236+
237+
const ColumnIcon = ({
238+
indexed,
239+
isDesignatedTimestamp,
240+
type
241+
}: {
242+
indexed?: boolean;
243+
isDesignatedTimestamp: boolean;
244+
type?: string;
245+
}) => {
246+
if (!type) return null
247+
248+
if (indexed) {
249+
return (
250+
<IconWithTooltip
251+
icon={<RocketIcon size="13px" />}
252+
placement="top"
253+
tooltip="Indexed"
254+
/>
255+
)
256+
}
257+
258+
if (isDesignatedTimestamp) {
259+
return (
260+
<IconWithTooltip
261+
icon={<SortDownIcon size="14px" />}
262+
placement="top"
263+
tooltip="Designated timestamp"
264+
/>
265+
)
266+
}
267+
268+
return getIcon(type)
269+
}
270+
189271
const Row = ({
190272
className,
191273
designatedTimestamp,
@@ -260,26 +342,14 @@ const Row = ({
260342
{isExpandable && expanded && <ChevronDownIcon size="14px" />}
261343
{isExpandable && !expanded && <ChevronRightIcon size="14px" />}
262344

263-
{kind === "column" && indexed && (
264-
<IconWithTooltip
265-
icon={<RocketIcon size="13px" />}
266-
placement="top"
267-
tooltip="Indexed"
345+
{kind === "column" && (
346+
<ColumnIcon
347+
indexed={indexed}
348+
isDesignatedTimestamp={Boolean(!indexed && name === designatedTimestamp)}
349+
type={type}
268350
/>
269351
)}
270352

271-
{kind === "column" && !indexed && name === designatedTimestamp && (
272-
<IconWithTooltip
273-
icon={<SortDownIcon size="14px" />}
274-
placement="top"
275-
tooltip="Designated timestamp"
276-
/>
277-
)}
278-
279-
{kind === "column" && !indexed && name !== designatedTimestamp && (
280-
<DotIcon size="12px" />
281-
)}
282-
283353
<StyledTitle
284354
color="foreground"
285355
ellipsis

0 commit comments

Comments
 (0)
Failed to load comments.