Skip to content
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
Next Next commit
hide actions from unpriviledged users
  • Loading branch information
aslilac committed Nov 6, 2023
commit 91cf527dd2c8501f8b742a63ae86aa4ba73f6dce
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ const TemplateVersionsPage = () => {
string | undefined
>();

console.log("permissions.canUpdateTemplate", permissions.canUpdateTemplate);

return (
<>
<Helmet>
Expand Down
59 changes: 31 additions & 28 deletions site/src/pages/TemplatePage/TemplateVersionsPage/VersionRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const VersionRow: React.FC<VersionRowProps> = ({
});

const jobStatus = version.job.status;
const showActions = onPromoteClick || onArchiveClick;

return (
<TimelineEntry
Expand Down Expand Up @@ -77,6 +78,7 @@ export const VersionRow: React.FC<VersionRowProps> = ({
<Stack direction="row" alignItems="center" spacing={2}>
{isActive && <Pill text="Active" type="success" />}
{isLatest && <Pill text="Newest" type="info" />}

{jobStatus === "pending" && (
<Pill text={<>Pending&hellip;</>} type="warning" lightBorder />
)}
Expand All @@ -87,34 +89,35 @@ export const VersionRow: React.FC<VersionRowProps> = ({
<Pill text="Canceled" type="neutral" lightBorder />
)}
{jobStatus === "failed" && <Pill text="Failed" type="error" />}
{jobStatus === "failed" ? (
<Button
css={styles.promoteButton}
disabled={isActive || version.archived}
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
if (onArchiveClick) {
onArchiveClick(version.id);
}
}}
>
Archive&hellip;
</Button>
) : (
<Button
css={styles.promoteButton}
disabled={isActive || jobStatus !== "succeeded"}
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
if (onPromoteClick) {
onPromoteClick(version.id);
}
}}
>
Promote&hellip;
</Button>

{showActions && (
<>
{jobStatus === "failed" ? (
<Button
css={styles.promoteButton}
disabled={isActive || version.archived}
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
onArchiveClick?.(version.id);
}}
>
Archive&hellip;
</Button>
) : (
<Button
css={styles.promoteButton}
disabled={isActive || jobStatus !== "succeeded"}
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
onPromoteClick?.(version.id);
}}
>
Promote&hellip;
</Button>
)}
</>
)}
</Stack>
</Stack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,14 @@ export const Example: Story = {
},
MockTemplateVersion,
],
onPromoteClick: undefined,
},
};

export const CanPromote: Story = {
export const NoEditPermission: Story = {
args: {
activeVersionId: MockTemplateVersion.id,
onPromoteClick: action("onPromoteClick"),
versions: [
{
...MockTemplateVersion,
id: "2",
name: "test-template-version-2",
created_at: "2022-05-18T18:39:01.382927298Z",
},
MockTemplateVersion,
],
...Example.args,
onPromoteClick: undefined,
onArchiveClick: undefined,
},
};

Expand Down Expand Up @@ -95,6 +86,14 @@ export const BuildStatuses: Story = {
},
};

export const BuildStatusesNoEditPermission: Story = {
args: {
...BuildStatuses.args,
onPromoteClick: undefined,
onArchiveClick: undefined,
},
};

export const Empty: Story = {
args: {
versions: [],
Expand Down