Files
supabase/apps/studio/components/interfaces/Database/Functions/Functions.utils.ts
Ivan Vasilov a775e3ba69 chore: Migrate create-function store from mobx to react-hook-form (#21888)
* Refactor and remove the CreateFunctionStore.

* Fix a duplicate key in the functions table.

* More fixes for the create-function form.

* Add excluded schemas to schema selector.

* Cleanup the createFunction code after the merge.

* Remove unneeded wrapper fragments.

* Minor fixes for the FormItemLayout stories.

* Refactor the CreateFunction panel using the new FormItemLayout.

* Revert the migration to use FormItemLayout. Will revisit later.

* Add a CSS class for popover content width to match its trigger width. Use it on the schema selector.

* Replace all listboxes with selects.

* Fix the comments.

* Switch to FormItemLayout wherever possible.

* Some fixes

* minor lint

* One more lint

---------

Co-authored-by: Jonathan Summers-Muir <MildTomato@users.noreply.github.com>
Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2024-03-14 14:38:52 +08:00

37 lines
1022 B
TypeScript

import { isEmpty } from 'lodash'
/**
* convert argument_types = "a integer, b integer"
* to args = {value: [{name:'a', type:'integer'}, {name:'b', type:'integer'}]}
*/
export function convertArgumentTypes(value: string) {
const items = value?.split(',')
if (isEmpty(value) || !items || items?.length == 0) return { value: [] }
const temp = items.map((x) => {
const str = x.trim()
const space = str.indexOf(' ')
const name = str.slice(0, space !== 1 ? space : 0)
const type = str.slice(space + 1)
return { name, type }
})
return { value: temp }
}
/**
* convert config_params = {search_path: "auth, public"}
* to {value: [{name: 'search_path', value: 'auth, public'}]}
*/
export function convertConfigParams(value: Record<string, string> | null | undefined) {
const temp = []
if (value) {
for (var key in value) {
temp.push({ name: key, value: value[key] })
}
}
return { value: temp }
}
export function hasWhitespace(value: string) {
return /\s/.test(value)
}