Merge branch 'master' into revert-15323-revert-15215-chore/aws-v2-to-v3

This commit is contained in:
Sam Rose 2025-01-22 10:42:01 +00:00 committed by GitHub
commit 0c1c41bedb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 115 additions and 35 deletions

View File

@ -1,4 +1,5 @@
<script>
import { datasources } from "@/stores/builder"
import { Divider, Heading } from "@budibase/bbui"
export let dividerState
@ -6,6 +7,8 @@
export let dataSet
export let value
export let onSelect
$: displayDatasourceName = $datasources.list.length > 1
</script>
{#if dividerState}
@ -21,7 +24,7 @@
{#each dataSet as data}
<li
class="spectrum-Menu-item"
class:is-selected={value?.label === data.label &&
class:is-selected={value?.resourceId === data.resourceId &&
value?.type === data.type}
role="option"
aria-selected="true"
@ -29,7 +32,9 @@
on:click={() => onSelect(data)}
>
<span class="spectrum-Menu-itemLabel">
{data.datasourceName ? `${data.datasourceName} - ` : ""}{data.label}
{data.datasourceName && displayDatasourceName
? `${data.datasourceName} - `
: ""}{data.label}
</span>
<svg
class="spectrum-Icon spectrum-UIIcon-Checkmark100 spectrum-Menu-checkmark spectrum-Menu-itemIcon"

View File

@ -34,7 +34,7 @@
import ClientBindingPanel from "@/components/common/bindings/ClientBindingPanel.svelte"
import DataSourceCategory from "@/components/design/settings/controls/DataSourceSelect/DataSourceCategory.svelte"
import { API } from "@/api"
import { datasourceSelect as format } from "@/helpers/data/format"
import { sortAndFormat } from "@/helpers/data/format"
export let value = {}
export let otherSources
@ -51,25 +51,13 @@
let modal
$: text = value?.label ?? "Choose an option"
$: tables = $tablesStore.list
.map(table => format.table(table, $datasources.list))
.sort((a, b) => {
// sort tables alphabetically, grouped by datasource
const dsA = a.datasourceName ?? ""
const dsB = b.datasourceName ?? ""
const dsComparison = dsA.localeCompare(dsB)
if (dsComparison !== 0) {
return dsComparison
}
return a.label.localeCompare(b.label)
})
$: tables = sortAndFormat.tables($tablesStore.list, $datasources.list)
$: viewsV1 = $viewsStore.list.map(view => ({
...view,
label: view.name,
type: "view",
}))
$: viewsV2 = $viewsV2Store.list.map(format.viewV2)
$: viewsV2 = sortAndFormat.viewsV2($viewsV2Store.list, $datasources.list)
$: views = [...(viewsV1 || []), ...(viewsV2 || [])]
$: queries = $queriesStore.list
.filter(q => showAllQueries || q.queryVerb === "read" || q.readable)

View File

@ -1,22 +1,32 @@
<script>
import { Select } from "@budibase/bbui"
import { Popover, Select } from "@budibase/bbui"
import { createEventDispatcher, onMount } from "svelte"
import { tables as tablesStore, viewsV2 } from "@/stores/builder"
import { tableSelect as format } from "@/helpers/data/format"
import {
tables as tableStore,
datasources as datasourceStore,
viewsV2 as viewsV2Store,
} from "@/stores/builder"
import DataSourceCategory from "./DataSourceSelect/DataSourceCategory.svelte"
import { sortAndFormat } from "@/helpers/data/format"
export let value
let anchorRight, dropdownRight
const dispatch = createEventDispatcher()
$: tables = $tablesStore.list.map(format.table)
$: views = $viewsV2.list.map(format.viewV2)
$: tables = sortAndFormat.tables($tableStore.list, $datasourceStore.list)
$: views = sortAndFormat.viewsV2($viewsV2Store.list, $datasourceStore.list)
$: options = [...(tables || []), ...(views || [])]
$: text = value?.label ?? "Choose an option"
const onChange = e => {
dispatch(
"change",
options.find(x => x.resourceId === e.detail)
options.find(x => x.resourceId === e.resourceId)
)
dropdownRight.hide()
}
onMount(() => {
@ -29,10 +39,47 @@
})
</script>
<Select
on:change={onChange}
value={value?.resourceId}
{options}
getOptionValue={x => x.resourceId}
getOptionLabel={x => x.label}
/>
<div class="container" bind:this={anchorRight}>
<Select
readonly
value={text}
options={[text]}
on:click={dropdownRight.show}
/>
</div>
<Popover bind:this={dropdownRight} anchor={anchorRight}>
<div class="dropdown">
<DataSourceCategory
heading="Tables"
dataSet={tables}
{value}
onSelect={onChange}
/>
{#if views?.length}
<DataSourceCategory
dividerState={true}
heading="Views"
dataSet={views}
{value}
onSelect={onChange}
/>
{/if}
</div>
</Popover>
<style>
.container {
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: center;
}
.container :global(:first-child) {
flex: 1 1 auto;
}
.dropdown {
padding: var(--spacing-m) 0;
z-index: 99999999;
}
</style>

View File

@ -9,11 +9,18 @@ export const datasourceSelect = {
datasourceName: datasource?.name,
}
},
viewV2: view => ({
...view,
label: view.name,
type: "viewV2",
}),
viewV2: (view, datasources) => {
const datasource = datasources
.filter(f => f.entities)
.flatMap(d => d.entities)
.find(ds => ds._id === view.tableId)
return {
...view,
label: view.name,
type: "viewV2",
datasourceName: datasource?.name,
}
},
}
export const tableSelect = {
@ -31,3 +38,36 @@ export const tableSelect = {
resourceId: view.id,
}),
}
export const sortAndFormat = {
tables: (tables, datasources) => {
return tables
.map(table => {
const formatted = datasourceSelect.table(table, datasources)
return {
...formatted,
resourceId: table._id,
}
})
.sort((a, b) => {
// sort tables alphabetically, grouped by datasource
const dsA = a.datasourceName ?? ""
const dsB = b.datasourceName ?? ""
const dsComparison = dsA.localeCompare(dsB)
if (dsComparison !== 0) {
return dsComparison
}
return a.label.localeCompare(b.label)
})
},
viewsV2: (views, datasources) => {
return views.map(view => {
const formatted = datasourceSelect.viewV2(view, datasources)
return {
...formatted,
resourceId: view.id,
}
})
},
}