Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for campaign sort bug #2384

Merged
merged 4 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions src/components/AdminCampaignList/CampaignTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export class CampaignTable extends React.Component {
};

state = {
dataTableKey: "initial"
dataTableKey: "initial",
campaigns: [...this.props.data.organization.campaigns.campaigns]
};

statusIsChanging = campaign => {
Expand Down Expand Up @@ -119,7 +120,8 @@ export class CampaignTable extends React.Component {
customBodyRender: (value, tableMeta) => {
const campaign = campaigns.find(c => c.id === tableMeta.rowData[0]);
return this.renderArchiveIcon(campaign);
}
},
sort: false
},
style: {
width: "5em"
Expand Down Expand Up @@ -305,8 +307,7 @@ export class CampaignTable extends React.Component {
};

render() {
const { campaigns, pageInfo } = this.props.data.organization.campaigns;
const { limit, offset, total } = pageInfo;
const { limit, offset, total } = this.props.data.organization.campaigns.pageInfo;
const displayPage = Math.floor(offset / limit) + 1;
let rowSizeList = [10, 20, 50, 100];

Expand Down Expand Up @@ -346,14 +347,14 @@ export class CampaignTable extends React.Component {
break;
case "sort":
this.clearCampaignSelection();
campaigns.sort(this.sortFunc(tableState.sortOrder.name));
this.state.campaigns.sort(this.sortFunc(tableState.sortOrder.name));
if (tableState.sortOrder.direction === "desc") {
campaigns.reverse();
this.state.campaigns.reverse()
}
break;
case "rowSelectionChange":
const ids = tableState.selectedRows.data.map(({ index }) => {
return campaigns[index].id;
return this.state.campaigns[index].id;
});
this.props.handleChecked(ids);
break;
Expand All @@ -365,17 +366,17 @@ export class CampaignTable extends React.Component {
}
};

return campaigns.length === 0 ? (
return this.state.campaigns.length === 0 ? (
<Empty title="No campaigns" icon={<SpeakerNotesIcon />} />
) : (
<div>
<br />
<br />
<MUIDataTable
data={campaigns}
data={this.state.campaigns}
columns={this.prepareTableColumns(
this.props.data.organization,
campaigns
this.state.campaigns
)}
options={options}
/>
Expand Down
4 changes: 2 additions & 2 deletions src/containers/AdminCampaignList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { dataTest } from "../lib/attributes";
import loadData from "./hoc/load-data";
import theme from "../styles/theme";
import SortBy, {
DUE_DATE_DESC_SORT
ID_DESC_SORT
} from "../components/AdminCampaignList/SortBy";
import Search from "../components/Search";
import CampaignTable from "../components/AdminCampaignList/CampaignTable";
Expand All @@ -38,7 +38,7 @@ const INITIAL_FILTER = {
isArchived: false,
searchString: ""
};
const INITIAL_SORT_BY = DUE_DATE_DESC_SORT.value;
const INITIAL_SORT_BY = ID_DESC_SORT.value;

export class AdminCampaignList extends React.Component {
static propTypes = {
Expand Down
Loading