Skip to content

Commit

Permalink
refactor: converted functions to memos for best practice
Browse files Browse the repository at this point in the history
  • Loading branch information
eemaanamir authored and arbrandes committed Mar 6, 2024
1 parent 87c1cb5 commit 6dd835d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable react/no-unstable-nested-components */

import React, { useState } from 'react';
import React, { useMemo, useState } from 'react';
import PropTypes from 'prop-types';
import { useParams } from 'react-router-dom';
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
Expand Down Expand Up @@ -51,15 +51,15 @@ function BulkEmailContentHistory({ intl }) {
* up a level (the `subject` field). We also convert the `sent_to` data to be a String rather than an array to fix a
* display bug in the table.
*/
function transformDataForTable() {
const transformDataForTable = useMemo(() => {
const tableData = emailHistoryData?.map((item) => ({
...item,
subject: item.email.subject,
sent_to: item.sent_to.join(', '),
created: new Date(item.created).toLocaleString(),
}));
return tableData || [];
}
}, [emailHistoryData]);

/**
* This function is responsible for setting the current `messageContent` state data. This will be the contents of a
Expand Down Expand Up @@ -100,7 +100,7 @@ function BulkEmailContentHistory({ intl }) {
* contents of a previously sent message.
*/
const additionalColumns = () => {
const tableData = transformDataForTable();
const tableData = transformDataForTable;

return [
{
Expand Down Expand Up @@ -137,7 +137,7 @@ function BulkEmailContentHistory({ intl }) {
{showHistoricalEmailContentTable ? (
<BulkEmailTaskManagerTable
errorRetrievingData={errorRetrievingData}
tableData={transformDataForTable()}
tableData={transformDataForTable}
tableDescription={intl.formatMessage(messages.emailHistoryTableViewMessageInstructions)}
alertWarningMessage={intl.formatMessage(messages.noEmailData)}
alertErrorMessage={intl.formatMessage(messages.errorFetchingEmailHistoryData)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useMemo, useState } from 'react';
import { useParams } from 'react-router-dom';
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';

Expand Down Expand Up @@ -41,13 +41,13 @@ function BulkEmailTaskHistory({ intl }) {
setShowHistoricalTaskContentTable(true);
}

function transformDataForTable() {
const transformDataForTable = useMemo(() => {
const tableData = emailTaskHistoryData?.map((item) => ({
...item,
created: new Date(item.created).toLocaleString(),
}));
return tableData || [];
}
}, [emailTaskHistoryData]);

const tableColumns = [
{
Expand Down Expand Up @@ -103,7 +103,7 @@ function BulkEmailTaskHistory({ intl }) {
{showHistoricalTaskContentTable ? (
<BulkEmailTaskManagerTable
errorRetrievingData={errorRetrievingData}
tableData={transformDataForTable()}
tableData={transformDataForTable}
alertWarningMessage={intl.formatMessage(messages.noTaskHistoryData)}
alertErrorMessage={intl.formatMessage(messages.errorFetchingTaskHistoryData)}
columns={tableColumns}
Expand Down

0 comments on commit 6dd835d

Please sign in to comment.