Skip to content

Commit b04e54b

Browse files
awaseemjoshenlim
andauthored
fix: sentry errors (supabase#40875)
* fix: SUPABASE-APP-90D * fix: SUPABASE-APP-90C * fix: SUPABASE-APP-6HC * fix: SUPABASE-APP-A38 * fix: SUPABASE-APP-9JB * Improve types for RowContextMenu.tsx * Improve types for useChartHighlight * Nit --------- Co-authored-by: Joshen Lim <[email protected]>
1 parent 5e4e519 commit b04e54b

File tree

6 files changed

+64
-42
lines changed

6 files changed

+64
-42
lines changed

apps/studio/components/grid/components/editor/BooleanEditor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const BooleanEditor = <TRow, TSummaryRow = unknown>({
3232
size="small"
3333
onBlur={onBlur}
3434
onChange={onChange}
35-
defaultValue={value === null ? 'null' : value.toString()}
35+
defaultValue={!!value ? value.toString() : 'null'}
3636
style={{ width: `${column.width}px` }}
3737
>
3838
<Select.Option value="true">TRUE</Select.Option>

apps/studio/components/grid/components/menu/RowContextMenu.tsx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,38 @@ import { useTableEditorTableStateSnapshot } from 'state/table-editor-table'
1010
import { copyToClipboard, DialogSectionSeparator } from 'ui'
1111
import { formatClipboardValue } from '../../utils/common'
1212

13-
export type RowContextMenuProps = {
13+
type RowContextMenuProps = {
1414
rows: SupaRow[]
1515
}
1616

17+
type RowContextMenuItemProps = ItemParams<{ rowIdx: number }, string>
18+
1719
export const RowContextMenu = ({ rows }: RowContextMenuProps) => {
1820
const tableEditorSnap = useTableEditorStateSnapshot()
1921
const snap = useTableEditorTableStateSnapshot()
2022

21-
function onDeleteRow(p: ItemParams) {
22-
const { props } = p
23-
const { rowIdx } = props
23+
function onDeleteRow(p: RowContextMenuItemProps) {
24+
const rowIdx = p.props?.rowIdx
25+
if (!rowIdx) return
26+
2427
const row = rows[rowIdx]
2528
if (row) tableEditorSnap.onDeleteRows([row])
2629
}
2730

28-
function onEditRowClick(p: ItemParams) {
29-
const { props } = p
30-
const { rowIdx } = props
31+
function onEditRowClick(p: RowContextMenuItemProps) {
32+
const rowIdx = p.props?.rowIdx
33+
if (!rowIdx) return
34+
3135
const row = rows[rowIdx]
3236
tableEditorSnap.onEditRow(row)
3337
}
3438

3539
const onCopyCellContent = useCallback(
36-
(p: ItemParams) => {
37-
const { props } = p
40+
(p: RowContextMenuItemProps) => {
41+
const rowIdx = p.props?.rowIdx
42+
if (!snap.selectedCellPosition || !rowIdx) return
3843

39-
if (!snap.selectedCellPosition || !props) {
40-
return
41-
}
42-
43-
const { rowIdx } = props
4444
const row = rows[rowIdx]
45-
4645
const columnKey = snap.gridColumns[snap.selectedCellPosition.idx as number].key
4746

4847
const value = row[columnKey]
@@ -55,9 +54,10 @@ export const RowContextMenu = ({ rows }: RowContextMenuProps) => {
5554
)
5655

5756
const onCopyRowContent = useCallback(
58-
(p: ItemParams) => {
59-
const { props } = p
60-
const { rowIdx } = props
57+
(p: RowContextMenuItemProps) => {
58+
const rowIdx = p.props?.rowIdx
59+
if (!rowIdx) return
60+
6161
const row = rows[rowIdx]
6262
copyToClipboard(JSON.stringify(row))
6363
toast.success('Copied row to clipboard')

apps/studio/components/ui/Charts/ComposedChart.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -354,30 +354,34 @@ export function ComposedChart({
354354
data={data}
355355
syncId={syncId}
356356
style={{ cursor: 'crosshair' }}
357-
onMouseMove={(e: any) => {
357+
onMouseMove={({ activeLabel, activeTooltipIndex, activePayload }) => {
358+
if (!activeTooltipIndex) return
359+
358360
setIsActiveHoveredChart(true)
359-
if (e.activeTooltipIndex !== focusDataIndex) {
360-
setFocusDataIndex(e.activeTooltipIndex)
361-
setActivePayload(e.activePayload)
361+
if (activeTooltipIndex !== focusDataIndex) {
362+
setFocusDataIndex(activeTooltipIndex)
363+
setActivePayload(activePayload ?? [])
362364
}
363365

364-
setHover(e.activeTooltipIndex)
366+
setHover(activeTooltipIndex)
365367

366-
const activeTimestamp = data[e.activeTooltipIndex]?.timestamp
368+
const activeTimestamp = data[activeTooltipIndex]?.timestamp
367369
chartHighlight?.handleMouseMove({
368370
activeLabel: activeTimestamp?.toString(),
369-
coordinates: e.activeLabel,
371+
coordinates: activeLabel,
370372
})
371373
}}
372-
onMouseDown={(e: any) => {
373-
const activeTimestamp = data[e.activeTooltipIndex]?.timestamp
374+
onMouseDown={({ activeLabel, activeTooltipIndex }) => {
375+
if (!activeTooltipIndex) return
376+
377+
const activeTimestamp = data[activeTooltipIndex]?.timestamp
374378
chartHighlight?.handleMouseDown({
375379
activeLabel: activeTimestamp?.toString(),
376-
coordinates: e.activeLabel,
380+
coordinates: activeLabel,
377381
})
378382
}}
379383
onMouseUp={chartHighlight?.handleMouseUp}
380-
onMouseLeave={(e) => {
384+
onMouseLeave={() => {
381385
setIsActiveHoveredChart(false)
382386
setFocusDataIndex(null)
383387
setActivePayload(null)

apps/studio/components/ui/Charts/useChartHighlight.tsx

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,35 @@
1-
import { useState } from 'react'
21
import dayjs from 'dayjs'
2+
import { useState } from 'react'
3+
4+
type ChartHighlightMouseEvent = {
5+
activeLabel?: string
6+
coordinates?: string
7+
}
38

49
export interface ChartHighlight {
510
left: string | undefined
611
right: string | undefined
7-
coordinates: { left: any; right: any }
12+
coordinates: { left?: string; right?: string }
813
isSelecting: boolean
914
popoverPosition: { x: number; y: number } | null
10-
handleMouseDown: (e: { activeLabel?: string; coordinates?: any }) => void
11-
handleMouseMove: (e: { activeLabel?: string; coordinates?: any }) => void
12-
handleMouseUp: (e: any) => void
15+
handleMouseDown: (e: ChartHighlightMouseEvent) => void
16+
handleMouseMove: (e: ChartHighlightMouseEvent) => void
17+
handleMouseUp: (e: { chartX?: number; chartY?: number }) => void
1318
clearHighlight: () => void
1419
}
1520

1621
export function useChartHighlight(): ChartHighlight {
1722
const [left, setLeft] = useState<string | undefined>(undefined)
1823
const [right, setRight] = useState<string | undefined>(undefined)
19-
const [coordinates, setCoordinates] = useState<any>({ left: undefined, right: undefined })
24+
const [coordinates, setCoordinates] = useState<{ left?: string; right?: string }>({
25+
left: undefined,
26+
right: undefined,
27+
})
2028
const [isSelecting, setIsSelecting] = useState(false)
2129
const [popoverPosition, setPopoverPosition] = useState<{ x: number; y: number } | null>(null)
2230
const [initialPoint, setInitialPoint] = useState<string | undefined>(undefined)
2331

24-
const handleMouseDown = (e: any) => {
32+
const handleMouseDown = (e: ChartHighlightMouseEvent) => {
2533
clearHighlight()
2634
if (!e || !e.activeLabel) return
2735
setIsSelecting(true)
@@ -31,7 +39,7 @@ export function useChartHighlight(): ChartHighlight {
3139
setCoordinates({ left: e.coordinates, right: e.coordinates })
3240
}
3341

34-
const handleMouseMove = (e: any) => {
42+
const handleMouseMove = (e: ChartHighlightMouseEvent) => {
3543
if (!isSelecting || !e || !e.activeLabel) return
3644

3745
const currentTimestamp = dayjs(e.activeLabel)
@@ -56,11 +64,21 @@ export function useChartHighlight(): ChartHighlight {
5664
}
5765
}
5866

59-
const handleMouseUp = (e: any) => {
67+
const handleMouseUp = (e: unknown) => {
6068
if (!isSelecting) return
6169
setIsSelecting(false)
62-
setPopoverPosition({ x: e.chartX, y: e.chartY })
6370
setInitialPoint(undefined)
71+
72+
if (
73+
typeof e === 'object' &&
74+
e !== null &&
75+
'chartX' in e &&
76+
'chartY' in e &&
77+
typeof e.chartX === 'number' &&
78+
typeof e.chartY === 'number'
79+
) {
80+
setPopoverPosition({ x: e.chartX, y: e.chartY })
81+
}
6482
}
6583

6684
const clearHighlight = () => {

apps/studio/components/ui/DataTable/TimelineChart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export function TimelineChart<TChart extends BaseChartSchema>({
6565
}
6666
}
6767

68-
const handleMouseUp: CategoricalChartFunc = (e) => {
68+
const handleMouseUp: CategoricalChartFunc = () => {
6969
if (refAreaLeft && refAreaRight) {
7070
const [left, right] = [refAreaLeft, refAreaRight].sort(
7171
(a, b) => new Date(a).getTime() - new Date(b).getTime()

apps/studio/state/storage-explorer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ function createStorageExplorerState({
338338
})
339339
}
340340

341-
const newFolder = state.columns[columnIndex].items?.find((x) => x.name === formattedName)
341+
const newFolder = state.columns[columnIndex]?.items?.find((x) => x?.name === formattedName)
342342
if (newFolder) state.openFolder(columnIndex, newFolder)
343343
},
344344

0 commit comments

Comments
 (0)