Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deleting a column on google spreadsheet messes with the data #13652

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
OptionSelectDnD,
Layout,
AbsTooltip,
ProgressCircle,
} from "@budibase/bbui"
import { SWITCHABLE_TYPES, ValidColumnNameRegex } from "@budibase/shared-core"
import { createEventDispatcher, getContext, onMount } from "svelte"
Expand Down Expand Up @@ -245,11 +246,11 @@
}

async function saveColumn() {
savingColumn = true
if (errors?.length) {
return
}

savingColumn = true
let saveColumn = cloneDeep(editableColumn)

delete saveColumn.fieldId
Expand Down Expand Up @@ -289,6 +290,8 @@
}
} catch (err) {
notifications.error(`Error saving column: ${err.message}`)
} finally {
savingColumn = false
}
}

Expand Down Expand Up @@ -739,7 +742,20 @@
<Button quiet warning text on:click={confirmDelete}>Delete</Button>
{/if}
<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>
<Modal bind:this={jsonSchemaModal}>
<JSONSchemaModal
Expand Down Expand Up @@ -804,4 +820,9 @@
cursor: pointer;
color: var(--spectrum-global-color-gray-900);
}

.save-loading {
display: flex;
justify-content: center;
}
</style>
18 changes: 6 additions & 12 deletions packages/server/src/integrations/googlesheets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,11 @@ class GoogleSheetsIntegration implements DatasourcePlus {
}

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++) {
rowObject._id = rowNumber
rowObject[headers[i]] = values[i]
}
return rowObject
Expand Down Expand Up @@ -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 {
await sheet.setHeaderRow(updatedHeaderValues)
} catch (err) {
Expand All @@ -458,7 +452,7 @@ class GoogleSheetsIntegration implements DatasourcePlus {
}
}

async create(query: { sheet: string; row: any }) {
async create(query: { sheet: string; row: Row }) {
try {
await this.connect()
const sheet = this.client.sheetsByTitle[query.sheet]
Expand All @@ -474,7 +468,7 @@ class GoogleSheetsIntegration implements DatasourcePlus {
}
}

async createBulk(query: { sheet: string; rows: any[] }) {
async createBulk(query: { sheet: string; rows: Row[] }) {
try {
await this.connect()
const sheet = this.client.sheetsByTitle[query.sheet]
Expand Down
9 changes: 5 additions & 4 deletions packages/server/src/integrations/tests/googlesheets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,11 @@ describe("Google Sheets Integration", () => {
})
expect(sheet.loadHeaderRow).toHaveBeenCalledTimes(1)
expect(sheet.setHeaderRow).toHaveBeenCalledTimes(1)
expect(sheet.setHeaderRow).toHaveBeenCalledWith(["name"])

// No undefined are sent
expect((sheet.setHeaderRow as any).mock.calls[0][0]).toHaveLength(1)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what this was meant to do, as it was already asserted on the previous lines

expect(sheet.setHeaderRow).toHaveBeenCalledWith([
"name",
"description",
"location",
])
})
})

Expand Down
Loading