Merge pull request #13652 from Budibase/budi-8222/deleting-a-column-on-google-spreadsheet-messes-with-the-data
Deleting a column on google spreadsheet messes with the data
This commit is contained in:
commit
938e44b583
|
@ -12,6 +12,7 @@
|
||||||
OptionSelectDnD,
|
OptionSelectDnD,
|
||||||
Layout,
|
Layout,
|
||||||
AbsTooltip,
|
AbsTooltip,
|
||||||
|
ProgressCircle,
|
||||||
} from "@budibase/bbui"
|
} from "@budibase/bbui"
|
||||||
import { SWITCHABLE_TYPES, ValidColumnNameRegex } from "@budibase/shared-core"
|
import { SWITCHABLE_TYPES, ValidColumnNameRegex } from "@budibase/shared-core"
|
||||||
import { createEventDispatcher, getContext, onMount } from "svelte"
|
import { createEventDispatcher, getContext, onMount } from "svelte"
|
||||||
|
@ -245,11 +246,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveColumn() {
|
async function saveColumn() {
|
||||||
savingColumn = true
|
|
||||||
if (errors?.length) {
|
if (errors?.length) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
savingColumn = true
|
||||||
let saveColumn = cloneDeep(editableColumn)
|
let saveColumn = cloneDeep(editableColumn)
|
||||||
|
|
||||||
delete saveColumn.fieldId
|
delete saveColumn.fieldId
|
||||||
|
@ -289,6 +290,8 @@
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
notifications.error(`Error saving column: ${err.message}`)
|
notifications.error(`Error saving column: ${err.message}`)
|
||||||
|
} finally {
|
||||||
|
savingColumn = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -739,7 +742,20 @@
|
||||||
<Button quiet warning text on:click={confirmDelete}>Delete</Button>
|
<Button quiet warning text on:click={confirmDelete}>Delete</Button>
|
||||||
{/if}
|
{/if}
|
||||||
<Button secondary newStyles on:click={cancelEdit}>Cancel</Button>
|
<Button secondary newStyles on:click={cancelEdit}>Cancel</Button>
|
||||||
<Button disabled={invalid} newStyles cta on:click={saveColumn}>Save</Button>
|
<Button
|
||||||
|
disabled={invalid || savingColumn}
|
||||||
|
newStyles
|
||||||
|
cta
|
||||||
|
on:click={saveColumn}
|
||||||
|
>
|
||||||
|
{#if savingColumn}
|
||||||
|
<div class="save-loading">
|
||||||
|
<ProgressCircle overBackground={true} size="S" />
|
||||||
|
</div>
|
||||||
|
{:else}
|
||||||
|
Save
|
||||||
|
{/if}
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
<Modal bind:this={jsonSchemaModal}>
|
<Modal bind:this={jsonSchemaModal}>
|
||||||
<JSONSchemaModal
|
<JSONSchemaModal
|
||||||
|
@ -804,4 +820,9 @@
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
color: var(--spectrum-global-color-gray-900);
|
color: var(--spectrum-global-color-gray-900);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.save-loading {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -371,9 +371,11 @@ class GoogleSheetsIntegration implements DatasourcePlus {
|
||||||
}
|
}
|
||||||
|
|
||||||
buildRowObject(headers: string[], values: string[], rowNumber: number) {
|
buildRowObject(headers: string[], values: string[], rowNumber: number) {
|
||||||
const rowObject: { rowNumber: number; [key: string]: any } = { rowNumber }
|
const rowObject: { rowNumber: number } & Row = {
|
||||||
|
rowNumber,
|
||||||
|
_id: rowNumber.toString(),
|
||||||
|
}
|
||||||
for (let i = 0; i < headers.length; i++) {
|
for (let i = 0; i < headers.length; i++) {
|
||||||
rowObject._id = rowNumber
|
|
||||||
rowObject[headers[i]] = values[i]
|
rowObject[headers[i]] = values[i]
|
||||||
}
|
}
|
||||||
return rowObject
|
return rowObject
|
||||||
|
@ -430,14 +432,6 @@ class GoogleSheetsIntegration implements DatasourcePlus {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear out deleted columns
|
|
||||||
for (let key of sheet.headerValues) {
|
|
||||||
if (!Object.keys(table.schema).includes(key)) {
|
|
||||||
const idx = updatedHeaderValues.indexOf(key)
|
|
||||||
updatedHeaderValues.splice(idx, 1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await sheet.setHeaderRow(updatedHeaderValues)
|
await sheet.setHeaderRow(updatedHeaderValues)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -458,7 +452,7 @@ class GoogleSheetsIntegration implements DatasourcePlus {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(query: { sheet: string; row: any }) {
|
async create(query: { sheet: string; row: Row }) {
|
||||||
try {
|
try {
|
||||||
await this.connect()
|
await this.connect()
|
||||||
const sheet = this.client.sheetsByTitle[query.sheet]
|
const sheet = this.client.sheetsByTitle[query.sheet]
|
||||||
|
@ -474,7 +468,7 @@ class GoogleSheetsIntegration implements DatasourcePlus {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async createBulk(query: { sheet: string; rows: any[] }) {
|
async createBulk(query: { sheet: string; rows: Row[] }) {
|
||||||
try {
|
try {
|
||||||
await this.connect()
|
await this.connect()
|
||||||
const sheet = this.client.sheetsByTitle[query.sheet]
|
const sheet = this.client.sheetsByTitle[query.sheet]
|
||||||
|
|
|
@ -129,10 +129,11 @@ describe("Google Sheets Integration", () => {
|
||||||
})
|
})
|
||||||
expect(sheet.loadHeaderRow).toHaveBeenCalledTimes(1)
|
expect(sheet.loadHeaderRow).toHaveBeenCalledTimes(1)
|
||||||
expect(sheet.setHeaderRow).toHaveBeenCalledTimes(1)
|
expect(sheet.setHeaderRow).toHaveBeenCalledTimes(1)
|
||||||
expect(sheet.setHeaderRow).toHaveBeenCalledWith(["name"])
|
expect(sheet.setHeaderRow).toHaveBeenCalledWith([
|
||||||
|
"name",
|
||||||
// No undefined are sent
|
"description",
|
||||||
expect((sheet.setHeaderRow as any).mock.calls[0][0]).toHaveLength(1)
|
"location",
|
||||||
|
])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue