Skip to content

Commit

Permalink
feat: add edit functionality for dataset rules
Browse files Browse the repository at this point in the history
  • Loading branch information
kahosan committed Dec 9, 2024
1 parent 8a6588c commit d76bb6e
Showing 1 changed file with 46 additions and 4 deletions.
50 changes: 46 additions & 4 deletions src/entrypoints/options/components/Dataset.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<script lang="ts">
import { rules } from '../store'
import { Button } from '$lib/components/ui/button'
import { TrashIcon } from 'lucide-svelte'
import { Input } from '$lib/components/ui/input';
import { CheckIcon, EditIcon, TrashIcon } from 'lucide-svelte'
import {
Table,
TableBody,
Expand All @@ -13,6 +14,16 @@
import { uniqBy } from 'lodash-es'
import { toast } from 'svelte-sonner'
let edit: null | number = null
function changeEdit(index: number) {
if (edit === index) {
edit = null
} else {
edit = index
}
}
function deleteRule(index: number) {
$rules = $rules.filter((_, i) => i !== index)
}
Expand Down Expand Up @@ -64,9 +75,40 @@
<TableBody>
{#each $rules as rule, index (index)}
<TableRow>
<TableCell>{rule.from}</TableCell>
<TableCell>{rule.to}</TableCell>
<TableCell class="text-right">
<TableCell>
{#if edit === index}
<Input
type="text"
class="w-full"
bind:value={rule.from}
/>
{:else}
{rule.from}
{/if}
</TableCell>
<TableCell>
{#if edit === index}
<Input
type="text"
class="w-full"
bind:value={rule.to}
/>
{:else}
{rule.to}
{/if}
</TableCell>
<TableCell class="text-right space-x-2">
<Button
variant="default"
size="icon"
on:click={() => changeEdit(index)}
>
{#if edit === index}
<CheckIcon class="h-4 w-4" />
{:else}
<EditIcon class="h-4 w-4" />
{/if}
</Button>
<Button
variant="destructive"
size="icon"
Expand Down

0 comments on commit d76bb6e

Please sign in to comment.