Skip to content

Commit

Permalink
Add new property to show edit button for cluster table dependent on p…
Browse files Browse the repository at this point in the history
…ermission

Signed-off-by: Mirjam Aulbach <[email protected]>
  • Loading branch information
programmiri committed Aug 29, 2024
1 parent c9cfb58 commit f9e7508
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
1 change: 1 addition & 0 deletions coral/src/app/features/configuration/clusters/Clusters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ function Clusters() {
? handleShowDeleteModal
: undefined
}
showEdit={permissions.addDeleteEditClusters}
ariaLabel={`Cluster overview, page ${clusters?.currentPage ?? 0} of ${
clusters?.totalPages ?? 0
}`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,20 +264,28 @@ describe("ClusterTable.tsx", () => {
describe("shows all clusters as a table (user with permissions.addDeleteEditClusters)", () => {
const tableLabel = "Cluster overview";
beforeAll(() => {
Object.defineProperty(window, "location", {
value: {
assign: jest.fn(),
},
writable: true,
});

customRender(
<ClustersTable
clusters={testCluster}
ariaLabel={tableLabel}
handleShowConnectModal={mockHandleShowConnectModal}
handleShowDeleteModal={mockHandleShowDeleteModal}
showEdit={true}
/>,
{ queryClient: true }
);
});

afterAll(cleanup);

it("renders a table with an acessible name", async () => {
it("renders a table with an accessible name", async () => {
const table = screen.getByRole("table", {
name: tableLabel,
});
Expand Down Expand Up @@ -490,6 +498,30 @@ describe("ClusterTable.tsx", () => {
},
});
});

it(`displays an edit button that redirects to Klaw for ${cluster.clusterName}`, async () => {
const table = screen.getByRole("table", {
name: tableLabel,
});
const row = within(table).getByRole("row", {
name: new RegExp(`${cluster.clusterName}`),
});
const menuButton = within(row).getByRole("button", {
name: "Context menu",
});

await userEvent.click(menuButton);

const editButton = screen.getByRole("menuitem", {
name: "Edit",
});

await userEvent.click(editButton);

expect(window.location.assign).toHaveBeenCalledWith(
"http://localhost/modifyCluster?clusterId=1&clusterType=kafka"
);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,20 @@ import { ClusterDetails } from "src/domain/cluster";
import { clusterTypeToString } from "src/services/formatter/cluster-type-formatter";
import { kafkaFlavorToString } from "src/services/formatter/kafka-flavor-formatter";
import deleteIcon from "@aivenio/aquarium/dist/src/icons/delete";
import editIcon from "@aivenio/aquarium/dist/src/icons/edit";
import camelCase from "lodash/camelCase";

type ClustersTableProps = {
clusters: ClusterDetails[];
ariaLabel: string;
handleShowConnectModal?: ({ show, data }: ClusterConnectModalState) => void;
handleShowDeleteModal?: ({ show, data }: ClusterDeleteModalState) => void;
showEdit?: boolean;
};

interface ClustersTableRow {
id: ClusterDetails["clusterId"];
type: ClusterDetails["clusterType"];
clusterName: ClusterDetails["clusterName"];
bootstrapServers: ClusterDetails["bootstrapServers"];
protocol: ClusterDetails["protocol"];
Expand All @@ -37,11 +41,18 @@ interface ClustersTableRow {
}

const ClustersTable = (props: ClustersTableProps) => {
const { clusters, ariaLabel, handleShowConnectModal, handleShowDeleteModal } =
props;
const {
clusters,
ariaLabel,
showEdit,
handleShowConnectModal,
handleShowDeleteModal,
} = props;

const isAdminUser =
handleShowConnectModal !== undefined && handleShowDeleteModal !== undefined;
handleShowConnectModal !== undefined &&
handleShowDeleteModal !== undefined &&
showEdit === true;

const columns: Array<DataTableColumn<ClustersTableRow>> = [
{
Expand Down Expand Up @@ -129,6 +140,7 @@ const ClustersTable = (props: ClustersTableProps) => {
const rows: ClustersTableRow[] = clusters.map((cluster) => {
return {
id: cluster.clusterId,
type: cluster.clusterType,
clusterName: cluster.clusterName,
bootstrapServers: cluster.bootstrapServers,
protocol: cluster.protocol,
Expand All @@ -155,6 +167,9 @@ const ClustersTable = (props: ClustersTableProps) => {
noWrap={false}
menu={
<DropdownMenu.Items>
<DropdownMenu.Item icon={editIcon} key="edit">
Edit
</DropdownMenu.Item>
<DropdownMenu.Item icon={deleteIcon} key="delete">
Remove
</DropdownMenu.Item>
Expand All @@ -171,6 +186,13 @@ const ClustersTable = (props: ClustersTableProps) => {
},
});
}
if (action === "edit") {
const { id, type } = data;
const typeForUrl = camelCase(type).toLowerCase();
window.location.assign(
`${window.origin}/modifyCluster?clusterId=${id}&clusterType=${typeForUrl}`
);
}
}}
/>
) : (
Expand Down

0 comments on commit f9e7508

Please sign in to comment.