Skip to content

Commit 2c6f263

Browse files
Merge pull request #1776 from rocket-admin/ai-ddl-improvements
Ai ddl improvements
2 parents 8ca1841 + 5a8c5ad commit 2c6f263

5 files changed

Lines changed: 56 additions & 45 deletions

File tree

frontend/src/app/components/dashboard/dashboard.component.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ export class DashboardComponent implements OnInit, OnDestroy {
200200
} else {
201201
tableName = this.allTables[0]?.table;
202202
}
203-
this.router.navigate([`/dashboard/${this.connectionID}/${tableName}`], { replaceUrl: true });
203+
this.router.navigate([`/dashboard/${this.connectionID}/${tableName}`], { replaceUrl: true, queryParamsHandling: 'preserve' });
204204
this.selectedTableName = tableName;
205205
}
206206
}),
@@ -271,7 +271,8 @@ export class DashboardComponent implements OnInit, OnDestroy {
271271
this.sortOrder = queryParams.sort_direction;
272272

273273
const search = queryParams.search;
274-
this.getRows(search);
274+
const uncached = queryParams.uncached === 'true';
275+
this.getRows(search, uncached);
275276
console.log('getRows from setTable');
276277

277278
const selectedTableProperties = this.allTables.find((table: any) => table.table === this.selectedTableName);
@@ -389,7 +390,7 @@ export class DashboardComponent implements OnInit, OnDestroy {
389390
});
390391
}
391392

392-
getRows(search?: string) {
393+
getRows(search?: string, uncached?: boolean) {
393394
console.log('getRows, filters:', this.filters);
394395
this._uiSettings.getUiSettings().subscribe((settings: UiSettings) => {
395396
this.uiSettings = settings?.connections[this.connectionID];
@@ -404,6 +405,7 @@ export class DashboardComponent implements OnInit, OnDestroy {
404405
sortOrder: this.sortOrder,
405406
filters: this.filters,
406407
search,
408+
uncached,
407409
});
408410
});
409411
}

frontend/src/app/components/dashboard/db-tables-data-source.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ interface RowsParams {
3131
comparators?: object;
3232
search?: string;
3333
isTablePageSwitched?: boolean;
34+
uncached?: boolean;
3435
}
3536

3637
export class TablesDataSource implements DataSource<Object> {
@@ -118,6 +119,7 @@ export class TablesDataSource implements DataSource<Object> {
118119
comparators,
119120
search,
120121
isTablePageSwitched,
122+
uncached,
121123
}: RowsParams) {
122124
this.loadingSubject.next(true);
123125
this.alert_primaryKeysInfo = null;
@@ -135,6 +137,7 @@ export class TablesDataSource implements DataSource<Object> {
135137
filters,
136138
comparators,
137139
search,
140+
uncached,
138141
});
139142

140143
if (fetchedTable) {

frontend/src/app/components/edit-database-schema/edit-database-schema.component.html

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ <h3 class="schema-chat__diagram-title">{{ message.text }}</h3>
156156
<div class="schema-chat__open-tables">
157157
<a mat-flat-button color="primary" (click)="onOpenTables()"
158158
[routerLink]="['/dashboard', connectionID]"
159+
[queryParams]="{uncached: 'true'}"
159160
data-testid="schema-open-tables-button">
160161
<mat-icon>table_chart</mat-icon>
161162
Open tables
@@ -164,45 +165,44 @@ <h3 class="schema-chat__diagram-title">{{ message.text }}</h3>
164165
}
165166

166167
<!-- Input form / Actions -->
167-
@if (!applied()) {
168-
<div class="schema-chat__form">
169-
@if (pendingBatch()) {
170-
<div class="schema-chat__actions">
171-
<button mat-stroked-button type="button" (click)="onReject()" [disabled]="applying()"
172-
data-testid="schema-reject-button">
173-
Reject
174-
</button>
175-
<button mat-flat-button color="primary" type="button" (click)="onApprove()" [disabled]="applying()"
176-
data-testid="schema-approve-button">
177-
@if (applying()) {
178-
Applying...
179-
} @else {
180-
<mat-icon>check</mat-icon>
181-
Apply All
182-
}
168+
<div class="schema-chat__form">
169+
@if (pendingBatch()) {
170+
<div class="schema-chat__actions">
171+
<button mat-stroked-button type="button" (click)="onReject()" [disabled]="applying()"
172+
data-testid="schema-reject-button">
173+
Reject
174+
</button>
175+
<button mat-flat-button color="primary" type="button" (click)="onApprove()" [disabled]="applying()"
176+
data-testid="schema-approve-button">
177+
@if (applying()) {
178+
Applying...
179+
} @else {
180+
<mat-icon>check</mat-icon>
181+
Apply All
182+
}
183+
</button>
184+
</div>
185+
} @else {
186+
<form (ngSubmit)="onSubmit()">
187+
<mat-form-field appearance="outline" class="schema-chat__input-field">
188+
<mat-label>{{showClose || isRoutedPage() ? 'Describe the changes you need...' : 'Describe the database you need...'}}</mat-label>
189+
<textarea matInput
190+
name="schemaPrompt"
191+
[ngModel]="userPrompt()"
192+
(ngModelChange)="userPrompt.set($event)"
193+
(keydown)="onKeydown($event)"
194+
rows="2"
195+
maxlength="1000"
196+
[disabled]="submitting()"
197+
data-testid="schema-prompt-textarea"
198+
></textarea>
199+
<button mat-icon-button matSuffix type="submit"
200+
[disabled]="!userPrompt().trim() || submitting()"
201+
class="schema-chat__send-button">
202+
<mat-icon>send</mat-icon>
183203
</button>
184-
</div>
185-
} @else {
186-
<form (ngSubmit)="onSubmit()">
187-
<mat-form-field appearance="outline" class="schema-chat__input-field">
188-
<mat-label>{{showClose || isRoutedPage() ? 'Describe the changes you need...' : 'Describe the database you need...'}}</mat-label>
189-
<textarea matInput
190-
name="schemaPrompt"
191-
[ngModel]="userPrompt()"
192-
(ngModelChange)="userPrompt.set($event)"
193-
(keydown)="onKeydown($event)"
194-
rows="2"
195-
maxlength="1000"
196-
data-testid="schema-prompt-textarea"
197-
></textarea>
198-
<button mat-icon-button matSuffix type="submit"
199-
[disabled]="!userPrompt().trim() || submitting()"
200-
class="schema-chat__send-button">
201-
<mat-icon>send</mat-icon>
202-
</button>
203-
</mat-form-field>
204-
</form>
205-
}
206-
</div>
207-
}
204+
</mat-form-field>
205+
</form>
206+
}
207+
</div>
208208
</div>

frontend/src/app/components/edit-database-schema/edit-database-schema.component.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export class EditDatabaseSchemaComponent implements OnInit, AfterViewInit {
105105
}
106106
if (result && result.changes.length > 0) {
107107
const summary = result.changes.map(c => `**${c.changeType}** \`${c.targetTableName}\`${c.aiSummary ? ' — ' + c.aiSummary : ''}`).join('\n');
108+
this.applied.set(false);
108109
this.messages.update(msgs => [...msgs, {
109110
role: 'ai',
110111
text: `I've generated ${result.changes.length} change(s) for your database:\n\n${summary}\n\nReview the SQL below and approve or reject.`,
@@ -145,10 +146,12 @@ export class EditDatabaseSchemaComponent implements OnInit, AfterViewInit {
145146
}]);
146147
} else {
147148
this.applied.set(true);
148-
this.messages.update(msgs => [...msgs, {
149+
this.messages.update(msgs => msgs.map(m =>
150+
m === batch ? { ...m, batchId: undefined } : m
151+
).concat({
149152
role: 'ai',
150153
text: 'All changes applied successfully! Your tables have been created.',
151-
}]);
154+
}));
152155
this._loadDiagram('Updated Database Structure');
153156
}
154157
}

frontend/src/app/services/tables.service.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ interface TableParams {
2727
filters?: object;
2828
comparators?: object;
2929
search?: string;
30+
uncached?: boolean;
3031
}
3132

3233
@Injectable({
@@ -121,6 +122,7 @@ export class TablesService {
121122
referencedColumn,
122123
filters,
123124
search,
125+
uncached,
124126
}: TableParams) {
125127
let foreignKeyRowParamName =
126128
foreignKeyRowName === 'autocomplete' ? foreignKeyRowName : `f_${foreignKeyRowName}__eq`;
@@ -140,6 +142,7 @@ export class TablesService {
140142
...(referencedColumn ? { referencedColumn } : {}),
141143
...(sortColumn ? { sort_by: sortColumn } : {}),
142144
...(sortOrder ? { sort_order: sortOrder } : {}),
145+
...(uncached ? { _uncached: 'true' } : {}),
143146
},
144147
},
145148
)

0 commit comments

Comments
 (0)