Skip to content

Commit

Permalink
Change to more descriptive var names
Browse files Browse the repository at this point in the history
  • Loading branch information
pmakode-akamai committed Jan 9, 2025
1 parent 1599819 commit 1b6e458
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ export const DomainRecords = (props: Props) => {
return;
}

updateConfirmDialog((c) => ({
...c,
updateConfirmDialog((confirmDialog) => ({
...confirmDialog,
errors: undefined,
submitting: true,
}));
Expand All @@ -118,14 +118,17 @@ export const DomainRecords = (props: Props) => {
})
.catch((errorResponse) => {
const errors = getAPIErrorOrDefault(errorResponse);
updateConfirmDialog((c) => ({
...c,
updateConfirmDialog((confirmDialog) => ({
...confirmDialog,
errors,
submitting: false,
}));
});

updateConfirmDialog((c) => ({ ...c, submitting: true }));
updateConfirmDialog((confirmDialog) => ({
...confirmDialog,
submitting: true,
}));
};

const handleCloseDialog = () => {
Expand All @@ -136,10 +139,10 @@ export const DomainRecords = (props: Props) => {
}));
};

const handleOpenSOADrawer = (d: Domain) => {
return d.type === 'master'
? openForEditPrimaryDomain(d)
: openForEditSecondaryDomain(d);
const handleOpenSOADrawer = (domain: Domain) => {
return domain.type === 'master'
? openForEditPrimaryDomain(domain)
: openForEditSecondaryDomain(domain);
};

const openForCreation = (type: RecordType) =>
Expand All @@ -162,11 +165,11 @@ export const DomainRecords = (props: Props) => {
type,
}));

const openForEditPrimaryDomain = (f: Partial<Domain>) =>
openForEditing('master', f);
const openForEditPrimaryDomain = (fields: Partial<Domain>) =>
openForEditing('master', fields);

const openForEditSecondaryDomain = (f: Partial<Domain>) =>
openForEditing('slave', f);
const openForEditSecondaryDomain = (fields: Partial<Domain>) =>
openForEditing('slave', fields);

const renderDialogActions = () => {
return (
Expand All @@ -187,7 +190,7 @@ export const DomainRecords = (props: Props) => {
const resetDrawer = () => updateDrawer(() => defaultDrawerState);

const updateConfirmDialog = (
fn: (d: ConfirmationState) => ConfirmationState
fn: (confirmDialog: ConfirmationState) => ConfirmationState
) => {
setState((prevState) => {
const newState = over(lensPath(['confirmDialog']), fn, prevState);
Expand All @@ -197,7 +200,7 @@ export const DomainRecords = (props: Props) => {
});
};

const updateDrawer = (fn: (d: DrawerState) => DrawerState) => {
const updateDrawer = (fn: (drawer: DrawerState) => DrawerState) => {
setState((prevState) => {
return over(lensPath(['drawer']), fn, prevState);
});
Expand All @@ -213,13 +216,13 @@ export const DomainRecords = (props: Props) => {
openForCreateNSRecord: () => openForCreation('NS'),
openForCreateSRVRecord: () => openForCreation('SRV'),
openForCreateTXTRecord: () => openForCreation('TXT'),
openForEditARecord: (f) => openForEditing('AAAA', f),
openForEditCAARecord: (f) => openForEditing('CAA', f),
openForEditCNAMERecord: (f) => openForEditing('CNAME', f),
openForEditMXRecord: (f) => openForEditing('MX', f),
openForEditNSRecord: (f) => openForEditing('NS', f),
openForEditSRVRecord: (f) => openForEditing('SRV', f),
openForEditTXTRecord: (f) => openForEditing('TXT', f),
openForEditARecord: (fields) => openForEditing('AAAA', fields),
openForEditCAARecord: (fields) => openForEditing('CAA', fields),
openForEditCNAMERecord: (fields) => openForEditing('CNAME', fields),
openForEditMXRecord: (fields) => openForEditing('MX', fields),
openForEditNSRecord: (fields) => openForEditing('NS', fields),
openForEditSRVRecord: (fields) => openForEditing('SRV', fields),
openForEditTXTRecord: (fields) => openForEditing('TXT', fields),
};

// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type { Domain, DomainRecord } from '@linode/api-v4/lib/domains';

export interface IType {
columns: {
render: (r: Domain | DomainRecord) => JSX.Element | null | string;
render: (record: Domain | DomainRecord) => JSX.Element | null | string;
title: string;
}[];
data: any[];
Expand All @@ -29,7 +29,7 @@ export interface IType {

export interface GenerateTypesHandlers {
confirmDeletion: (recordId: number) => void;
handleOpenSOADrawer: (d: Domain) => void;
handleOpenSOADrawer: (domain: Domain) => void;
openForCreateARecord: () => void;
openForCreateCAARecord: () => void;
openForCreateCNAMERecord: () => void;
Expand All @@ -38,28 +38,31 @@ export interface GenerateTypesHandlers {
openForCreateSRVRecord: () => void;
openForCreateTXTRecord: () => void;
openForEditARecord: (
f: Pick<DomainRecord, 'id' | 'name' | 'target' | 'ttl_sec'>
fields: Pick<DomainRecord, 'id' | 'name' | 'target' | 'ttl_sec'>
) => void;
openForEditCAARecord: (
f: Pick<DomainRecord, 'id' | 'name' | 'tag' | 'target' | 'ttl_sec'>
fields: Pick<DomainRecord, 'id' | 'name' | 'tag' | 'target' | 'ttl_sec'>
) => void;
openForEditCNAMERecord: (
f: Pick<DomainRecord, 'id' | 'name' | 'target' | 'ttl_sec'>
fields: Pick<DomainRecord, 'id' | 'name' | 'target' | 'ttl_sec'>
) => void;
openForEditMXRecord: (
f: Pick<DomainRecord, 'id' | 'name' | 'priority' | 'target' | 'ttl_sec'>
fields: Pick<
DomainRecord,
'id' | 'name' | 'priority' | 'target' | 'ttl_sec'
>
) => void;
openForEditNSRecord: (
f: Pick<DomainRecord, 'id' | 'name' | 'target' | 'ttl_sec'>
fields: Pick<DomainRecord, 'id' | 'name' | 'target' | 'ttl_sec'>
) => void;
openForEditSRVRecord: (
f: Pick<
fields: Pick<
DomainRecord,
'id' | 'name' | 'port' | 'priority' | 'protocol' | 'target' | 'weight'
>
) => void;
openForEditTXTRecord: (
f: Pick<DomainRecord, 'id' | 'name' | 'target' | 'ttl_sec'>
fields: Pick<DomainRecord, 'id' | 'name' | 'target' | 'ttl_sec'>
) => void;
}

Expand All @@ -77,11 +80,11 @@ export const generateTypes = (
{
columns: [
{
render: (d: Domain) => d.domain,
render: (domain: Domain) => domain.domain,
title: 'Primary Domain',
},
{
render: (d: Domain) => d.soa_email,
render: (domain: Domain) => domain.soa_email,
title: 'Email',
},
{
Expand All @@ -101,10 +104,10 @@ export const generateTypes = (
title: 'Expire Time',
},
{
render: (d: Domain) => {
return d.type === 'master' ? (
render: (domain: Domain) => {
return domain.type === 'master' ? (
<DomainRecordActionMenu
editPayload={d}
editPayload={domain}
label={props.domain.domain}
onEdit={handlers.handleOpenSOADrawer}
/>
Expand All @@ -123,15 +126,15 @@ export const generateTypes = (
{
columns: [
{
render: (r: DomainRecord) => r.target,
render: (record: DomainRecord) => record.target,
title: 'Name Server',
},
{
render: (r: DomainRecord) => {
const sd = r.name;
return isEmpty(sd)
render: (record: DomainRecord) => {
const subdomain = record.name;
return isEmpty(subdomain)
? props.domain.domain
: `${sd}.${props.domain.domain}`;
: `${subdomain}.${props.domain.domain}`;
},
title: 'Subdomain',
},
Expand Down Expand Up @@ -182,15 +185,15 @@ export const generateTypes = (
{
columns: [
{
render: (r: DomainRecord) => r.target,
render: (record: DomainRecord) => record.target,
title: 'Mail Server',
},
{
render: (r: DomainRecord) => String(r.priority),
render: (record: DomainRecord) => String(record.priority),
title: 'Preference',
},
{
render: (r: DomainRecord) => r.name,
render: (record: DomainRecord) => record.name,
title: 'Subdomain',
},
{
Expand Down Expand Up @@ -232,10 +235,10 @@ export const generateTypes = (
{
columns: [
{
render: (r: DomainRecord) => r.name || props.domain.domain,
render: (record: DomainRecord) => record.name || props.domain.domain,
title: 'Hostname',
},
{ render: (r: DomainRecord) => r.target, title: 'IP Address' },
{ render: (record: DomainRecord) => record.target, title: 'IP Address' },
{ render: getTTL, title: 'TTL' },
{
render: (domainRecordParams: DomainRecord) => {
Expand All @@ -261,7 +264,7 @@ export const generateTypes = (
},
],
data: props.domainRecords.filter(
(r) => typeEq('AAAA', r) || typeEq('A', r)
(record) => typeEq('AAAA', record) || typeEq('A', record)
),
link: () =>
createLink('Add an A/AAAA Record', handlers.openForCreateARecord),
Expand All @@ -273,8 +276,8 @@ export const generateTypes = (
/** CNAME Record */
{
columns: [
{ render: (r: DomainRecord) => r.name, title: 'Hostname' },
{ render: (r: DomainRecord) => r.target, title: 'Aliases to' },
{ render: (record: DomainRecord) => record.name, title: 'Hostname' },
{ render: (record: DomainRecord) => record.target, title: 'Aliases to' },
{ render: getTTL, title: 'TTL' },
{
render: (domainRecordParams: DomainRecord) => {
Expand Down Expand Up @@ -311,11 +314,11 @@ export const generateTypes = (
{
columns: [
{
render: (r: DomainRecord) => r.name || props.domain.domain,
render: (record: DomainRecord) => record.name || props.domain.domain,
title: 'Hostname',
},
{
render: (r: DomainRecord) => truncateEnd(r.target, 100),
render: (record: DomainRecord) => truncateEnd(record.target, 100),
title: 'Value',
},
{ render: getTTL, title: 'TTL' },
Expand Down Expand Up @@ -351,21 +354,24 @@ export const generateTypes = (
/** SRV Record */
{
columns: [
{ render: (r: DomainRecord) => r.name, title: 'Service/Protocol' },
{
render: (record: DomainRecord) => record.name,
title: 'Service/Protocol',
},
{
render: () => props.domain.domain,
title: 'Name',
},
{
render: (r: DomainRecord) => String(r.priority),
render: (record: DomainRecord) => String(record.priority),
title: 'Priority',
},
{
render: (r: DomainRecord) => String(r.weight),
render: (record: DomainRecord) => String(record.weight),
title: 'Weight',
},
{ render: (r: DomainRecord) => String(r.port), title: 'Port' },
{ render: (r: DomainRecord) => r.target, title: 'Target' },
{ render: (record: DomainRecord) => String(record.port), title: 'Port' },
{ render: (record: DomainRecord) => record.target, title: 'Target' },
{ render: getTTL, title: 'TTL' },
{
render: ({
Expand Down Expand Up @@ -409,10 +415,10 @@ export const generateTypes = (
/** CAA Record */
{
columns: [
{ render: (r: DomainRecord) => r.name, title: 'Name' },
{ render: (r: DomainRecord) => r.tag, title: 'Tag' },
{ render: (record: DomainRecord) => record.name, title: 'Name' },
{ render: (record: DomainRecord) => record.tag, title: 'Tag' },
{
render: (r: DomainRecord) => r.target,
render: (record: DomainRecord) => record.target,
title: 'Value',
},
{ render: getTTL, title: 'TTL' },
Expand Down

0 comments on commit 1b6e458

Please sign in to comment.