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:
Ashley Harrison 2023-03-01 15:59:32 +00:00 committed by GitHub
parent 22aa09d392
commit a534119c44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 4 deletions

View File

@ -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}

View File

@ -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,

View File

@ -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;
};