fix(webui): review settings drop the in-force echo and rewrite the approval hint
This commit is contained in:
4 files changed
+77
-176
No files matched your search
@@ -9,20 +9,21 @@ import { Switch } from "@/components/ui/switch";
|
||||
import { resourcesForPage, useSettingsStore } from "@/stores/settings";
|
||||
import DraftHint from "./DraftHint.vue";
|
||||
import HistoryLink from "./HistoryLink.vue";
|
||||
import { inForceLabel, reviewDialStatus, type ReviewDials } from "./review";
|
||||
|
||||
const KIND = "review-settings";
|
||||
|
||||
interface ReviewDials {
|
||||
precision_gate: boolean;
|
||||
approve_before_post: boolean;
|
||||
}
|
||||
|
||||
const store = useSettingsStore();
|
||||
const { catalog, catalogError } = storeToRefs(store);
|
||||
onMounted(() => Promise.all([store.load(), store.loadConfig()]));
|
||||
onMounted(() => store.load());
|
||||
|
||||
const resources = computed(() => resourcesForPage(catalog.value, "review"));
|
||||
const dials = computed(() => store.drafts[KIND]?.value as ReviewDials | undefined);
|
||||
const error = computed(() => store.pageErrorFor(KIND));
|
||||
// What the daemon has in force, read from the published config projection, so
|
||||
// a draft edit is visibly not yet the effective policy.
|
||||
const status = computed(() => (dials.value ? reviewDialStatus(store.config, dials.value) : undefined));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -44,24 +45,16 @@ const status = computed(() => (dials.value ? reviewDialStatus(store.config, dial
|
||||
>
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Switch id="review-precision" v-model="dials.precision_gate" aria-label="Precision gate" />
|
||||
<span class="text-xs text-fg-subtle">
|
||||
{{ inForceLabel(status?.precision_gate.inForce)
|
||||
}}<template v-if="status?.precision_gate.pending"> · save to apply</template>
|
||||
</span>
|
||||
<DraftHint :kind="KIND" path="precision_gate" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SettingRow
|
||||
label="Approve before posting"
|
||||
for="review-approve"
|
||||
hint="Draft waits for you before it posts."
|
||||
hint="Hold drafted reviews until someone approves them."
|
||||
>
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Switch id="review-approve" v-model="dials.approve_before_post" aria-label="Approve before posting" />
|
||||
<span class="text-xs text-fg-subtle">
|
||||
{{ inForceLabel(status?.approve_before_post.inForce)
|
||||
}}<template v-if="status?.approve_before_post.pending"> · save to apply</template>
|
||||
</span>
|
||||
<DraftHint :kind="KIND" path="approve_before_post" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
import type { ConfigView } from "./types";
|
||||
|
||||
/** The two pr-review dials as the control-plane resource carries them. */
|
||||
export interface ReviewDials {
|
||||
precision_gate: boolean;
|
||||
approve_before_post: boolean;
|
||||
}
|
||||
|
||||
export type ReviewDial = keyof ReviewDials;
|
||||
|
||||
/** One dial's resolved state: what is in force (from the published config
|
||||
* projection) beside the unsaved draft the page is editing. `inForce` is
|
||||
* undefined until the projection arrives, so the page shows "unknown" rather
|
||||
* than inventing a value; `pending` reports a draft edit the save bar has not
|
||||
* written yet. */
|
||||
export interface ReviewDialStatus {
|
||||
inForce: boolean | undefined;
|
||||
draft: boolean;
|
||||
pending: boolean;
|
||||
}
|
||||
|
||||
const DIALS: ReviewDial[] = ["precision_gate", "approve_before_post"];
|
||||
|
||||
/**
|
||||
* reviewDialStatus pairs each dial's effective value with its draft, so the
|
||||
* page can show what is in force beside the control and whether saving would
|
||||
* change it. The projection's `review` block is the layered cfg.Review the
|
||||
* daemon published; the draft is the review-settings resource document.
|
||||
*/
|
||||
export function reviewDialStatus(
|
||||
view: ConfigView | null | undefined,
|
||||
draft: ReviewDials,
|
||||
): Record<ReviewDial, ReviewDialStatus> {
|
||||
const inForce = view?.review;
|
||||
const statuses = {} as Record<ReviewDial, ReviewDialStatus>;
|
||||
for (const dial of DIALS) {
|
||||
const effective = inForce?.[dial];
|
||||
statuses[dial] = {
|
||||
inForce: effective,
|
||||
draft: draft[dial],
|
||||
pending: effective !== undefined && effective !== draft[dial],
|
||||
};
|
||||
}
|
||||
return statuses;
|
||||
}
|
||||
|
||||
/** inForceLabel renders one dial's effective value for the line beside it. */
|
||||
export function inForceLabel(value: boolean | undefined): string {
|
||||
if (value === undefined) return "In force: unknown";
|
||||
return value ? "In force: on" : "In force: off";
|
||||
}
|
||||
Reference in new issue
Block a user