-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
maintenance: fixing minor code smells #29706
base: next
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -6,41 +6,37 @@ import { addons } from '@storybook/core/manager-api'; | |
|
||
import Provider from './provider'; | ||
|
||
export class FakeProvider extends Provider { | ||
constructor() { | ||
super(); | ||
|
||
// @ts-expect-error (Converted from ts-ignore) | ||
this.addons = addons; | ||
// @ts-expect-error (Converted from ts-ignore) | ||
this.channel = { | ||
on: () => {}, | ||
once: () => {}, | ||
off: () => {}, | ||
emit: () => {}, | ||
addListener: () => {}, | ||
removeListener: () => {}, | ||
}; | ||
} | ||
export const FakeProvider = () => { | ||
// @ts-expect-error (Converted from ts-ignore) | ||
const addonsInstance = addons; | ||
// @ts-expect-error (Converted from ts-ignore) | ||
const channel = { | ||
on: () => {}, | ||
once: () => {}, | ||
off: () => {}, | ||
emit: () => {}, | ||
addListener: () => {}, | ||
removeListener: () => {}, | ||
}; | ||
|
||
// @ts-expect-error (Converted from ts-ignore) | ||
getElements(type) { | ||
return addons.getElements(type); | ||
} | ||
const getElements = (type: string) => addonsInstance.getElements(type); | ||
|
||
renderPreview() { | ||
return <div>This is from a 'renderPreview' call from FakeProvider</div>; | ||
} | ||
const renderPreview = () => <div>This is from a 'renderPreview' call from FakeProvider</div>; | ||
|
||
// @ts-expect-error (Converted from ts-ignore) | ||
handleAPI(api) { | ||
addons.loadAddons(api); | ||
} | ||
const handleAPI = (api: any) => addonsInstance.loadAddons(api); | ||
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. style: api parameter should be properly typed instead of any |
||
|
||
const getConfig = () => ({}); | ||
|
||
getConfig() { | ||
return {}; | ||
} | ||
} | ||
return ( | ||
<Provider | ||
renderPreview={renderPreview} | ||
getElements={getElements} | ||
handleAPI={handleAPI} | ||
getConfig={getConfig} | ||
/> | ||
); | ||
}; | ||
|
||
export const Centered = styled.div({ | ||
width: '100vw', | ||
|
@@ -51,15 +47,13 @@ export const Centered = styled.div({ | |
flexDirection: 'column', | ||
}); | ||
|
||
export class PrettyFakeProvider extends FakeProvider { | ||
renderPreview(...args: any[]) { | ||
return ( | ||
<Centered> | ||
This is from a 'renderPreview' call from FakeProvider | ||
<hr /> | ||
'renderPreview' was called with: | ||
<pre>{JSON.stringify(args, null, 2)}</pre> | ||
</Centered> | ||
); | ||
} | ||
} | ||
export const PrettyFakeProvider = (props: any) => { | ||
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. style: props should be properly typed instead of any |
||
return ( | ||
<Centered> | ||
This is from a 'renderPreview' call from FakeProvider | ||
<hr /> | ||
'renderPreview' was called with: | ||
<pre>{JSON.stringify(props, null, 2)}</pre> | ||
</Centered> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ const TextStyle = styled.div(({ theme }) => ({ | |
lineHeight: '20px', | ||
margin: 0, | ||
})); | ||
|
||
const Text = styled.div(({ theme }) => ({ | ||
fontSize: theme.typography.size.s2, | ||
lineHeight: '20px', | ||
|
@@ -50,24 +51,31 @@ export const AuthBlock: FC<{ loginUrl: string; id: string }> = ({ loginUrl, id } | |
const [isAuthAttempted, setAuthAttempted] = useState(false); | ||
|
||
const refresh = useCallback(() => { | ||
globalWindow.document.location.reload(); | ||
setAuthAttempted(false); | ||
}, []); | ||
Comment on lines
53
to
55
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. logic: Setting isAuthAttempted to false won't trigger a page refresh. Need to actually reload the page to fetch new data. |
||
|
||
const open = useCallback<React.MouseEventHandler>((e) => { | ||
e.preventDefault(); | ||
const childWindow = globalWindow.open(loginUrl, `storybook_auth_${id}`, 'resizable,scrollbars'); | ||
|
||
// poll for window to close | ||
const timer = setInterval(() => { | ||
if (!childWindow) { | ||
logger.error('unable to access loginUrl window'); | ||
clearInterval(timer); | ||
} else if (childWindow.closed) { | ||
clearInterval(timer); | ||
setAuthAttempted(true); | ||
} | ||
}, 1000); | ||
}, []); | ||
const open = useCallback<React.MouseEventHandler>( | ||
(e) => { | ||
e.preventDefault(); | ||
const childWindow = globalWindow.open( | ||
loginUrl, | ||
`storybook_auth_${id}`, | ||
'resizable,scrollbars' | ||
); | ||
|
||
// poll for window to close | ||
const timer = setInterval(() => { | ||
if (!childWindow) { | ||
logger.error('unable to access loginUrl window'); | ||
clearInterval(timer); | ||
} else if (childWindow.closed) { | ||
clearInterval(timer); | ||
setAuthAttempted(true); | ||
} | ||
}, 1000); | ||
}, | ||
[loginUrl, id] | ||
); | ||
|
||
return ( | ||
<Contained> | ||
|
@@ -79,7 +87,6 @@ export const AuthBlock: FC<{ loginUrl: string; id: string }> = ({ loginUrl, id } | |
this Storybook. | ||
</Text> | ||
<div> | ||
{/* TODO: Make sure this button is working without the deprecated props */} | ||
<Button small gray onClick={refresh}> | ||
<SyncIcon /> | ||
Refresh now | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -278,6 +278,8 @@ const SourceCodeMessage: FC<{ | |
|
||
const LoginRequiredMessage: FC<RefType> = ({ loginUrl, id }) => { | ||
const theme = useTheme(); | ||
const [isLoggedIn, setIsLoggedIn] = useState(false); | ||
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. syntax: useState import is missing from React imports at the top of the file |
||
|
||
const open = useCallback<MouseEventHandler>((e) => { | ||
e.preventDefault(); | ||
const childWindow = globalWindow.open(loginUrl, `storybook_auth_${id}`, 'resizable,scrollbars'); | ||
|
@@ -288,11 +290,15 @@ const LoginRequiredMessage: FC<RefType> = ({ loginUrl, id }) => { | |
clearInterval(timer); | ||
} else if (childWindow.closed) { | ||
clearInterval(timer); | ||
document.location.reload(); | ||
setIsLoggedIn(true); | ||
} | ||
}, 1000); | ||
}, []); | ||
|
||
if (isLoggedIn) { | ||
return <div>Login Successful!</div>; | ||
} | ||
Comment on lines
+298
to
+300
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. style: success message should be styled consistently with other messages using the Message component |
||
|
||
return ( | ||
<Message onClick={open}> | ||
<LockIcon color={theme.color.gold} /> | ||
|
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.
style: Consider using a proper mock object or testing utility instead of ts-expect-error and empty function stubs