Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NO-TICKET] Define a better return type for defaultMenuLinks #3211

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions packages/ds-healthcare-gov/src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import defaultMenuLinks from './defaultMenuLinks';
export interface Link {
href: string;
label: React.ReactNode;
// TODO: I don't think this is necessary to require - PW
ariaLabel: string;
ariaLabel?: string;
className?: string;
onClick?: (...args: any[]) => any;
}
Expand Down Expand Up @@ -130,7 +129,7 @@ export interface HeaderProps {
export const VARIATION_NAMES = {
LOGGED_IN: 'logged-in',
LOGGED_OUT: 'logged-out',
};
} as const;

/**
* For information about how and when to use this component,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@ export interface DefaultMenuLinkOptions {
languageLinkClassName?: string;
}

export interface DefaultMenuLinksObject {
[VARIATION_NAMES.LOGGED_OUT]: Array<Link | DefaultLink>;
[VARIATION_NAMES.LOGGED_IN]: Array<Link | DefaultLink>;
}

/**
* Default menu links for each header variation.
* Apps can import this method into their app if they need to
* extend the existing default list of menu links.
*/
export function defaultMenuLinks(options: DefaultMenuLinkOptions = {}) {
export function defaultMenuLinks(options: DefaultMenuLinkOptions = {}): DefaultMenuLinksObject {
const {
deConsumer,
subpath = '',
Expand All @@ -44,8 +49,8 @@ export function defaultMenuLinks(options: DefaultMenuLinkOptions = {}) {
const isSpanish = languageMatches('es');

// NOTE: order matters here and links will be displayed in order added to the arrays
const loggedOut = [];
const loggedIn = [];
const loggedOut: Array<Link | DefaultLink> = [];
const loggedIn: Array<Link | DefaultLink> = [];

// Links other than the ones inside this if should need to be explicitly hidden for their
// respective variations. This means the language and login will show even if a custom set
Expand Down Expand Up @@ -95,9 +100,10 @@ export function defaultMenuLinks(options: DefaultMenuLinkOptions = {}) {
});
}

const links = {};
links[VARIATION_NAMES.LOGGED_OUT] = loggedOut;
links[VARIATION_NAMES.LOGGED_IN] = loggedIn;
const links: DefaultMenuLinksObject = {
[VARIATION_NAMES.LOGGED_OUT]: loggedOut,
[VARIATION_NAMES.LOGGED_IN]: loggedIn,
};

return links;
}
Expand Down