mirror of
https://github.com/discourse/discourse.git
synced 2026-08-03 09:53:24 -05:00
DEV: Replace deprecated Ember's array compact (#35259)
This commit replaces the use of `.compact()` with `.filter((item) => item != null)` across multiple JavaScript files in the codebase. Additionally, it introduces a new logging handler for a specific deprecation in the deprecation workflow. **Main Changes:** * Replaced `.compact()` with `.filter((item) => item != null)` to eliminate the Ember Array dependency and align with native JavaScript practices. * Deprecation Workflow: Added a log handler for discourse.native-array-extensions.compact.
This commit is contained in:
@@ -37,7 +37,7 @@ export default class AdminReportTable extends Component {
|
||||
// check if we have at least one cell which contains a value
|
||||
const sum = totalsForSample
|
||||
.map((t) => t.value)
|
||||
.compact()
|
||||
.filter((item) => item != null)
|
||||
.reduce((s, v) => s + v, 0);
|
||||
|
||||
return sum >= 1 && total && datesFiltering;
|
||||
|
||||
@@ -66,7 +66,7 @@ export default class DashboardNewFeatures extends Component {
|
||||
features: visibleFeatures,
|
||||
};
|
||||
})
|
||||
.compact();
|
||||
.filter((item) => item != null);
|
||||
}
|
||||
|
||||
@bind
|
||||
|
||||
@@ -69,7 +69,7 @@ export default class EditCategoryGeneral extends Component {
|
||||
? null
|
||||
: c.color.toUpperCase();
|
||||
})
|
||||
.compact();
|
||||
.filter((item) => item != null);
|
||||
}
|
||||
|
||||
@cached
|
||||
|
||||
@@ -166,7 +166,7 @@ export default class UserCardContents extends CardContentsBase {
|
||||
const value = userFields ? userFields[field.get("id")] : null;
|
||||
return isEmpty(value) ? null : EmberObject.create({ value, field });
|
||||
})
|
||||
.compact();
|
||||
.filter((item) => item != null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -169,7 +169,7 @@ export default class UserController extends Controller {
|
||||
: null;
|
||||
return isEmpty(value) ? null : EmberObject.create({ value, field });
|
||||
})
|
||||
.compact();
|
||||
.filter((item) => item != null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -265,6 +265,10 @@ const DeprecationWorkflow = new DiscourseDeprecationWorkflow([
|
||||
handler: "log",
|
||||
matchId: "discourse.native-array-extensions.any",
|
||||
},
|
||||
{
|
||||
handler: "log",
|
||||
matchId: "discourse.native-array-extensions.compact",
|
||||
},
|
||||
{
|
||||
handler: "log",
|
||||
matchId: "discourse.native-array-extensions.filterBy",
|
||||
|
||||
@@ -73,7 +73,7 @@ export function translateResults(results, opts) {
|
||||
(c) => c.id === (category.id || category.model.id)
|
||||
);
|
||||
})
|
||||
.compact();
|
||||
.filter((item) => item != null);
|
||||
|
||||
results.grouped_search_result?.extra?.categories?.forEach((category) =>
|
||||
Site.current().updateCategory(category)
|
||||
@@ -99,7 +99,7 @@ export function translateResults(results, opts) {
|
||||
url: getURL(`/g/${name}`),
|
||||
};
|
||||
})
|
||||
.compact();
|
||||
.filter((item) => item != null);
|
||||
|
||||
results.tags = results.tags
|
||||
.map(function (tag) {
|
||||
@@ -109,7 +109,7 @@ export function translateResults(results, opts) {
|
||||
url: getURL("/tag/" + tagName),
|
||||
});
|
||||
})
|
||||
.compact();
|
||||
.filter((item) => item != null);
|
||||
|
||||
return translateResultsCallbacks
|
||||
.reduce(
|
||||
|
||||
@@ -86,7 +86,7 @@ export default {
|
||||
.split("|")
|
||||
.concat(_customSharingIds)
|
||||
.map((s) => _sources[s])
|
||||
.compact();
|
||||
.filter((item) => item != null);
|
||||
|
||||
return privateContext
|
||||
? sources.filter((s) => s.showInPrivateContext)
|
||||
|
||||
@@ -274,7 +274,7 @@ function pluginAdminRouteLinks(router) {
|
||||
return;
|
||||
}
|
||||
})
|
||||
.compact();
|
||||
.filter((item) => item != null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -337,7 +337,7 @@ export default class AdminSidebarPanel extends BaseCustomSidebarPanel {
|
||||
return pluginLink;
|
||||
}
|
||||
})
|
||||
.compact();
|
||||
.filter((item) => item != null);
|
||||
this.adminNavManager.amendLinksToSection("plugins", pluginLinksToAdd);
|
||||
|
||||
this.adminSidebarStateManager.setLinkKeywords(
|
||||
|
||||
@@ -1140,7 +1140,7 @@ export default class PostStream extends RestModel {
|
||||
|
||||
// Load our unloaded posts by id
|
||||
return this.loadIntoIdentityMap(unloaded, opts).then(() => {
|
||||
return postIds.map((p) => identityMap[p]).compact();
|
||||
return postIds.map((p) => identityMap[p]).filter((item) => item != null);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1110,7 +1110,7 @@ export default class TopicTrackingState extends EmberObject {
|
||||
return { topic, newTopic, unreadTopic };
|
||||
}
|
||||
})
|
||||
.compact();
|
||||
.filter((item) => item != null);
|
||||
}
|
||||
|
||||
_stateKey(topicOrId) {
|
||||
|
||||
@@ -365,7 +365,7 @@ export default class StoreService extends Service {
|
||||
|
||||
const hydrated = obj[k]
|
||||
.map((id) => this._lookupSubType(subType, type, id, root))
|
||||
.compact();
|
||||
.filter((item) => item != null);
|
||||
|
||||
obj[this.pluralize(subType)] = hydrated;
|
||||
if (hydrated.length !== 0) {
|
||||
|
||||
@@ -46,7 +46,9 @@ export function extendTopicModel(api) {
|
||||
}
|
||||
|
||||
assignments() {
|
||||
return [this.topicAssignment(), ...this.postAssignments()].compact();
|
||||
return [this.topicAssignment(), ...this.postAssignments()].filter(
|
||||
(item) => item != null
|
||||
);
|
||||
}
|
||||
|
||||
postAssignments() {
|
||||
|
||||
Reference in New Issue
Block a user