Skip to content

Commit

Permalink
Fix addNavHrefs for CtxSwitcher and TopNavDropDown (#3544)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesDoberer authored Dec 6, 2023
1 parent 2c47dbe commit 4d3f689
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion core/src/TopNavDropDown.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
'getUnsavedChangesModalPromise'
);
let openViewInModal = getContext('openViewInModal');
let addNavHrefForAnchor;
export let addNavHrefForAnchor;
const getNodeSubtitle = () => {};
//TODO refactor
Expand Down
42 changes: 22 additions & 20 deletions core/src/navigation/ContextSwitcher.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -42,35 +42,35 @@
export let defaultLabel;
let preserveSubPathOnSwitch;
let getUnsavedChangesModalPromise = getContext(
'getUnsavedChangesModalPromise'
'getUnsavedChangesModalPromise',
);
let store = getContext('store');
let getTranslation = getContext('getTranslation');
let prevContextSwitcherToggle = false;
let selectedNodePath;
let addNavHrefForAnchor;
export let addNavHrefForAnchor;
let isContextSwitcherDropdownShown;
onMount(async () => {
StateHelpers.doOnStoreChange(
store,
async () => {
const contextSwitcherConfig = LuigiConfig.getConfigValue(
'navigation.contextSwitcher'
'navigation.contextSwitcher',
);
contextSwitcherEnabled = !!contextSwitcherConfig;
if (!contextSwitcherEnabled) {
return;
}
customOptionsRenderer = GenericHelpers.isFunction(
contextSwitcherConfig.customOptionsRenderer
contextSwitcherConfig.customOptionsRenderer,
)
? contextSwitcherConfig.customOptionsRenderer
: undefined;
customSelectedOptionRenderer = GenericHelpers.isFunction(
contextSwitcherConfig.customSelectedOptionRenderer
contextSwitcherConfig.customSelectedOptionRenderer,
)
? contextSwitcherConfig.customSelectedOptionRenderer
: undefined;
Expand All @@ -80,7 +80,7 @@
alwaysShowDropdown =
contextSwitcherConfig.alwaysShowDropdown !== false; // default is true
actions = await LuigiConfig.getConfigValueAsync(
'navigation.contextSwitcher.actions'
'navigation.contextSwitcher.actions',
);
const currentPath = Routing.getCurrentPath();
Expand All @@ -95,14 +95,14 @@
if (
ContextSwitcherHelpers.isContextSwitcherDetailsView(
currentPath,
contextSwitcherConfig.parentNodePath
contextSwitcherConfig.parentNodePath,
)
) {
await setSelectedContext(currentPath);
}
}
},
['navigation.contextSwitcher']
['navigation.contextSwitcher'],
);
RoutingHelpers.addRouteChangeListener((path) => setSelectedContext(path));
Expand Down Expand Up @@ -155,18 +155,18 @@
selectedOption = await ContextSwitcherHelpers.getSelectedOption(
currentPath,
options,
parentNodePath
parentNodePath,
);
selectedLabel = await ContextSwitcherHelpers.getSelectedLabel(
currentPath,
options,
parentNodePath,
fallbackLabelResolver
fallbackLabelResolver,
);
selectedNodePath = await ContextSwitcherHelpers.getSelectedNode(
currentPath,
options,
parentNodePath
parentNodePath,
);
preserveSubPathOnSwitch = conf.preserveSubPathOnSwitch;
}
Expand All @@ -178,18 +178,18 @@
selectedOption = await ContextSwitcherHelpers.getSelectedOption(
currentPath,
options,
parentNodePath
parentNodePath,
);
selectedLabel = await ContextSwitcherHelpers.getSelectedLabel(
currentPath,
options,
parentNodePath,
fallbackLabelResolver
fallbackLabelResolver,
);
selectedNodePath = await ContextSwitcherHelpers.getSelectedNode(
currentPath,
options,
parentNodePath
parentNodePath,
);
}
Expand All @@ -216,7 +216,7 @@
() => {
Routing.navigateTo(path);
},
() => {}
() => {},
);
}
Expand All @@ -229,8 +229,8 @@
Routing.navigateTo(
ContextSwitcherHelpers.getNodePathFromCurrentPath(
option,
selectedOption
)
selectedOption,
),
);
} else {
Routing.navigateTo(option.link);
Expand All @@ -239,7 +239,7 @@
dispatch('toggleDropdownState');
}
},
() => {}
() => {},
);
}
Expand All @@ -261,7 +261,7 @@
<div class="fd-popover__control" on:click|stopPropagation={() => {}}>
{#if addNavHrefForAnchor && selectedOption !== config.defaultLabel}
<a
href={selectedNodePath}
href={selectedOption ? getRouteLink(selectedOption) : undefined}
class="fd-button fd-button--transparent fd-shellbar__button fd-button--menu fd-shellbar__button--menu lui-ctx-switch-menu"
aria-expanded={dropDownStates.contextSwitcherPopover || false}
aria-haspopup="true"
Expand Down Expand Up @@ -350,7 +350,9 @@
{#if !selectedLabel}
{$getTranslation(config.defaultLabel)}
{/if}
{#if selectedLabel} {selectedLabel} {/if}
{#if selectedLabel}
{selectedLabel}
{/if}
</h2>
</div>
</div>
Expand Down

0 comments on commit 4d3f689

Please sign in to comment.