Skip to content

Commit

Permalink
ADD delete context
Browse files Browse the repository at this point in the history
  • Loading branch information
RecuencoJones committed Nov 29, 2022
1 parent 762e3fa commit ca37e20
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 6 deletions.
15 changes: 15 additions & 0 deletions src/background/ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ async function getContextForName(name) {
return context;
}

async function deleteContextWithName(name) {
const db = await getDB();
const index = db.contexts.findIndex((context) => context.name === name);

if (~index) {
db.contexts.splice(index, 1);

await saveDB(db);
}
}

function hoistOrUnshift(array, item, keyOf) {
const index = array.findIndex((i) => keyOf(i) === keyOf(item));

Expand Down Expand Up @@ -87,6 +98,10 @@ function registerIpcHandlers() {
return context;
});

ipcMain.handle('deleteContext', async (event, contextName) => {
await deleteContextWithName(contextName);
});

ipcMain.handle('listResourceType', async (event, contextName, resourceType) => {
const context = await getContextForName(contextName);
const config = await loadKubeConfig(context);
Expand Down
1 change: 1 addition & 0 deletions src/background/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ contextBridge.exposeInMainWorld('api', {
'listClusters',
'listUsers',
'getContext',
'deleteContext',
'saveContext',
'listContexts',
'addRecentView',
Expand Down
58 changes: 52 additions & 6 deletions src/foreground/pages/ListContexts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,26 @@
</nav>
<section class="view">
<h4>{{ $t('page.contexts.choosecontext') }}</h4>
<div v-for="context of contexts" :key="context.name">
<router-link :to="'/contexts/' + context.name"><i class="bi-box" /> {{ context.name }}</router-link>
</div>
<table>
<thead>
<tr>
<th>Name</th>
<th></th>
</tr>
</thead>
<tbody>
<tr v-for="context of contexts" :key="context.name">
<td>
<router-link :to="'/contexts/' + context.name"><i class="bi-box" /> {{ context.name }}</router-link>
</td>
<td class="actions">
<button class="btn btn--text" @click="deleteContext(context)">
<i class="bi-trash" />
</button>
</td>
</tr>
</tbody>
</table>
</section>
</main>
</template>
Expand All @@ -22,10 +39,15 @@ export default {
methods: {
async loadContexts() {
this.contexts = await api.listContexts();
},
async deleteContext(context) {
await api.deleteContext(context.name);
await this.loadContexts();
}
},
mounted() {
this.loadContexts()
this.loadContexts();
}
}
</script>
Expand All @@ -35,8 +57,32 @@ export default {
.view {
padding: 10vh 20vw;
div {
padding: 0.25rem 0;
table {
width: 100%;
border-collapse: collapse;
thead {
th {
text-align: left;
padding: .5rem;
}
}
tbody {
tr {
td {
padding: .5rem;
&.actions {
text-align: right;
.btn {
color: inherit;
}
}
}
}
}
}
}
}
Expand Down

0 comments on commit ca37e20

Please sign in to comment.