mirror of
https://github.com/grafana/grafana.git
synced 2025-01-15 19:22:34 -06:00
Command Palette: Sign out link now works correctly (#63742)
* pass target to command palette urls so sign out link works correctly * improve types
This commit is contained in:
parent
22aa09d392
commit
a534119c44
@ -155,13 +155,16 @@ export const KBarResults: React.FC<KBarResultsProps> = (props) => {
|
||||
}}
|
||||
>
|
||||
{rowVirtualizer.virtualItems.map((virtualRow) => {
|
||||
const item = itemsRef.current[virtualRow.index];
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
const item = itemsRef.current[virtualRow.index] as ActionImpl & {
|
||||
url?: string;
|
||||
target?: React.HTMLAttributeAnchorTarget;
|
||||
};
|
||||
|
||||
// ActionImpl constructor copies all properties from action onto ActionImpl
|
||||
// so our url property is secretly there, but completely untyped
|
||||
// Preferably this change is upstreamed and ActionImpl has this
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
const url = (item as ActionImpl & { url?: string }).url;
|
||||
const { target, url } = item;
|
||||
|
||||
const handlers = typeof item !== 'string' && {
|
||||
onPointerMove: () =>
|
||||
@ -200,6 +203,7 @@ export const KBarResults: React.FC<KBarResultsProps> = (props) => {
|
||||
<a
|
||||
key={virtualRow.index}
|
||||
href={url}
|
||||
target={target}
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
ref={active ? (activeRef as React.RefObject<HTMLAnchorElement>) : null}
|
||||
{...childProps}
|
||||
|
@ -14,7 +14,7 @@ function navTreeToActions(navTree: NavModelItem[], parents: NavModelItem[] = [])
|
||||
const navActions: CommandPaletteAction[] = [];
|
||||
|
||||
for (const navItem of navTree) {
|
||||
const { url, text, isCreateAction, children } = navItem;
|
||||
const { url, target, text, isCreateAction, children } = navItem;
|
||||
const hasChildren = Boolean(children?.length);
|
||||
|
||||
if (!(url || hasChildren)) {
|
||||
@ -33,6 +33,7 @@ function navTreeToActions(navTree: NavModelItem[], parents: NavModelItem[] = [])
|
||||
name: text,
|
||||
section: section,
|
||||
url: url && locationUtil.stripBaseFromUrl(url),
|
||||
target,
|
||||
parent: parents.length > 0 && !isCreateAction ? idForNavItem(parents[parents.length - 1]) : undefined,
|
||||
priority: priority,
|
||||
subtitle: isCreateAction ? undefined : subtitle,
|
||||
|
@ -9,11 +9,13 @@ export type CommandPaletteAction = RootCommandPaletteAction | ChildCommandPalett
|
||||
type RootCommandPaletteAction = Omit<Action, 'parent'> & {
|
||||
section: NotNullable<Action['section']>;
|
||||
priority: NotNullable<Action['priority']>;
|
||||
target?: React.HTMLAttributeAnchorTarget;
|
||||
url?: string;
|
||||
};
|
||||
|
||||
type ChildCommandPaletteAction = Action & {
|
||||
parent: NotNullable<Action['parent']>;
|
||||
priority: NotNullable<Action['priority']>;
|
||||
target?: React.HTMLAttributeAnchorTarget;
|
||||
url?: string;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user