Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Scaffold new action for fk cell

Joshen Lim21230dea07ba
diff --git a/studio/components/grid/components/formatter/ForeignKeyFormatter.tsx b/studio/components/grid/components/formatter/ForeignKeyFormatter.tsx
index e6abb30516f..16eb3b46fe2 100644
--- a/studio/components/grid/components/formatter/ForeignKeyFormatter.tsx
+++ b/studio/components/grid/components/formatter/ForeignKeyFormatter.tsx
@@ -1,43 +1,52 @@
-import * as React from 'react'
+import Link from 'next/link'
+import { PropsWithChildren } from 'react'
import { FormatterProps } from '@supabase/react-data-grid'
import { SupaRow } from '../../types'
import { NullValue } from '../common'
import { ForeignTableModal } from '../common/ForeignTableModal'
import { useDispatch, useTrackedState } from '../../store'
import { deepClone } from '../../utils'
+import * as Tooltip from '@radix-ui/react-tooltip'
+import { Button, IconArrowRight } from 'ui'
+import { useParams } from 'hooks'
-export const ForeignKeyFormatter = (
- p: React.PropsWithChildren<FormatterProps<SupaRow, unknown>>
-) => {
- const state = useTrackedState()
- const dispatch = useDispatch()
+export const ForeignKeyFormatter = (p: PropsWithChildren<FormatterProps<SupaRow, unknown>>) => {
+ const { ref, id } = useParams()
const value = p.row[p.column.key]
- function onRowChange(_value: any | null) {
- const rowData = deepClone(p.row)
- rowData[p.column.key] = _value
-
- const { error } = state.rowService!.update(rowData, p.row, p.column.key)
- if (error) {
- if (state.onError) state.onError(error)
- } else {
- dispatch({
- type: 'EDIT_ROW',
- payload: { row: rowData, idx: p.row.idx },
- })
- }
- }
-
- function onChange(_value: any | null) {
- onRowChange(_value)
- }
-
return (
<div className="sb-grid-foreign-key-formatter flex justify-between">
<span className="sb-grid-foreign-key-formatter__text">
{value === null ? <NullValue /> : value}
</span>
- <ForeignTableModal columnName={p.column.key} defaultValue={value} onChange={onChange} />
+ <Tooltip.Root delayDuration={0}>
+ <Tooltip.Trigger>
+ <Link href={`/project/${ref}/editor/${id}?filter={primary_key}%3Aeq%3A${value}`}>
+ <a>
+ <Button
+ type="default"
+ size="tiny"
+ className="translate-y-[2px]"
+ onClick={() => {}}
+ icon={<IconArrowRight size="tiny" />}
+ style={{ padding: '3px' }}
+ />
+ </a>
+ </Link>
+ </Tooltip.Trigger>
+ <Tooltip.Content side="bottom">
+ <Tooltip.Arrow className="radix-tooltip-arrow" />
+ <div
+ className={[
+ 'rounded bg-scale-100 py-1 px-2 leading-none shadow',
+ 'border border-scale-200',
+ ].join(' ')}
+ >
+ <span className="text-xs text-scale-1200">View referencing record</span>
+ </div>
+ </Tooltip.Content>
+ </Tooltip.Root>
+ {/* <ForeignTableModal columnName={p.column.key} defaultValue={value} onChange={onChange} /> */}
</div>
)
}
diff --git a/studio/components/grid/components/grid/Grid.tsx b/studio/components/grid/components/grid/Grid.tsx
index a5194aa0c9f..ff4c3e09d9e 100644
--- a/studio/components/grid/components/grid/Grid.tsx
+++ b/studio/components/grid/components/grid/Grid.tsx
@@ -6,7 +6,6 @@ import { GridProps, SupaRow } from '../../types'
import { useDispatch, useTrackedState } from '../../store'
import RowRenderer from './RowRenderer'
import AwesomeDebouncePromise from 'awesome-debounce-promise'
-import { useTableRowUpdateMutation } from 'data/table-rows/table-row-update-mutation'
function rowKeyGetter(row: SupaRow) {
return row?.idx ?? -1