Skip to content

Commit 6105882

Browse files
fix(dashboard): address review feedback on RestoreJob views
- Replace rename-only wording on spec.targetApplicationRef form labels so users discover that the field also supports restoring into a different application, not just renaming. - Drop VMInstance-specific keys from the spec.options form label; the restore options are driver-specific, so hardcoding one driver's keys is misleading once other drivers land. - Render a single "Same as backup" fallback for an omitted spec.targetApplicationRef on the details page instead of the noisy "-.-/-" produced by concatenating three missing path fallbacks. - De-duplicate the time-block / time-icon / time-value component IDs within the restorejob-details factory by prefixing them with created-, started-at-, and completed-at-. - Mark non-CRD-backed stock-project-factory-*-details sidebars (kube-*, plan, backupjob, backup, restorejob) as static in upsertMultipleSidebars so they pick up consistent managed-by labels instead of being left unmanaged. Signed-off-by: Myasnikov Daniil <[email protected]>
1 parent 310b0ec commit 6105882

2 files changed

Lines changed: 38 additions & 23 deletions

File tree

‎internal/controller/dashboard/sidebar.go‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,12 @@ func (m *Manager) ensureSidebar(ctx context.Context, crd *cozyv1alpha1.Applicati
281281
"stock-instance-builtin-table",
282282
}
283283

284-
// Add details sidebars for all CRDs with dashboard config
284+
// Add details sidebars for all CRDs with dashboard config, and collect
285+
// the set of IDs that are genuinely CRD-backed (dynamic). The hardcoded
286+
// `-details` IDs above (e.g. kube-* and backup/backupjob/plan/restorejob)
287+
// are not tied to an ApplicationDefinition and must be treated as static
288+
// so they receive consistent labels via upsertMultipleSidebars().
289+
dynamicDetailsIDs := map[string]bool{}
285290
for i := range all {
286291
def := &all[i]
287292
if def.Spec.Dashboard == nil {
@@ -291,17 +296,22 @@ func (m *Manager) ensureSidebar(ctx context.Context, crd *cozyv1alpha1.Applicati
291296
lowerKind := strings.ToLower(kind)
292297
detailsID := fmt.Sprintf("stock-project-factory-%s-details", lowerKind)
293298
targetIDs = append(targetIDs, detailsID)
299+
dynamicDetailsIDs[detailsID] = true
294300
}
295301

296302
// 7) Upsert all target sidebars with identical menuItems and keysAndTags
297-
return m.upsertMultipleSidebars(ctx, crd, targetIDs, keysAndTags, menuItems)
303+
return m.upsertMultipleSidebars(ctx, crd, targetIDs, dynamicDetailsIDs, keysAndTags, menuItems)
298304
}
299305

300306
// upsertMultipleSidebars creates/updates several Sidebar resources with the same menu spec.
307+
// dynamicDetailsIDs identifies `stock-project-factory-<kind>-details` sidebars that are
308+
// backed by an ApplicationDefinition and should therefore be owned by that CRD.
309+
// Any other ID is treated as a static sidebar (managed-by labels, no owner ref).
301310
func (m *Manager) upsertMultipleSidebars(
302311
ctx context.Context,
303312
crd *cozyv1alpha1.ApplicationDefinition,
304313
ids []string,
314+
dynamicDetailsIDs map[string]bool,
305315
keysAndTags map[string]any,
306316
menuItems []any,
307317
) error {
@@ -317,8 +327,10 @@ func (m *Manager) upsertMultipleSidebars(
317327

318328
if _, err := controllerutil.CreateOrUpdate(ctx, m.Client, obj, func() error {
319329
// Only set owner reference for dynamic sidebars (stock-project-factory-{kind}-details)
320-
// Static sidebars (stock-instance-*, stock-project-*) should not have owner references
321-
if strings.HasPrefix(id, "stock-project-factory-") && strings.HasSuffix(id, "-details") {
330+
// that are actually backed by an ApplicationDefinition. Static sidebars — including
331+
// hardcoded details sidebars for built-in/backup resources — must fall through to the
332+
// static-label branch so they're managed consistently.
333+
if strings.HasPrefix(id, "stock-project-factory-") && strings.HasSuffix(id, "-details") && dynamicDetailsIDs[id] {
322334
// This is a dynamic sidebar, set owner reference only if it matches the current CRD
323335
_, _, kind := pickGVK(crd)
324336
lowerKind := strings.ToLower(kind)

‎internal/controller/dashboard/static_refactored.go‎

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -563,14 +563,14 @@ func CreateAllCustomFormsOverrides() []*dashboardv1alpha1.CustomFormsOverride {
563563
createFormItem("metadata.namespace", "Namespace", "text"),
564564
createFormItem("spec.backupRef.name", "Backup", "text"),
565565
// Target application: leave empty to restore into the same application
566-
// as referenced by the selected Backup. Fill all three only to rename
567-
// or restore into a different application.
568-
createFormItem("spec.targetApplicationRef.apiGroup", "Target Application API Group (optional, only for rename)", "text"),
569-
createFormItem("spec.targetApplicationRef.kind", "Target Application Kind (optional, only for rename)", "text"),
570-
createFormItem("spec.targetApplicationRef.name", "Target Application Name (optional, only for rename)", "text"),
571-
// Driver-specific options (key-value editor). Known keys for VMInstance:
572-
// targetNamespace, failIfTargetExists, keepOriginalPVC, keepOriginalIpAndMac.
573-
createFormItem("spec.options", "Options (VMInstance keys: targetNamespace, failIfTargetExists, keepOriginalPVC, keepOriginalIpAndMac)", "object"),
566+
// as referenced by the selected Backup. Fill all three to restore into
567+
// a different application (e.g. rename, or restore into a new target).
568+
createFormItem("spec.targetApplicationRef.apiGroup", "Target Application API Group (optional, used to restore into a different application)", "text"),
569+
createFormItem("spec.targetApplicationRef.kind", "Target Application Kind (optional, used to restore into a different application)", "text"),
570+
createFormItem("spec.targetApplicationRef.name", "Target Application Name (optional, used to restore into a different application)", "text"),
571+
// Driver-specific options (key-value editor). Refer to the backup driver
572+
// documentation for supported keys.
573+
createFormItem("spec.options", "Options (driver-specific key/value pairs)", "object"),
574574
},
575575
"schema": createSchema(map[string]any{
576576
"backupRef": map[string]any{
@@ -2034,20 +2034,20 @@ func CreateAllFactories() []*dashboardv1alpha1.Factory {
20342034
}),
20352035
}),
20362036
antdFlexVertical("meta-created-block", 4, []any{
2037-
antdText("time-label", true, "Created", nil),
2038-
antdFlex("time-block", 6, []any{
2037+
antdText("created-time-label", true, "Created", nil),
2038+
antdFlex("created-time-block", 6, []any{
20392039
map[string]any{
20402040
"type": "antdText",
20412041
"data": map[string]any{
2042-
"id": "time-icon",
2042+
"id": "created-time-icon",
20432043
"text": "🌐",
20442044
},
20452045
},
20462046
map[string]any{
20472047
"type": "parsedText",
20482048
"data": map[string]any{
20492049
"formatter": "timestamp",
2050-
"id": "time-value",
2050+
"id": "created-time-value",
20512051
"text": "{reqsJsonPath[0]['.metadata.creationTimestamp']['-']}",
20522052
},
20532053
},
@@ -2067,7 +2067,10 @@ func CreateAllFactories() []*dashboardv1alpha1.Factory {
20672067
}),
20682068
antdFlexVertical("spec-target-application-ref-block", 4, []any{
20692069
antdText("target-application-ref-label", true, "Target Application", nil),
2070-
parsedText("target-application-ref-value", "{reqsJsonPath[0]['.spec.targetApplicationRef.kind']['-']}.{reqsJsonPath[0]['.spec.targetApplicationRef.apiGroup']['-']}/{reqsJsonPath[0]['.spec.targetApplicationRef.name']['-']}", nil),
2070+
// targetApplicationRef is optional — when absent, the restore targets
2071+
// the same application as the selected Backup. Show a single friendly
2072+
// fallback in that case instead of rendering "-.-/-".
2073+
parsedText("target-application-ref-value", "{reqsJsonPath[0]['.spec.targetApplicationRef.name']['Same as backup']}", nil),
20712074
}),
20722075
antdFlexVertical("spec-options-target-namespace-block", 4, []any{
20732076
antdText("options-target-namespace-label", true, "Target Namespace", nil),
@@ -2087,39 +2090,39 @@ func CreateAllFactories() []*dashboardv1alpha1.Factory {
20872090
}),
20882091
antdFlexVertical("status-started-at-block", 4, []any{
20892092
antdText("started-at-label", true, "Started At", nil),
2090-
antdFlex("time-block", 6, []any{
2093+
antdFlex("started-at-time-block", 6, []any{
20912094
map[string]any{
20922095
"type": "antdText",
20932096
"data": map[string]any{
2094-
"id": "time-icon",
2097+
"id": "started-at-time-icon",
20952098
"text": "🌐",
20962099
},
20972100
},
20982101
map[string]any{
20992102
"type": "parsedText",
21002103
"data": map[string]any{
21012104
"formatter": "timestamp",
2102-
"id": "time-value",
2105+
"id": "started-at-time-value",
21032106
"text": "{reqsJsonPath[0]['.status.startedAt']['-']}",
21042107
},
21052108
},
21062109
}),
21072110
}),
21082111
antdFlexVertical("status-completed-at-block", 4, []any{
21092112
antdText("completed-at-label", true, "Completed At", nil),
2110-
antdFlex("time-block", 6, []any{
2113+
antdFlex("completed-at-time-block", 6, []any{
21112114
map[string]any{
21122115
"type": "antdText",
21132116
"data": map[string]any{
2114-
"id": "time-icon",
2117+
"id": "completed-at-time-icon",
21152118
"text": "🌐",
21162119
},
21172120
},
21182121
map[string]any{
21192122
"type": "parsedText",
21202123
"data": map[string]any{
21212124
"formatter": "timestamp",
2122-
"id": "time-value",
2125+
"id": "completed-at-time-value",
21232126
"text": "{reqsJsonPath[0]['.status.completedAt']['-']}",
21242127
},
21252128
},

0 commit comments

Comments
 (0)