Skip to content

Modular logistics and supply chain operating system (LSOS)

feat: Add navigation history persistence to orchestrator

roncodes11f6d173b78e
diff --git a/console/app/routes/onboard/index.js b/console/app/routes/onboard/index.js
index 16e4b55a..b3000175 100644
--- a/console/app/routes/onboard/index.js
+++ b/console/app/routes/onboard/index.js
@@ -12,7 +12,8 @@ export default class OnboardIndexRoute extends Route {
};
beforeModel() {
- this.orchestrator.start();
+ // Resume from previous session if data exists in localStorage
+ this.orchestrator.start(null, { resume: true });
}
model() {
diff --git a/console/app/services/onboarding-orchestrator.js b/console/app/services/onboarding-orchestrator.js
index fb9fb237..559fb867 100644
--- a/console/app/services/onboarding-orchestrator.js
+++ b/console/app/services/onboarding-orchestrator.js
@@ -12,6 +12,13 @@ export default class OnboardingOrchestratorService extends Service {
@tracked history = [];
@tracked sessionId = null;
+ /**
+ * localStorage key for persisting navigation history
+ */
+ get historyStorageKey() {
+ return `onboarding:history:${this.flow?.id || 'default'}`;
+ }
+
async start(flowId = null, opts = {}) {
const flow = this.onboardingRegistry.getFlow(flowId ?? this.onboardingRegistry.defaultFlow);
if (!flow) throw new Error(`Onboarding flow '${flowId}' not found`);
@@ -21,6 +28,11 @@ export default class OnboardingOrchestratorService extends Service {
this.sessionId = opts.sessionId || null;
this.history = [];
+ // Restore history if resuming from a previous session
+ if (opts.resume) {
+ this._restoreHistory();
+ }
+
// Execute onFlowWillStart hook if defined
if (typeof this.flow.onFlowWillStart === 'function') {
await this.flow.onFlowWillStart(this.flow, this);
@@ -73,7 +85,10 @@ export default class OnboardingOrchestratorService extends Service {
await leaving.afterLeave(this.onboardingContext);
}
- if (!this.history.includes(leaving)) this.history.push(leaving);
+ if (!this.history.includes(leaving)) {
+ this.history.push(leaving);
+ this._persistHistory();
+ }
// Support both string and function for next property
let nextId;
@@ -97,6 +112,9 @@ export default class OnboardingOrchestratorService extends Service {
await this.flow.onFlowDidEnd(leaving, this);
}
+ // Clear history from localStorage when flow completes
+ this._clearHistory();
+
return;
}
@@ -108,6 +126,7 @@ export default class OnboardingOrchestratorService extends Service {
const prev = this.history[this.history.length - 1];
if (prev && prev.allowBack === false) return;
this.history = this.history.slice(0, -1);
+ this._persistHistory();
await this.goto(prev.id);
}
@@ -137,4 +156,59 @@ export default class OnboardingOrchestratorService extends Service {
return currentPath.steps?.some(s => s.id === stepId) ?? false;
}
+
+ /**
+ * Persist navigation history to localStorage
+ * Stores only step IDs to keep storage lightweight
+ * @private
+ */
+ _persistHistory() {
+ if (!this.flow) return;
+
+ try {
+ const historyIds = this.history.map(step => step.id);
+ localStorage.setItem(this.historyStorageKey, JSON.stringify(historyIds));
+ } catch (error) {
+ console.warn('[OnboardingOrchestrator] Failed to persist history:', error);
+ }
+ }
+
+ /**
+ * Restore navigation history from localStorage
+ * Reconstructs step objects from stored IDs
+ * @private
+ */
+ _restoreHistory() {
+ if (!this.flow) return;
+
+ try {
+ const stored = localStorage.getItem(this.historyStorageKey);
+ if (!stored) return;
+
+ const historyIds = JSON.parse(stored);
+ this.history = historyIds
+ .map(id => this.flow.steps.find(s => s.id === id))
+ .filter(Boolean); // Remove any invalid steps
+
+ console.log('[OnboardingOrchestrator] Restored history:', this.history.map(s => s.id));
+ } catch (error) {
+ console.warn('[OnboardingOrchestrator] Failed to restore history:', error);
+ this.history = [];
+ }
+ }
+
+ /**
+ * Clear navigation history from localStorage
+ * Called when flow completes or is reset
+ * @private
+ */
+ _clearHistory() {
+ if (!this.flow) return;
+
+ try {
+ localStorage.removeItem(this.historyStorageKey);
+ } catch (error) {
+ console.warn('[OnboardingOrchestrator] Failed to clear history:', error);
+ }
+ }
}