Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/linode/manager into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jaalah committed Jan 31, 2024
2 parents d91488e + ae7f8a1 commit 79d4f41
Show file tree
Hide file tree
Showing 11 changed files with 303 additions and 190 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tech Stories
---

Refactor AccessKeyTable - Eliminate react anti patterns. ([#10124](https://github.com/linode/manager/pull/10124))
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-10127-fixed-1706638177404.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Fixed
---

Breadcrumb label in NodeBalancers details & create pages ([#10127](https://github.com/linode/manager/pull/10127))
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ const NodeBalancerCreate = () => {
breadcrumbDataAttrs: {
'data-qa-create-nodebalancer-header': true,
},
crumbOverrides: [{ label: 'NodeBalancers', position: 1 }],
pathname: '/nodebalancers/create',
}}
title="Create"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export const NodeBalancerDetail = () => {
<React.Fragment>
<LandingHeader
breadcrumbProps={{
crumbOverrides: [{ label: 'NodeBalancers', position: 1 }],
firstAndLastOnly: true,
onEditHandlers: {
editableTextTitle: nodeBalancerLabel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
import { getAPIErrorOrDefault, getErrorMap } from 'src/utilities/errorUtils';

import { AccessKeyDrawer } from './AccessKeyDrawer';
import { AccessKeyTable } from './AccessKeyTable';
import { AccessKeyTable } from './AccessKeyTable/AccessKeyTable';
import { OMC_AccessKeyDrawer } from './OMC_AccessKeyDrawer';
import { RevokeAccessKeyDialog } from './RevokeAccessKeyDialog';
import ViewPermissionsDrawer from './ViewPermissionsDrawer';
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useAccountManagement } from 'src/hooks/useAccountManagement';
import { useFlags } from 'src/hooks/useFlags';
import { isFeatureEnabled } from 'src/utilities/accountCapabilities';

import { OpenAccessDrawer } from './types';
import { OpenAccessDrawer } from '../types';

interface Props {
label: string;
Expand All @@ -18,9 +18,12 @@ interface Props {
openRevokeDialog: (key: ObjectStorageKey) => void;
}

export const AccessKeyMenu = (props: Props) => {
const { objectStorageKey, openDrawer, openRevokeDialog } = props;

export const AccessKeyActionMenu = ({
label,
objectStorageKey,
openDrawer,
openRevokeDialog,
}: Props) => {
const flags = useFlags();
const { account } = useAccountManagement();

Expand Down Expand Up @@ -56,7 +59,7 @@ export const AccessKeyMenu = (props: Props) => {
{isObjMultiClusterEnabled ? (
<ActionMenu
actionsList={actions}
ariaLabel={`Action menu for Object Storage Key ${props.label}`}
ariaLabel={`Action menu for Object Storage Key ${label}`}
/>
) : (
<>
Expand All @@ -72,7 +75,7 @@ export const AccessKeyMenu = (props: Props) => {
<Hidden mdUp>
<ActionMenu
actionsList={actions}
ariaLabel={`Action menu for Object Storage Key ${props.label}`}
ariaLabel={`Action menu for Object Storage Key ${label}`}
/>
</Hidden>
</>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import {
ObjectStorageKey,
RegionS3EndpointAndID,
} from '@linode/api-v4/lib/object-storage';
import { APIError } from '@linode/api-v4/lib/types';
import { styled } from '@mui/material/styles';
import React, { useState } from 'react';

import { Table } from 'src/components/Table';

import { TableCell } from 'src/components/TableCell';
import { TableHead } from 'src/components/TableHead';
import { TableRow } from 'src/components/TableRow';
import { TableBody } from 'src/components/TableBody';

import { useAccountManagement } from 'src/hooks/useAccountManagement';
import { useFlags } from 'src/hooks/useFlags';
import { isFeatureEnabled } from 'src/utilities/accountCapabilities';

import { HostNamesDrawer } from '../HostNamesDrawer';
import { OpenAccessDrawer } from '../types';

import { AccessKeyTableBody } from './AccessKeyTableBody';

export interface AccessKeyTableProps {
data: ObjectStorageKey[] | undefined;
error: APIError[] | null | undefined;
isLoading: boolean;
isRestrictedUser: boolean;
openDrawer: OpenAccessDrawer;
openRevokeDialog: (objectStorageKey: ObjectStorageKey) => void;
}

export const AccessKeyTable = (props: AccessKeyTableProps) => {
const {
data,
error,
isLoading,
isRestrictedUser,
openDrawer,
openRevokeDialog,
} = props;

const [showHostNamesDrawer, setShowHostNamesDrawers] = useState<boolean>(
false
);
const [hostNames, setHostNames] = useState<RegionS3EndpointAndID[]>([]);

const flags = useFlags();
const { account } = useAccountManagement();

const isObjMultiClusterEnabled = isFeatureEnabled(
'Object Storage Access Key Regions',
Boolean(flags.objMultiCluster),
account?.capabilities ?? []
);

return (
<>
<Table
aria-label="List of Object Storage Access Keys"
colCount={2}
data-testid="data-qa-access-key-table"
rowCount={data?.length}
>
<TableHead>
<TableRow data-qa-table-head>
<StyledLabelCell data-qa-header-label>Label</StyledLabelCell>
<StyledLabelCell data-qa-header-key>Access Key</StyledLabelCell>
{isObjMultiClusterEnabled && (
<StyledLabelCell data-qa-header-key>
Regions/S3 Hostnames
</StyledLabelCell>
)}
{/* empty cell for kebab menu */}
<TableCell />
</TableRow>
</TableHead>
<TableBody>
<AccessKeyTableBody
data={data}
error={error}
isLoading={isLoading}
isRestrictedUser={isRestrictedUser}
openDrawer={openDrawer}
openRevokeDialog={openRevokeDialog}
setHostNames={setHostNames}
setShowHostNamesDrawers={setShowHostNamesDrawers}
/>
</TableBody>
</Table>
{isObjMultiClusterEnabled && (
<HostNamesDrawer
onClose={() => setShowHostNamesDrawers(false)}
open={showHostNamesDrawer}
regions={hostNames}
/>
)}
</>
);
};

const StyledLabelCell = styled(TableCell)(() => ({
width: '35%',
}));
Loading

0 comments on commit 79d4f41

Please sign in to comment.