Merge branch 'master' into remove-dead-code
This commit is contained in:
commit
b8e5fce724
|
@ -1,23 +1,23 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import {
|
import {
|
||||||
default as AbsTooltip,
|
default as AbsTooltip,
|
||||||
TooltipPosition,
|
TooltipPosition,
|
||||||
TooltipType,
|
TooltipType,
|
||||||
} from "../Tooltip/AbsTooltip.svelte"
|
} from "../Tooltip/AbsTooltip.svelte"
|
||||||
|
|
||||||
export let name = "Add"
|
export let name: string = "Add"
|
||||||
export let hidden = false
|
export let hidden: boolean = false
|
||||||
export let size = "M"
|
export let size = "M"
|
||||||
export let hoverable = false
|
export let hoverable: boolean = false
|
||||||
export let disabled = false
|
export let disabled: boolean = false
|
||||||
export let color = undefined
|
export let color: string | undefined = undefined
|
||||||
export let hoverColor = undefined
|
export let hoverColor: string | undefined = undefined
|
||||||
export let tooltip = undefined
|
export let tooltip: string | undefined = undefined
|
||||||
export let tooltipPosition = TooltipPosition.Bottom
|
export let tooltipPosition = TooltipPosition.Bottom
|
||||||
export let tooltipType = TooltipType.Default
|
export let tooltipType = TooltipType.Default
|
||||||
export let tooltipColor = undefined
|
export let tooltipColor: string | undefined = undefined
|
||||||
export let tooltipWrap = true
|
export let tooltipWrap: boolean = true
|
||||||
export let newStyles = false
|
export let newStyles: boolean = false
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<AbsTooltip
|
<AbsTooltip
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
export let type = TooltipType.Default
|
export let type = TooltipType.Default
|
||||||
export let text = ""
|
export let text = ""
|
||||||
export let fixed = false
|
export let fixed = false
|
||||||
export let color = null
|
export let color = ""
|
||||||
export let noWrap = false
|
export let noWrap = false
|
||||||
|
|
||||||
let wrapper
|
let wrapper
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
GroupUserDatasource,
|
GroupUserDatasource,
|
||||||
DataFetchOptions,
|
DataFetchOptions,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { SDK, Component } from "../../index"
|
|
||||||
|
|
||||||
type ProviderDatasource = Exclude<
|
type ProviderDatasource = Exclude<
|
||||||
DataFetchDatasource,
|
DataFetchDatasource,
|
||||||
|
@ -29,8 +28,8 @@
|
||||||
export let paginate: boolean
|
export let paginate: boolean
|
||||||
export let autoRefresh: number
|
export let autoRefresh: number
|
||||||
|
|
||||||
const { styleable, Provider, ActionTypes, API } = getContext<SDK>("sdk")
|
const { styleable, Provider, ActionTypes, API } = getContext("sdk")
|
||||||
const component = getContext<Component>("component")
|
const component = getContext("component")
|
||||||
|
|
||||||
let interval: ReturnType<typeof setInterval>
|
let interval: ReturnType<typeof setInterval>
|
||||||
let queryExtensions: Record<string, any> = {}
|
let queryExtensions: Record<string, any> = {}
|
||||||
|
|
|
@ -1,37 +1,43 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import { getContext } from "svelte"
|
import { getContext } from "svelte"
|
||||||
import InnerFormBlock from "./InnerFormBlock.svelte"
|
import InnerFormBlock from "./InnerFormBlock.svelte"
|
||||||
import { Utils } from "@budibase/frontend-core"
|
import { Utils } from "@budibase/frontend-core"
|
||||||
import FormBlockWrapper from "./FormBlockWrapper.svelte"
|
import FormBlockWrapper from "./FormBlockWrapper.svelte"
|
||||||
import { get } from "svelte/store"
|
import { get } from "svelte/store"
|
||||||
|
import { TableSchema, UIDatasource } from "@budibase/types"
|
||||||
|
|
||||||
export let actionType
|
type Field = { name: string; active: boolean }
|
||||||
export let dataSource
|
|
||||||
export let size
|
export let actionType: string
|
||||||
export let disabled
|
export let dataSource: UIDatasource
|
||||||
export let fields
|
export let size: string
|
||||||
export let buttons
|
export let disabled: boolean
|
||||||
export let buttonPosition
|
export let fields: (Field | string)[]
|
||||||
export let title
|
export let buttons: {
|
||||||
export let description
|
"##eventHandlerType": string
|
||||||
export let rowId
|
parameters: Record<string, string>
|
||||||
export let actionUrl
|
}[]
|
||||||
export let noRowsMessage
|
export let buttonPosition: "top" | "bottom"
|
||||||
export let notificationOverride
|
export let title: string
|
||||||
export let buttonsCollapsed
|
export let description: string
|
||||||
export let buttonsCollapsedText
|
export let rowId: string
|
||||||
|
export let actionUrl: string
|
||||||
|
export let noRowsMessage: string
|
||||||
|
export let notificationOverride: boolean
|
||||||
|
export let buttonsCollapsed: boolean
|
||||||
|
export let buttonsCollapsedText: string
|
||||||
|
|
||||||
// Legacy
|
// Legacy
|
||||||
export let showDeleteButton
|
export let showDeleteButton: boolean
|
||||||
export let showSaveButton
|
export let showSaveButton: boolean
|
||||||
export let saveButtonLabel
|
export let saveButtonLabel: boolean
|
||||||
export let deleteButtonLabel
|
export let deleteButtonLabel: boolean
|
||||||
|
|
||||||
const { fetchDatasourceSchema, generateGoldenSample } = getContext("sdk")
|
const { fetchDatasourceSchema, generateGoldenSample } = getContext("sdk")
|
||||||
const component = getContext("component")
|
const component = getContext("component")
|
||||||
const context = getContext("context")
|
const context = getContext("context")
|
||||||
|
|
||||||
let schema
|
let schema: TableSchema
|
||||||
|
|
||||||
$: fetchSchema(dataSource)
|
$: fetchSchema(dataSource)
|
||||||
$: id = $component.id
|
$: id = $component.id
|
||||||
|
@ -61,7 +67,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const convertOldFieldFormat = fields => {
|
const convertOldFieldFormat = (fields: (Field | string)[]): Field[] => {
|
||||||
if (!fields) {
|
if (!fields) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
@ -82,11 +88,11 @@
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const getDefaultFields = (fields, schema) => {
|
const getDefaultFields = (fields: Field[], schema: TableSchema) => {
|
||||||
if (!schema) {
|
if (!schema) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
let defaultFields = []
|
let defaultFields: Field[] = []
|
||||||
|
|
||||||
if (!fields || fields.length === 0) {
|
if (!fields || fields.length === 0) {
|
||||||
Object.values(schema)
|
Object.values(schema)
|
||||||
|
@ -101,15 +107,14 @@
|
||||||
return [...fields, ...defaultFields].filter(field => field.active)
|
return [...fields, ...defaultFields].filter(field => field.active)
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchSchema = async () => {
|
const fetchSchema = async (datasource: UIDatasource) => {
|
||||||
schema = (await fetchDatasourceSchema(dataSource)) || {}
|
schema = (await fetchDatasourceSchema(datasource)) || {}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<FormBlockWrapper {actionType} {dataSource} {rowId} {noRowsMessage}>
|
<FormBlockWrapper {actionType} {dataSource} {rowId} {noRowsMessage}>
|
||||||
<InnerFormBlock
|
<InnerFormBlock
|
||||||
{dataSource}
|
{dataSource}
|
||||||
{actionUrl}
|
|
||||||
{actionType}
|
{actionType}
|
||||||
{size}
|
{size}
|
||||||
{disabled}
|
{disabled}
|
||||||
|
@ -117,7 +122,6 @@
|
||||||
{title}
|
{title}
|
||||||
{description}
|
{description}
|
||||||
{schema}
|
{schema}
|
||||||
{notificationOverride}
|
|
||||||
buttons={buttonsOrDefault}
|
buttons={buttonsOrDefault}
|
||||||
buttonPosition={buttons ? buttonPosition : "top"}
|
buttonPosition={buttons ? buttonPosition : "top"}
|
||||||
{buttonsCollapsed}
|
{buttonsCollapsed}
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import { getContext } from "svelte"
|
import { getContext } from "svelte"
|
||||||
import { Icon } from "@budibase/bbui"
|
import { Icon } from "@budibase/bbui"
|
||||||
import MissingRequiredSetting from "./MissingRequiredSetting.svelte"
|
import MissingRequiredSetting from "./MissingRequiredSetting.svelte"
|
||||||
import MissingRequiredAncestor from "./MissingRequiredAncestor.svelte"
|
import MissingRequiredAncestor from "./MissingRequiredAncestor.svelte"
|
||||||
|
|
||||||
export let missingRequiredSettings
|
export let missingRequiredSettings:
|
||||||
export let missingRequiredAncestors
|
| { key: string; label: string }[]
|
||||||
|
| undefined
|
||||||
|
export let missingRequiredAncestors: string[] | undefined
|
||||||
|
|
||||||
const component = getContext("component")
|
const component = getContext("component")
|
||||||
const { styleable, builderStore } = getContext("sdk")
|
const { styleable, builderStore } = getContext("sdk")
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
import { Component, Context, SDK } from "."
|
||||||
|
|
||||||
|
declare module "svelte" {
|
||||||
|
export function getContext(key: "sdk"): SDK
|
||||||
|
export function getContext(key: "component"): Component
|
||||||
|
export function getContext(key: "context"): Context
|
||||||
|
}
|
|
@ -7,9 +7,17 @@ export interface SDK {
|
||||||
styleable: any
|
styleable: any
|
||||||
Provider: any
|
Provider: any
|
||||||
ActionTypes: typeof ActionTypes
|
ActionTypes: typeof ActionTypes
|
||||||
|
fetchDatasourceSchema: any
|
||||||
|
generateGoldenSample: any
|
||||||
|
builderStore: Readable<{
|
||||||
|
inBuilder: boolean
|
||||||
|
}>
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Component = Readable<{
|
export type Component = Readable<{
|
||||||
id: string
|
id: string
|
||||||
styles: any
|
styles: any
|
||||||
|
errorState: boolean
|
||||||
}>
|
}>
|
||||||
|
|
||||||
|
export type Context = Readable<{}>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { API } from "api"
|
import { API } from "api"
|
||||||
import { DataFetchMap, DataFetchType } from "@budibase/frontend-core"
|
import { DataFetchMap, DataFetchType } from "@budibase/frontend-core"
|
||||||
|
import { FieldType, TableSchema } from "@budibase/types"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a fetch instance for a given datasource.
|
* Constructs a fetch instance for a given datasource.
|
||||||
|
@ -42,14 +43,14 @@ export const fetchDatasourceSchema = async <
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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: any
|
let schema: TableSchema | undefined
|
||||||
if (datasource?.type !== "query" || !options?.formSchema) {
|
if (datasource?.type !== "query" || !options?.formSchema) {
|
||||||
schema = instance.getSchema(definition as any)
|
schema = instance.getSchema(definition as any) as TableSchema
|
||||||
} else if ("parameters" in definition && definition.parameters?.length) {
|
} else if ("parameters" in definition && definition.parameters?.length) {
|
||||||
schema = {}
|
schema = {}
|
||||||
definition.parameters.forEach(param => {
|
for (const param of definition.parameters) {
|
||||||
schema[param.name] = { ...param, type: "string" }
|
schema[param.name] = { ...param, type: FieldType.STRING }
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
if (!schema) {
|
if (!schema) {
|
||||||
return null
|
return null
|
||||||
|
@ -57,11 +58,11 @@ export const fetchDatasourceSchema = async <
|
||||||
|
|
||||||
// Strip hidden fields from views
|
// Strip hidden fields from views
|
||||||
if (datasource.type === "viewV2") {
|
if (datasource.type === "viewV2") {
|
||||||
Object.keys(schema).forEach(field => {
|
for (const field of Object.keys(schema)) {
|
||||||
if (!schema[field].visible) {
|
if (!schema[field].visible) {
|
||||||
delete schema[field]
|
delete schema[field]
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enrich schema with relationships if required
|
// Enrich schema with relationships if required
|
||||||
|
|
|
@ -123,9 +123,11 @@ async function parseSchema(view: CreateViewRequest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function get(ctx: Ctx<void, ViewResponseEnriched>) {
|
export async function get(ctx: Ctx<void, ViewResponseEnriched>) {
|
||||||
ctx.body = {
|
const view = await sdk.views.getEnriched(ctx.params.viewId)
|
||||||
data: await sdk.views.getEnriched(ctx.params.viewId),
|
if (!view) {
|
||||||
|
ctx.throw(404)
|
||||||
}
|
}
|
||||||
|
ctx.body = { data: view }
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetch(ctx: Ctx<void, ViewFetchResponseEnriched>) {
|
export async function fetch(ctx: Ctx<void, ViewFetchResponseEnriched>) {
|
||||||
|
|
|
@ -22,7 +22,9 @@ export async function get(viewId: string): Promise<ViewV2> {
|
||||||
return ensureQueryUISet(found)
|
return ensureQueryUISet(found)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getEnriched(viewId: string): Promise<ViewV2Enriched> {
|
export async function getEnriched(
|
||||||
|
viewId: string
|
||||||
|
): Promise<ViewV2Enriched | undefined> {
|
||||||
const { tableId } = utils.extractViewInfoFromID(viewId)
|
const { tableId } = utils.extractViewInfoFromID(viewId)
|
||||||
|
|
||||||
const { datasourceId, tableName } = breakExternalTableId(tableId)
|
const { datasourceId, tableName } = breakExternalTableId(tableId)
|
||||||
|
@ -32,7 +34,7 @@ export async function getEnriched(viewId: string): Promise<ViewV2Enriched> {
|
||||||
const views = Object.values(table.views!).filter(isV2)
|
const views = Object.values(table.views!).filter(isV2)
|
||||||
const found = views.find(v => v.id === viewId)
|
const found = views.find(v => v.id === viewId)
|
||||||
if (!found) {
|
if (!found) {
|
||||||
throw new Error("No view found")
|
return
|
||||||
}
|
}
|
||||||
return await enrichSchema(ensureQueryUISet(found), table.schema)
|
return await enrichSchema(ensureQueryUISet(found), table.schema)
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,9 @@ export async function get(viewId: string): Promise<ViewV2> {
|
||||||
return pickApi(tableId).get(viewId)
|
return pickApi(tableId).get(viewId)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getEnriched(viewId: string): Promise<ViewV2Enriched> {
|
export async function getEnriched(
|
||||||
|
viewId: string
|
||||||
|
): Promise<ViewV2Enriched | undefined> {
|
||||||
const { tableId } = utils.extractViewInfoFromID(viewId)
|
const { tableId } = utils.extractViewInfoFromID(viewId)
|
||||||
return pickApi(tableId).getEnriched(viewId)
|
return pickApi(tableId).getEnriched(viewId)
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,13 +17,15 @@ export async function get(viewId: string): Promise<ViewV2> {
|
||||||
return ensureQueryUISet(found)
|
return ensureQueryUISet(found)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getEnriched(viewId: string): Promise<ViewV2Enriched> {
|
export async function getEnriched(
|
||||||
|
viewId: string
|
||||||
|
): Promise<ViewV2Enriched | undefined> {
|
||||||
const { tableId } = utils.extractViewInfoFromID(viewId)
|
const { tableId } = utils.extractViewInfoFromID(viewId)
|
||||||
const table = await sdk.tables.getTable(tableId)
|
const table = await sdk.tables.getTable(tableId)
|
||||||
const views = Object.values(table.views!).filter(isV2)
|
const views = Object.values(table.views!).filter(isV2)
|
||||||
const found = views.find(v => v.id === viewId)
|
const found = views.find(v => v.id === viewId)
|
||||||
if (!found) {
|
if (!found) {
|
||||||
throw new Error("No view found")
|
return
|
||||||
}
|
}
|
||||||
return await enrichSchema(ensureQueryUISet(found), table.schema)
|
return await enrichSchema(ensureQueryUISet(found), table.schema)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue