Merge pull request #8857 from Budibase/fix/sample-data-edit-removed-delete-fixed

Remove ability to edit the 'Sample Data' datasource name
This commit is contained in:
deanhannigan 2022-11-30 09:08:54 +00:00 committed by GitHub
commit b66cf84876
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 6 deletions

View File

@ -5,6 +5,7 @@
import { ActionMenu, MenuItem, Icon } from "@budibase/bbui" import { ActionMenu, MenuItem, Icon } from "@budibase/bbui"
import ConfirmDialog from "components/common/ConfirmDialog.svelte" import ConfirmDialog from "components/common/ConfirmDialog.svelte"
import UpdateDatasourceModal from "components/backend/DatasourceNavigator/modals/UpdateDatasourceModal.svelte" import UpdateDatasourceModal from "components/backend/DatasourceNavigator/modals/UpdateDatasourceModal.svelte"
import { BUDIBASE_DATASOURCE_TYPE } from "constants/backend"
export let datasource export let datasource
@ -42,7 +43,9 @@
<div slot="control" class="icon"> <div slot="control" class="icon">
<Icon size="S" hoverable name="MoreSmallList" /> <Icon size="S" hoverable name="MoreSmallList" />
</div> </div>
<MenuItem icon="Edit" on:click={updateDatasourceDialog.show}>Edit</MenuItem> {#if datasource.type !== BUDIBASE_DATASOURCE_TYPE}
<MenuItem icon="Edit" on:click={updateDatasourceDialog.show}>Edit</MenuItem>
{/if}
<MenuItem icon="Delete" on:click={confirmDeleteDialog.show}>Delete</MenuItem> <MenuItem icon="Delete" on:click={confirmDeleteDialog.show}>Delete</MenuItem>
</ActionMenu> </ActionMenu>

View File

@ -174,6 +174,7 @@ export const SWITCHABLE_TYPES = [
] ]
export const BUDIBASE_INTERNAL_DB_ID = "bb_internal" export const BUDIBASE_INTERNAL_DB_ID = "bb_internal"
export const DEFAULT_BB_DATASOURCE_ID = "datasource_internal_bb_default"
export const BUDIBASE_DATASOURCE_TYPE = "budibase" export const BUDIBASE_DATASOURCE_TYPE = "budibase"
export const DB_TYPE_INTERNAL = "internal" export const DB_TYPE_INTERNAL = "internal"
export const DB_TYPE_EXTERNAL = "external" export const DB_TYPE_EXTERNAL = "external"

View File

@ -1,7 +1,8 @@
<script> <script>
import { datasources } from "stores/backend" import { datasources } from "stores/backend"
import { DEFAULT_BB_DATASOURCE_ID } from "constants/backend"
datasources.select("datasource_internal_bb_default") datasources.select(DEFAULT_BB_DATASOURCE_ID)
</script> </script>
<slot /> <slot />

View File

@ -152,7 +152,14 @@ export async function update(ctx: BBContext) {
let datasource = await db.get(datasourceId) let datasource = await db.get(datasourceId)
const auth = datasource.config.auth const auth = datasource.config.auth
await invalidateVariables(datasource, ctx.request.body) await invalidateVariables(datasource, ctx.request.body)
datasource = { ...datasource, ...ctx.request.body }
const isBudibaseSource = datasource.type === dbCore.BUDIBASE_DATASOURCE_TYPE
const dataSourceBody = isBudibaseSource
? { name: ctx.request.body?.name }
: ctx.request.body
datasource = { ...datasource, ...dataSourceBody }
if (auth && !ctx.request.body.auth) { if (auth && !ctx.request.body.auth) {
// don't strip auth config from DB // don't strip auth config from DB
datasource.config.auth = auth datasource.config.auth = auth
@ -163,7 +170,7 @@ export async function update(ctx: BBContext) {
datasource._rev = response.rev datasource._rev = response.rev
// Drain connection pools when configuration is changed // Drain connection pools when configuration is changed
if (datasource.source) { if (datasource.source && !isBudibaseSource) {
const source = await getIntegration(datasource.source) const source = await getIntegration(datasource.source)
if (source && source.pool) { if (source && source.pool) {
await source.pool.end() await source.pool.end()

View File

@ -18,7 +18,8 @@ export const DEFAULT_INVENTORY_TABLE_ID = "ta_bb_inventory"
export const DEFAULT_EXPENSES_TABLE_ID = "ta_bb_expenses" export const DEFAULT_EXPENSES_TABLE_ID = "ta_bb_expenses"
export const DEFAULT_EMPLOYEE_TABLE_ID = "ta_bb_employee" export const DEFAULT_EMPLOYEE_TABLE_ID = "ta_bb_employee"
export const DEFAULT_BB_DATASOURCE_ID = "datasource_internal_bb_default" export const DEFAULT_BB_DATASOURCE_ID = "datasource_internal_bb_default"
export const DEFAULT_BB_DATASOURCE = {
const defaultDatasource = {
_id: DEFAULT_BB_DATASOURCE_ID, _id: DEFAULT_BB_DATASOURCE_ID,
type: dbCore.BUDIBASE_DATASOURCE_TYPE, type: dbCore.BUDIBASE_DATASOURCE_TYPE,
name: "Sample Data", name: "Sample Data",
@ -26,6 +27,8 @@ export const DEFAULT_BB_DATASOURCE = {
config: {}, config: {},
} }
export const DEFAULT_BB_DATASOURCE = defaultDatasource
function syncLastIds(table: Table, rowCount: number) { function syncLastIds(table: Table, rowCount: number) {
Object.keys(table.schema).forEach(key => { Object.keys(table.schema).forEach(key => {
const entry = table.schema[key] const entry = table.schema[key]
@ -634,8 +637,14 @@ export function buildDefaultDocs() {
} }
) )
const dataSource = {
...defaultDatasource,
updatedAt: new Date().toISOString(),
createdAt: new Date().toISOString(),
}
return [ return [
DEFAULT_BB_DATASOURCE, dataSource,
inventoryData.table, inventoryData.table,
employeeData.table, employeeData.table,
jobData.table, jobData.table,