From 21835b0b03aea33f55b3caf0917019c951704e55 Mon Sep 17 00:00:00 2001 From: Simon Backx Date: Fri, 6 Jan 2023 16:04:22 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20duplicate=20member=20col?= =?UTF-8?q?umns=20when=20filtering?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refs https://ghost.slack.com/archives/CTH5NDJMS/p1672999077197199 When filtering on the same filter twice, columns were added twice. This change removes duplicate columns. --- ghost/admin/app/controllers/members.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ghost/admin/app/controllers/members.js b/ghost/admin/app/controllers/members.js index d928ff1fc8..01345210ee 100644 --- a/ghost/admin/app/controllers/members.js +++ b/ghost/admin/app/controllers/members.js @@ -173,12 +173,12 @@ export default class MembersController extends Controller { } get filterColumns() { - return this.availableFilters.flatMap((filter) => { + const columns = this.availableFilters.flatMap((filter) => { if (filter.properties?.getColumns) { return filter.properties?.getColumns(filter).map((c) => { return { label: filter.properties.columnLabel, // default value if not provided - ...c, + ...c, name: filter.type }; }); @@ -193,7 +193,12 @@ export default class MembersController extends Controller { ]; } return []; - }).splice(0, 2); // Maximum 2 columns + }); + // Remove duplicates by label + const uniqueColumns = columns.filter((c, i) => { + return columns.findIndex(c2 => c2.label === c.label) === i; + }); + return uniqueColumns.splice(0, 2); // Maximum 2 columns } includeTierQuery() {