Skip to content

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

Deprecate old CreateHook folder

Joshen Lim029b2dcada62
diff --git a/studio/components/interfaces/Database/Hooks/CreateHook/CheckboxEvents.tsx b/studio/components/interfaces/Database/Hooks/CreateHook/CheckboxEvents.tsx
deleted file mode 100644
index cf4825e3326..00000000000
--- a/studio/components/interfaces/Database/Hooks/CreateHook/CheckboxEvents.tsx
+++ /dev/null
@@ -1,56 +0,0 @@
-import { FC, useContext } from 'react'
-import { observer } from 'mobx-react-lite'
-import { Checkbox } from 'ui'
-import { union, without } from 'lodash'
-import { CreateHookContext } from './'
-
-const CheckboxEvents: FC = observer(({}) => {
- const _localState: any = useContext(CreateHookContext)
- return (
- // @ts-ignore
- <Checkbox.Group
- name="events"
- label="Events"
- id="events"
- layout="horizontal"
- size="medium"
- onChange={(e) => {
- const temp = _localState.formState.events.value
- const value = e.target.checked
- ? union(temp, [e.target.value])
- : without(temp, e.target.value)
- _localState.onFormChange({
- key: 'events',
- value: value,
- })
- }}
- error={_localState.formState.events.error}
- labelOptional="The type of events that will trigger your function hook"
- descriptionText="These are the events that are watched by the function hook, only the events selected above will fire the function hook on the table you've selected."
- >
- <Checkbox
- value="INSERT"
- id="INSERT"
- label="Insert"
- description={'Any insert operation on the table'}
- checked={_localState.formState.events.value.includes('INSERT')}
- />
- <Checkbox
- value="UPDATE"
- id="UPDATE"
- label="Update"
- description="Any update operation, of any column in the table"
- checked={_localState.formState.events.value.includes('UPDATE')}
- />
- <Checkbox
- value="DELETE"
- id="DELETE"
- label="Delete"
- description="Any deletion of a record"
- checked={_localState.formState.events.value.includes('DELETE')}
- />
- </Checkbox.Group>
- )
-})
-
-export default CheckboxEvents
diff --git a/studio/components/interfaces/Database/Hooks/CreateHook/InputName.tsx b/studio/components/interfaces/Database/Hooks/CreateHook/InputName.tsx
deleted file mode 100644
index ba2f3b9ee61..00000000000
--- a/studio/components/interfaces/Database/Hooks/CreateHook/InputName.tsx
+++ /dev/null
@@ -1,27 +0,0 @@
-import { FC, useContext } from 'react'
-import { observer } from 'mobx-react-lite'
-import { Input } from 'ui'
-import { CreateHookContext } from './'
-
-const InputName: FC = observer(({}) => {
- const _localState: any = useContext(CreateHookContext)
- return (
- <Input
- id="name"
- label="Name"
- layout="horizontal"
- placeholder="Name of your function hook"
- value={_localState.formState.name.value}
- onChange={(e) =>
- _localState.onFormChange({
- key: 'name',
- value: e.target.value,
- })
- }
- size="medium"
- error={_localState.formState.name.error}
- />
- )
-})
-
-export default InputName
diff --git a/studio/components/interfaces/Database/Hooks/CreateHook/RadioGroupHookService/RadioGroupHookService.constants.ts b/studio/components/interfaces/Database/Hooks/CreateHook/RadioGroupHookService/RadioGroupHookService.constants.ts
deleted file mode 100644
index 4b292673fb4..00000000000
--- a/studio/components/interfaces/Database/Hooks/CreateHook/RadioGroupHookService/RadioGroupHookService.constants.ts
+++ /dev/null
@@ -1,41 +0,0 @@
-export const hookServiceOptions: {
- id: string
- label: string
- badge: string
- badgeType: 'brand' | 'amber'
- description: string
- img_url: string
-}[] = [
- {
- id: 'http_request',
- label: 'HTTP Request',
- badge: 'Alpha',
- badgeType: 'brand',
- description: 'Send an HTTP request to any URL.',
- img_url: 'http-request.png',
- },
- {
- id: 'supabase_function',
- label: 'Supabase Function',
- badge: 'Coming soon',
- badgeType: 'amber',
- description: 'Choose a Supabase Function to run.',
- img_url: 'supabase-severless-function.png',
- },
- {
- id: 'google_cloud_function',
- label: 'Google cloud run',
- badge: 'Coming soon',
- badgeType: 'amber',
- description: 'Choose a google cloud function to run',
- img_url: 'google-cloud-run.png',
- },
- {
- id: 'aws_lambda_function',
- label: 'AWS Lambda',
- badge: 'Coming soon',
- badgeType: 'amber',
- description: 'Choose an AWS Lambda function to run.',
- img_url: 'aws-lambda-severless-function.png',
- },
-]
diff --git a/studio/components/interfaces/Database/Hooks/CreateHook/RadioGroupHookService/RadioHookService.tsx b/studio/components/interfaces/Database/Hooks/CreateHook/RadioGroupHookService/RadioHookService.tsx
deleted file mode 100644
index a576e35ff3b..00000000000
--- a/studio/components/interfaces/Database/Hooks/CreateHook/RadioGroupHookService/RadioHookService.tsx
+++ /dev/null
@@ -1,52 +0,0 @@
-import Image from 'next/image'
-import { FC, useContext } from 'react'
-import { observer } from 'mobx-react-lite'
-import { Radio, Badge } from 'ui'
-import { BASE_PATH } from 'lib/constants'
-import { CreateHookContext } from '../'
-
-interface Props {
- id: string
- description: string
- label: string
- img_url: string
- badgeType: 'brand' | 'amber'
- badge: string
-}
-
-const RadioHookService: FC<Props> = observer(
- ({ id, description, label, img_url, badgeType, badge }) => {
- const _localState: any = useContext(CreateHookContext)
- return (
- <Radio
- id={id}
- value={id}
- checked={_localState.formState.hookService.value == id}
- // @ts-ignore
- beforeLabel={
- <>
- <div className="flex items-center space-x-5">
- {/* <div className="h-3 w-3"> */}
- <Image
- src={`${BASE_PATH}/img/function-providers/${img_url}`}
- layout="fixed"
- width="32"
- height="32"
- />
- {/* </div> */}
- <div className="flex-col space-y-0">
- <div className="flex space-x-1">
- <span className="text-scale-1200">{label}</span>
- <Badge color={badgeType}>{badge}</Badge>
- </div>
- <span className="text-scale-900">{description}</span>
- </div>
- </div>
- </>
- }
- />
- )
- }
-)
-
-export default RadioHookService
diff --git a/studio/components/interfaces/Database/Hooks/CreateHook/RadioGroupHookService/index.tsx b/studio/components/interfaces/Database/Hooks/CreateHook/RadioGroupHookService/index.tsx
deleted file mode 100644
index 17afba4014a..00000000000
--- a/studio/components/interfaces/Database/Hooks/CreateHook/RadioGroupHookService/index.tsx
+++ /dev/null
@@ -1,35 +0,0 @@
-import { FC, useContext } from 'react'
-import { observer } from 'mobx-react-lite'
-import { Radio } from 'ui'
-
-import { CreateHookContext } from '../'
-import RadioHookService from './RadioHookService'
-import { hookServiceOptions } from './RadioGroupHookService.constants'
-
-const RadioGroupHookService: FC = observer(({}) => {
- const _localState: any = useContext(CreateHookContext)
- return (
- <>
- <div className="provider-radio-group">
- <Radio.Group
- type="cards"
- layout="vertical"
- onChange={(event) => {
- _localState.onFormChange({
- key: 'hookService',
- value: event.target.value,
- })
- }}
- value={_localState.formState.hookService.value}
- error={_localState.formState.hookService.error}
- >
- {hookServiceOptions.map((x) => (
- <RadioHookService key={x.id} {...x} />
- ))}
- </Radio.Group>
- </div>
- </>
- )
-})
-
-export default RadioGroupHookService
diff --git a/studio/components/interfaces/Database/Hooks/CreateHook/SelectEnabledMode.tsx b/studio/components/interfaces/Database/Hooks/CreateHook/SelectEnabledMode.tsx
deleted file mode 100644
index 7c114d7d735..00000000000
--- a/studio/components/interfaces/Database/Hooks/CreateHook/SelectEnabledMode.tsx
+++ /dev/null
@@ -1,30 +0,0 @@
-import { FC, useContext } from 'react'
-import { observer } from 'mobx-react-lite'
-import { Select } from 'ui'
-import { CreateHookContext } from './'
-
-const SelectEnabledMode: FC = observer(({}) => {
- const _localState: any = useContext(CreateHookContext)
- return (
- <Select
- id="enabled-mode"
- label="Enabled mode"
- layout="horizontal"
- value={_localState.formState.enabledMode.value}
- onChange={(e) =>
- _localState.onFormChange({
- key: 'enabledMode',
- value: e.target.value,
- })
- }
- size="small"
- >
- <Select.Option value="ORIGIN">Origin</Select.Option>
- <Select.Option value="REPLICA">Replica</Select.Option>
- <Select.Option value="ALWAYS">Always</Select.Option>
- <Select.Option value="DISABLED">Disabled</Select.Option>
- </Select>
- )
-})
-
-export default SelectEnabledMode
diff --git a/studio/components/interfaces/Database/Hooks/CreateHook/ServiceConfigForm/InputMultiServiceHeaders.tsx b/studio/components/interfaces/Database/Hooks/CreateHook/ServiceConfigForm/InputMultiServiceHeaders.tsx
deleted file mode 100644
index 84be5e4695b..00000000000
--- a/studio/components/interfaces/Database/Hooks/CreateHook/ServiceConfigForm/InputMultiServiceHeaders.tsx
+++ /dev/null
@@ -1,49 +0,0 @@
-import { FC, useContext } from 'react'
-import { observer } from 'mobx-react-lite'
-import { Button, IconPlus } from 'ui'
-
-import { CreateHookContext } from '../'
-import InputServiceHeader from './InputServiceHeader'
-
-const InputMultiServiceHeaders: FC = observer(({}) => {
- const _localState: any = useContext(CreateHookContext)
-
- function onAddArgument() {
- _localState.onFormArrayChange({
- key: 'serviceHeaders',
- value: { name: '', value: '' },
- operation: 'add',
- })
- }
-
- return (
- <div>
- <div className="flex items-center justify-between">
- <h5>HTTP Headers</h5>
- </div>
- <div className="space-y-2 pt-4">
- {_localState.formState.serviceHeaders.value.map(
- (
- x: { name: string; value: string; error?: { name?: string; value?: string } },
- idx: number
- ) => (
- <InputServiceHeader
- key={`serviceHeader-${idx}`}
- idx={idx}
- name={x.name}
- value={x.value}
- error={x.error}
- />
- )
- )}
- <div className="">
- <Button type="dashed" icon={<IconPlus />} onClick={onAddArgument}>
- Add a new header
- </Button>
- </div>
- </div>
- </div>
- )
-})
-
-export default InputMultiServiceHeaders
diff --git a/studio/components/interfaces/Database/Hooks/CreateHook/ServiceConfigForm/InputMultiServiceParams.tsx b/studio/components/interfaces/Database/Hooks/CreateHook/ServiceConfigForm/InputMultiServiceParams.tsx
deleted file mode 100644
index 576a1cfd83e..00000000000
--- a/studio/components/interfaces/Database/Hooks/CreateHook/ServiceConfigForm/InputMultiServiceParams.tsx
+++ /dev/null
@@ -1,47 +0,0 @@
-import { FC, useContext } from 'react'
-import { observer } from 'mobx-react-lite'
-import { Button, IconPlus } from 'ui'
-
-import { CreateHookContext } from '../'
-import InputServiceParam from './InputServiceParam'
-
-const InputMultiServiceParams: FC = observer(({}) => {
- const _localState: any = useContext(CreateHookContext)
-
- function onAddArgument() {
- _localState.onFormArrayChange({
- key: 'serviceParams',
- value: { name: '', value: '' },
- operation: 'add',
- })
- }
-
- return (
- <div>
- <div className="flex items-center justify-between">
- <h5>HTTP Params</h5>
- </div>
- <div className="space-y-2 pt-4">
- {_localState.formState.serviceParams.value.map(
- (
- x: { name: string; value: string; error?: { name?: string; value?: string } },
- idx: number
- ) => (
- <InputServiceParam
- key={`serviceParam-${idx}`}
- idx={idx}
- name={x.name}
- value={x.value}
- error={x.error}
- />
- )
- )}
- <Button type="dashed" icon={<IconPlus />} onClick={onAddArgument}>
- Add a new param
- </Button>
- </div>
- </div>
- )
-})
-
-export default InputMultiServiceParams
diff --git a/studio/components/interfaces/Database/Hooks/CreateHook/ServiceConfigForm/InputServiceHeader.tsx b/studio/components/interfaces/Database/Hooks/CreateHook/ServiceConfigForm/InputServiceHeader.tsx
deleted file mode 100644
index d9e587b4a48..00000000000
--- a/studio/components/interfaces/Database/Hooks/CreateHook/ServiceConfigForm/InputServiceHeader.tsx
+++ /dev/null
@@ -1,77 +0,0 @@
-import { FC, useContext, FormEvent } from 'react'
-import { observer } from 'mobx-react-lite'
-import { Input, IconTrash, Button } from 'ui'
-import { CreateHookContext } from '../'
-
-interface Props {
- idx: number
- name: string
- value: string
- error?: { name?: string; value?: string }
-}
-
-const InputServiceHeader: FC<Props> = observer(({ idx, name, value, error }) => {
- const _localState: any = useContext(CreateHookContext)
-
- function onNameChange(e: FormEvent<HTMLInputElement>) {
- const _value = e.currentTarget.value
- _localState.onFormArrayChange({
- key: 'serviceHeaders',
- value: { name: _value, value },
- idx,
- operation: 'update',
- })
- }
-
- function onValueChange(e: FormEvent<HTMLInputElement>) {
- const _value = e.currentTarget.value
- _localState.onFormArrayChange({
- key: 'serviceHeaders',
- value: { name, value: _value },
- idx,
- operation: 'update',
- })
- }
-
- function onDelete() {
- _localState.onFormArrayChange({
- key: 'serviceHeaders',
- idx,
- operation: 'delete',
- })
- }
-
- return (
- <div className="flex space-x-1">
- <Input
- id={`name-${idx}`}
- className="flex-1"
- placeholder="Header name"
- value={name}
- onChange={onNameChange}
- size="small"
- error={error?.name}
- />
- <Input
- id={`value-${idx}`}
- className="flex-1"
- placeholder="Header value"
- value={value}
- onChange={onValueChange}
- size="small"
- error={error?.value}
- />
- <div>
- <Button
- danger
- type="primary"
- icon={<IconTrash size="tiny" />}
- onClick={onDelete}
- size="small"
- />
- </div>
- </div>
- )
-})
-
-export default InputServiceHeader
diff --git a/studio/components/interfaces/Database/Hooks/CreateHook/ServiceConfigForm/InputServiceParam.tsx b/studio/components/interfaces/Database/Hooks/CreateHook/ServiceConfigForm/InputServiceParam.tsx
deleted file mode 100644
index 4045966d5ba..00000000000
--- a/studio/components/interfaces/Database/Hooks/CreateHook/ServiceConfigForm/InputServiceParam.tsx
+++ /dev/null
@@ -1,77 +0,0 @@
-import { FC, useContext, FormEvent } from 'react'
-import { observer } from 'mobx-react-lite'
-import { Input, IconTrash, Button } from 'ui'
-import { CreateHookContext } from '../'
-
-interface Props {
- idx: number
- name: string
- value: string
- error?: { name?: string; value?: string }
-}
-
-const InputServiceParam: FC<Props> = observer(({ idx, name, value, error }) => {
- const _localState: any = useContext(CreateHookContext)
-
- function onNameChange(e: FormEvent<HTMLInputElement>) {
- const _value = e.currentTarget.value
- _localState.onFormArrayChange({
- key: 'serviceParams',
- value: { name: _value, value },
- idx,
- operation: 'update',
- })
- }
-
- function onValueChange(e: FormEvent<HTMLInputElement>) {
- const _value = e.currentTarget.value
- _localState.onFormArrayChange({
- key: 'serviceParams',
- value: { name, value: _value },
- idx,
- operation: 'update',
- })
- }
-
- function onDelete() {
- _localState.onFormArrayChange({
- key: 'serviceParams',
- idx,
- operation: 'delete',
- })
- }
-
- return (
- <div className="flex space-x-1">
- <Input
- id={`name-${idx}`}
- className="flex-1"
- placeholder="Param name"
- value={name}
- onChange={onNameChange}
- size="small"
- error={error?.name}
- />
- <Input
- id={`value-${idx}`}
- className="flex-1"
- placeholder="Param value"
- value={value}
- onChange={onValueChange}
- size="small"
- error={error?.value}
- />
- <div>
- <Button
- danger
- type="primary"
- icon={<IconTrash size="tiny" />}
- onClick={onDelete}
- size="small"
- />
- </div>
- </div>
- )
-})
-
-export default InputServiceParam
diff --git a/studio/components/interfaces/Database/Hooks/CreateHook/ServiceConfigForm/InputServiceTimeout.tsx b/studio/components/interfaces/Database/Hooks/CreateHook/ServiceConfigForm/InputServiceTimeout.tsx
deleted file mode 100644
index ae255fb0be6..00000000000
--- a/studio/components/interfaces/Database/Hooks/CreateHook/ServiceConfigForm/InputServiceTimeout.tsx
+++ /dev/null
@@ -1,30 +0,0 @@
-import { FC, useContext } from 'react'
-import { observer } from 'mobx-react-lite'
-import { Input } from 'ui'
-import { CreateHookContext } from '../'
-
-// Not used currently
-
-const InputServiceTimeout: FC = observer(({}) => {
- const _localState: any = useContext(CreateHookContext)
- return (
- <Input
- id="timeout-ms"
- type="number"
- label="Request timeout"
- layout="horizontal"
- descriptionText="Request timeout value in millisecond"
- value={_localState.formState.serviceTimeoutMs.value}
- onChange={(e) =>
- _localState.onFormChange({
- key: 'serviceTimeoutMs',
- value: e.target.value,
- })
- }
- size="medium"
- error={_localState.formState.serviceTimeoutMs.error}
- />
- )
-})
-
-export default InputServiceTimeout
diff --git a/studio/components/interfaces/Database/Hooks/CreateHook/ServiceConfigForm/InputServiceUrl.tsx b/studio/components/interfaces/Database/Hooks/CreateHook/ServiceConfigForm/InputServiceUrl.tsx
deleted file mode 100644
index f65aaa19efe..00000000000
--- a/studio/components/interfaces/Database/Hooks/CreateHook/ServiceConfigForm/InputServiceUrl.tsx
+++ /dev/null
@@ -1,29 +0,0 @@
-import { FC, useContext } from 'react'
-import { observer } from 'mobx-react-lite'
-import { Input } from 'ui'
-import { CreateHookContext } from '../'
-
-const InputServiceUrl: FC = observer(({}) => {
- const _localState: any = useContext(CreateHookContext)
- return (
- <Input
- id="service-url"
- type="url"
- label="URL"
- layout="horizontal"
- placeholder="http://api.com/path/resource"
- descriptionText="URL of the HTTP request. Must include HTTP/HTTPS"
- value={_localState.formState.serviceUrl.value}
- onChange={(e) =>
- _localState.onFormChange({
- key: 'serviceUrl',
- value: e.target.value,
- })
- }
- size="medium"
- error={_localState.formState.serviceUrl.error}
- />
- )
-})
-
-export default InputServiceUrl
diff --git a/studio/components/interfaces/Database/Hooks/CreateHook/ServiceConfigForm/SelectServiceMethod.tsx b/studio/components/interfaces/Database/Hooks/CreateHook/ServiceConfigForm/SelectServiceMethod.tsx
deleted file mode 100644
index fca6069eb39..00000000000
--- a/studio/components/interfaces/Database/Hooks/CreateHook/ServiceConfigForm/SelectServiceMethod.tsx
+++ /dev/null
@@ -1,28 +0,0 @@
-import { FC, useContext } from 'react'
-import { observer } from 'mobx-react-lite'
-import { Select } from 'ui'
-import { CreateHookContext } from '../'
-
-const SelectServiceMethod: FC = observer(({}) => {
- const _localState: any = useContext(CreateHookContext)
- return (
- <Select
- id="method"
- label="Method"
- layout="horizontal"
- value={_localState.formState.serviceMethod.value}
- onChange={(e) =>
- _localState.onFormChange({
- key: 'serviceMethod',
- value: e.target.value,
- })
- }
- size="small"
- >
- <Select.Option value="GET">GET</Select.Option>
- <Select.Option value="POST">POST</Select.Option>
- </Select>
- )
-})
-
-export default SelectServiceMethod
diff --git a/studio/components/interfaces/Database/Hooks/CreateHook/ServiceConfigForm/ServiceUnavailableBox.tsx b/studio/components/interfaces/Database/Hooks/CreateHook/ServiceConfigForm/ServiceUnavailableBox.tsx
deleted file mode 100644
index 59e5ae128a8..00000000000
--- a/studio/components/interfaces/Database/Hooks/CreateHook/ServiceConfigForm/ServiceUnavailableBox.tsx
+++ /dev/null
@@ -1,29 +0,0 @@
-import { FC, useContext } from 'react'
-import { observer } from 'mobx-react-lite'
-import { Alert, Button } from 'ui'
-import { CreateHookContext } from '../'
-
-const ServiceUnavailableBox: FC = observer(({}) => {
- const _localState: any = useContext(CreateHookContext)
- return (
- <Alert variant="warning" title="Service under development" withIcon>
- <div className="space-y-4">
- <div>We currently do not support this service.</div>
- <Button
- type="default"
- className="flex-grow"
- onClick={() =>
- _localState.onFormChange({
- key: 'hookService',
- value: 'http_request',
- })
- }
- >
- Switch to HTTP
- </Button>
- </div>
- </Alert>
- )
-})
-
-export default ServiceUnavailableBox
diff --git a/studio/components/interfaces/Database/Hooks/CreateHook/ServiceConfigForm/index.tsx b/studio/components/interfaces/Database/Hooks/CreateHook/ServiceConfigForm/index.tsx
deleted file mode 100644
index 7570f170706..00000000000
--- a/studio/components/interfaces/Database/Hooks/CreateHook/ServiceConfigForm/index.tsx
+++ /dev/null
@@ -1,44 +0,0 @@
-import { FC, useContext } from 'react'
-import { observer } from 'mobx-react-lite'
-import { SidePanel } from 'ui'
-
-import { CreateHookContext } from '../'
-import SelectServiceMethod from './SelectServiceMethod'
-import InputServiceUrl from './InputServiceUrl'
-import InputMultiServiceHeaders from './InputMultiServiceHeaders'
-import InputMultiServiceParams from './InputMultiServiceParams'
-import ServiceUnavailableBox from './ServiceUnavailableBox'
-
-const ServiceConfigForm: FC = observer(({}) => {
- const _localState: any = useContext(CreateHookContext)
- return (
- <>
- {_localState.formState.hookService.value === 'http_request' ? (
- <>
- <SidePanel.Separator />
- <div className="space-y-10">
- <div className="space-y-6 px-6">
- <h5>HTTP Request</h5>
- <SelectServiceMethod />
- <InputServiceUrl />
- </div>
- <SidePanel.Separator />
- <div className="px-6">
- <InputMultiServiceHeaders />
- </div>
- <SidePanel.Separator />
- <div className="px-6">
- <InputMultiServiceParams />
- </div>
- </div>
- </>
- ) : (
- <div className="px-6">
- <ServiceUnavailableBox />
- </div>
- )}
- </>
- )
-})
-
-export default ServiceConfigForm
diff --git a/studio/components/interfaces/Database/Hooks/CreateHook/TableSelection.tsx b/studio/components/interfaces/Database/Hooks/CreateHook/TableSelection.tsx
deleted file mode 100644
index 3e46504f3f9..00000000000
--- a/studio/components/interfaces/Database/Hooks/CreateHook/TableSelection.tsx
+++ /dev/null
@@ -1,97 +0,0 @@
-import Link from 'next/link'
-import SVG from 'react-inlinesvg'
-import { FC, useContext } from 'react'
-import { observer } from 'mobx-react-lite'
-import { Input, Listbox } from 'ui'
-
-import { CreateHookContext } from './'
-import { useStore } from 'hooks'
-import { BASE_PATH } from 'lib/constants'
-
-const TableSelection: FC = observer(({}) => {
- const { ui } = useStore()
- const projectRef = ui.selectedProject?.ref
- const _localState: any = useContext(CreateHookContext)
-
- if (_localState.tables.length === 0) {
- return (
- <Input
- label="Table"
- layout="horizontal"
- disabled
- placeholder="No tables created, please create one first"
- // @ts-ignore
- descriptionText={
- <p className="text-scale-1000">
- <span className="text-scale-1000">
- This is the table the trigger will watch for changes. There's currently no tables
- created - please create one{' '}
- </span>
- <Link href={`/project/${projectRef}/editor`}>
- <a className="text-brand-900">here</a>
- </Link>
- <span className="text-scale-1000"> first.</span>
- </p>
- }
- />
- )
- }
-
- return (
- <Listbox
- id="table"
- label="Table"
- layout="horizontal"
- value={_localState.formState.tableId.value}
- onChange={(id) => {
- const _table = _localState.tables.find((x: any) => x.id === id)
- if (_table) {
- _localState.onFormChange({
- key: 'schema',
- value: _table.schema,
- })
- _localState.onFormChange({
- key: 'table',
- value: _table.name,
- })
- _localState.onFormChange({
- key: 'tableId',
- value: id,
- })
- }
- }}
- size="medium"
- error={_localState.formState.table.error}
- descriptionText="This is the table the trigger will watch for changes. You can only select 1 table for a trigger."
- >
- {_localState.tables.map((x: any) => {
- return (
- <Listbox.Option
- id={x.id}
- key={x.id}
- value={x.id}
- label={x.name}
- addOnBefore={() => (
- <div className="flex items-center justify-center rounded bg-scale-1200 p-1 text-scale-100 ">
- <SVG
- src={`${BASE_PATH}/img/table-editor.svg`}
- style={{ width: `16px`, height: `16px`, strokeWidth: '1px' }}
- preProcessor={(code) =>
- code.replace(/svg/, 'svg class="m-auto text-color-inherit"')
- }
- />
- </div>
- )}
- >
- <div className="flex flex-row items-center space-x-2">
- <p>{x.name}</p>
- <p className="text-scale-1100">{x.schema}</p>
- </div>
- </Listbox.Option>
- )
- })}
- </Listbox>
- )
-})
-
-export default TableSelection
diff --git a/studio/components/interfaces/Database/Hooks/CreateHook/index.tsx b/studio/components/interfaces/Database/Hooks/CreateHook/index.tsx
deleted file mode 100644
index 27c9d32842d..00000000000
--- a/studio/components/interfaces/Database/Hooks/CreateHook/index.tsx
+++ /dev/null
@@ -1,514 +0,0 @@
-import { makeAutoObservable } from 'mobx'
-import { FC, useEffect, createContext } from 'react'
-import { observer, useLocalObservable } from 'mobx-react-lite'
-import { isEmpty, mapValues, has, filter, keyBy, isUndefined } from 'lodash'
-import { Dictionary } from 'components/grid'
-import { Badge, Input, SidePanel } from 'ui'
-import { useStore } from 'hooks'
-
-import InputName from './InputName'
-import SelectEnabledMode from './SelectEnabledMode'
-import CheckboxEvents from './CheckboxEvents'
-import TableSelection from './TableSelection'
-import RadioGroupHookService from './RadioGroupHookService'
-import ServiceConfigForm from './ServiceConfigForm'
-
-import { formatArguments, convertKeyValue, hasWhitespace, isValidHttpUrl } from '../Hooks.utils'
-
-// [Joshen] TODO: Refactor to use Form component
-
-class CreateHookFormState {
- id: number | undefined
- originalName: string | undefined
- // @ts-ignore
- enabledMode: { value: string }
- // @ts-ignore
- events: { value: string[]; error?: string }
- // @ts-ignore
- name: { value: string; error?: string }
- // @ts-ignore
- schema: { value: string }
- // @ts-ignore
- table: { value: string; error?: string }
- // @ts-ignore
- tableId: { value: number; error?: string }
- // @ts-ignore
- hookService: { value: string; error?: string }
- // @ts-ignore
- serviceUrl: { value: string; error?: string }
- // @ts-ignore
- serviceMethod: { value: string; error?: string }
- // @ts-ignore
- serviceHeaders: {
- value: { name: string; value: string; error?: { name?: string; value?: string } }[]
- }
- // @ts-ignore
- serviceParams: {
- value: { name: string; value: string; error?: { name?: string; value?: string } }[]
- }
- // @ts-ignore
- serviceTimeoutMs: { value: string; error?: string }
-
- constructor() {
- makeAutoObservable(this)
- this.reset()
- }
-
- get requestBody() {
- return {
- id: this.id,
- activation: 'AFTER',
- enabled_mode: this.enabledMode.value,
- events: this.events.value,
- function_args: [
- this.serviceUrl.value.replaceAll(' ', ''),
- this.serviceMethod.value,
- JSON.stringify(mapValues(keyBy(this.serviceHeaders.value, 'name'), 'value')),
- formatArguments(this.serviceParams.value),
- this.serviceTimeoutMs.value,
- ],
- function_name: 'http_request',
- function_schema: 'supabase_functions',
- orientation: 'ROW',
- name: this.name.value,
- schema: this.schema.value,
- table: this.table.value,
- table_id: this.tableId.value,
- }
- }
-
- reset(hook?: Dictionary<any>) {
- this.id = hook?.id
- this.originalName = hook?.name
- this.enabledMode = { value: hook?.enabled_mode ?? 'ORIGIN' }
- this.events = { value: hook?.events ?? [] }
- this.name = { value: hook?.name ?? '' }
- this.schema = { value: hook?.schema ?? '' }
- this.table = { value: hook?.table ?? '' }
- this.tableId = { value: hook?.table_id ?? '' }
- // TODO: hook obj doesn't have service field
- this.hookService = { value: 'http_request' }
- /**
- * hook.function_args contains 5 params in order
- * [url, method, headers, params, timeout]
- */
- this.serviceUrl = { value: hook?.function_args?.length == 5 ? hook?.function_args[0] : '' }
- this.serviceMethod = {
- value: hook?.function_args?.length == 5 ? hook?.function_args[1] : 'GET',
- }
- this.serviceHeaders =
- hook?.function_args?.length == 5
- ? convertKeyValue(hook?.function_args[2])
- : { value: [{ name: 'Content-type', value: 'application/json' }] }
-
- this.serviceParams =
- hook?.function_args?.length == 5 ? convertKeyValue(hook?.function_args[3]) : { value: [] }
-
- this.serviceTimeoutMs = {
- value: hook?.function_args?.length == 5 ? hook?.function_args[4] : '1000',
- }
- }
-
- update(state: Dictionary<any>) {
- this.enabledMode = state.enabledMode
- this.events = state.events
- this.name = state.name
- this.schema = state.schema
- this.table = state.table
- this.tableId = state.tableId
- this.hookService = state.hookService
- this.serviceUrl = state.serviceUrl
- this.serviceMethod = state.serviceMethod
- this.serviceHeaders = state.serviceHeaders
- this.serviceParams = state.serviceParams
- this.serviceTimeoutMs = state.serviceTimeoutMs
- }
-}
-
-interface ICreateHookStore {
- loading: boolean
- formState: CreateHookFormState
- meta: any
- project: any
- tables: Dictionary<any>[]
- onFormChange: (value: { key: string; value: any }) => void
- onFormArrayChange: (value: {
- operation: 'add' | 'delete' | 'update'
- key: string
- idx?: number
- value?: any
- }) => void
- setDefaultSelectedTable: () => void
- setLoading: (value: boolean) => void
- setTables: (value: Dictionary<any>[]) => void
- validateForm: () => boolean
-}
-
-class CreateHookStore implements ICreateHookStore {
- loading = false
- formState = new CreateHookFormState()
- meta = null
- project = null
- tables = []
-
- constructor() {
- makeAutoObservable(this)
- }
-
- get title() {
- return this.formState.id
- ? `Edit '${this.formState.originalName}' database webhook`
- : 'Add a new database webhook'
- }
-
- get isEditing() {
- return this.formState.id != undefined
- }
-
- // set first table as default selection
- setDefaultSelectedTable = () => {
- if (this.tables?.length != 0) {
- this.formState.schema.value = (this.tables[0] as any).schema
- this.formState.table.value = (this.tables[0] as any).name
- this.formState.tableId.value = (this.tables[0] as any).id
- }
- }
-
- setLoading = (value: boolean) => {
- this.loading = value
- }
-
- setTables = (value: Dictionary<any>[]) => {
- this.tables = value as any
- this.setDefaultSelectedTable()
- }
-
- onFormChange = ({ key, value }: { key: string; value: any }) => {
- if (has(this.formState, key)) {
- const temp = (this.formState as any)[key] as any
- ;(this.formState as any)[key] = { ...temp, value, error: undefined }
- } else {
- ;(this.formState as any)[key] = { value }
- }
- }
-
- onFormArrayChange = ({
- operation,
- key,
- idx,
- value,
- }: {
- operation: 'add' | 'delete' | 'update'
- key: string
- idx?: number
- value?: any
- }) => {
- switch (operation) {
- case 'add': {
- if (has(this.formState, key)) {
- ;(this.formState as any)[key].value.push(value)
- } else {
- ;(this.formState as any)[key] = { value: [value] }
- }
- break
- }
- case 'delete': {
- if (has(this.formState, key)) {
- const temp = filter(
- (this.formState as any)[key].value,
- (_: any, index: number) => index != idx
- ) as any
- ;(this.formState as any)[key].value = temp
- }
- break
- }
- default: {
- if (has(this.formState, key) && !isUndefined(idx)) {
- ;(this.formState as any)[key].value[idx] = value
- } else {
- ;(this.formState as any)[key] = { value: [{ value }] }
- }
- }
- }
- }
-
- validateForm = () => {
- let isValidated = true
- const _state = mapValues(this.formState, (x: { value: any }, key: string) => {
- switch (key) {
- case 'name': {
- if (isEmpty(x.value) || hasWhitespace(x.value)) {
- isValidated = false
- return { ...x, error: 'Invalid hook name' }
- } else {
- return x
- }
- }
- case 'events': {
- if (isEmpty(x.value)) {
- isValidated = false
- return { ...x, error: 'Select at least 1 event' }
- } else {
- return x
- }
- }
- case 'table': {
- if (isEmpty(x.value)) {
- isValidated = false
- return { ...x, error: 'You must choose a table' }
- } else {
- return x
- }
- }
- case 'hookService': {
- if (x.value != 'http_request') {
- isValidated = false
- return { ...x, error: 'Not supported service' }
- } else {
- return x
- }
- }
- case 'serviceTimeoutMs': {
- if (isEmpty(x.value) || isNaN(x.value)) {
- isValidated = false
- return { ...x, error: 'Invalid input' }
- } else {
- return x
- }
- }
- case 'serviceUrl': {
- if (isEmpty(x.value) || !isValidHttpUrl(x.value)) {
- isValidated = false
- return { ...x, error: 'Invalid input' }
- } else {
- return x
- }
- }
- case 'serviceMethod': {
- if (isEmpty(x.value)) {
- isValidated = false
- return { ...x, error: 'Invalid input' }
- } else {
- return x
- }
- }
- case 'serviceHeaders':
- case 'serviceParams': {
- const temp = x.value?.map((i: Dictionary<any>) => {
- const error: any = { name: undefined, value: undefined }
- if (isEmpty(i.name) || hasWhitespace(i.name)) {
- isValidated = false
- error.name = 'Invalid name'
- }
- if (isEmpty(i.value)) {
- isValidated = false
- error.value = 'Missing value'
- }
- return { ...i, error }
- })
- x.value = temp
- return x
- }
- default:
- return x
- }
- })
- if (!isValidated) {
- this.formState.update(_state)
- }
- return isValidated
- }
-}
-
-export const CreateHookContext = createContext<ICreateHookStore | null>(null)
-
-interface CreateHookProps {
- hook?: any
- visible: boolean
- setVisible: (value: boolean) => void
-}
-
-const CreateHook: FC<CreateHookProps> = ({ hook, visible = true, setVisible }) => {
- const { meta, ui } = useStore()
- const project = ui.selectedProject
-
- const _localState: any = useLocalObservable(() => new CreateHookStore())
- _localState.meta = meta
- _localState.project = project
-
- useEffect(() => {
- const fetchSchemas = async () => {
- await _localState.meta.tables.load()
- const tables = _localState!.meta!.tables.list(
- (table: any) => !meta.excludedSchemas.includes(table.schema)
- )
- _localState.setTables(tables)
- }
-
- fetchSchemas()
- }, [])
-
- useEffect(() => {
- if (hook) {
- _localState.formState.reset(hook)
- } else {
- _localState.formState.reset()
- _localState.setDefaultSelectedTable()
- }
- }, [visible, hook])
-
- async function handleSubmit() {
- try {
- if (_localState.validateForm()) {
- _localState.setLoading(true)
-
- const body = _localState.formState.requestBody
-
- console.log({ body })
-
- const response: any = _localState.isEditing
- ? await _localState.meta.hooks.update(body.id, body)
- : await _localState.meta.hooks.create(body)
-
- if (response.error) {
- ui.setNotification({
- category: 'error',
- message: `Failed to create hook: ${response.error.message ?? 'Submit request failed'}`,
- })
- _localState.setLoading(false)
- } else {
- ui.setNotification({
- category: 'success',
- message: `${_localState.isEditing ? 'Updated' : 'Created new'} hook called ${
- response.name
- }`,
- })
- _localState.setLoading(false)
- setVisible(!visible)
- }
- }
- } catch (error: any) {
- ui.setNotification({ category: 'error', message: `Failed to create hook: ${error.message}` })
- _localState.setLoading(false)
- }
- }
-
- return (
- <SidePanel
- size="large"
- visible={visible}
- loading={_localState.loading}
- header={_localState.title}
- className="hooks-sidepanel mr-0 transform transition-all duration-300 ease-in-out"
- onConfirm={handleSubmit}
- onCancel={() => setVisible(!visible)}
- >
- <CreateHookContext.Provider value={_localState}>
- <div className="space-y-10 py-6">
- {_localState.isEditing ? (
- <>
- <div className="space-y-10 px-6">
- <InputName />
- <SelectEnabledMode />
- </div>
-
- {_localState.formState.serviceHeaders.value.length > 0 && (
- <>
- <SidePanel.Separator />
- <div className="space-y-2 px-6">
- <div className="flex items-center space-x-2">
- <h5 className="text-base text-scale-1200">HTTP Headers</h5>
- <Badge color="gray">Read only</Badge>
- </div>
- <div className="space-y-2">
- {_localState.formState.serviceHeaders.value.map(
- (serviceHeader: { name: string; value: string }) => (
- <div
- key={serviceHeader.name}
- className="flex items-center justify-center space-x-2"
- >
- <Input
- disabled
- className="w-full flex-1"
- readOnly
- value={serviceHeader.name}
- />
- <Input
- disabled
- className="w-full flex-1"
- readOnly
- value={serviceHeader.value}
- />
- </div>
- )
- )}
- </div>
- </div>
- <p className="mx-6 mt-12 text-sm text-scale-1100">
- <strong>Note:</strong> You can only edit a webhook's name and mode. To change
- other settings, you'll need to delete and recreate the webhook.
- </p>
- </>
- )}
-
- {_localState.formState.serviceParams.value.length > 0 && (
- <>
- <SidePanel.Separator />
- <div className="space-y-2 px-6">
- <div className="flex items-center space-x-2">
- <h5 className="text-base text-scale-1200">HTTP Parameters</h5>
- <Badge color="gray">Read only</Badge>
- </div>
- <div className="space-y-2">
- {_localState.formState.serviceParams.value.map(
- (serviceParam: { name: string; value: string }) => (
- <div
- key={serviceParam.name}
- className="flex items-center justify-center space-x-2"
- >
- <Input
- disabled
- className="w-full flex-1"
- readOnly
- value={serviceParam.name}
- />
- <Input
- disabled
- className="w-full flex-1"
- readOnly
- value={serviceParam.value}
- />
- </div>
- )
- )}
- </div>
- </div>
- </>
- )}
- </>
- ) : (
- <>
- <div className="px-6">
- <InputName />
- </div>
- <SidePanel.Separator />
- <div className="space-y-6 px-6">
- <h5 className="text-base text-scale-1200">Conditions to fire hook</h5>
- <TableSelection />
- <CheckboxEvents />
- </div>
- <SidePanel.Separator />
- <div className="space-y-6 px-6">
- <h5 className="text-base text-scale-1200">Type of hook</h5>
- <RadioGroupHookService />
- </div>
- <ServiceConfigForm />
- </>
- )}
- </div>
- </CreateHookContext.Provider>
- </SidePanel>
- )
-}
-
-export default observer(CreateHook)
diff --git a/studio/components/interfaces/Database/Hooks/EditHookPanel.tsx b/studio/components/interfaces/Database/Hooks/EditHookPanel.tsx
index 41546e91b9c..7e1da3ffded 100644
--- a/studio/components/interfaces/Database/Hooks/EditHookPanel.tsx
+++ b/studio/components/interfaces/Database/Hooks/EditHookPanel.tsx
@@ -11,6 +11,7 @@ import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectConte
import { isValidHttpUrl } from './Hooks.utils'
import { PostgresTrigger } from '@supabase/postgres-meta'
import { useDatabaseTriggerUpdateMutation } from 'data/database-triggers/database-trigger-update-mutation'
+import { ENABLED_MODE_OPTIONS } from './Hooks.constants'
// Also see if we can add the input field for enabled_mode
@@ -264,7 +265,26 @@ const EditHookPanel = ({ visible, selectedHook, onClose }: EditHookPanelProps) =
header={<FormSectionLabel className="lg:!col-span-4">General</FormSectionLabel>}
>
<FormSectionContent loading={false} className="lg:!col-span-8">
- <Input id="name" name="name" label="Name" />
+ <Input
+ id="name"
+ name="name"
+ label="Name"
+ descriptionText="Do not use spaces/whitespaces"
+ />
+ <Listbox
+ size="medium"
+ id="enabled_mode"
+ name="enabled_mode"
+ label="Enabled mode"
+ descriptionText="Determines if a trigger should or should not fire. Can also be used to disable a trigger, but not delete it"
+ >
+ {ENABLED_MODE_OPTIONS.map((option) => (
+ <Listbox.Option key={option.value} value={option.value} label={option.label}>
+ {option.label}
+ <span className="block text-scale-900">{option.description}</span>
+ </Listbox.Option>
+ ))}
+ </Listbox>
</FormSectionContent>
</FormSection>
<SidePanel.Separator />
diff --git a/studio/components/interfaces/Database/Hooks/Hooks.constants.ts b/studio/components/interfaces/Database/Hooks/Hooks.constants.ts
new file mode 100644
index 00000000000..05484379a2a
--- /dev/null
+++ b/studio/components/interfaces/Database/Hooks/Hooks.constants.ts
@@ -0,0 +1,14 @@
+export const ENABLED_MODE_OPTIONS = [
+ { label: 'Origin', value: 'ORIGIN', description: 'This is the default behaviour' },
+ {
+ label: 'Replica',
+ value: 'REPLICA',
+ description: 'Will only fire if the session is in “replica” mode',
+ },
+ {
+ label: 'Always',
+ value: 'ALWAYS',
+ description: 'Will fire regardless of the current replication role',
+ },
+ { label: 'Disabled', value: 'DISABLED', description: 'Will not fire' },
+]
diff --git a/studio/pages/project/[ref]/database/hooks/index.tsx b/studio/pages/project/[ref]/database/hooks/index.tsx
index f1227cda726..9502ff34ba6 100644
--- a/studio/pages/project/[ref]/database/hooks/index.tsx
+++ b/studio/pages/project/[ref]/database/hooks/index.tsx
@@ -10,7 +10,6 @@ import { API_URL } from 'lib/constants'
import { post } from 'lib/common/fetch'
import { DatabaseLayout } from 'components/layouts'
import NoPermission from 'components/ui/NoPermission'
-import CreateHook from 'components/interfaces/Database/Hooks/CreateHook'
import HooksList from 'components/interfaces/Database/Hooks/HooksList/HooksList'
import DeleteHookModal from 'components/interfaces/Database/Hooks/DeleteHookModal'
import EditHookPanel from 'components/interfaces/Database/Hooks/EditHookPanel'
@@ -25,7 +24,6 @@ const HooksPage: NextPageWithLayout = () => {
const [filterString, setFilterString] = useState<string>('')
const [selectedHook, setSelectedHook] = useState<any>()
const [showCreateHookForm, setShowCreateHookForm] = useState<boolean>(false)
- const [showUpdateHookForm, setShowUpdateHookForm] = useState<boolean>(false)
const [showDeleteHookForm, setShowDeleteHookForm] = useState<boolean>(false)
const canReadWebhooks = checkPermissions(PermissionAction.TENANT_SQL_ADMIN_READ, 'triggers')
@@ -87,11 +85,6 @@ const HooksPage: NextPageWithLayout = () => {
deleteHook={deleteHook}
enableHooks={enableHooksForProject}
/>
- {/* <CreateHook
- hook={selectedHook}
- visible={showCreateHookForm}
- setVisible={setShowCreateHookForm}
- /> */}
<EditHookPanel
visible={showCreateHookForm}
selectedHook={selectedHook}