[HIMA-28] working on breadcrumb

This commit is contained in:
Eraldo Hasanaj
2019-02-12 11:22:49 +01:00
parent 821c9c9eba
commit 2b6189e195

View File

@@ -15,6 +15,7 @@ import {
} from '../actions/product.actions';
import { ItemDTO } from 'dist/cat-service/lib/dtos';
import { getCurrentProcess } from '../../utils/process.util';
import { Search } from '../../models/search.model';
export class ProcessStateModel {
processes: Process[];
@@ -378,7 +379,10 @@ export class ProcessState {
if (!state.processes) {
return;
}
const currentProcess = getCurrentProcess(state.processes);
const currentProcess = this.updateBreadcrumbForCurrentProcess(
getCurrentProcess(state.processes),
payload.query,
'/search-results#start');
if (
currentProcess.search === payload &&
currentProcess.itemsDTO &&
@@ -577,4 +581,37 @@ export class ProcessState {
})
});
}
updateBreadcrumbForCurrentProcess(process: Process, payload: string, path: string) {
const breadcrumbExist = process.breadcrumbs.filter(
(breadcrumb: Breadcrumb) => breadcrumb.name === payload
);
if (breadcrumbExist.length > 0) {
return process;
}
const updatedBreadcrumbs = process.breadcrumbs.map(
(breadcrumb: Breadcrumb) => {
if (breadcrumb.path === path) {
return { name: payload, path: path };
}
return breadcrumb;
}
);
if (updatedBreadcrumbs.length < 1) {
return {
...process,
breadcrumbs: [
...process.breadcrumbs,
{
name: payload,
path: path
}
]
};
}
return {
...process,
breadcrumb: [...updatedBreadcrumbs]
};
}
}