1
0
Fork 0
mirror of synced 2024-06-03 02:55:14 +12:00

Update remaining usage of API in client library

This commit is contained in:
Andrew Kingston 2022-01-20 09:57:57 +00:00
parent b970c315f1
commit 71cf06e6f4
5 changed files with 35 additions and 23 deletions

View file

@ -9,7 +9,7 @@
import Router from "./Router.svelte"
import { enrichProps, propsAreSame } from "utils/componentProps"
import { builderStore } from "stores"
import { hashString } from "utils/helpers"
import { Helpers } from "@budibase/frontend-core"
import Manifest from "manifest.json"
import { getActiveConditions, reduceConditionActions } from "utils/conditions"
import Placeholder from "components/app/Placeholder.svelte"
@ -106,7 +106,7 @@
// Raw settings are all settings excluding internal props and children
$: rawSettings = getRawSettings(instance)
$: instanceKey = hashString(JSON.stringify(rawSettings))
$: instanceKey = Helpers.hashString(JSON.stringify(rawSettings))
// Update and enrich component settings
$: updateSettings(rawSettings, instanceKey, settingsDefinition, $context)
@ -300,7 +300,7 @@
// Generates a key used to determine when components need to fully remount.
// Currently only toggling editing requires remounting.
const getRenderKey = (id, editing) => {
return hashString(`${id}-${editing}`)
return Helpers.hashString(`${id}-${editing}`)
}
</script>

View file

@ -29,10 +29,14 @@
for (let i = 0; i < fileList.length; i++) {
data.append("file", fileList[i])
}
return await API.uploadAttachment({
data,
tableId: formContext?.dataSource?.tableId,
})
try {
return await API.uploadAttachment({
data,
tableId: formContext?.dataSource?.tableId,
})
} catch (error) {
return []
}
}
</script>

View file

@ -1,7 +1,7 @@
<script>
import { getContext } from "svelte"
import InnerForm from "./InnerForm.svelte"
import { hashString } from "utils/helpers"
import { Helpers } from "@budibase/frontend-core"
export let dataSource
export let theme
@ -50,13 +50,17 @@
dataSource._id &&
actionType === "Create"
) {
const query = await API.fetchQueryDefinition(dataSource._id)
let paramSchema = {}
const params = query.parameters || []
params.forEach(param => {
paramSchema[param.name] = { ...param, type: "string" }
})
schema = paramSchema
try {
const query = await API.fetchQueryDefinition(dataSource._id)
let paramSchema = {}
const params = query.parameters || []
params.forEach(param => {
paramSchema[param.name] = { ...param, type: "string" }
})
schema = paramSchema
} catch (error) {
schema = {}
}
}
// For all other cases, just grab the normal schema
@ -71,7 +75,7 @@
}
$: initialValues = getInitialValues(actionType, dataSource, $context)
$: resetKey = hashString(
$: resetKey = Helpers.hashString(
JSON.stringify(initialValues) + JSON.stringify(schema)
)
</script>

View file

@ -2,7 +2,7 @@
import { setContext, getContext } from "svelte"
import { derived, get, writable } from "svelte/store"
import { createValidatorFromConstraints } from "./validation"
import { generateID } from "utils/helpers"
import { Helpers } from "@budibase/frontend-core"
import { deepGet, deepSet } from "@budibase/bbui"
import { cloneDeep } from "lodash/fp"
@ -153,7 +153,7 @@
// If we've already registered this field then keep some existing state
let initialValue = deepGet(initialValues, field) ?? defaultValue
let initialError = null
let fieldId = `id-${generateID()}`
let fieldId = `id-${Helpers.uuid()}`
const existingField = getField(field)
if (existingField) {
const { fieldState } = get(existingField)

View file

@ -30,17 +30,21 @@
const fetchTable = async id => {
if (id) {
const result = await API.fetchTableDefinition(id)
if (!result.error) {
tableDefinition = result
try {
tableDefinition = await API.fetchTableDefinition(id)
} catch (error) {
tableDefinition = null
}
}
}
const fetchRows = async id => {
if (id) {
const rows = await API.fetchTableData(id)
options = rows && !rows.error ? rows : []
try {
options = await API.fetchTableData(id)
} catch (error) {
options = []
}
}
}