Select and conditional fields

This commit is contained in:
Adria Navarro 2023-06-28 12:05:18 +01:00
parent 534b4fffb4
commit 352ea72c53
6 changed files with 87 additions and 9 deletions

View File

@ -4,11 +4,13 @@
import LongFormField from "./fields/LongForm.svelte" import LongFormField from "./fields/LongForm.svelte"
import FieldGroupField from "./fields/FieldGroup.svelte" import FieldGroupField from "./fields/FieldGroup.svelte"
import StringField from "./fields/String.svelte" import StringField from "./fields/String.svelte"
import SelectField from "./fields/Select.svelte"
export let type export let type
export let value export let value
export let error export let error
export let name export let name
export let config
export let showModal = () => {} export let showModal = () => {}
const selectComponent = type => { const selectComponent = type => {
@ -20,6 +22,8 @@
return LongFormField return LongFormField
} else if (type === "fieldGroup") { } else if (type === "fieldGroup") {
return FieldGroupField return FieldGroupField
} else if (type === "select") {
return SelectField
} else { } else {
return StringField return StringField
} }
@ -34,6 +38,7 @@
{value} {value}
{error} {error}
{name} {name}
{config}
{showModal} {showModal}
on:blur on:blur
on:change on:change

View File

@ -0,0 +1,30 @@
<script>
import { Label, Select } from "@budibase/bbui"
export let type
export let name
export let value
export let error
export let config
</script>
<div class="form-row">
<Label>{name}</Label>
<Select
on:blur
on:change
options={config.options}
{type}
value={value || undefined}
{error}
/>
</div>
<style>
.form-row {
display: grid;
grid-template-columns: 20% 1fr;
grid-gap: var(--spacing-l);
align-items: center;
}
</style>

View File

@ -82,13 +82,14 @@
/> />
{/if} {/if}
{#each $configStore.validatedConfig as { type, key, value, error, name, hidden }} {#each $configStore.validatedConfig as { type, key, value, error, name, hidden, config }}
{#if hidden === undefined || !eval(processStringSync(hidden, $configStore.config))} {#if hidden === undefined || !eval(processStringSync(hidden, $configStore.config))}
<ConfigInput <ConfigInput
{type} {type}
{value} {value}
{error} {error}
{name} {name}
{config}
showModal={() => showModal={() =>
showModal(newValue => configStore.updateFieldValue(key, newValue))} showModal(newValue => configStore.updateFieldValue(key, newValue))}
on:blur={() => configStore.markFieldActive(key)} on:blur={() => configStore.markFieldActive(key)}

View File

@ -102,6 +102,7 @@ export const createValidatedConfigStore = (integration, config) => {
name: capitalise(properties.display || key), name: capitalise(properties.display || key),
type: properties.type, type: properties.type,
hidden: properties.hidden, hidden: properties.hidden,
config: properties.config,
}) })
}) })

View File

@ -76,6 +76,33 @@ const SCHEMA: Integration = {
type: DatasourceFieldType.BOOLEAN, type: DatasourceFieldType.BOOLEAN,
default: true, default: true,
}, },
authType: {
type: DatasourceFieldType.SELECT,
config: { options: ["Active Directory"] },
},
adAuthConfig: {
type: DatasourceFieldType.FIELD_GROUP,
default: true,
display: "Configure Active Directory",
hidden: "'{{authType}}' !== 'Active Directory'",
fields: {
clientId: {
type: DatasourceFieldType.STRING,
required: false,
display: "Client ID",
},
clientSecret: {
type: DatasourceFieldType.STRING,
required: false,
display: "Client secret",
},
tenantId: {
type: DatasourceFieldType.STRING,
required: false,
display: "Tenant ID",
},
},
},
}, },
query: { query: {
create: { create: {

View File

@ -36,6 +36,7 @@ export enum DatasourceFieldType {
JSON = "json", JSON = "json",
FILE = "file", FILE = "file",
FIELD_GROUP = "fieldGroup", FIELD_GROUP = "fieldGroup",
SELECT = "select",
} }
export enum SourceName { export enum SourceName {
@ -103,15 +104,28 @@ export interface ExtraQueryConfig {
} }
} }
interface DatasourceBasicFieldConfig {
type: DatasourceFieldType
display?: string
required?: boolean
default?: any
deprecated?: boolean
hidden?: string
}
interface DatasourceSelectFieldConfig extends DatasourceBasicFieldConfig {
type: DatasourceFieldType.SELECT
config: { options: string[] }
}
type DatasourceFieldConfig =
| DatasourceBasicFieldConfig
| DatasourceSelectFieldConfig
export interface DatasourceConfig { export interface DatasourceConfig {
[key: string]: { [key: string]: DatasourceFieldConfig & {
type: string fields?: DatasourceConfig
display?: string }
required?: boolean
default?: any
deprecated?: boolean
hidden?: string
} & { fields?: DatasourceConfig }
} }
export interface Integration { export interface Integration {