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

Issue #1 Fix: Case Insensitivity #3

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bachowsky
Copy link

  • Case Insensitivity logic is added, by passing a new optional parameter in to subject. If user sets isHeaderCaseSensitive parameter as false in his application, rows will be filtered with case insensitivity.

@vercel
Copy link

vercel bot commented Jul 12, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ng-mat-table-filter ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 12, 2023 6:39am

Copy link
Owner

@besimgurbuz besimgurbuz left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, I have some comments.

@@ -0,0 +1 @@
export type CaseSensitivityType = true | false;
Copy link
Owner

Choose a reason for hiding this comment

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

I think there is no need to create a type for sensitivity state.

Comment on lines +45 to +52
if (filter.isCaseSensitive == false) {
return this.operators[filter.operator](
value.toString().toLowerCase(),
filter.input?.toString().toLowerCase()
);
} else {
return this.operators[filter.operator](value, filter.input);
}
Copy link
Owner

@besimgurbuz besimgurbuz Jul 20, 2023

Choose a reason for hiding this comment

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

I have a suggestion for this code block;

Suggested change
if (filter.isCaseSensitive == false) {
return this.operators[filter.operator](
value.toString().toLowerCase(),
filter.input?.toString().toLowerCase()
);
} else {
return this.operators[filter.operator](value, filter.input);
}
const operatorFn = this.operators[filter.operator];
if (filter.isCaseSensitive) {
return operatorFn(value, filter.input);
}
return operatorFn(value.toString().toLowerCase(), filter.input?.toString()?.toLowerCase());

@@ -29,6 +29,7 @@ export class MatTableFilterButtonComponent
{
public intlService = inject(MatTableFilterIntlService);
private cd = inject(ChangeDetectorRef);
private isCaseSensitive = true;
Copy link
Owner

Choose a reason for hiding this comment

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

I think there is no need to have another field to hold case sensitivity state. You can just use sensitivityType

@@ -27,6 +28,7 @@ import {MatTableHeaderType} from './models/header-type';
export class MatTableFilterHeader implements AfterViewInit {
@Input({required: false}) matTableFilterHeaderType: MatTableHeaderType =
'string';
@Input({required: false}) isHeaderCaseSensitive: CaseSensitivityType = true;
Copy link
Owner

Choose a reason for hiding this comment

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

The naming is important here. To infer the developer that this field is coming from MatTableFilterHeader, it should prefixed as matTableFilter. So changing the attribute name to matTableFilterCaseSensitive or matTableFilterIsCaseSensitive would be much better.


export class MatTableTriggerer<T extends MatTableDefaultFilterSelection> {
protected matColumnDef = inject(MatColumnDef);
protected selectedFilterSubject = new Subject<T>();

public headerType!: MatTableHeaderType;
public sensitivityType!: CaseSensitivityType;
Copy link
Owner

Choose a reason for hiding this comment

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

With my suggestion on holding this field as just plain boolean, this field's name can also changed to caseSensitive or isCaseSensitive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Case Insensitivity can also be added into string comparisons
2 participants