Skip to content

Commit

Permalink
feat(coretabs): add truncate action to drop down
Browse files Browse the repository at this point in the history
  • Loading branch information
wmontgomery committed Aug 25, 2022
1 parent b6a2664 commit 25e334e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
21 changes: 18 additions & 3 deletions apps/studio/src/components/CoreTabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@
</div>
<modal :name="modalName" class="beekeeper-modal vue-dialog sure header-sure" @opened="sureOpened" @closed="sureClosed" @before-open="beforeOpened">
<div class="dialog-content">
<<<<<<< HEAD
<div class="dialog-c-title">Really {{this.titleCaseAction}} <span class="tab-like"><tab-icon :tab="tabIcon" /> {{this.dbElement}}</span>?</div>
=======
<div class="dialog-c-title">Really {{this.dbAction | titleCase}} <span class="tab-like"><tab-icon :tab="tabIcon" /> {{this.dbElement}}</span>?</div>
>>>>>>> 9a65503c (feat(coretabs): add truncate action to drop down)
<p>This change cannot be undone</p>
</div>
<div class="vue-dialog-buttons">
Expand Down Expand Up @@ -126,6 +130,13 @@
},
watch: {
},
filters: {
titleCase: function (value) {
if (!value) return ''
value = value.toString()
return value.charAt(0).toUpperCase() + value.slice(1)
}
},
computed: {
...mapState('tabs', { 'activeTab': 'active'}),
Expand Down Expand Up @@ -199,13 +210,18 @@
this.$nextTick(async() => {
if (this.dbAction.toLowerCase() === 'delete') {
await this.connection.dropElement(dbName, entityType?.toUpperCase(), schema)
// timeout is more about aesthetics so it doesn't refresh the table right away.
setTimeout(() => {
return setTimeout(() => {
this.$store.dispatch('updateTables')
this.$store.dispatch('updateRoutines')
}, 500)
}
if (this.dbAction.toLowerCase() === 'truncate') {
await this.connection.truncateElement(dbName, entityType?.toUpperCase(), schema)
}
})
},
beforeOpened() {
Expand Down Expand Up @@ -237,7 +253,6 @@
}
},
async setActiveTab(tab) {
console.log("setting active tab", tab)
await this.$store.dispatch('tabs/setActive', tab)
},
async addTab(item: OpenTab) {
Expand Down
7 changes: 7 additions & 0 deletions apps/studio/src/mixins/TableListContextMenus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ export default {
this.$root.$emit('deleteDatabaseElement', {item, action: 'delete'})
}
},
{
name: "Truncate",
slug: 'sql-truncate',
handler: ({ item }) => {
this.$root.$emit('deleteDatabaseElement', {item, action: 'truncate'})
}
},
]
}
},
Expand Down
4 changes: 2 additions & 2 deletions apps/studio/tests/integration/lib/db/clients/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ export function runCommonTests(getUtil) {
await prepareTestTable(getUtil())
})

test.only("Should truncate table", async () => {
test("Should truncate table", async () => {
await getUtil().truncateTableTests()
})

test.only("Bad input shouldn't allow table truncate", async () => {
test("Bad input shouldn't allow table truncate", async () => {
await getUtil().badTruncateTableTests()
})
})
Expand Down
Binary file modified dev/sakila.db
Binary file not shown.

0 comments on commit 25e334e

Please sign in to comment.