@@ -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
133190type SourceBadge =
@@ -519,8 +576,20 @@ function ToggleSwitch({
519576}
520577
521578export 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 }
0 commit comments