Skip to content

Commit

Permalink
change breadcrumbs state storage from local to session storage
Browse files Browse the repository at this point in the history
  • Loading branch information
avzz-19 committed Dec 24, 2024
1 parent bbb4e2b commit 4765d53
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/controllers/authenticated/security/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Controller from '@ember/controller';
import type SecurityFileModel from 'irene/models/security/file';
import type { AkBreadcrumbsItemProps } from 'irene/services/ak-breadcrumbs';

export default class AuthenticatedSecurityAnalysisController extends Controller {
export default class AuthenticatedSecurityFileController extends Controller {
declare model: SecurityFileModel;

get breadcrumbs(): AkBreadcrumbsItemProps {
Expand Down
17 changes: 9 additions & 8 deletions app/services/ak-breadcrumbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,11 @@ export default class AkBreadcrumbsService extends Service {
// SCENARIO A: In cases where same route exists in crumbs but with diff models, return fallback or recalculate breadcrumbs
// SCENARIO B: If navigation to a page is from a different route group return fallback or an empty array to allow for regenration;
if (
(routeFrom &&
originCrumbProps?.title &&
routeFromCrumbProps?.title &&
originCrumbProps?.routeGroup !== routeFromCrumbProps?.routeGroup) ||
originRouteHasDiffModelWithSameRouteInCrumbs
routeFrom &&
originCrumbProps?.title &&
routeFromCrumbProps?.title &&
(originCrumbProps?.routeGroup !== routeFromCrumbProps?.routeGroup ||
originRouteHasDiffModelWithSameRouteInCrumbs)
) {
return (
originCrumbProps?.fallbackCrumbs?.map((it) => ({
Expand Down Expand Up @@ -364,7 +364,7 @@ export default class AkBreadcrumbsService extends Service {
items: Partial<AkBreadcrumbsItemProps>[],
route: string
): void {
this.window.localStorage.setItem(
this.window.sessionStorage.setItem(
'lastBreadcrumbsState',
JSON.stringify({
route,
Expand All @@ -384,7 +384,7 @@ export default class AkBreadcrumbsService extends Service {
route: string;
} | null {
return JSON.parse(
this.window.localStorage.getItem('lastBreadcrumbsState') ?? 'null'
this.window.sessionStorage.getItem('lastBreadcrumbsState') ?? 'null'
);
}

Expand Down Expand Up @@ -444,7 +444,8 @@ export default class AkBreadcrumbsService extends Service {
(it.route === routeName ||
this._addIndexToRoute(it.route) === routeName ||
it.route?.includes(String(routeName))) &&
it.models?.join(',') === routeCrumbs?.models?.join(',')
it.models?.join(',') === routeCrumbs?.models?.join(',') &&
it.title === routeCrumbs?.title
)
);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/breadcrumbs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ module('Acceptance | Breadcrumbs Test', function (hooks) {

// Clear breadcrumbs in local storage
this.window = this.owner.lookup('service:browser/window');
this.window.localStorage.removeItem('lastBreadcrumbsState');
this.window.sessionStorage.removeItem('lastBreadcrumbsState');
});

test('forward navigation crumbs generation to registered routes (Root A -> Parent A -> Child A)', async function (assert) {
Expand Down

0 comments on commit 4765d53

Please sign in to comment.