Skip to content

Commit

Permalink
can delete plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexErrant committed Aug 23, 2023
1 parent ecedc40 commit 65100cd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
18 changes: 18 additions & 0 deletions app/src/components/pluginsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { type Plugin } from "shared-dom"
import { db } from "../db"
import "ag-grid-community/styles/ag-grid.css"
import "ag-grid-community/styles/ag-theme-alpine.css"
import { throwExp } from "shared"

LicenseManager.setLicenseKey(import.meta.env.VITE_AG_GRID_LICENSE)

Expand Down Expand Up @@ -42,6 +43,23 @@ const columnDefs: Array<ColDef<Plugin>> = [
return <relative-time date={props.data?.updated} />
},
},
{
headerName: "Delete",
cellRenderer: (props: ICellRendererParams<Plugin>) => (
<button
onClick={async () => {
if (props.data?.name != null) {
await db.deletePlugin(props.data.name)
} else {
console.error(props)
throwExp("props.data is null, how did this occur?")
}
}}
>
Delete
</button>
),
},
]

const getRowId = (params: GetRowIdParams<Plugin>) => params.data.name
Expand Down
5 changes: 5 additions & 0 deletions app/src/sqlite/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { type Plugin } from "shared-dom"
import { getDb, getKysely } from "./crsqlite"
import { type Plugin as PluginEntity } from "./database"
import { type PluginName } from "shared"

function entityToDomain(entity: PluginEntity): Plugin {
return {
Expand Down Expand Up @@ -41,4 +42,8 @@ export const pluginCollectionMethods = {
const plugins = await db.selectFrom("plugin").selectAll().execute()
return plugins.map(entityToDomain)
},
deletePlugin: async function (name: PluginName) {
const db = await getKysely()
await db.deleteFrom("plugin").where("name", "=", name).execute()
},
}

0 comments on commit 65100cd

Please sign in to comment.