feat(frontend): add activate/deactivate toggle for tag rules
- Toggle button (filled/hollow circle) on each rule row - Inactive rules dim to 45% opacity - Toggle via delete + recreate with new is_active value - Mock: track is_active per rule (Map instead of Set) - Show all available tags by default in add-rule picker Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -57,6 +57,27 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function toggleRule(rule: TagRule) {
|
||||
if (busy) return;
|
||||
busy = true;
|
||||
error = '';
|
||||
const thenTagId = rule.then_tag_id!;
|
||||
const newActive = !rule.is_active;
|
||||
try {
|
||||
await api.delete(`/tags/${tagId}/rules/${thenTagId}`);
|
||||
const updated = await api.post<TagRule>(`/tags/${tagId}/rules`, {
|
||||
then_tag_id: thenTagId,
|
||||
is_active: newActive,
|
||||
apply_to_existing: false,
|
||||
});
|
||||
onRulesChange(rules.map((r) => r.then_tag_id === thenTagId ? updated : r));
|
||||
} catch (e) {
|
||||
error = e instanceof ApiError ? e.message : 'Failed to update rule';
|
||||
} finally {
|
||||
busy = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function removeRule(thenTagId: string) {
|
||||
if (busy) return;
|
||||
busy = true;
|
||||
@@ -86,12 +107,30 @@
|
||||
<div class="rule-list">
|
||||
{#each rules as rule (rule.then_tag_id)}
|
||||
{@const t = tagForId(rule.then_tag_id)}
|
||||
<div class="rule-row">
|
||||
<div class="rule-row" class:inactive={!rule.is_active}>
|
||||
{#if t}
|
||||
<TagBadge tag={t} size="sm" />
|
||||
{:else}
|
||||
<span class="unknown">{rule.then_tag_name ?? rule.then_tag_id}</span>
|
||||
{/if}
|
||||
<button
|
||||
class="toggle-btn"
|
||||
class:active={rule.is_active}
|
||||
onclick={() => toggleRule(rule)}
|
||||
title={rule.is_active ? 'Deactivate rule' : 'Activate rule'}
|
||||
aria-label={rule.is_active ? 'Deactivate rule' : 'Activate rule'}
|
||||
>
|
||||
{#if rule.is_active}
|
||||
<svg width="12" height="12" viewBox="0 0 12 12" fill="none" aria-hidden="true">
|
||||
<circle cx="6" cy="6" r="5" stroke="currentColor" stroke-width="1.5"/>
|
||||
<circle cx="6" cy="6" r="2.5" fill="currentColor"/>
|
||||
</svg>
|
||||
{:else}
|
||||
<svg width="12" height="12" viewBox="0 0 12 12" fill="none" aria-hidden="true">
|
||||
<circle cx="6" cy="6" r="5" stroke="currentColor" stroke-width="1.5"/>
|
||||
</svg>
|
||||
{/if}
|
||||
</button>
|
||||
<button
|
||||
class="remove-btn"
|
||||
onclick={() => removeRule(rule.then_tag_id!)}
|
||||
@@ -107,22 +146,29 @@
|
||||
<!-- Add rule -->
|
||||
<div class="add-section">
|
||||
<div class="section-label">Add rule</div>
|
||||
<input
|
||||
class="search"
|
||||
type="search"
|
||||
placeholder="Search tags to add…"
|
||||
bind:value={search}
|
||||
autocomplete="off"
|
||||
/>
|
||||
{#if search.trim()}
|
||||
<div class="tag-pick">
|
||||
{#each filteredTags as t (t.id)}
|
||||
<TagBadge tag={t} size="sm" onclick={() => addRule(t.id!)} />
|
||||
{:else}
|
||||
<span class="empty">No matching tags</span>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
<div class="search-wrap">
|
||||
<input
|
||||
class="search"
|
||||
type="search"
|
||||
placeholder="Search tags to add…"
|
||||
bind:value={search}
|
||||
autocomplete="off"
|
||||
/>
|
||||
{#if search}
|
||||
<button class="search-clear" onclick={() => (search = '')} aria-label="Clear search">
|
||||
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" aria-hidden="true">
|
||||
<path d="M2 2l10 10M12 2L2 12" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/>
|
||||
</svg>
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="tag-pick">
|
||||
{#each filteredTags as t (t.id)}
|
||||
<TagBadge tag={t} size="sm" onclick={() => addRule(t.id!)} />
|
||||
{:else}
|
||||
<span class="empty">{search.trim() ? 'No matching tags' : 'All tags already added'}</span>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -157,6 +203,31 @@
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.rule-row.inactive {
|
||||
opacity: 0.45;
|
||||
}
|
||||
|
||||
.toggle-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: none;
|
||||
border: none;
|
||||
color: var(--color-text-muted);
|
||||
cursor: pointer;
|
||||
padding: 2px 3px;
|
||||
border-radius: 3px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.toggle-btn.active {
|
||||
color: var(--color-accent);
|
||||
}
|
||||
|
||||
.toggle-btn:hover {
|
||||
color: var(--color-text-primary);
|
||||
}
|
||||
|
||||
.remove-btn {
|
||||
background: none;
|
||||
border: none;
|
||||
@@ -193,6 +264,12 @@
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.search-wrap {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.search {
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
@@ -211,6 +288,27 @@
|
||||
border-color: var(--color-accent);
|
||||
}
|
||||
|
||||
.search-clear {
|
||||
position: absolute;
|
||||
right: 6px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border-radius: 50%;
|
||||
border: none;
|
||||
background: none;
|
||||
color: var(--color-text-muted);
|
||||
cursor: pointer;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.search-clear:hover {
|
||||
color: var(--color-text-primary);
|
||||
background-color: color-mix(in srgb, var(--color-accent) 20%, transparent);
|
||||
}
|
||||
|
||||
.tag-pick {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
|
||||
Reference in New Issue
Block a user