|
25 | 25 | import React, { MouseEvent, useContext, useState, useEffect, useRef } from "react"
|
26 | 26 | import styled from "styled-components"
|
27 | 27 | import { Rocket } from "@styled-icons/boxicons-regular"
|
28 |
| -import { SortDown } from "@styled-icons/boxicons-regular" |
| 28 | +import { SortDown, Font } from "@styled-icons/boxicons-regular" |
29 | 29 | import { ChevronRight } from "@styled-icons/boxicons-solid"
|
30 | 30 | import { Error as ErrorIcon } from "@styled-icons/boxicons-regular"
|
31 | 31 | 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' |
32 | 34 | import type { TreeNodeKind } from "../../../components/Tree"
|
33 | 35 | import * as QuestDB from "../../../utils/questdb"
|
34 | 36 | import Highlighter from "react-highlight-words"
|
35 | 37 | import { TableIcon } from "../table-icon"
|
36 | 38 | import { Box } from "@questdb/react-components"
|
37 | 39 | import { Text, TransitionDuration, IconWithTooltip, spinAnimation } from "../../../components"
|
38 |
| -import type { TextProps } from "../../../components" |
39 | 40 | import { color } from "../../../utils"
|
40 | 41 | import { SchemaContext } from "../SchemaContext"
|
41 | 42 | import { Checkbox } from "../checkbox"
|
@@ -186,6 +187,87 @@ const ErrorItem = styled.div`
|
186 | 187 | gap: 0.5rem;
|
187 | 188 | `
|
188 | 189 |
|
| 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 | + |
189 | 271 | const Row = ({
|
190 | 272 | className,
|
191 | 273 | designatedTimestamp,
|
@@ -260,26 +342,14 @@ const Row = ({
|
260 | 342 | {isExpandable && expanded && <ChevronDownIcon size="14px" />}
|
261 | 343 | {isExpandable && !expanded && <ChevronRightIcon size="14px" />}
|
262 | 344 |
|
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} |
268 | 350 | />
|
269 | 351 | )}
|
270 | 352 |
|
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 |
| - |
283 | 353 | <StyledTitle
|
284 | 354 | color="foreground"
|
285 | 355 | ellipsis
|
|
0 commit comments