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

Revert "Deploy button front (#2552)" #2599

Merged
merged 3 commits into from
Jan 14, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -27,7 +27,6 @@ cffi_bin

# Pyenv Stuff
.python-version
venv

# Autogenerated Protobufs
lib/streamlit/proto/*_pb2.py
Expand Down
2 changes: 1 addition & 1 deletion e2e/specs/st_main_menu.spec.js
Expand Up @@ -33,7 +33,7 @@ describe("main menu", () => {
cy.get('[data-testid="main-menu-popover"]').invoke(
"attr",
"style",
"transform: translate3d(20px, 20px, 0px);"
"transform: translate3d(20px, 20px, 0px)"
);
cy.get('[data-testid="main-menu-list"]').matchImageSnapshot("main_menu");

Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 16 additions & 51 deletions frontend/src/App.tsx
Expand Up @@ -50,14 +50,13 @@ import {
ForwardMsgMetadata,
Initialize,
NewReport,
IDeployParams,
PageConfig,
PageInfo,
SessionEvent,
WidgetStates,
SessionState,
Config,
IGitInfo,
GitInfo,
} from "autogen/proto"
import { without, concat } from "lodash"

Expand Down Expand Up @@ -104,7 +103,7 @@ interface State {
initialSidebarState: PageConfig.SidebarState
allowRunOnSave: boolean
reportFinishedHandlers: (() => void)[]
gitInfo?: IGitInfo | null
deployParams?: IDeployParams | null
}

const ELEMENT_LIST_BUFFER_TIMEOUT_MS = 10
Expand Down Expand Up @@ -162,7 +161,7 @@ export class App extends PureComponent<Props, State> {
initialSidebarState: PageConfig.SidebarState.AUTO,
allowRunOnSave: true,
reportFinishedHandlers: [],
gitInfo: null,
deployParams: null,
}

this.sessionEventDispatcher = new SessionEventDispatcher()
Expand Down Expand Up @@ -239,21 +238,6 @@ export class App extends PureComponent<Props, State> {
this.openDialog(newDialog)
}

showDeployError = (
title: string,
errorNode: ReactNode,
onContinue?: () => void
): void => {
this.openDialog({
type: DialogType.DEPLOY_ERROR,
title,
msg: errorNode,
onContinue,
onClose: () => {},
onTryAgain: this.sendLoadGitInfoBackMsg,
})
}

/**
* Checks if the code version from the backend is different than the frontend
*/
Expand Down Expand Up @@ -298,12 +282,6 @@ export class App extends PureComponent<Props, State> {
}
}

handleGitInfoChanged = (gitInfo: IGitInfo): void => {
this.setState({
gitInfo,
})
}

/**
* Callback when we get a message from the server.
*/
Expand Down Expand Up @@ -335,8 +313,6 @@ export class App extends PureComponent<Props, State> {
this.handlePageConfigChanged(pageConfig),
pageInfoChanged: (pageInfo: PageInfo) =>
this.handlePageInfoChanged(pageInfo),
gitInfoChanged: (gitInfo: GitInfo) =>
this.handleGitInfoChanged(gitInfo),
reportFinished: (status: ForwardMsg.ReportFinishedStatus) =>
this.handleReportFinished(status),
uploadReportProgress: (progress: number) =>
Expand Down Expand Up @@ -521,7 +497,12 @@ export class App extends PureComponent<Props, State> {
}

const { reportHash } = this.state
const { reportId, name: reportName, scriptPath } = newReportProto
const {
reportId,
name: reportName,
scriptPath,
deployParams,
} = newReportProto

const newReportHash = hashString(
SessionInfo.current.installationId + scriptPath
Expand All @@ -539,9 +520,10 @@ export class App extends PureComponent<Props, State> {
if (reportHash === newReportHash) {
this.setState({
reportId,
deployParams,
})
} else {
this.clearAppState(newReportHash, reportId, reportName)
this.clearAppState(newReportHash, reportId, reportName, deployParams)
}
}

Expand Down Expand Up @@ -621,13 +603,15 @@ export class App extends PureComponent<Props, State> {
clearAppState(
reportHash: string,
reportId: string,
reportName: string
reportName: string,
deployParams?: IDeployParams | null
): void {
this.setState(
{
reportId,
reportName,
reportHash,
deployParams,
elements: ReportRoot.empty(),
},
() => {
Expand Down Expand Up @@ -787,19 +771,6 @@ export class App extends PureComponent<Props, State> {
this.widgetMgr.sendUpdateWidgetsMessage()
}

sendLoadGitInfoBackMsg = (): void => {
if (!this.isServerConnected()) {
logError("Cannot load git information when disconnected from server.")
return
}

this.sendBackMsg(
new BackMsg({
loadGitInfo: true,
})
)
}

sendRerunBackMsg = (widgetStates?: WidgetStates | undefined): void => {
const { queryParams } = this.props.s4aCommunication.currentState

Expand Down Expand Up @@ -949,6 +920,7 @@ export class App extends PureComponent<Props, State> {
const {
allowRunOnSave,
connectionState,
deployParams,
dialog,
elements,
initialSidebarState,
Expand All @@ -958,7 +930,6 @@ export class App extends PureComponent<Props, State> {
reportRunState,
sharingEnabled,
userSettings,
gitInfo,
} = this.state
const outerDivClass = classNames("stApp", {
"streamlit-embedded": isEmbeddedInIFrame(),
Expand Down Expand Up @@ -1019,13 +990,7 @@ export class App extends PureComponent<Props, State> {
screenCastState={this.props.screenCast.currentState}
s4aMenuItems={this.props.s4aCommunication.currentState.items}
sendS4AMessage={this.props.s4aCommunication.sendMessage}
gitInfo={gitInfo}
showDeployError={this.showDeployError}
closeDialog={this.closeDialog}
isDeployErrorModalOpen={
this.state.dialog?.type === DialogType.DEPLOY_ERROR
}
loadGitInfo={this.sendLoadGitInfoBackMsg}
deployParams={deployParams}
/>
</Header>

Expand Down
152 changes: 1 addition & 151 deletions frontend/src/components/core/MainMenu/MainMenu.test.tsx
Expand Up @@ -18,23 +18,9 @@
import React from "react"
import { shallow } from "lib/test_util"
import { IMenuItem } from "hocs/withS4ACommunication/types"
import { Args as SessionInfoArgs, SessionInfo } from "lib/SessionInfo"

import { GitInfo, IGitInfo } from "autogen/proto"
import { IDeployErrorDialog } from "components/core/StreamlitDialog/DeployErrorDialogs/types"
import {
DetachedHead,
ModuleIsNotAdded,
NoRepositoryDetected,
RepoIsAhead,
UncommittedChanges,
UntrackedFiles,
} from "components/core/StreamlitDialog/DeployErrorDialogs"

import MainMenu, { Props } from "./MainMenu"

const { GitStates } = GitInfo

const getProps = (extend?: Partial<Props>): Props => ({
aboutCallback: jest.fn(),
clearCacheCallback: jest.fn(),
Expand All @@ -47,29 +33,10 @@ const getProps = (extend?: Partial<Props>): Props => ({
settingsCallback: jest.fn(),
shareCallback: jest.fn(),
sharingEnabled: false,
isDeployErrorModalOpen: false,
showDeployError: jest.fn(),
loadGitInfo: jest.fn(),
closeDialog: jest.fn(),
...extend,
})

describe("App", () => {
beforeAll(() => {
SessionInfo.current = new SessionInfo({
sessionId: "sessionId",
streamlitVersion: "sv",
pythonVersion: "pv",
installationId: "iid",
installationIdV1: "iid1",
installationIdV2: "iid2",
authorEmail: "ae",
maxCachedMessageAge: 2,
commandLine: "command line",
userMapboxToken: "mpt",
} as SessionInfoArgs)
})

it("renders without crashing", () => {
const props = getProps()
const wrapper = shallow(<MainMenu {...props} />)
Expand Down Expand Up @@ -160,7 +127,7 @@ describe("App", () => {
})

it("should render deploy app menu item", () => {
const props = getProps({ gitInfo: {} })
const props = getProps({ deployParams: {} })
const wrapper = shallow(<MainMenu {...props} />)
const popoverContent = wrapper.find("StatefulPopover").prop("content")
// @ts-ignore
Expand All @@ -185,121 +152,4 @@ describe("App", () => {
"About",
])
})

describe("Onclick deploy button", () => {
function testDeployErrorModal(
gitInfo: Partial<IGitInfo>,
dialogComponent: (module: string) => IDeployErrorDialog
): void {
const props = getProps({
gitInfo,
})
const wrapper = shallow(<MainMenu {...props} />)
const popoverContent = wrapper.find("StatefulPopover").prop("content")
// @ts-ignore
const menuWrapper = shallow(popoverContent(() => {})).dive()

const items: any = menuWrapper.prop("items")

const deployOption = items.find(
// @ts-ignore
({ label }) => label === "Deploy this app"
)

deployOption.onClick()

// @ts-ignore
const dialog = dialogComponent(props.gitInfo.module)

expect(props.showDeployError.mock.calls[0][0]).toStrictEqual(
dialog.title
)
expect(props.showDeployError.mock.calls[0][1]).toStrictEqual(dialog.body)
}

it("no repo or remote", () => {
testDeployErrorModal(
{
state: GitStates.DEFAULT,
},
NoRepositoryDetected
)
})

it("empty repo", () => {
testDeployErrorModal(
{
repository: "",
branch: "",
module: "",
state: GitStates.DEFAULT,
},
NoRepositoryDetected
)
})

it("repo is detached", () => {
testDeployErrorModal(
{
repository: "repo",
branch: "branch",
module: "module",
state: GitStates.HEAD_DETACHED,
},
DetachedHead
)
})

it("script was not added to the repo", () => {
testDeployErrorModal(
{
repository: "repo",
branch: "branch",
module: "module.py",
isHeadDetached: false,
untrackedFiles: ["module.py"],
},
ModuleIsNotAdded
)
})

it("uncommitted changes", () => {
testDeployErrorModal(
{
repository: "repo",
branch: "branch",
module: "module.py",
isHeadDetached: false,
uncommittedFiles: ["module.py"],
untrackedFiles: [],
},
UncommittedChanges
)
})

it("changes not pushed to Github", () => {
const deployParams: IGitInfo = {
repository: "repo",
branch: "branch",
module: "module.py",
uncommittedFiles: [],
untrackedFiles: [],
state: GitStates.AHEAD_OF_REMOTE,
}
testDeployErrorModal(deployParams, RepoIsAhead)
})

it("untracked files", () => {
testDeployErrorModal(
{
repository: "repo",
branch: "branch",
module: "module.py",
isHeadDetached: false,
untrackedFiles: ["another-file.py"],
},
UntrackedFiles
)
})
})
})