feat(plugin-sql-editor): CB-2029 script renaming extension

This commit is contained in:
Wroud
2022-07-12 14:47:40 +03:00
parent 5f67f54a83
commit 22f67dc801
2 changed files with 22 additions and 6 deletions
@@ -117,7 +117,14 @@ export class ResourceSqlDataSource extends BaseSqlDataSource {
return false;
}
return !!this.actions && !!this.nodeInfo && !this.isOutdated() && this.saved && name.trim().length > 0;
name = name.trim();
return (
!!this.actions
&& !!this.nodeInfo
&& this.saved
&& name.length > 0
);
}
setScript(script: string): void {
@@ -143,10 +150,19 @@ export class ResourceSqlDataSource extends BaseSqlDataSource {
async rename(name: string | null) {
await this.write();
if (!this.actions || !this.nodeInfo || !this.saved || !name?.trim()) {
if (
!this.actions
|| !this.nodeInfo
|| !this.saved
|| !name?.trim()
) {
return;
}
if (!name.toLowerCase().endsWith('.sql')) {
name += '.sql';
}
this.lastAction = this.rename.bind(this, name);
this.loading = true;
this.message = 'Renaming script...';
@@ -130,18 +130,18 @@ export class SqlEditorBootstrap extends Bootstrap {
const connection = this.connectionInfoResource.get(dataSource.executionContext?.connectionId ?? '');
const name = getSqlEditorName(state, dataSource, connection);
const regexp = /^(.*?)(\.\w+)$/ig.exec(name);
const result = await this.commonDialogService.open(RenameDialog, {
value: name,
value: regexp?.[1] ?? name,
objectName: name,
icon: '/icons/sql_script_m.svg',
validation: name => (
!this.sqlEditorTabService.sqlEditorTabs.some(tab => (
tab.handlerState.order !== state.order
&& this.sqlEditorService.getName(tab.handlerState) === name.trim()
)
&& this.sqlEditorService.getName(tab.handlerState) === name.trim()
))
&& dataSource.canRename(name)
)
),
});