-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(state): support filter and sort by link field (#195)
- Loading branch information
1 parent
2f0a8e0
commit fe6ef2e
Showing
3 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { isEmpty } from '../../common'; | ||
import { AITableFilterCondition, AITableFilterOperation } from '../../../types'; | ||
import { Field } from './field'; | ||
import { AITableField, FieldValue, LinkFieldValue } from '@ai-table/grid'; | ||
import { isObject, isString } from 'ngx-tethys/util'; | ||
|
||
export class LinkField extends Field { | ||
override isMeetFilter(condition: AITableFilterCondition<string>, cellValue: FieldValue) { | ||
const cellTextValue = this.cellValueToString(cellValue); | ||
switch (condition.operation) { | ||
case AITableFilterOperation.empty: | ||
return isEmpty(cellTextValue); | ||
case AITableFilterOperation.exists: | ||
return !isEmpty(cellTextValue); | ||
case AITableFilterOperation.contain: | ||
return !isEmpty(cellTextValue) && this.stringInclude(cellTextValue, condition.value); | ||
default: | ||
return super.isMeetFilter(condition, cellTextValue); | ||
} | ||
} | ||
|
||
override eq(cv1: LinkFieldValue | string | null, cv2: LinkFieldValue | string | null): boolean { | ||
return this.cellValueToString(cv1) === this.cellValueToString(cv2); | ||
} | ||
|
||
override compare(cellValue1: FieldValue, cellValue2: FieldValue, field: AITableField): number { | ||
const cellTextValue1 = this.cellValueToString(cellValue1); | ||
const cellTextValue2 = this.cellValueToString(cellValue2); | ||
|
||
return super.compare(cellTextValue1, cellTextValue2, field); | ||
} | ||
|
||
cellValueToString(cellValue: LinkFieldValue | string | null): string { | ||
if (isString(cellValue)) { | ||
return cellValue; | ||
} | ||
if (isObject(cellValue)) { | ||
return cellValue.text; | ||
} | ||
return ''; | ||
} | ||
} |