Merge pull request #11689 from Budibase/duplicate-column
Add option to duplicate columns
This commit is contained in:
commit
69a64464f0
|
@ -20,6 +20,8 @@
|
|||
config,
|
||||
ui,
|
||||
columns,
|
||||
definition,
|
||||
datasource,
|
||||
} = getContext("grid")
|
||||
|
||||
const bannedDisplayColumnTypes = [
|
||||
|
@ -118,6 +120,33 @@
|
|||
open = false
|
||||
}
|
||||
|
||||
const duplicateColumn = async () => {
|
||||
open = false
|
||||
|
||||
// Generate new name
|
||||
let newName = `${column.name} copy`
|
||||
let attempts = 2
|
||||
while ($definition.schema[newName]) {
|
||||
newName = `${column.name} copy ${attempts++}`
|
||||
}
|
||||
|
||||
// Save schema with new column
|
||||
const existingColumnDefinition = $definition.schema[column.name]
|
||||
await datasource.actions.saveDefinition({
|
||||
...$definition,
|
||||
schema: {
|
||||
...$definition.schema,
|
||||
[newName]: {
|
||||
...existingColumnDefinition,
|
||||
name: newName,
|
||||
schema: {
|
||||
...existingColumnDefinition.schema,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
onMount(() => subscribe("close-edit-column", cancelEdit))
|
||||
</script>
|
||||
|
||||
|
@ -192,6 +221,13 @@
|
|||
>
|
||||
Edit column
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
icon="Duplicate"
|
||||
on:click={duplicateColumn}
|
||||
disabled={!$config.canEditColumns}
|
||||
>
|
||||
Duplicate column
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
icon="Label"
|
||||
on:click={makeDisplayColumn}
|
||||
|
|
Loading…
Reference in New Issue