Skip to content

Commit

Permalink
chore: use .some() instead of .find() when used as boolean response
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Dec 14, 2020
1 parent 96ce9bd commit 6a7d980
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 21 deletions.
14 changes: 7 additions & 7 deletions packages/common/src/extensions/contextMenuExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export class ContextMenuExtension implements Extension {
// show context menu: Copy (cell value)
if (contextMenu && !contextMenu.hideCopyCellValueCommand) {
const commandName = 'copy';
if (!originalCustomItems.find((item: MenuCommandItem) => item.hasOwnProperty('command') && item.command === commandName)) {
if (!originalCustomItems.some((item: MenuCommandItem) => item.hasOwnProperty('command') && item.command === commandName)) {
menuCustomItems.push(
{
iconCssClass: contextMenu.iconCopyCellValueCommand || 'fa fa-clone',
Expand Down Expand Up @@ -224,7 +224,7 @@ export class ContextMenuExtension implements Extension {
// show context menu: Export to file
if ((gridOptions?.enableExport || gridOptions?.enableTextExport) && contextMenu && !contextMenu.hideExportCsvCommand) {
const commandName = 'export-csv';
if (!originalCustomItems.find((item: MenuCommandItem) => item.hasOwnProperty('command') && item.command === commandName)) {
if (!originalCustomItems.some((item: MenuCommandItem) => item.hasOwnProperty('command') && item.command === commandName)) {
menuCustomItems.push(
{
iconCssClass: contextMenu.iconExportCsvCommand || 'fa fa-download',
Expand Down Expand Up @@ -254,7 +254,7 @@ export class ContextMenuExtension implements Extension {
// show context menu: Export to Excel
if (gridOptions && gridOptions.enableExcelExport && contextMenu && !contextMenu.hideExportExcelCommand) {
const commandName = 'export-excel';
if (!originalCustomItems.find((item: MenuCommandItem) => item.hasOwnProperty('command') && item.command === commandName)) {
if (!originalCustomItems.some((item: MenuCommandItem) => item.hasOwnProperty('command') && item.command === commandName)) {
menuCustomItems.push(
{
iconCssClass: contextMenu.iconExportExcelCommand || 'fa fa-file-excel-o text-success',
Expand Down Expand Up @@ -282,7 +282,7 @@ export class ContextMenuExtension implements Extension {
// show context menu: export to text file as tab delimited
if ((gridOptions?.enableExport || gridOptions?.enableTextExport) && contextMenu && !contextMenu.hideExportTextDelimitedCommand) {
const commandName = 'export-text-delimited';
if (!originalCustomItems.find((item: MenuCommandItem) => item.hasOwnProperty('command') && item.command === commandName)) {
if (!originalCustomItems.some((item: MenuCommandItem) => item.hasOwnProperty('command') && item.command === commandName)) {
menuCustomItems.push(
{
iconCssClass: contextMenu.iconExportTextDelimitedCommand || 'fa fa-download',
Expand Down Expand Up @@ -319,7 +319,7 @@ export class ContextMenuExtension implements Extension {
// show context menu: Clear Grouping (except for Tree Data which shouldn't have this feature)
if (gridOptions && !gridOptions.enableTreeData && contextMenu && !contextMenu.hideClearAllGrouping) {
const commandName = 'clear-grouping';
if (!originalCustomItems.find((item: MenuCommandItem) => item.hasOwnProperty('command') && item.command === commandName)) {
if (!originalCustomItems.some((item: MenuCommandItem) => item.hasOwnProperty('command') && item.command === commandName)) {
menuCustomItems.push(
{
iconCssClass: contextMenu.iconClearGroupingCommand || 'fa fa-times',
Expand All @@ -341,7 +341,7 @@ export class ContextMenuExtension implements Extension {
// show context menu: Collapse all Groups
if (gridOptions && contextMenu && !contextMenu.hideCollapseAllGroups) {
const commandName = 'collapse-all-groups';
if (!originalCustomItems.find((item: MenuCommandItem) => item.hasOwnProperty('command') && item.command === commandName)) {
if (!originalCustomItems.some((item: MenuCommandItem) => item.hasOwnProperty('command') && item.command === commandName)) {
menuCustomItems.push(
{
iconCssClass: contextMenu.iconCollapseAllGroupsCommand || 'fa fa-compress',
Expand Down Expand Up @@ -372,7 +372,7 @@ export class ContextMenuExtension implements Extension {
// show context menu: Expand all Groups
if (gridOptions && contextMenu && !contextMenu.hideExpandAllGroups) {
const commandName = 'expand-all-groups';
if (!originalCustomItems.find((item: MenuCommandItem) => item.hasOwnProperty('command') && item.command === commandName)) {
if (!originalCustomItems.some((item: MenuCommandItem) => item.hasOwnProperty('command') && item.command === commandName)) {
menuCustomItems.push(
{
iconCssClass: contextMenu.iconExpandAllGroupsCommand || 'fa fa-expand',
Expand Down
18 changes: 9 additions & 9 deletions packages/common/src/extensions/gridMenuExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export class GridMenuExtension implements Extension {
// show grid menu: Clear Frozen Columns
if (this.sharedService.gridOptions && this._gridMenuOptions && !this._gridMenuOptions.hideClearFrozenColumnsCommand) {
const commandName = 'clear-frozen-columns';
if (!originalCustomItems.find((item: GridMenuItem) => item.hasOwnProperty('command') && item.command === commandName)) {
if (!originalCustomItems.some((item: GridMenuItem) => item.hasOwnProperty('command') && item.command === commandName)) {
gridMenuCustomItems.push(
{
iconCssClass: this._gridMenuOptions.iconClearFrozenColumnsCommand || 'fa fa-times',
Expand All @@ -249,7 +249,7 @@ export class GridMenuExtension implements Extension {
// show grid menu: Clear all Filters
if (this.sharedService.gridOptions && this._gridMenuOptions && !this._gridMenuOptions.hideClearAllFiltersCommand) {
const commandName = 'clear-filter';
if (!originalCustomItems.find((item: GridMenuItem) => item.hasOwnProperty('command') && item.command === commandName)) {
if (!originalCustomItems.some((item: GridMenuItem) => item.hasOwnProperty('command') && item.command === commandName)) {
gridMenuCustomItems.push(
{
iconCssClass: this._gridMenuOptions.iconClearAllFiltersCommand || 'fa fa-filter text-danger',
Expand All @@ -265,7 +265,7 @@ export class GridMenuExtension implements Extension {
// show grid menu: toggle filter row
if (this.sharedService.gridOptions && this._gridMenuOptions && !this._gridMenuOptions.hideToggleFilterCommand) {
const commandName = 'toggle-filter';
if (!originalCustomItems.find((item: GridMenuItem) => item.hasOwnProperty('command') && item.command === commandName)) {
if (!originalCustomItems.some((item: GridMenuItem) => item.hasOwnProperty('command') && item.command === commandName)) {
gridMenuCustomItems.push(
{
iconCssClass: this._gridMenuOptions.iconToggleFilterCommand || 'fa fa-random',
Expand All @@ -281,7 +281,7 @@ export class GridMenuExtension implements Extension {
// show grid menu: refresh dataset
if (backendApi && this.sharedService.gridOptions && this._gridMenuOptions && !this._gridMenuOptions.hideRefreshDatasetCommand) {
const commandName = 'refresh-dataset';
if (!originalCustomItems.find((item: GridMenuItem) => item.hasOwnProperty('command') && item.command === commandName)) {
if (!originalCustomItems.some((item: GridMenuItem) => item.hasOwnProperty('command') && item.command === commandName)) {
gridMenuCustomItems.push(
{
iconCssClass: this._gridMenuOptions.iconRefreshDatasetCommand || 'fa fa-refresh',
Expand All @@ -299,7 +299,7 @@ export class GridMenuExtension implements Extension {
// show grid menu: toggle pre-header row
if (this.sharedService.gridOptions && this._gridMenuOptions && !this._gridMenuOptions.hideTogglePreHeaderCommand) {
const commandName = 'toggle-preheader';
if (!originalCustomItems.find((item: GridMenuItem) => item.hasOwnProperty('command') && item.command === commandName)) {
if (!originalCustomItems.some((item: GridMenuItem) => item.hasOwnProperty('command') && item.command === commandName)) {
gridMenuCustomItems.push(
{
iconCssClass: this._gridMenuOptions.iconTogglePreHeaderCommand || 'fa fa-random',
Expand All @@ -317,7 +317,7 @@ export class GridMenuExtension implements Extension {
// show grid menu: Clear all Sorting
if (this.sharedService.gridOptions && this._gridMenuOptions && !this._gridMenuOptions.hideClearAllSortingCommand) {
const commandName = 'clear-sorting';
if (!originalCustomItems.find((item: GridMenuItem) => item.hasOwnProperty('command') && item.command === commandName)) {
if (!originalCustomItems.some((item: GridMenuItem) => item.hasOwnProperty('command') && item.command === commandName)) {
gridMenuCustomItems.push(
{
iconCssClass: this._gridMenuOptions.iconClearAllSortingCommand || 'fa fa-unsorted text-danger',
Expand All @@ -334,7 +334,7 @@ export class GridMenuExtension implements Extension {
// show grid menu: Export to file
if ((this.sharedService.gridOptions?.enableExport || this.sharedService.gridOptions?.enableTextExport) && this._gridMenuOptions && !this._gridMenuOptions.hideExportCsvCommand) {
const commandName = 'export-csv';
if (!originalCustomItems.find((item: GridMenuItem) => item.hasOwnProperty('command') && item.command === commandName)) {
if (!originalCustomItems.some((item: GridMenuItem) => item.hasOwnProperty('command') && item.command === commandName)) {
gridMenuCustomItems.push(
{
iconCssClass: this._gridMenuOptions.iconExportCsvCommand || 'fa fa-download',
Expand All @@ -350,7 +350,7 @@ export class GridMenuExtension implements Extension {
// show grid menu: Export to Excel
if (this.sharedService.gridOptions && this.sharedService.gridOptions.enableExcelExport && this._gridMenuOptions && !this._gridMenuOptions.hideExportExcelCommand) {
const commandName = 'export-excel';
if (!originalCustomItems.find((item: GridMenuItem) => item.hasOwnProperty('command') && item.command === commandName)) {
if (!originalCustomItems.some((item: GridMenuItem) => item.hasOwnProperty('command') && item.command === commandName)) {
gridMenuCustomItems.push(
{
iconCssClass: this._gridMenuOptions.iconExportExcelCommand || 'fa fa-file-excel-o text-success',
Expand All @@ -366,7 +366,7 @@ export class GridMenuExtension implements Extension {
// show grid menu: export to text file as tab delimited
if ((this.sharedService.gridOptions?.enableExport || this.sharedService.gridOptions?.enableTextExport) && this._gridMenuOptions && !this._gridMenuOptions.hideExportTextDelimitedCommand) {
const commandName = 'export-text-delimited';
if (!originalCustomItems.find((item: GridMenuItem) => item.hasOwnProperty('command') && item.command === commandName)) {
if (!originalCustomItems.some((item: GridMenuItem) => item.hasOwnProperty('command') && item.command === commandName)) {
gridMenuCustomItems.push(
{
iconCssClass: this._gridMenuOptions.iconExportTextDelimitedCommand || 'fa fa-download',
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/services/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export function convertHierarchicalViewToParentChildArrayByReference<T = any>(hi
if (Array.isArray(hierarchicalArray)) {
for (const item of hierarchicalArray) {
if (item) {
const itemExist = outputArrayRef.find((itm: T) => itm[identifierPropName] === item[identifierPropName]);
const itemExist = outputArrayRef.some((itm: T) => itm[identifierPropName] === item[identifierPropName]);
if (!itemExist) {
item[treeLevelPropName] = treeLevel; // save tree level ref
item[parentPropName] = parentId || null;
Expand Down
4 changes: 1 addition & 3 deletions packages/odata/src/services/grid-odata.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,7 @@ export class GridOdataService implements BackendService {
// if user defined some "presets", then we need to find the filters from the column definitions instead
let columnDef: Column | undefined;
if (isUpdatedByPresetOrDynamically && Array.isArray(this._columnDefinitions)) {
columnDef = this._columnDefinitions.find((column: Column) => {
return column.id === columnFilter.columnId;
});
columnDef = this._columnDefinitions.find((column: Column) => column.id === columnFilter.columnId);
} else {
columnDef = columnFilter.columnDef;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class UniversalContainerService implements ContainerService {
}

registerInstance(key: string, instance: any) {
const dependency = this.dependencies.find(dep => dep.key === key);
const dependency = this.dependencies.some(dep => dep.key === key);
if (!dependency) {
this.dependencies.push({ key, instance });
}
Expand Down

0 comments on commit 6a7d980

Please sign in to comment.