-
Notifications
You must be signed in to change notification settings - Fork 364
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
refactor: [M3-8783] - Migrate /volumes to Tanstack Router #11154
Changes from all commits
ef8432b
1825a08
1f76c3b
906d1a1
9cd1480
ec44117
b5a73d4
3770439
7faf676
5873b3c
4fe2d4f
e2c3a08
2ab5a69
80bf0d6
c563c83
c5258a8
77490ce
9be5e51
bdfa4dd
af33dbf
e0d9566
5656d01
9062419
403ea72
49f296e
55f909a
748eb0d
8696686
5337929
30938ae
22ca472
3ed5e99
ac19483
6c5c570
8af2e9a
92ace27
a3de9ca
4a39156
6927d90
cc2198e
2d228e2
83103bd
0c09de5
0b0d678
afaaa1d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@linode/manager": Tech Stories | ||
--- | ||
|
||
Migrate `/volumes` to Tanstack router ([#11154](https://github.com/linode/manager/pull/11154)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from 'react'; | ||
|
||
import { TanstackLink } from './TanstackLinks'; | ||
|
||
import type { TanstackLinkComponentProps } from './TanstackLinks'; | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
export const AsButtonPrimary: StoryObj<TanstackLinkComponentProps> = { | ||
render: () => ( | ||
<TanstackLink linkType="primary" to="/"> | ||
Home | ||
</TanstackLink> | ||
), | ||
}; | ||
|
||
export const AsButtonSecondary: StoryObj<TanstackLinkComponentProps> = { | ||
render: () => ( | ||
<TanstackLink linkType="secondary" to="/"> | ||
Home | ||
</TanstackLink> | ||
), | ||
}; | ||
|
||
export const AsLink: StoryObj<TanstackLinkComponentProps> = { | ||
render: () => ( | ||
<TanstackLink linkType="link" to="/"> | ||
Home | ||
</TanstackLink> | ||
), | ||
}; | ||
|
||
const meta: Meta<TanstackLinkComponentProps> = { | ||
parameters: { | ||
tanStackRouter: true, | ||
}, | ||
title: 'Foundations/Link/Tanstack Link', | ||
}; | ||
export default meta; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { Button } from '@linode/ui'; | ||
import { omitProps } from '@linode/ui'; | ||
import { LinkComponent } from '@tanstack/react-router'; | ||
import { createLink } from '@tanstack/react-router'; | ||
import * as React from 'react'; | ||
|
||
import { MenuItem } from 'src/components/MenuItem'; | ||
|
||
import type { ButtonProps, ButtonType } from '@linode/ui'; | ||
import type { LinkProps as TanStackLinkProps } from '@tanstack/react-router'; | ||
|
||
export interface TanstackLinkComponentProps | ||
extends Omit<ButtonProps, 'buttonType' | 'href'> { | ||
linkType: 'link' | ButtonType; | ||
tooltipAnalyticsEvent?: (() => void) | undefined; | ||
tooltipText?: string; | ||
} | ||
|
||
export interface TanStackLinkRoutingProps { | ||
linkType: TanstackLinkComponentProps['linkType']; | ||
params?: TanStackLinkProps['params']; | ||
preload?: TanStackLinkProps['preload']; | ||
search?: TanStackLinkProps['search']; | ||
to: TanStackLinkProps['to']; | ||
} | ||
|
||
const LinkComponent = React.forwardRef< | ||
HTMLButtonElement, | ||
TanstackLinkComponentProps | ||
>((props, ref) => { | ||
const _props = omitProps(props, ['linkType']); | ||
|
||
return <Button component="a" ref={ref} {..._props} />; | ||
abailly-akamai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
|
||
const MenuItemLinkComponent = React.forwardRef< | ||
HTMLButtonElement, | ||
TanstackLinkComponentProps | ||
>((props, ref) => { | ||
const _props = omitProps(props, ['linkType']); | ||
|
||
return <MenuItem component="a" ref={ref} {..._props} />; | ||
}); | ||
|
||
const CreatedLinkComponent = createLink(LinkComponent); | ||
const CreatedMenuItemLinkComponent = createLink(MenuItemLinkComponent); | ||
|
||
/** | ||
* @deprecated | ||
* This is marked as deprecated to discourage usage until the migration is complete. | ||
* While not technically deprecated, these components should not be used anywhere in the app. | ||
* They will be replacing our Links eventually, but have only been introduced early to test their functionality. | ||
*/ | ||
export const TanstackLink: LinkComponent<typeof LinkComponent> = (props) => { | ||
return ( | ||
<CreatedLinkComponent | ||
{...props} | ||
sx={(theme) => ({ | ||
...(props.linkType === 'link' && { | ||
'&:hover': { | ||
textDecoration: 'underline', | ||
}, | ||
fontFamily: theme.font.normal, | ||
fontSize: '0.875rem', | ||
minWidth: 'initial', | ||
padding: 0, | ||
}), | ||
})} | ||
/> | ||
); | ||
}; | ||
|
||
/** | ||
* @deprecated | ||
* This is marked as deprecated to discourage usage until the migration is complete. | ||
* While not technically deprecated, these components should not be used anywhere in the app. | ||
* They will be replacing our Links eventually, but have only been introduced early to test their functionality. | ||
*/ | ||
export const TanstackMenuItemLink: LinkComponent< | ||
typeof MenuItemLinkComponent | ||
> = (props) => { | ||
return <CreatedMenuItemLinkComponent {...props} />; | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note, this component is not in use in this PR - it was introduced while exploring prefetching, which is too early to do during the migration of some feature. I left it in here because it will be helpful in the near future. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @coliu-akamai to answer your question above, both components in this file are marked as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this allows routed components to render properly - should not be needed often