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

refactor: Convert UI files to TS #3475

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
11 changes: 8 additions & 3 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Preview } from '@storybook/react'
import { themes } from '@storybook/theming'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import React from 'react'

import Layout from './Layout'
Expand All @@ -8,6 +9,8 @@ export const parameters = {
actions: { argTypesRegex: '^on[A-Z].*' },
}

const queryClient = new QueryClient()

const localStorageResetDecorator = (Story) => {
window.localStorage.clear()
return <Story />
Expand All @@ -16,9 +19,11 @@ const localStorageResetDecorator = (Story) => {
export const decorators = [
localStorageResetDecorator,
(Story) => (
<Layout>
<Story />
</Layout>
<QueryClientProvider client={queryClient}>
<Layout>
<Story />
</Layout>
</QueryClientProvider>
),
]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useCallback } from 'react'
import { useParams } from 'react-router-dom'

import { useMyContexts, useOwner } from 'services/user'
Expand All @@ -21,6 +22,9 @@ function MyContextSwitcher({ pageName }: MyContextSwitcherProps) {
isLoading,
} = useMyContexts({ provider })
const { data: activeContext } = useOwner({ username: owner })
const memoizedOnLoadMore = useCallback(() => {
hasNextPage && fetchNextPage()
}, [hasNextPage, fetchNextPage])

if (!myContexts || !myContexts?.currentUser) return null

Expand All @@ -44,7 +48,7 @@ function MyContextSwitcher({ pageName }: MyContextSwitcherProps) {
contexts={contexts}
currentUser={currentUser}
isLoading={isLoading}
onLoadMore={() => hasNextPage && fetchNextPage()}
onLoadMore={memoizedOnLoadMore}
/>
</div>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ export default function AdminTable() {
email: user.email,
revoke: (
<>
{/* @ts-expect-error */}
<Button
hook="toggle admin status"
disabled={isUpdatingUser}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ function EmailAddress() {
</p>
)}
<div className="flex gap-1">
{/* @ts-expect-error */}
<Button
hook="update-email"
type="submit"
Expand All @@ -95,7 +94,6 @@ function EmailAddress() {
>
Update
</Button>
{/* @ts-expect-error */}
<Button
type="button"
hook="cancel-email"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function TriggerSyncBanner() {
to={undefined}
hook="backfill-task"
variant="primary"
onClick={mutate}
onClick={() => mutate()}
disabled={false}
>
Enable component analytics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function TriggerSyncBanner() {
to={undefined}
hook="backfill-task"
variant="primary"
onClick={mutate}
onClick={() => mutate()}
disabled={false}
>
Enable flag analytics
Expand Down
1 change: 1 addition & 0 deletions src/shared/AppLink/AppLink.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ AppLink.propTypes = {
// You can find the page name in this file
// https://github.com/codecov/gazebo/blob/main/src/services/navigation/useNavLinks.js
pageName: PropTypes.string.isRequired,
exact: PropTypes.bool,
text: PropTypes.string,
options: PropTypes.object,
activeClassName: PropTypes.string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ const LicenseExpirationModal: React.FC<LicenseExpirationModalArgs> = ({
}
footer={
<div className="flex gap-2">
{/* @ts-expect-error */}
<Button
to={{ pageName: 'generateSelfHostedLicense' }}
showExternalIcon={false}
Expand Down
9 changes: 7 additions & 2 deletions src/shared/ListRepo/ReposTableTeam/ReposTableTeam.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import cs from 'classnames'
import isEmpty from 'lodash/isEmpty'
import PropTypes from 'prop-types'
import { useContext, useMemo, useState } from 'react'
import { useCallback, useContext, useMemo, useState } from 'react'
import { useParams } from 'react-router-dom'

import {
Expand Down Expand Up @@ -175,6 +175,11 @@ const ReposTableTeam = ({ searchValue }: ReposTableTeamProps) => {
owner,
})

const fetchNextPageCallback = useCallback(
() => fetchNextPage(),
[fetchNextPage]
)

const isCurrentUserPartOfOrg = !!reposData?.pages?.[0]?.isCurrentUserPartOfOrg

const tableData = useMemo(() => {
Expand Down Expand Up @@ -266,7 +271,7 @@ const ReposTableTeam = ({ searchValue }: ReposTableTeamProps) => {
<Button
hook="load-more"
isLoading={isFetchingNextPage}
onClick={fetchNextPage}
onClick={fetchNextPageCallback}
to={undefined}
disabled={false}
>
Expand Down
2 changes: 1 addition & 1 deletion src/ui/Avatar/Avatar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function Avatar({ user, border = 'none', ariaLabel, className = '' }) {

Avatar.propTypes = {
user: PropTypes.shape({
username: PropTypes.string.isRequired,
username: PropTypes.string,
avatarUrl: PropTypes.string,
}),
border: PropTypes.oneOf(['light', 'dark', 'none']),
Expand Down
89 changes: 0 additions & 89 deletions src/ui/Button/Button.stories.jsx

This file was deleted.

117 changes: 117 additions & 0 deletions src/ui/Button/Button.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import { type Meta, type StoryObj } from '@storybook/react'

import Button from './Button'

import Icon from '../Icon'

const meta: Meta<typeof Button> = {
title: 'Components/Button',
component: Button,
argTypes: { onClick: { action: 'clicked' } },
}

export default meta

type Story = StoryObj<typeof Button>

export const NormalButton: Story = {
args: {
children: 'Normal button',
variant: 'default',
disabled: false,
},
render: (args) => <Button {...args} />,
}

export const PrimaryButton: Story = {
args: {
children: 'Primary button',
variant: 'primary',
disabled: false,
},
render: (args) => <Button {...args} />,
}

export const DangerButton: Story = {
args: {
children: 'Danger button',
variant: 'danger',
disabled: false,
},
render: (args) => <Button {...args} />,
}

export const DisabledButton: Story = {
args: {
children: 'Disabled button',
disabled: true,
},
render: (args) => <Button {...args} />,
}

export const SecondaryButton: Story = {
args: {
children: 'Secondary button',
variant: 'secondary',
disabled: false,
},
render: (args) => <Button {...args} />,
}

export const PlainButton: Story = {
args: {
children: 'Plain button',
variant: 'plain',
},
render: (args) => <Button {...args} />,
}

export const ListboxButton: Story = {
args: {
children: 'Listbox button',
variant: 'listbox',
},
render: (args) => <Button {...args} />,
}

export const GitHubButton: Story = {
args: {
children: 'GitHub Button',
variant: 'github',
},
render: (args) => <Button {...args} />,
}

export const GitLabButton: Story = {
args: {
children: 'GitLab Button',
variant: 'gitlab',
},
render: (args) => <Button {...args} />,
}

export const BitbucketButton: Story = {
args: {
children: 'Bitbucket Button',
variant: 'bitbucket',
},
render: (args) => <Button {...args} />,
}
export const OktaButton: Story = {
args: {
children: 'Okta Button',
variant: 'okta',
},
render: (args) => <Button {...args} />,
}

export const MixedButton: Story = {
args: {
children: (
<>
Mixed content <Icon name="search" size="sm" />
</>
),
},
render: (args) => <Button {...args} />,
}
19 changes: 0 additions & 19 deletions src/ui/Button/Button.test.jsx → src/ui/Button/Button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,6 @@ describe('Button', () => {
})
})

describe('when rendered without `to` prop', () => {
let mockError

beforeEach(() => {
mockError = vi.fn()
const spy = vi.spyOn(console, 'error')
spy.mockImplementation(mockError)
})

afterEach(() => {
vi.clearAllMocks()
})

it('PropTypes warning is thrown that developers need to provide a hook prop if not using to', () => {
render(<Button>hola</Button>, { wrapper: MemoryRouter })
expect(mockError).toHaveBeenCalledTimes(1)
})
})

describe('when isLoading', () => {
it('disables the button', () => {
render(
Expand Down
Loading
Loading