-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: main
Are you sure you want to change the base?
Conversation
bachowsky
commented
Jul 12, 2023
- 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.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this 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; |
There was a problem hiding this comment.
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.
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); | ||
} |
There was a problem hiding this comment.
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;
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
.