Skip to content

Commit

Permalink
refactor: [M3-9016] - Convert DomainRecords.tsx to functional compo…
Browse files Browse the repository at this point in the history
…nent (linode#11447)

* Initial commit

* More refactoring...

* Consolidate Pagination Footer

* Few fixes...

* Fix NS record domain render

* Added changeset: Refactor DomainRecords and convert DomainRecords to functional component

* Update changeset

* Fix DomainRecordTable paginatedData type

* Refactor generateTypes

* Memoize generateTypes

* Utility rename for clarity

* Update tablerow key

* Change to more descriptive var names

* Fix typo

* Use scrollErrorIntoViewV2

* Fix linting

* Refactor to remove some ramda dependencies and avoid `any` types
  • Loading branch information
pmakode-akamai authored Jan 13, 2025
1 parent a2686c1 commit 584aab4
Show file tree
Hide file tree
Showing 12 changed files with 1,007 additions and 903 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@linode/manager': Tech Stories
---

Refactor and convert DomainRecords to functional component ([#11447](https://github.com/linode/manager/pull/11447))
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ export interface ConfirmationDialogProps extends DialogProps {
* - Avoid “Are you sure?” language. Assume the user knows what they want to do while helping them avoid unintended consequences.
*
*/
export const ConfirmationDialog = (props: ConfirmationDialogProps) => {
export const ConfirmationDialog = React.forwardRef<
HTMLDivElement,
ConfirmationDialogProps
>((props, ref) => {
const { actions, children, ...dialogProps } = props;

return (
<Dialog {...dialogProps} PaperProps={{ role: undefined }}>
<Dialog {...dialogProps} PaperProps={{ role: undefined }} ref={ref}>
{children}
<Stack
direction="row"
Expand All @@ -39,4 +42,4 @@ export const ConfirmationDialog = (props: ConfirmationDialogProps) => {
</Stack>
</Dialog>
);
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import {
} from 'src/queries/domains';

import { DeleteDomain } from '../DeleteDomain';
import DomainRecords from '../DomainRecords';
import { DownloadDNSZoneFileButton } from '../DownloadDNSZoneFileButton';
import { DomainRecords } from './DomainRecords/DomainRecords';

import type { DomainState } from 'src/routes/domains';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Domain } from '@linode/api-v4/lib/domains';
import { has } from 'ramda';
import * as React from 'react';

import { Action, ActionMenu } from 'src/components/ActionMenu/ActionMenu';
import { ActionMenu } from 'src/components/ActionMenu/ActionMenu';

import type { Domain } from '@linode/api-v4/lib/domains';
import type { Action } from 'src/components/ActionMenu/ActionMenu';

interface EditPayload {
id?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
transferHelperText as helperText,
isValidCNAME,
isValidDomainRecord,
} from './domainUtils';
} from '../../domainUtils';

import type {
Domain,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import React from 'react';

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

import { StyledTableCell } from './DomainRecords.styles';

import type { IType } from './generateTypes';
import type { Domain, DomainRecord } from '@linode/api-v4/lib/domains';

interface DomainRecordTableProps {
count: number;
handlePageChange: (page: number) => void;
handlePageSizeChange: (pageSize: number) => void;
page: number;
pageSize: number;
paginatedData: Domain[] | DomainRecord[];
type: IType;
}

export const DomainRecordTable = (props: DomainRecordTableProps) => {
const {
count,
handlePageChange,
handlePageSizeChange,
page,
pageSize,
paginatedData,
type,
} = props;

return (
<>
<Table aria-label={`List of Domains ${type.title}`}>
<TableHead>
<TableRow>
{type.columns.length > 0 &&
type.columns.map((col, columnIndex) => {
return <TableCell key={columnIndex}>{col.title}</TableCell>;
})}
</TableRow>
</TableHead>
<TableBody>
{type.data.length === 0 ? (
<TableRowEmpty colSpan={type.columns.length} />
) : (
paginatedData.map((data, idx) => {
return (
<TableRow
data-qa-record-row={type.title}
key={`domain-record-${idx}`}
>
{type.columns.length > 0 &&
type.columns.map(({ render, title }, columnIndex) => {
return (
<StyledTableCell
data-qa-column={title}
key={columnIndex}
parentColumn={title}
>
{render(data)}
</StyledTableCell>
);
})}
</TableRow>
);
})
)}
</TableBody>
</Table>
<PaginationFooter
count={count}
eventCategory={`${type.title.toLowerCase()} panel`}
handlePageChange={handlePageChange}
handleSizeChange={handlePageSizeChange}
page={page}
pageSize={pageSize}
// Disabling show All as it is impacting page performance.
showAll={false}
/>
</>
);
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { styled } from '@mui/material/styles';
import Grid from '@mui/material/Unstable_Grid2';

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

export const StyledGrid = styled(Grid, { label: 'StyledGrid' })(
({ theme }) => ({
margin: 0,
marginTop: theme.spacing(2),
width: '100%',
'& .MuiGrid-item': {
paddingLeft: 0,
paddingRight: 0,
Expand All @@ -16,30 +14,33 @@ export const StyledGrid = styled(Grid, { label: 'StyledGrid' })(
marginRight: theme.spacing(),
},
},
margin: 0,
marginTop: theme.spacing(2),
[theme.breakpoints.down('md')]: {
marginLeft: theme.spacing(),
marginRight: theme.spacing(),
},
width: '100%',
})
);

export const StyledTableCell = styled(TableCell, { label: 'StyledTabelCell' })(
export const StyledTableCell = styled(TableCell, { label: 'StyledTableCell' })(
({ theme }) => ({
whiteSpace: 'nowrap' as const,
width: 'auto',
'& .data': {
maxWidth: 300,
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap' as const,
[theme.breakpoints.up('md')]: {
maxWidth: 750,
},
whiteSpace: 'nowrap' as const,
},
'&:last-of-type': {
display: 'flex',
justifyContent: 'flex-end',
},
whiteSpace: 'nowrap' as const,
width: 'auto',
})
);

Expand Down
Loading

0 comments on commit 584aab4

Please sign in to comment.