@volo/ngx-lepton-x.core 5.0.2 → 5.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1180,6 +1180,9 @@ class NavbarService {
1180
1180
  this.menuItems = inject(LPX_MENU_ITEMS);
1181
1181
  this.store = new DataStore(this.addContainerLinks(this.menuItems));
1182
1182
  this.navbarItems$ = this.store.sliceState((state) => state);
1183
+ // Source reference to navbar items, used for checking item existence
1184
+ // without being affected by potential future transformations of navbarItems$
1185
+ this.sourceNavbarItems$ = this.navbarItems$;
1183
1186
  this.groupedNavbarItems$ = this.store
1184
1187
  .sliceState((state) => state)
1185
1188
  .pipe(map((items) => {
@@ -1200,28 +1203,31 @@ class NavbarService {
1200
1203
  setNavbarItems(...menuItems) {
1201
1204
  this.store.set([...this.addContainerLinks(menuItems)]);
1202
1205
  }
1203
- // TODO: muhammed: refactor this method to be readable
1204
1206
  addChildren(id, ...menuItems) {
1205
1207
  const parent = this.findById(id, this.store.state);
1206
1208
  const update = (items, location, link = '') => {
1207
- const i = location.shift();
1209
+ const [currentIndex, ...remainingPath] = location;
1208
1210
  return items.reduce((acc, item, index) => {
1209
- return [
1210
- ...acc,
1211
- ...(index === i
1212
- ? [
1213
- {
1214
- ...item,
1215
- children: !location.length
1216
- ? [
1217
- ...(item.children || []),
1218
- ...this.addContainerLinks(menuItems, `${link}/${item.containerLink}`),
1219
- ]
1220
- : update(item.children || [], location, `${link}/${item.containerLink}`),
1221
- },
1222
- ]
1223
- : [item]),
1224
- ];
1211
+ if (index === currentIndex) {
1212
+ const containerLink = item.containerLink || '';
1213
+ const childLink = `${link}/${containerLink}`;
1214
+ const isTargetParent = remainingPath.length === 0;
1215
+ let updatedChildren = update(item.children || [], remainingPath, childLink);
1216
+ if (isTargetParent) {
1217
+ updatedChildren = [
1218
+ ...(item.children || []),
1219
+ ...this.addContainerLinks(menuItems, childLink),
1220
+ ];
1221
+ }
1222
+ return [
1223
+ ...acc,
1224
+ {
1225
+ ...item,
1226
+ children: updatedChildren,
1227
+ },
1228
+ ];
1229
+ }
1230
+ return [...acc, item];
1225
1231
  }, []);
1226
1232
  };
1227
1233
  const updated = update(this.store.state, parent.location);
@@ -1685,7 +1691,7 @@ class NavbarComponent {
1685
1691
  this.injector = inject(Injector);
1686
1692
  this.didResized = false;
1687
1693
  this.initialHover = false;
1688
- this.showFilterMenu$ = this.service.navbarItems$.pipe(map$1((items) => !!items.length));
1694
+ this.showFilterMenu$ = this.service.sourceNavbarItems$.pipe(map$1((items) => !!items.length));
1689
1695
  this.contentBefore = this.flatContents(CONTENT_BEFORE_ROUTES);
1690
1696
  this.contentAfter = this.flatContents(CONTENT_AFTER_ROUTES);
1691
1697
  }