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

refactor(icons): remove unnecessary icons and reuse the icon registration logic in Grid Filtering and QueryBuilder #14859

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
2393573
refactor(icons): remove unnecessary icons & reuse the logic in Filter…
teodosiah Oct 1, 2024
daee624
fix(icons): resove circular dependency issue
teodosiah Oct 1, 2024
4b38084
Merge branch 'master' into thristodorova/feat-14604
gedinakova Oct 2, 2024
bc6b908
Merge branch 'master' into thristodorova/feat-14604
teodosiah Oct 3, 2024
7396911
Merge branch 'master' into thristodorova/feat-14604
ChronosSF Oct 7, 2024
553434d
Merge branch 'master' into thristodorova/feat-14604
teodosiah Oct 7, 2024
91f709d
Merge branch 'master' into thristodorova/feat-14604
teodosiah Oct 7, 2024
2640343
feat(filtering): address comments and remove injection
teodosiah Oct 8, 2024
489a16c
Merge branch 'master' into thristodorova/feat-14604
gedinakova Oct 9, 2024
439617e
Merge branch 'master' into thristodorova/feat-14604
gedinakova Oct 10, 2024
aeb9257
Merge branch 'master' into thristodorova/feat-14604
teodosiah Oct 11, 2024
dede7ad
Merge branch 'master' into thristodorova/feat-14604
gedinakova Oct 14, 2024
bcb5a15
chore(*): revert filtering icons import
teodosiah Oct 14, 2024
4ce6604
Merge branch 'master' into thristodorova/feat-14604
teodosiah Oct 14, 2024
c296eda
Merge branch 'thristodorova/feat-14604' of https://github.com/IgniteU…
teodosiah Oct 14, 2024
4a2a718
Merge branch 'master' into thristodorova/feat-14604
teodosiah Oct 15, 2024
7f814d5
Merge branch 'master' into thristodorova/feat-14604
teodosiah Oct 17, 2024
f8a1cf8
Merge branch 'master' into thristodorova/feat-14604
teodosiah Oct 18, 2024
04f8fdf
Merge branch 'master' into thristodorova/feat-14604
teodosiah Oct 22, 2024
4117e8a
Merge branch 'master' into thristodorova/feat-14604
teodosiah Nov 21, 2024
57936b6
Merge branch 'master' into thristodorova/feat-14604
gedinakova Dec 3, 2024
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {
Inject,
Injectable,
OnDestroy,
Optional,
} from '@angular/core';
import { FilteringExpressionsTree, IFilteringExpressionsTree } from '../../data-operations/filtering-expressions-tree';
import { IFilteringExpression, FilteringLogic } from '../../data-operations/filtering-expression.interface';
Expand All @@ -14,12 +16,13 @@ import { IgxOverlayService } from '../../services/overlay/overlay';
import { useAnimation } from '@angular/animations';
import { AbsoluteScrollStrategy } from '../../services/overlay/scroll/absolute-scroll-strategy';
import { IgxIconService } from '../../icon/icon.service';
import { editor, pinLeft, unpinLeft } from '@igniteui/material-icons-extended';
import { ExpressionUI, generateExpressionsList } from './excel-style/common';
import { ColumnType, GridType } from '../common/grid.interface';
import { formatDate } from '../../core/utils';
import { ExcelStylePositionStrategy } from './excel-style/excel-style-position-strategy';
import { fadeIn } from 'igniteui-angular/animations';
import { FILTERING_ICONS } from '../../icon/filtering-icons';
import { pinLeft, unpinLeft } from '@igniteui/material-icons-extended';

/**
* @hidden
Expand Down Expand Up @@ -55,6 +58,7 @@ export class IgxFilteringService implements OnDestroy {
constructor(
private iconService: IgxIconService,
protected _overlayService: IgxOverlayService,
@Optional() @Inject(FILTERING_ICONS) _filteringIcons: any
) { }

public ngOnDestroy(): void {
Expand Down Expand Up @@ -318,10 +322,6 @@ export class IgxFilteringService implements OnDestroy {
* Register filtering SVG icons in the icon service.
*/
public registerSVGIcons(): void {
const editorIcons = editor as any[];
editorIcons.forEach(icon => {
this.iconService.addSvgIconFromText(icon.name, icon.value, 'imx-icons');
});
this.iconService.addSvgIconFromText(pinLeft.name, pinLeft.value, 'imx-icons');
this.iconService.addSvgIconFromText(unpinLeft.name, unpinLeft.value, 'imx-icons');
}
Expand Down
44 changes: 44 additions & 0 deletions projects/igniteui-angular/src/lib/icon/filtering-icons.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { InjectionToken, inject } from '@angular/core';
import { IMXIcon, contains, doesNotContain, endsWith, equals, greaterThan, greaterThanOrEqual, isAfter, isBefore, isEmpty, isFalse, isNull, isNotNull, isTrue, lastMonth, lastYear, lessThan, lessThanOrEqual, nextMonth, nextYear, notEmpty, notEqual, selectAll, startsWith, thisMonth, thisYear, today, ungroup, yesterday } from '@igniteui/material-icons-extended';
import { IgxIconService } from './icon.service';

export const filteringIcons: IMXIcon[] = [
contains,
doesNotContain,
endsWith,
equals,
greaterThan,
greaterThanOrEqual,
isAfter,
isBefore,
isEmpty,
isFalse,
isNotNull,
isNull,
isTrue,
lastMonth,
lastYear,
lessThan,
lessThanOrEqual,
nextMonth,
nextYear,
notEmpty,
notEqual,
selectAll,
startsWith,
thisMonth,
thisYear,
today,
ungroup,
yesterday
];
export const FILTERING_ICONS = new InjectionToken<void>('FILTERING_ICONS', {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, not exactly what I had in mind, but could consider.
First issue with the token approach is it doesn't tree-shake without explicit /*@__PURE__*/ before it (see others in the repo) and thus drags the factory function and the icons collection with the exports from the package, thus making those permanently in the bundle. See the bundle app build warning here:
https://github.com/IgniteUI/igniteui-angular/actions/runs/11162862017/job/31028455568#step:16:63
(just FYI same thing happens w/ just a chip component active).

The other issue with this is that due to this being injected (thus on component init) - these icons will be registered even when not in use, so again might be better as a simpler reusable function.

Also no reason for filteringIcons and registerFilteringSVGIconsFactory to be exported as far as I can tell.

Copy link
Member

@damyanpetev damyanpetev Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also something going on with the extended icons - I get all of them bundled, which makes no sense and there might be an additional issue there as well.

Edit: Yeah, there seems to be an issue with the icons exports as they stand atm.
Even a simple import { contains } from '@igniteui/material-icons-extended'; will pull the entire package it seems:
image
That's with the Bundle test app that uses the default application builder. Possibly related to angular/angular-cli#26622, though not exactly as everything shakes out fine if the 'bundles' per category are not exported from the main barrel. Still digging.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, seems to be to do with the all export. If split like this:

import {
    contains, doesNotContain, endsWith, equals, greaterThan, greaterThanOrEqual, isAfter, isBefore,
    isEmpty, isFalse, isNull, isNotNull, isTrue, lastMonth, lastYear, lessThan, lessThanOrEqual, nextMonth,
    nextYear, notEmpty, notEqual, selectAll, startsWith, thisMonth, thisYear, today, ungroup, yesterday
} from '@igniteui/material-icons-extended/editor';

import { type IMXIcon } from '@igniteui/material-icons-extended';

Tree-shaking seems to work fine

providedIn: 'root',
factory: () => registerFilteringSVGIconsFactory(inject(IgxIconService))
});

export function registerFilteringSVGIconsFactory(iconService: IgxIconService) {
filteringIcons.forEach(icon => {
iconService.addSvgIconFromText(icon.name, icon.value, 'imx-icons');
});
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { AfterViewInit, ContentChild, EventEmitter, LOCALE_ID, Output, Pipe, PipeTransform } from '@angular/core';
import { AfterViewInit, ContentChild, EventEmitter, LOCALE_ID, Optional, Output, Pipe, PipeTransform } from '@angular/core';
import { getLocaleFirstDayOfWeek, NgIf, NgFor, NgTemplateOutlet, NgClass, DatePipe } from '@angular/common';
import { Inject } from '@angular/core';
import {
Component, Input, ViewChild, ChangeDetectorRef, ViewChildren, QueryList, ElementRef, OnDestroy, HostBinding
} from '@angular/core';
import { FormsModule } from '@angular/forms';
import { Subject } from 'rxjs';
import { editor } from '@igniteui/material-icons-extended';
import { IButtonGroupEventArgs, IgxButtonGroupComponent } from '../buttonGroup/buttonGroup.component';
import { IgxChipComponent } from '../chips/chip.component';
import { IQueryBuilderResourceStrings, QueryBuilderResourceStringsEN } from '../core/i18n/query-builder-resources';
Expand Down Expand Up @@ -37,6 +36,7 @@ import { IgxPrefixDirective } from '../directives/prefix/prefix.directive';
import { IgxIconComponent } from '../icon/icon.component';
import { getCurrentResourceStrings } from '../core/i18n/resources';
import { IgxIconButtonDirective } from '../directives/button/icon-button.directive';
import { FILTERING_ICONS } from '../icon/filtering-icons';

const DEFAULT_PIPE_DATE_FORMAT = 'mediumDate';
const DEFAULT_PIPE_TIME_FORMAT = 'mediumTime';
Expand Down Expand Up @@ -146,7 +146,6 @@ export class IgxQueryBuilderComponent implements AfterViewInit, OnDestroy {
this._fields = fields;

if (this._fields) {
this.registerSVGIcons();

this._fields.forEach(field => {
this.setFilters(field);
Expand Down Expand Up @@ -398,7 +397,8 @@ export class IgxQueryBuilderComponent implements AfterViewInit, OnDestroy {
protected iconService: IgxIconService,
protected platform: PlatformUtil,
protected el: ElementRef,
@Inject(LOCALE_ID) protected _localeId: string) {
@Inject(LOCALE_ID) protected _localeId: string,
@Optional() @Inject(FILTERING_ICONS) _filteringIcons: any) {
this.locale = this.locale || this._localeId;
}

Expand Down Expand Up @@ -1207,13 +1207,5 @@ export class IgxQueryBuilderComponent implements AfterViewInit, OnDestroy {
this.rootGroup = this.createExpressionGroupItem(this.expressionTree);
this.currentGroup = this.rootGroup;
}

private registerSVGIcons(): void {
const editorIcons = editor as any[];

editorIcons.forEach((icon) => {
this.iconService.addSvgIconFromText(icon.name, icon.value, 'imx-icons');
});
}
}

Loading