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

feat(grid): support clear matchedCells when keywords is null and search by progress #209

Merged
merged 2 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 1 addition & 3 deletions packages/grid/src/grid.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,7 @@ export class AITableGrid extends AITableGridBase implements OnInit, OnDestroy {
});
effect(
() => {
if (this.aiKeywords()) {
this.aiTableGridMatchCellService.findMatchedCells(this.aiKeywords()!, this.aiReferences());
}
this.aiTableGridMatchCellService.findMatchedCells(this.aiKeywords()!, this.aiReferences());
},
{ allowSignalWrites: true }
);
Expand Down
8 changes: 8 additions & 0 deletions packages/grid/src/services/match-cell.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export class AITableGridMatchCellService {
}

findMatchedCells(keywords: string, references: AITableReferences) {
if (!keywords) {
this.clearMatchedCells();
return;
}
let matchedCells: string[] = [];
this.aiTable.records().forEach((record) => {
this.aiTable.fields().forEach((field) => {
Expand All @@ -23,6 +27,10 @@ export class AITableGridMatchCellService {
this.aiTable.matchedCells.set([...matchedCells]);
}

private clearMatchedCells() {
this.aiTable.matchedCells.set([]);
}

private isCellMatchKeywords(aiTable: AITable, field: AITableField, recordId: string, keywords: string, references: AITableReferences) {
const cellValue = AITableQueries.getFieldValue(aiTable, [recordId, field._id]);
const transformValue = transformCellValue(aiTable, field, cellValue);
Expand Down
3 changes: 2 additions & 1 deletion packages/grid/src/utils/field/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { AITableFieldType } from '../../index';
import { Field } from './field';
import { LinkField } from './link';
import { MemberField } from './member';
import { ProgressField } from './progress';
import { SelectField } from './select';
import { TextField } from './text';

Expand All @@ -16,7 +17,7 @@ export const ViewOperationMap: Record<AITableFieldType, Field> = {
[AITableFieldType.rate]: new TextField(),
[AITableFieldType.link]: new LinkField(),
[AITableFieldType.member]: new MemberField(),
[AITableFieldType.progress]: new TextField(),
[AITableFieldType.progress]: new ProgressField(),
[AITableFieldType.createdBy]: new MemberField(),
[AITableFieldType.updatedBy]: new MemberField()
};
9 changes: 6 additions & 3 deletions packages/grid/src/utils/field/progress.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { AITableField } from '../../index';
import { AITableField, isEmpty } from '../../index';
import { Field } from './field';

export class ProgressField extends Field {
cellFullText(transformValue: number, field: AITableField): string[] {
const fullText = `${transformValue}%`;
return [fullText];
let fullText: string[] = [];
if (!isEmpty(transformValue)) {
fullText.push(`${transformValue}%`);
}
return fullText;
}
}
Loading