Skip to content

Commit 1695b93

Browse files
feat: use checkbox for rule endpoints
1 parent 1782991 commit 1695b93

File tree

3 files changed

+61
-55
lines changed

3 files changed

+61
-55
lines changed

internal/repo/rule.go

+4
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ func RuleEndpointsSet(ctx context.Context, db database.Querier, ruleID int64, en
154154
}
155155

156156
func ruleEndpointsSet(ctx context.Context, db database.QuerierTx, now models.Time, ruleID int64, endpointIDs []int64) error {
157+
if len(endpointIDs) == 0 {
158+
return nil
159+
}
160+
157161
stmt := RulesToEndpoints.
158162
INSERT(
159163
RulesToEndpoints.Internal,

web/components/rule_form.templ

+20-18
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,17 @@ templ RuleFormCreate(props RuleFormCreateProps) {
4343
})
4444
</label>
4545
</div>
46-
<div class="form-control">
47-
<label class="label">
48-
<span class="label-text">Endpoints</span>
49-
</label>
50-
<select name="endpoints" class="select select-bordered" multiple>
51-
for i, end := range props.Endpoints {
52-
<option value={ strconv.FormatInt(end.ID, 10) } selected?={ props.EndpointsSelections[i] }>{ end.Name }</option>
53-
}
54-
</select>
55-
</div>
46+
<fieldset>
47+
<legend>Endpoints</legend>
48+
for i, end := range props.Endpoints {
49+
<div class="form-control">
50+
<label class="cursor-pointer label">
51+
<span class="label-text">{ end.Name }</span>
52+
<input type="checkbox" class="toggle" name="endpoints" value={ strconv.FormatInt(end.ID, 10) } checked?={ props.EndpointsSelections[i] } />
53+
</label>
54+
</div>
55+
}
56+
</fieldset>
5657
<button type="submit" class="btn btn-primary btn-block">Create Rule</button>
5758
if props.Flash != nil {
5859
{! props.Flash }
@@ -95,16 +96,17 @@ templ RuleFormUpdate(props RuleFormUpdateProps) {
9596
@RuleExpressionCheckLabel(RuleExpressionLabelProps{Error: props.ExpressionError})
9697
</label>
9798
</div>
98-
<div class="form-control">
99-
<label class="label">
100-
<span class="label-text">Endpoints</span>
101-
</label>
102-
<select disabled?={ props.Rule.Internal } name="endpoints" class="select select-bordered" multiple>
99+
<fieldset>
100+
<legend class="label-text">Endpoints</legend>
103101
for i, end := range props.Endpoints {
104-
<option value={ strconv.FormatInt(end.ID, 10) } selected?={ props.EndpointsSelections[i] }>{ end.Name }</option>
102+
<div class="form-control">
103+
<label class="cursor-pointer label">
104+
<span class="label-text">{ end.Name }</span>
105+
<input disabled?={ props.Rule.Internal } type="checkbox" class="toggle" name="endpoints" value={ strconv.FormatInt(end.ID, 10) } checked?={ props.EndpointsSelections[i] } />
106+
</label>
107+
</div>
105108
}
106-
</select>
107-
</div>
109+
</fieldset>
108110
<button disabled?={ props.Rule.Internal } type="submit" class="btn btn-primary btn-block">Update Rule</button>
109111
if props.Flash != nil {
110112
{! props.Flash }

web/components/rule_form_templ.go

+37-37
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)