Skip to content

Feat: delete template button #3781

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

Merged
merged 19 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Format
  • Loading branch information
presleyp committed Aug 29, 2022
commit 90db85d1a0394c938fc6aae4113e4960ff199e37
8 changes: 4 additions & 4 deletions site/src/components/DropdownButton/DropdownButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { action } from "@storybook/addon-actions"
import { Story } from "@storybook/react"
import { WorkspaceStateEnum } from "util/workspace"
import { DeleteButton, UpdateButton, StartButton, DisabledButton } from "./ActionCtas"
import { DeleteButton, DisabledButton, StartButton, UpdateButton } from "./ActionCtas"
import { DropdownButton, DropdownButtonProps } from "./DropdownButton"

export default {
Expand All @@ -16,15 +16,15 @@ WithDropdown.args = {
primaryAction: <StartButton handleAction={action("start")} />,
secondaryActions: [
{ action: "update", button: <UpdateButton handleAction={action("update")} /> },
{ action: "delete", button: <DeleteButton handleAction={action("delete")} /> }
{ action: "delete", button: <DeleteButton handleAction={action("delete")} /> },
],
canCancel: false
canCancel: false,
}

export const WithCancel = Template.bind({})
WithCancel.args = {
primaryAction: <DisabledButton workspaceState={WorkspaceStateEnum.deleting} />,
secondaryActions: [],
canCancel: true,
handleCancel: action("cancel")
handleCancel: action("cancel"),
}
95 changes: 50 additions & 45 deletions site/src/components/DropdownButton/DropdownButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@ import Popover from "@material-ui/core/Popover"
import { makeStyles } from "@material-ui/core/styles"
import { CloseDropdown, OpenDropdown } from "components/DropdownArrows/DropdownArrows"
import { DropdownContent } from "components/DropdownButton/DropdownContent/DropdownContent"
import { FC, ReactNode, useRef, useState, useEffect } from "react"
import { FC, ReactNode, useEffect, useRef, useState } from "react"
import { CancelButton } from "./ActionCtas"

export interface DropdownButtonProps {
primaryAction: ReactNode
secondaryActions: Array<{ action: string, button: ReactNode }>
secondaryActions: Array<{ action: string; button: ReactNode }>
canCancel: boolean
handleCancel?: () => void
}

export const DropdownButton: FC<DropdownButtonProps> = ({ primaryAction, secondaryActions, canCancel, handleCancel }) => {
export const DropdownButton: FC<DropdownButtonProps> = ({
primaryAction,
secondaryActions,
canCancel,
handleCancel,
}) => {
const styles = useStyles()
const anchorRef = useRef<HTMLButtonElement>(null)
const [isOpen, setIsOpen] = useState(false)
Expand All @@ -31,48 +36,48 @@ export const DropdownButton: FC<DropdownButtonProps> = ({ primaryAction, seconda

return (
<span className={styles.buttonContainer}>
{/* primary workspace CTA */}
<span data-testid="primary-cta" className={styles.primaryCta}>
{primaryAction}
</span>
{canCancel && handleCancel ? (
<CancelButton handleAction={handleCancel} />
) : (
<>
{/* popover toggle button */}
<Button
data-testid="workspace-actions-button"
aria-controls="workspace-actions-menu"
aria-haspopup="true"
className={styles.dropdownButton}
ref={anchorRef}
disabled={!secondaryActions.length}
onClick={() => {
setIsOpen(true)
}}
>
{isOpen ? <CloseDropdown /> : <OpenDropdown />}
</Button>
<Popover
classes={{ paper: styles.popoverPaper }}
id={id}
open={isOpen}
anchorEl={anchorRef.current}
onClose={() => setIsOpen(false)}
anchorOrigin={{
vertical: "bottom",
horizontal: "right",
}}
transformOrigin={{
vertical: "top",
horizontal: "right",
}}
>
{/* secondary workspace CTAs */}
<DropdownContent secondaryActions={secondaryActions} />
</Popover>
</>
)}
{/* primary workspace CTA */}
<span data-testid="primary-cta" className={styles.primaryCta}>
{primaryAction}
</span>
{canCancel && handleCancel ? (
<CancelButton handleAction={handleCancel} />
) : (
<>
{/* popover toggle button */}
<Button
data-testid="workspace-actions-button"
aria-controls="workspace-actions-menu"
aria-haspopup="true"
className={styles.dropdownButton}
ref={anchorRef}
disabled={!secondaryActions.length}
onClick={() => {
setIsOpen(true)
}}
>
{isOpen ? <CloseDropdown /> : <OpenDropdown />}
</Button>
<Popover
classes={{ paper: styles.popoverPaper }}
id={id}
open={isOpen}
anchorEl={anchorRef.current}
onClose={() => setIsOpen(false)}
anchorOrigin={{
vertical: "bottom",
horizontal: "right",
}}
transformOrigin={{
vertical: "top",
horizontal: "right",
}}
>
{/* secondary workspace CTAs */}
<DropdownContent secondaryActions={secondaryActions} />
</Popover>
</>
)}
</span>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { makeStyles } from "@material-ui/core/styles"
import { FC, ReactNode } from "react"

export interface DropdownContentProps {
secondaryActions: Array<{ action: string, button: ReactNode }>
secondaryActions: Array<{ action: string; button: ReactNode }>
}

/* secondary workspace CTAs */
Expand Down
8 changes: 4 additions & 4 deletions site/src/components/WorkspaceActions/WorkspaceActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export const WorkspaceActions: FC<WorkspaceActionsProps> = ({
handleUpdate,
handleCancel,
}) => {

const workspaceStatus: keyof typeof WorkspaceStateEnum = getWorkspaceStatus(
workspace.latest_build,
)
Expand Down Expand Up @@ -84,9 +83,10 @@ export const WorkspaceActions: FC<WorkspaceActionsProps> = ({
primaryAction={buttonMapping[actions.primary]}
canCancel={actions.canCancel}
handleCancel={handleCancel}
secondaryActions={actions.secondary.map((action) => ({ action, button: buttonMapping[action] }))}
secondaryActions={actions.secondary.map((action) => ({
action,
button: buttonMapping[action],
}))}
/>
)
}


9 changes: 6 additions & 3 deletions site/src/pages/TemplatePage/TemplatePageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const TemplatePageView: FC<React.PropsWithChildren<TemplatePageViewProps>
activeTemplateVersion,
templateResources,
templateVersions,
handleDeleteTemplate
handleDeleteTemplate,
}) => {
const styles = useStyles()
const readme = frontMatter(activeTemplateVersion.readme)
Expand Down Expand Up @@ -82,10 +82,13 @@ export const TemplatePageView: FC<React.PropsWithChildren<TemplatePageViewProps>
</Link>
}
secondaryActions={[
{ action: "delete", button: <DeleteButton handleAction={() => handleDeleteTemplate(template.id)} /> }
{
action: "delete",
button: <DeleteButton handleAction={() => handleDeleteTemplate(template.id)} />,
},
]}
canCancel={false}
/>
/>
</Stack>
}
>
Expand Down