Skip to content

Commit 2e39162

Browse files
committed
feat(console): clear the value saved beneath an env pin in Setup
A settings field an OS_* variable pins now offers, when a value is stored beneath the pin at the scope the page writes, a confirmed control that clears that saved value; the environment value stays in force. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibzzesuj1TsQQD4hQjM
1 parent 41dc302 commit 2e39162

13 files changed

Lines changed: 431 additions & 3 deletions

File tree

‎ui/apps/console/src/pages/settings/SettingsField.tsx‎

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,63 @@ export interface SettingsFieldProps {
128128
* not (the first-run checklist) keeps the badges a lower scope would see.
129129
*/
130130
writeScope?: SpecifierScope;
131+
/**
132+
* Clears the value stored beneath an env pin (objectstack#30665): the page
133+
* writes `null` for this key, the one write the server lets through a pin
134+
* (ADR-0007 D6). Offered only where {@link storedBeneathPin} holds, so a
135+
* host that does not pass it, or a row with nothing stored, shows nothing.
136+
*/
137+
onClearSaved?: () => void;
138+
}
139+
140+
/**
141+
* Whether a value is stored beneath the env pin at the scope this row writes,
142+
* the one a clear would null (objectstack#30665). Read off the server's
143+
* `cascadeChain` alone: the namespace read lists the stored cascade beneath an
144+
* in-force `env` entry, a secret's entries as the read mask or `null`. Nothing
145+
* stored, or stored only at another scope, is no control: a clear here could
146+
* not remove it.
147+
*/
148+
export function storedBeneathPin(
149+
resolved: ResolvedSettingValue | undefined,
150+
writeScope: SpecifierScope | undefined,
151+
): boolean {
152+
if (!resolved?.locked || resolved.source !== 'env' || !writeScope) return false;
153+
return (resolved.cascadeChain ?? []).some(
154+
(entry) => entry.scope === writeScope && entry.value !== null && entry.value !== undefined,
155+
);
156+
}
157+
158+
/**
159+
* The line and control under a pinned row that has a value stored beneath the
160+
* pin (objectstack#30665). The wording clears the saved value, never deletes
161+
* it, and says the environment value stays in force; the clear asks first,
162+
* because it writes at once rather than through the page's draft.
163+
*/
164+
function ClearSavedBeneathPin({ onClear, disabled }: { onClear: () => void; disabled?: boolean }) {
165+
const { t } = useObjectTranslation();
166+
return (
167+
<div className="flex items-center justify-between gap-3 mt-1" data-testid="settings-saved-beneath-pin">
168+
<p className="text-xs text-muted-foreground">{t('console.settingsView.savedBeneathPin')}</p>
169+
<AlertDialog>
170+
<AlertDialogTrigger asChild>
171+
<Button type="button" variant="outline" size="sm" className="h-7 shrink-0 text-xs" disabled={disabled}>
172+
{t('console.settingsView.clearSaved')}
173+
</Button>
174+
</AlertDialogTrigger>
175+
<AlertDialogContent>
176+
<AlertDialogHeader>
177+
<AlertDialogTitle>{t('console.settingsView.clearSaved')}</AlertDialogTitle>
178+
<AlertDialogDescription>{t('console.settingsView.clearSavedConfirm')}</AlertDialogDescription>
179+
</AlertDialogHeader>
180+
<AlertDialogFooter>
181+
<AlertDialogCancel>{t('actionConfirm.cancel')}</AlertDialogCancel>
182+
<AlertDialogAction onClick={onClear}>{t('console.settingsView.clearSaved')}</AlertDialogAction>
183+
</AlertDialogFooter>
184+
</AlertDialogContent>
185+
</AlertDialog>
186+
</div>
187+
);
131188
}
132189

133190
type SourceBadge =
@@ -519,8 +576,20 @@ function ToggleSwitch({
519576
}
520577

521578
export function SettingsField(props: SettingsFieldProps) {
522-
const { spec, resolved, value, onChange, onAction, locked, saving, labels, error, note, writeScope } =
523-
props;
579+
const {
580+
spec,
581+
resolved,
582+
value,
583+
onChange,
584+
onAction,
585+
locked,
586+
saving,
587+
labels,
588+
error,
589+
note,
590+
writeScope,
591+
onClearSaved,
592+
} = props;
524593
const id = useId();
525594
const { t, language } = useObjectTranslation();
526595
const disabled = Boolean(locked || saving);
@@ -691,6 +760,11 @@ export function SettingsField(props: SettingsFieldProps) {
691760
// control is a group that names itself from `labelId` instead.
692761
// A value already cleared in the draft has nothing left to reset.
693762
const onReset = value === null ? undefined : () => onChange(null);
763+
// The clear beneath an env pin, where a value is stored at this row's scope.
764+
const clearSaved =
765+
onClearSaved && storedBeneathPin(resolved, writeScope) ? (
766+
<ClearSavedBeneathPin onClear={onClearSaved} disabled={saving} />
767+
) : null;
694768
// `data-settings-key` lets the page find this row to focus it when a save is
695769
// blocked on it (objectui#13239).
696770
const wrapper = (children: React.ReactNode, labelFor: string | undefined = id) => (
@@ -723,6 +797,7 @@ export function SettingsField(props: SettingsFieldProps) {
723797
{note}
724798
</p>
725799
) : null}
800+
{clearSaved}
726801
</div>
727802
);
728803

@@ -832,6 +907,7 @@ export function SettingsField(props: SettingsFieldProps) {
832907
) : (
833908
<FieldDescription description={fieldHelp} />
834909
)}
910+
{clearSaved}
835911
</div>
836912
<ToggleSwitch
837913
id={id}

‎ui/apps/console/src/pages/settings/SettingsView.tsx‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
* Fetches manifest+values from `/api/settings/:namespace`, lays them
55
* out via <SettingsField>, tracks dirty state, and saves through PUT.
66
* A successful save or action reads the namespace again, manifest included.
7-
* Env-locked fields are read-only and show <EnvLockBadge>.
7+
* Env-locked fields are read-only and show <EnvLockBadge>; one with a value
8+
* stored beneath the pin offers to clear that saved value.
89
*/
910

1011
import { useEffect, useMemo, useRef, useState } from 'react';
@@ -596,6 +597,30 @@ export function SettingsView() {
596597
}
597598
};
598599

600+
/**
601+
* Clear the value stored beneath an env pin (objectstack#30665): `null` for
602+
* this one key, the write the server lets through a pin (ADR-0007 D6). It
603+
* writes at once, after the row's own confirm, and leaves the draft alone: the
604+
* row cannot be edited, so the clear is not one of the page's edits. The pin
605+
* still answers the key, so the row reads the env value before and after.
606+
*/
607+
const onClearSaved = async (key: string) => {
608+
setSaving(true);
609+
try {
610+
const res = await saveSettingsNamespace(namespace, { [key]: null });
611+
setPayload({ ...payload, values: { ...values, ...res.values } });
612+
toast.success(t('console.settingsView.savedCleared'));
613+
void reread(namespace);
614+
} catch (err: any) {
615+
// The pin itself never refuses a clear, so a refusal here is something
616+
// else (a lock a stored row carries, a 403): the server's sentence says
617+
// which, and `lockedByEnv` would misname it.
618+
toast.error(err?.message ?? t('console.settingsView.saveFailed'));
619+
} finally {
620+
setSaving(false);
621+
}
622+
};
623+
599624
const onAction = async (actionId: string) => {
600625
setSaving(true);
601626
try {
@@ -734,6 +759,7 @@ export function SettingsView() {
734759
// The scope the server writes this key at: the specifier's
735760
// own, else the manifest's, else the spec's default `tenant`.
736761
writeScope={spec.scope ?? manifest.scope ?? 'tenant'}
762+
onClearSaved={key ? () => onClearSaved(key) : undefined}
737763
/>
738764
);
739765
})}

0 commit comments

Comments
 (0)