Skip to content

Commit

Permalink
Upgrade prettier to 2.7.1 (streamlit#5455)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-kbregula authored Oct 4, 2022
1 parent eb12acb commit 7550b6e
Show file tree
Hide file tree
Showing 96 changed files with 2,804 additions and 38,849 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ repos:
name: Prettier
entry: ./scripts/run_in_subdirectory.py frontend/ yarn prettier --write
files: ^frontend/.*(.js|\.jsx|\.ts|\.tsx)$
exclude: /vendor/
language: node
pass_filenames: true
- id: typecheck
Expand Down
1 change: 1 addition & 0 deletions frontend/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor
3 changes: 2 additions & 1 deletion frontend/.prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"endOfLine": "lf",
"semi": false,
"trailingComma": "es5"
"trailingComma": "es5",
"arrowParens": "avoid"
}
8 changes: 2 additions & 6 deletions frontend/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,8 @@ Cypress.Commands.add("openSettings", () => {
Cypress.Commands.add("changeTheme", theme => {
cy.openSettings()
cy.get('[data-baseweb="modal"] .stSelectbox').then(el => {
cy.wrap(el)
.find("input")
.click()
cy.get("li")
.contains(theme)
.click()
cy.wrap(el).find("input").click()
cy.get("li").contains(theme).click()
})
cy.get('[data-baseweb="modal"] [aria-label="Close"]').click()
})
Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
"jest-websocket-mock": "^2.2.0",
"marked": "^4.0.12",
"mock-socket": "^9.0.3",
"prettier": "^1.18.2",
"prettier": "^2.7.1",
"prop-types": "^15.7.2",
"react-responsive-carousel": "^3.2.23",
"react-scripts": "4.0.3",
Expand Down
5 changes: 1 addition & 4 deletions frontend/src/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,7 @@ describe("App", () => {
scriptName: "scriptName",
})

wrapper
.find(MainMenu)
.props()
.screencastCallback()
wrapper.find(MainMenu).props().screencastCallback()

expect(props.screenCast.startRecording).toHaveBeenCalledWith(
"streamlit-scriptName-date"
Expand Down
26 changes: 10 additions & 16 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,8 @@ export class App extends PureComponent<Props, State> {
this.closeDialog()
}

const {
requestedPageScriptHash,
} = this.props.hostCommunication.currentState
const { requestedPageScriptHash } =
this.props.hostCommunication.currentState
if (requestedPageScriptHash !== null) {
this.onPageChange(requestedPageScriptHash)
this.props.hostCommunication.onPageChanged()
Expand Down Expand Up @@ -438,13 +437,8 @@ export class App extends PureComponent<Props, State> {
}

handlePageConfigChanged = (pageConfig: PageConfig): void => {
const {
title,
favicon,
layout,
initialSidebarState,
menuItems,
} = pageConfig
const { title, favicon, layout, initialSidebarState, menuItems } =
pageConfig

MetricsManager.current.enqueue("pageConfigChanged", {
favicon,
Expand Down Expand Up @@ -588,7 +582,8 @@ export class App extends PureComponent<Props, State> {
customThemeDefined,
})

const customComponentCounter = MetricsManager.current.getAndResetCustomComponentCounter()
const customComponentCounter =
MetricsManager.current.getAndResetCustomComponentCounter()
Object.entries(customComponentCounter).forEach(([name, count]) => {
MetricsManager.current.enqueue("customComponentStats", {
name,
Expand Down Expand Up @@ -1276,9 +1271,8 @@ export class App extends PureComponent<Props, State> {
currentPageScriptHash,
} = this.state

const {
hideSidebarNav: hostHideSidebarNav,
} = this.props.hostCommunication.currentState
const { hideSidebarNav: hostHideSidebarNav } =
this.props.hostCommunication.currentState

const outerDivClass = classNames("stApp", {
"streamlit-embedded": isEmbeddedInIFrame(),
Expand Down Expand Up @@ -1311,8 +1305,8 @@ export class App extends PureComponent<Props, State> {
availableThemes: this.props.theme.availableThemes,
setTheme: this.setAndSendTheme,
addThemes: this.props.theme.addThemes,
sidebarChevronDownshift: this.props.hostCommunication.currentState
.sidebarChevronDownshift,
sidebarChevronDownshift:
this.props.hostCommunication.currentState.sidebarChevronDownshift,
getBaseUriParts: this.getBaseUriParts,
}}
>
Expand Down
14 changes: 4 additions & 10 deletions frontend/src/ThemedApp.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ describe("ThemedApp", () => {
it("updates theme", () => {
const wrapper = shallow(<ThemedApp />)
// @ts-ignore
wrapper
.find(AppWithScreencast)
.props()
.theme.setTheme(darkTheme)
wrapper.find(AppWithScreencast).props().theme.setTheme(darkTheme)
const updatedTheme: ThemeConfig = wrapper.find(AppWithScreencast).props()
.theme.activeTheme
expect(updatedTheme.name).toBe("Dark")
Expand All @@ -78,10 +75,7 @@ describe("ThemedApp", () => {
it("does not save Auto theme", () => {
const wrapper = shallow(<ThemedApp />)
// @ts-ignore
wrapper
.find(AppWithScreencast)
.props()
.theme.setTheme(darkTheme)
wrapper.find(AppWithScreencast).props().theme.setTheme(darkTheme)

wrapper
.find(AppWithScreencast)
Expand All @@ -105,8 +99,8 @@ describe("ThemedApp", () => {
app.props().theme.addThemes([darkTheme])

wrapper.update()
const newThemes = wrapper.find(AppWithScreencast).props().theme
.availableThemes
const newThemes = wrapper.find(AppWithScreencast).props()
.theme.availableThemes

// Should only have added one theme despite multiple calls adding themes.
expect(newThemes.length).toBe(initialThemes.length + 1)
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/components/core/AppView/AppView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@ function AppView(props: AppViewProps): ReactElement {
return () => window.removeEventListener("hashchange", listener, false)
}, [])

const { wideMode, initialSidebarState, embedded } = React.useContext(
AppContext
)
const { wideMode, initialSidebarState, embedded } =
React.useContext(AppContext)
const renderBlock = (node: BlockNode): ReactElement => (
<StyledAppViewBlockContainer
className="block-container"
Expand Down
47 changes: 25 additions & 22 deletions frontend/src/components/core/AppView/styled-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,28 +75,31 @@ export interface StyledAppViewBlockContainerProps {
isEmbedded: boolean
}

export const StyledAppViewBlockContainer = styled.div<
StyledAppViewBlockContainerProps
>(({ isWideMode, isEmbedded, theme }) => {
const topEmbedPadding = isEmbedded ? "1rem" : "6rem"
const bottomEmbedPadding = isEmbedded ? "1rem" : "10rem"
const wideSidePadding = isWideMode ? "5rem" : theme.spacing.lg
return {
flex: 1,
width: theme.sizes.full,
paddingLeft: theme.inSidebar ? theme.spacing.none : theme.spacing.lg,
paddingRight: theme.inSidebar ? theme.spacing.none : theme.spacing.lg,
// Increase side padding, if layout = wide and we're not on mobile
"@media (min-width: 576px)": {
paddingLeft: theme.inSidebar ? theme.spacing.none : wideSidePadding,
paddingRight: theme.inSidebar ? theme.spacing.none : wideSidePadding,
},
paddingTop: theme.inSidebar ? theme.spacing.none : topEmbedPadding,
paddingBottom: theme.inSidebar ? theme.spacing.none : bottomEmbedPadding,
minWidth: isWideMode ? "auto" : undefined,
maxWidth: isWideMode ? "initial" : theme.sizes.contentMaxWidth,
}
})
export const StyledAppViewBlockContainer =
styled.div<StyledAppViewBlockContainerProps>(
({ isWideMode, isEmbedded, theme }) => {
const topEmbedPadding = isEmbedded ? "1rem" : "6rem"
const bottomEmbedPadding = isEmbedded ? "1rem" : "10rem"
const wideSidePadding = isWideMode ? "5rem" : theme.spacing.lg
return {
flex: 1,
width: theme.sizes.full,
paddingLeft: theme.inSidebar ? theme.spacing.none : theme.spacing.lg,
paddingRight: theme.inSidebar ? theme.spacing.none : theme.spacing.lg,
// Increase side padding, if layout = wide and we're not on mobile
"@media (min-width: 576px)": {
paddingLeft: theme.inSidebar ? theme.spacing.none : wideSidePadding,
paddingRight: theme.inSidebar ? theme.spacing.none : wideSidePadding,
},
paddingTop: theme.inSidebar ? theme.spacing.none : topEmbedPadding,
paddingBottom: theme.inSidebar
? theme.spacing.none
: bottomEmbedPadding,
minWidth: isWideMode ? "auto" : undefined,
maxWidth: isWideMode ? "initial" : theme.sizes.contentMaxWidth,
}
}
)

export const StyledAppViewFooterLink = styled.a(({ theme }) => ({
color: theme.colors.fadedText60,
Expand Down
61 changes: 30 additions & 31 deletions frontend/src/components/core/Block/ElementNodeRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,69 +90,69 @@ import { StyledElementContainer } from "./styled-components"
const Audio = React.lazy(() => import("src/components/elements/Audio/"))
const Balloons = React.lazy(() => import("src/components/elements/Balloons/"))
const Snow = React.lazy(() => import("src/components/elements/Snow/"))
const ArrowDataFrame = React.lazy(() =>
import("src/components/widgets/DataFrame")
const ArrowDataFrame = React.lazy(
() => import("src/components/widgets/DataFrame")
)
const ArrowVegaLiteChart = React.lazy(() =>
import("src/components/elements/ArrowVegaLiteChart/")
const ArrowVegaLiteChart = React.lazy(
() => import("src/components/elements/ArrowVegaLiteChart/")
)

// BokehChart render function is sluggish. If the component is not debounced,
// AutoSizer causes it to rerender multiple times for different widths
// when the sidebar is toggled, which significantly slows down the app.
const BokehChart = React.lazy(() =>
import("src/components/elements/BokehChart/")
const BokehChart = React.lazy(
() => import("src/components/elements/BokehChart/")
)
const DebouncedBokehChart = debounceRender(BokehChart, 100)

const DataFrame = React.lazy(() => import("src/components/elements/DataFrame"))
const DeckGlJsonChart = React.lazy(() =>
import("src/components/elements/DeckGlJsonChart/")
const DeckGlJsonChart = React.lazy(
() => import("src/components/elements/DeckGlJsonChart/")
)
const GraphVizChart = React.lazy(() =>
import("src/components/elements/GraphVizChart/")
const GraphVizChart = React.lazy(
() => import("src/components/elements/GraphVizChart/")
)
const IFrame = React.lazy(() => import("src/components/elements/IFrame/"))
const ImageList = React.lazy(() =>
import("src/components/elements/ImageList/")
const ImageList = React.lazy(
() => import("src/components/elements/ImageList/")
)
const PlotlyChart = React.lazy(() =>
import("src/components/elements/PlotlyChart/")
const PlotlyChart = React.lazy(
() => import("src/components/elements/PlotlyChart/")
)
const VegaLiteChart = React.lazy(() =>
import("src/components/elements/VegaLiteChart/")
const VegaLiteChart = React.lazy(
() => import("src/components/elements/VegaLiteChart/")
)
const Video = React.lazy(() => import("src/components/elements/Video/"))

// Lazy-load widgets.
const Button = React.lazy(() => import("src/components/widgets/Button/"))
const DownloadButton = React.lazy(() =>
import("src/components/widgets/DownloadButton/")
const DownloadButton = React.lazy(
() => import("src/components/widgets/DownloadButton/")
)
const CameraInput = React.lazy(() =>
import("src/components/widgets/CameraInput")
const CameraInput = React.lazy(
() => import("src/components/widgets/CameraInput")
)
const Checkbox = React.lazy(() => import("src/components/widgets/Checkbox/"))
const ColorPicker = React.lazy(() =>
import("src/components/widgets/ColorPicker")
const ColorPicker = React.lazy(
() => import("src/components/widgets/ColorPicker")
)
const DateInput = React.lazy(() => import("src/components/widgets/DateInput/"))
const Multiselect = React.lazy(() =>
import("src/components/widgets/Multiselect/")
const Multiselect = React.lazy(
() => import("src/components/widgets/Multiselect/")
)
const Progress = React.lazy(() => import("src/components/elements/Progress/"))
const Spinner = React.lazy(() => import("src/components/elements/Spinner/"))
const Radio = React.lazy(() => import("src/components/widgets/Radio/"))
const Selectbox = React.lazy(() => import("src/components/widgets/Selectbox/"))
const Slider = React.lazy(() => import("src/components/widgets/Slider/"))
const FileUploader = React.lazy(() =>
import("src/components/widgets/FileUploader/")
const FileUploader = React.lazy(
() => import("src/components/widgets/FileUploader/")
)
const TextArea = React.lazy(() => import("src/components/widgets/TextArea/"))
const TextInput = React.lazy(() => import("src/components/widgets/TextInput/"))
const TimeInput = React.lazy(() => import("src/components/widgets/TimeInput/"))
const NumberInput = React.lazy(() =>
import("src/components/widgets/NumberInput/")
const NumberInput = React.lazy(
() => import("src/components/widgets/NumberInput/")
)

interface ElementNodeRendererProps extends BaseBlockProps {
Expand Down Expand Up @@ -375,9 +375,8 @@ const RawElementNodeRenderer = (
widgetProps.disabled = widgetProps.disabled || buttonProto.disabled
if (buttonProto.isFormSubmitter) {
const { formId } = buttonProto
const hasInProgressUpload = props.formsData.formsWithUploads.has(
formId
)
const hasInProgressUpload =
props.formsData.formsWithUploads.has(formId)
return (
<FormSubmitContent
element={buttonProto}
Expand Down
5 changes: 1 addition & 4 deletions frontend/src/components/core/MainMenu/MainMenu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,7 @@ describe("App", () => {

// @ts-ignore
const menuWrapper = mount(popoverContent(() => {}))
const items: any = menuWrapper
.find("StatefulMenu")
.at(1)
.prop("items")
const items: any = menuWrapper.find("StatefulMenu").at(1).prop("items")

const deployOption = items.find(
// @ts-ignore
Expand Down
8 changes: 2 additions & 6 deletions frontend/src/components/core/MainMenu/MainMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,8 @@ const SubMenu = ({
function MainMenu(props: Props): ReactElement {
const isServerDisconnected = !props.isServerConnected
const onClickDeployApp = useCallback((): void => {
const {
showDeployError,
closeDialog,
isDeployErrorModalOpen,
gitInfo,
} = props
const { showDeployError, closeDialog, isDeployErrorModalOpen, gitInfo } =
props

if (!gitInfo) {
const dialog = NoRepositoryDetected()
Expand Down
5 changes: 1 addition & 4 deletions frontend/src/components/core/Sidebar/Sidebar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,7 @@ describe("Sidebar Component", () => {
initialSidebarState: PageConfig.SidebarState.EXPANDED,
})

wrapper
.find("StyledSidebarCloseButton")
.find("button")
.simulate("click")
wrapper.find("StyledSidebarCloseButton").find("button").simulate("click")
expect(wrapper.find("Resizable").prop("isCollapsed")).toBe(true)
})

Expand Down
Loading

0 comments on commit 7550b6e

Please sign in to comment.