-
-
Notifications
You must be signed in to change notification settings - Fork 18
Add ordering and ordering_field to AIGeneratedTableSettings for enhanced table sorting #1527
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,6 @@ | ||||||||||||||||||||||||||||
| import { Injectable } from '@nestjs/common'; | ||||||||||||||||||||||||||||
| import { WidgetTypeEnum } from '../../enums/widget-type.enum.js'; | ||||||||||||||||||||||||||||
| import { QueryOrderingEnum } from '../../enums/query-ordering.enum.js'; | ||||||||||||||||||||||||||||
| import { checkFieldAutoincrement } from '../../helpers/check-field-autoincrement.js'; | ||||||||||||||||||||||||||||
| import { TableWidgetEntity } from '../widget/table-widget.entity.js'; | ||||||||||||||||||||||||||||
| import { TableInformation } from './ai-data-entities/types/ai-module-types.js'; | ||||||||||||||||||||||||||||
|
|
@@ -12,6 +13,8 @@ interface AIGeneratedTableSettings { | |||||||||||||||||||||||||||
| search_fields: string[]; | ||||||||||||||||||||||||||||
| readonly_fields: string[]; | ||||||||||||||||||||||||||||
| columns_view: string[]; | ||||||||||||||||||||||||||||
| ordering: string; | ||||||||||||||||||||||||||||
| ordering_field: string; | ||||||||||||||||||||||||||||
| widgets: Array<{ | ||||||||||||||||||||||||||||
| field_name: string; | ||||||||||||||||||||||||||||
| widget_type: string; | ||||||||||||||||||||||||||||
|
|
@@ -72,7 +75,9 @@ For each table, provide: | |||||||||||||||||||||||||||
| 2. search_fields: Columns that should be searchable (text fields like name, email, title) | ||||||||||||||||||||||||||||
| 3. readonly_fields: Columns that should not be editable (like auto_increment, timestamps) | ||||||||||||||||||||||||||||
| 4. columns_view: All columns in preferred display order | ||||||||||||||||||||||||||||
| 5. widgets: For each column, suggest the best widget type from: ${widgetTypes} | ||||||||||||||||||||||||||||
| 5. ordering: Default sort order - either "ASC" or "DESC" (use "DESC" for tables with timestamps to show newest first) | ||||||||||||||||||||||||||||
| 6. ordering_field: Column name to sort by default (prefer created_at, updated_at, or primary key) | ||||||||||||||||||||||||||||
| 7. widgets: For each column, suggest the best widget type from: ${widgetTypes} | ||||||||||||||||||||||||||||
| Available widget types and when to use them: | ||||||||||||||||||||||||||||
| - Password: for password fields | ||||||||||||||||||||||||||||
|
|
@@ -111,6 +116,8 @@ Respond ONLY with valid JSON in this exact format (no markdown, no explanations) | |||||||||||||||||||||||||||
| "search_fields": ["name", "email"], | ||||||||||||||||||||||||||||
| "readonly_fields": ["id", "created_at"], | ||||||||||||||||||||||||||||
| "columns_view": ["id", "name", "email", "created_at"], | ||||||||||||||||||||||||||||
| "ordering": "DESC", | ||||||||||||||||||||||||||||
| "ordering_field": "created_at", | ||||||||||||||||||||||||||||
| "widgets": [ | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| "field_name": "column_name", | ||||||||||||||||||||||||||||
|
|
@@ -148,6 +155,8 @@ Respond ONLY with valid JSON in this exact format (no markdown, no explanations) | |||||||||||||||||||||||||||
| settings.search_fields = this.filterValidColumns(tableSettings.search_fields, validColumnNames); | ||||||||||||||||||||||||||||
| settings.readonly_fields = this.filterValidColumns(tableSettings.readonly_fields, validColumnNames); | ||||||||||||||||||||||||||||
| settings.columns_view = this.filterValidColumns(tableSettings.columns_view, validColumnNames); | ||||||||||||||||||||||||||||
| settings.ordering = this.mapOrdering(tableSettings.ordering); | ||||||||||||||||||||||||||||
| settings.ordering_field = validColumnNames.includes(tableSettings.ordering_field) ? tableSettings.ordering_field : null; | ||||||||||||||||||||||||||||
|
Comment on lines
+158
to
+159
|
||||||||||||||||||||||||||||
| settings.ordering = this.mapOrdering(tableSettings.ordering); | |
| settings.ordering_field = validColumnNames.includes(tableSettings.ordering_field) ? tableSettings.ordering_field : null; | |
| const mappedOrdering = this.mapOrdering(tableSettings.ordering); | |
| const validOrderingField = validColumnNames.includes(tableSettings.ordering_field) | |
| ? tableSettings.ordering_field | |
| : null; | |
| if (mappedOrdering && validOrderingField) { | |
| settings.ordering = mappedOrdering; | |
| settings.ordering_field = validOrderingField; | |
| } else { | |
| settings.ordering = null; | |
| settings.ordering_field = null; | |
| } |
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 validation logic doesn't handle the case when
tableSettings.ordering_fieldis undefined or null. If the AI response is missing this field or it's null,validColumnNames.includes(undefined)orvalidColumnNames.includes(null)will be called, which will always return false but is not semantically clear. Consider adding an explicit check for undefined/null before the includes check.