fix: hide promote/archive buttons for template versions from users without permission (#10555)

This commit is contained in:
Kayla Washburn
2023-11-07 09:33:14 -07:00
committed by GitHub
parent 0a550815e9
commit 1dd3eb603b
2 changed files with 43 additions and 41 deletions
@@ -33,6 +33,7 @@ export const VersionRow: React.FC<VersionRowProps> = ({
});
const jobStatus = version.job.status;
const showActions = onPromoteClick || onArchiveClick;
return (
<TimelineEntry
@@ -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 />
)}
@@ -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>
@@ -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,
},
};
@@ -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: [],