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 30, 2022
commit e28639ec2aa0d7e94e250dab2dcbc8c71986f991
181 changes: 91 additions & 90 deletions site/src/pages/TemplatePage/TemplatePageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const TemplatePageView: FC<React.PropsWithChildren<TemplatePageViewProps>
templateVersions,
handleDeleteTemplate,
deleteTemplateError,
canDeleteTemplate
canDeleteTemplate,
}) => {
const styles = useStyles()
const readme = frontMatter(activeTemplateVersion.readme)
Expand All @@ -61,102 +61,103 @@ export const TemplatePageView: FC<React.PropsWithChildren<TemplatePageViewProps>
return resources.filter((resource) => resource.workspace_transition === "start")
}

const createWorkspaceButton = (className: string) => <Link
underline="none"
component={RouterLink}
to={`/templates/${template.name}/workspace`}
>
<Button className={className} startIcon={<AddCircleOutline />}>{Language.createButton}</Button>
</Link>

const createWorkspaceButton = (className: string) => (
<Link underline="none" component={RouterLink} to={`/templates/${template.name}/workspace`}>
<Button className={className} startIcon={<AddCircleOutline />}>
{Language.createButton}
</Button>
</Link>
)

return (
<Margins>
<>
{deleteTemplateError && <ErrorSummary error={deleteTemplateError} dismissible />}
<PageHeader
actions={
<Stack direction="row" spacing={1}>
<Link
underline="none"
component={RouterLink}
to={`/templates/${template.name}/settings`}
>
<Button variant="outlined" startIcon={<SettingsOutlined />}>
{Language.settingsButton}
</Button>
</Link>
{deleteTemplateError && <ErrorSummary error={deleteTemplateError} dismissible />}
<PageHeader
actions={
<Stack direction="row" spacing={1}>
<Link
underline="none"
component={RouterLink}
to={`/templates/${template.name}/settings`}
>
<Button variant="outlined" startIcon={<SettingsOutlined />}>
{Language.settingsButton}
</Button>
</Link>

{canDeleteTemplate ?
<DropdownButton
primaryAction={createWorkspaceButton(styles.actionButton)}
secondaryActions={[
{
action: "delete",
button: <DeleteButton handleAction={() => handleDeleteTemplate(template.id)} />,
},
]}
canCancel={false}
/>
:
createWorkspaceButton("")
}
{canDeleteTemplate ? (
<DropdownButton
primaryAction={createWorkspaceButton(styles.actionButton)}
secondaryActions={[
{
action: "delete",
button: (
<DeleteButton handleAction={() => handleDeleteTemplate(template.id)} />
),
},
]}
canCancel={false}
/>
) : (
createWorkspaceButton("")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could change the arg to be optional, it is not intuitive what an empty string means here.

)}
</Stack>
}
>
<Stack direction="row" spacing={3} className={styles.pageTitle}>
<div>
{hasIcon ? (
<div className={styles.iconWrapper}>
<img src={template.icon} alt="" />
</div>
) : (
<Avatar className={styles.avatar}>{firstLetter(template.name)}</Avatar>
)}
</div>
<div>
<PageHeaderTitle>{template.name}</PageHeaderTitle>
<PageHeaderSubtitle>
{template.description === "" ? Language.noDescription : template.description}
</PageHeaderSubtitle>
</div>
</Stack>
}
>
<Stack direction="row" spacing={3} className={styles.pageTitle}>
<div>
{hasIcon ? (
<div className={styles.iconWrapper}>
<img src={template.icon} alt="" />
</div>
) : (
<Avatar className={styles.avatar}>{firstLetter(template.name)}</Avatar>
)}
</div>
<div>
<PageHeaderTitle>{template.name}</PageHeaderTitle>
<PageHeaderSubtitle>
{template.description === "" ? Language.noDescription : template.description}
</PageHeaderSubtitle>
</div>
</Stack>
</PageHeader>
</PageHeader>

<Stack spacing={2.5}>
<TemplateStats template={template} activeVersion={activeTemplateVersion} />
<WorkspaceSection
title={Language.resourcesTitle}
contentsProps={{ className: styles.resourcesTableContents }}
>
<TemplateResourcesTable resources={getStartedResources(templateResources)} />
</WorkspaceSection>
<WorkspaceSection
title={Language.readmeTitle}
contentsProps={{ className: styles.readmeContents }}
>
<div className={styles.markdownWrapper}>
<ReactMarkdown
components={{
a: ({ href, target, children }) => (
<Link href={href} target={target}>
{children}
</Link>
),
}}
>
{readme.body}
</ReactMarkdown>
</div>
</WorkspaceSection>
<WorkspaceSection
title={Language.versionsTitle}
contentsProps={{ className: styles.versionsTableContents }}
>
<VersionsTable versions={templateVersions} />
</WorkspaceSection>
</Stack>
</>
<Stack spacing={2.5}>
<TemplateStats template={template} activeVersion={activeTemplateVersion} />
<WorkspaceSection
title={Language.resourcesTitle}
contentsProps={{ className: styles.resourcesTableContents }}
>
<TemplateResourcesTable resources={getStartedResources(templateResources)} />
</WorkspaceSection>
<WorkspaceSection
title={Language.readmeTitle}
contentsProps={{ className: styles.readmeContents }}
>
<div className={styles.markdownWrapper}>
<ReactMarkdown
components={{
a: ({ href, target, children }) => (
<Link href={href} target={target}>
{children}
</Link>
),
}}
>
{readme.body}
</ReactMarkdown>
</div>
</WorkspaceSection>
<WorkspaceSection
title={Language.versionsTitle}
contentsProps={{ className: styles.versionsTableContents }}
>
<VersionsTable versions={templateVersions} />
</WorkspaceSection>
</Stack>
</>
</Margins>
)
}
Expand Down
4 changes: 2 additions & 2 deletions site/src/xServices/auth/authXService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ export const permissionsToCheck = {
},
[checks.deleteTemplates]: {
object: {
resource_type: "template"
resource_type: "template",
},
action: "delete"
action: "delete",
},
[checks.viewAuditLog]: {
object: {
Expand Down