Merge branch 'v3-ui' into data-tidy-up
This commit is contained in:
commit
37ca13e118
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
const context = getContext("context")
|
const context = getContext("context")
|
||||||
const component = getContext("component")
|
const component = getContext("component")
|
||||||
const { API, fetchDatasourceSchema } = getContext("sdk")
|
const { fetchDatasourceSchema, fetchDatasourceDefinition } = getContext("sdk")
|
||||||
|
|
||||||
const getInitialFormStep = () => {
|
const getInitialFormStep = () => {
|
||||||
const parsedFormStep = parseInt(initialFormStep)
|
const parsedFormStep = parseInt(initialFormStep)
|
||||||
|
@ -32,9 +32,9 @@
|
||||||
return parsedFormStep
|
return parsedFormStep
|
||||||
}
|
}
|
||||||
|
|
||||||
let loaded = false
|
let definition
|
||||||
let schema
|
let schema
|
||||||
let table
|
let loaded = false
|
||||||
let currentStep = getContext("current-step") || writable(getInitialFormStep())
|
let currentStep = getContext("current-step") || writable(getInitialFormStep())
|
||||||
|
|
||||||
$: fetchSchema(dataSource)
|
$: fetchSchema(dataSource)
|
||||||
|
@ -84,12 +84,10 @@
|
||||||
|
|
||||||
// Fetches the form schema from this form's dataSource
|
// Fetches the form schema from this form's dataSource
|
||||||
const fetchSchema = async dataSource => {
|
const fetchSchema = async dataSource => {
|
||||||
if (dataSource?.tableId && !dataSource?.type?.startsWith("query")) {
|
try {
|
||||||
try {
|
definition = await fetchDatasourceDefinition(dataSource)
|
||||||
table = await API.fetchTableDefinition(dataSource.tableId)
|
} catch (error) {
|
||||||
} catch (error) {
|
definition = null
|
||||||
table = null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
const res = await fetchDatasourceSchema(dataSource)
|
const res = await fetchDatasourceSchema(dataSource)
|
||||||
schema = res || {}
|
schema = res || {}
|
||||||
|
@ -121,7 +119,7 @@
|
||||||
{readonly}
|
{readonly}
|
||||||
{actionType}
|
{actionType}
|
||||||
{schema}
|
{schema}
|
||||||
{table}
|
{definition}
|
||||||
{initialValues}
|
{initialValues}
|
||||||
{disableSchemaValidation}
|
{disableSchemaValidation}
|
||||||
{editAutoColumns}
|
{editAutoColumns}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
export let initialValues
|
export let initialValues
|
||||||
export let size
|
export let size
|
||||||
export let schema
|
export let schema
|
||||||
export let table
|
export let definition
|
||||||
export let disableSchemaValidation = false
|
export let disableSchemaValidation = false
|
||||||
export let editAutoColumns = false
|
export let editAutoColumns = false
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@
|
||||||
schemaConstraints,
|
schemaConstraints,
|
||||||
validationRules,
|
validationRules,
|
||||||
field,
|
field,
|
||||||
table
|
definition
|
||||||
)
|
)
|
||||||
|
|
||||||
// Sanitise the default value to ensure it doesn't contain invalid data
|
// Sanitise the default value to ensure it doesn't contain invalid data
|
||||||
|
@ -338,7 +338,7 @@
|
||||||
schemaConstraints,
|
schemaConstraints,
|
||||||
validationRules,
|
validationRules,
|
||||||
field,
|
field,
|
||||||
table
|
definition
|
||||||
)
|
)
|
||||||
|
|
||||||
// Update validator
|
// Update validator
|
||||||
|
|
|
@ -5,17 +5,17 @@ import { Helpers } from "@budibase/bbui"
|
||||||
/**
|
/**
|
||||||
* Creates a validation function from a combination of schema-level constraints
|
* Creates a validation function from a combination of schema-level constraints
|
||||||
* and custom validation rules
|
* and custom validation rules
|
||||||
* @param schemaConstraints any schema level constraints from the table
|
* @param schemaConstraints any schema level constraints from the datasource
|
||||||
* @param customRules any custom validation rules
|
* @param customRules any custom validation rules
|
||||||
* @param field the field name we are evaluating
|
* @param field the field name we are evaluating
|
||||||
* @param table the definition of the table we are evaluating
|
* @param definition the definition of the datasource we are evaluating
|
||||||
* @returns {function} a validator function which accepts test values
|
* @returns {function} a validator function which accepts test values
|
||||||
*/
|
*/
|
||||||
export const createValidatorFromConstraints = (
|
export const createValidatorFromConstraints = (
|
||||||
schemaConstraints,
|
schemaConstraints,
|
||||||
customRules,
|
customRules,
|
||||||
field,
|
field,
|
||||||
table
|
definition
|
||||||
) => {
|
) => {
|
||||||
let rules = []
|
let rules = []
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ export const createValidatorFromConstraints = (
|
||||||
if (schemaConstraints) {
|
if (schemaConstraints) {
|
||||||
// Required constraint
|
// Required constraint
|
||||||
if (
|
if (
|
||||||
field === table?.primaryDisplay ||
|
field === definition?.primaryDisplay ||
|
||||||
schemaConstraints.presence?.allowEmpty === false ||
|
schemaConstraints.presence?.allowEmpty === false ||
|
||||||
schemaConstraints.presence === true
|
schemaConstraints.presence === true
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -26,7 +26,10 @@ import Provider from "components/context/Provider.svelte"
|
||||||
import Block from "components/Block.svelte"
|
import Block from "components/Block.svelte"
|
||||||
import BlockComponent from "components/BlockComponent.svelte"
|
import BlockComponent from "components/BlockComponent.svelte"
|
||||||
import { ActionTypes } from "./constants"
|
import { ActionTypes } from "./constants"
|
||||||
import { fetchDatasourceSchema } from "./utils/schema.js"
|
import {
|
||||||
|
fetchDatasourceSchema,
|
||||||
|
fetchDatasourceDefinition,
|
||||||
|
} from "./utils/schema.js"
|
||||||
import { getAPIKey } from "./utils/api.js"
|
import { getAPIKey } from "./utils/api.js"
|
||||||
import { enrichButtonActions } from "./utils/buttonActions.js"
|
import { enrichButtonActions } from "./utils/buttonActions.js"
|
||||||
import { processStringSync, makePropSafe } from "@budibase/string-templates"
|
import { processStringSync, makePropSafe } from "@budibase/string-templates"
|
||||||
|
@ -66,6 +69,7 @@ export default {
|
||||||
linkable,
|
linkable,
|
||||||
getAction,
|
getAction,
|
||||||
fetchDatasourceSchema,
|
fetchDatasourceSchema,
|
||||||
|
fetchDatasourceDefinition,
|
||||||
fetchData,
|
fetchData,
|
||||||
QueryUtils,
|
QueryUtils,
|
||||||
ContextScopes: Constants.ContextScopes,
|
ContextScopes: Constants.ContextScopes,
|
||||||
|
|
|
@ -10,16 +10,13 @@ import ViewV2Fetch from "@budibase/frontend-core/src/fetch/ViewV2Fetch.js"
|
||||||
import QueryArrayFetch from "@budibase/frontend-core/src/fetch/QueryArrayFetch"
|
import QueryArrayFetch from "@budibase/frontend-core/src/fetch/QueryArrayFetch"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the schema of any kind of datasource.
|
* Constructs a fetch instance for a given datasource.
|
||||||
* All datasource fetch classes implement their own functionality to get the
|
* All datasource fetch classes implement their own functionality to get the
|
||||||
* schema of a datasource of their respective types.
|
* schema of a datasource of their respective types.
|
||||||
* @param datasource the datasource to fetch the schema for
|
* @param datasource the datasource
|
||||||
* @param options options for enriching the schema
|
* @returns
|
||||||
*/
|
*/
|
||||||
export const fetchDatasourceSchema = async (
|
const getDatasourceFetchInstance = datasource => {
|
||||||
datasource,
|
|
||||||
options = { enrichRelationships: false, formSchema: false }
|
|
||||||
) => {
|
|
||||||
const handler = {
|
const handler = {
|
||||||
table: TableFetch,
|
table: TableFetch,
|
||||||
view: ViewFetch,
|
view: ViewFetch,
|
||||||
|
@ -34,10 +31,23 @@ export const fetchDatasourceSchema = async (
|
||||||
if (!handler) {
|
if (!handler) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
const instance = new handler({ API })
|
return new handler({ API })
|
||||||
|
}
|
||||||
|
|
||||||
// Get the datasource definition and then schema
|
/**
|
||||||
const definition = await instance.getDefinition(datasource)
|
* Fetches the schema of any kind of datasource.
|
||||||
|
* @param datasource the datasource to fetch the schema for
|
||||||
|
* @param options options for enriching the schema
|
||||||
|
*/
|
||||||
|
export const fetchDatasourceSchema = async (
|
||||||
|
datasource,
|
||||||
|
options = { enrichRelationships: false, formSchema: false }
|
||||||
|
) => {
|
||||||
|
const instance = getDatasourceFetchInstance(datasource)
|
||||||
|
const definition = await instance?.getDefinition(datasource)
|
||||||
|
if (!definition) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
// Get the normal schema as long as we aren't wanting a form schema
|
// Get the normal schema as long as we aren't wanting a form schema
|
||||||
let schema
|
let schema
|
||||||
|
@ -75,6 +85,15 @@ export const fetchDatasourceSchema = async (
|
||||||
return instance.enrichSchema(schema)
|
return instance.enrichSchema(schema)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches the definition of any kind of datasource.
|
||||||
|
* @param datasource the datasource to fetch the schema for
|
||||||
|
*/
|
||||||
|
export const fetchDatasourceDefinition = async datasource => {
|
||||||
|
const instance = getDatasourceFetchInstance(datasource)
|
||||||
|
return await instance?.getDefinition(datasource)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the schema of relationship fields for a SQL table schema
|
* Fetches the schema of relationship fields for a SQL table schema
|
||||||
* @param schema the schema to enrich
|
* @param schema the schema to enrich
|
||||||
|
|
|
@ -6,6 +6,7 @@ export const buildViewV2Endpoints = API => ({
|
||||||
fetchDefinition: async viewId => {
|
fetchDefinition: async viewId => {
|
||||||
return await API.get({
|
return await API.get({
|
||||||
url: `/api/v2/views/${encodeURIComponent(viewId)}`,
|
url: `/api/v2/views/${encodeURIComponent(viewId)}`,
|
||||||
|
cache: true,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -184,7 +184,7 @@ export default class DataFetch {
|
||||||
|
|
||||||
// Build the query
|
// Build the query
|
||||||
let query = this.options.query
|
let query = this.options.query
|
||||||
if (!query && this.features.supportsSearch) {
|
if (!query) {
|
||||||
query = buildQuery(filter)
|
query = buildQuery(filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue