mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Don't wait for the database connection before rendering the Query Tool UI, for improved UX. Fixes #4453
In addition, unescape HTML entities in database names in the Query Tool title bar. Fixes #4584
This commit is contained in:
committed by
Dave Page
parent
25f85fe123
commit
234efc3be7
@@ -17,10 +17,11 @@ describe('#show_data', () => {
|
||||
let datagrid;
|
||||
let pgBrowser;
|
||||
let alertify;
|
||||
let transId = 98765432;
|
||||
beforeEach(() => {
|
||||
alertify = jasmine.createSpyObj('alertify', ['alert']);
|
||||
datagrid = {
|
||||
create_transaction: jasmine.createSpy('create_transaction'),
|
||||
launch_grid: jasmine.createSpy('launch_grid'),
|
||||
};
|
||||
pgBrowser = {
|
||||
treeMenu: new TreeFake(),
|
||||
@@ -98,12 +99,12 @@ describe('#show_data', () => {
|
||||
|
||||
context('cannot find the tree node', () => {
|
||||
it('does not create a transaction', () => {
|
||||
showDataGrid(datagrid, pgBrowser, alertify, {}, [{id: '10'}]);
|
||||
expect(datagrid.create_transaction).not.toHaveBeenCalled();
|
||||
showDataGrid(datagrid, pgBrowser, alertify, {}, [{id: '10'}], transId);
|
||||
expect(datagrid.launch_grid).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('display alert', () => {
|
||||
showDataGrid(datagrid, pgBrowser, alertify, {}, [{id: '10'}]);
|
||||
showDataGrid(datagrid, pgBrowser, alertify, {}, [{id: '10'}], transId);
|
||||
expect(alertify.alert).toHaveBeenCalledWith(
|
||||
'Data Grid Error',
|
||||
'No object selected.'
|
||||
@@ -113,59 +114,52 @@ describe('#show_data', () => {
|
||||
|
||||
context('current node is not underneath a server', () => {
|
||||
it('does not create a transaction', () => {
|
||||
showDataGrid(datagrid, pgBrowser, alertify, {}, [{id: 'parent'}]);
|
||||
expect(datagrid.create_transaction).not.toHaveBeenCalled();
|
||||
showDataGrid(datagrid, pgBrowser, alertify, {}, [{id: 'parent'}], transId);
|
||||
expect(datagrid.launch_grid).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
context('current node is not underneath a schema or view or catalog', () => {
|
||||
it('does not create a transaction', () => {
|
||||
showDataGrid(datagrid, pgBrowser, alertify, {}, [{id: 'database1'}]);
|
||||
expect(datagrid.create_transaction).not.toHaveBeenCalled();
|
||||
showDataGrid(datagrid, pgBrowser, alertify, {}, [{id: 'database1'}], transId);
|
||||
expect(datagrid.launch_grid).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
context('current node is underneath a schema', () => {
|
||||
it('does not create a transaction', () => {
|
||||
showDataGrid(datagrid, pgBrowser, alertify, {mnuid: 11}, [{id: 'schema1'}]);
|
||||
expect(datagrid.create_transaction).toHaveBeenCalledWith(
|
||||
'/initialize/datagrid/11/schema/1/2/3/4',
|
||||
null,
|
||||
'false',
|
||||
'pg',
|
||||
'',
|
||||
'schema1.schema1/database1/someuser@server1',
|
||||
''
|
||||
showDataGrid(datagrid, pgBrowser, alertify, {mnuid: 11}, [{id: 'schema1'}], transId);
|
||||
|
||||
expect(datagrid.launch_grid).toHaveBeenCalledWith(
|
||||
98765432,
|
||||
'/panel/98765432?is_query_tool=false&cmd_type=11&obj_type=schema&obj_id=4&sgid=1&sid=2&did=3&server_type=pg',
|
||||
false,
|
||||
'schema1.schema1/database1/someuser@server1'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
context('current node is underneath a view', () => {
|
||||
it('does not create a transaction', () => {
|
||||
showDataGrid(datagrid, pgBrowser, alertify, {mnuid: 11}, [{id: 'view1'}]);
|
||||
expect(datagrid.create_transaction).toHaveBeenCalledWith(
|
||||
'/initialize/datagrid/11/view/1/2/3/5',
|
||||
null,
|
||||
'false',
|
||||
'pg',
|
||||
'',
|
||||
'view1.view1/database1/someuser@server1',
|
||||
''
|
||||
showDataGrid(datagrid, pgBrowser, alertify, {mnuid: 11}, [{id: 'view1'}], transId);
|
||||
|
||||
expect(datagrid.launch_grid).toHaveBeenCalledWith(
|
||||
98765432,
|
||||
'/panel/98765432?is_query_tool=false&cmd_type=11&obj_type=view&obj_id=5&sgid=1&sid=2&did=3&server_type=pg',
|
||||
false,
|
||||
'view1.view1/database1/someuser@server1'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
context('current node is underneath a catalog', () => {
|
||||
it('does not create a transaction', () => {
|
||||
showDataGrid(datagrid, pgBrowser, alertify, {mnuid: 11}, [{id: 'catalog1'}]);
|
||||
expect(datagrid.create_transaction).toHaveBeenCalledWith(
|
||||
'/initialize/datagrid/11/catalog/1/2/3/6',
|
||||
null,
|
||||
'false',
|
||||
'pg',
|
||||
'',
|
||||
'catalog1.catalog1/database1/someuser@server1',
|
||||
''
|
||||
showDataGrid(datagrid, pgBrowser, alertify, {mnuid: 11}, [{id: 'catalog1'}], transId);
|
||||
expect(datagrid.launch_grid).toHaveBeenCalledWith(
|
||||
98765432,
|
||||
'/panel/98765432?is_query_tool=false&cmd_type=11&obj_type=catalog&obj_id=6&sgid=1&sid=2&did=3&server_type=pg',
|
||||
false,
|
||||
'catalog1.catalog1/database1/someuser@server1'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -17,10 +17,11 @@ describe('#showQueryTool', () => {
|
||||
let queryTool;
|
||||
let pgBrowser;
|
||||
let alertify;
|
||||
let transId = 98765432;
|
||||
beforeEach(() => {
|
||||
alertify = jasmine.createSpyObj('alertify', ['alert']);
|
||||
queryTool = {
|
||||
create_transaction: jasmine.createSpy('create_transaction'),
|
||||
launch_grid: jasmine.createSpy('launch_grid'),
|
||||
};
|
||||
pgBrowser = {
|
||||
treeMenu: new TreeFake(),
|
||||
@@ -66,10 +67,10 @@ describe('#showQueryTool', () => {
|
||||
|
||||
context('cannot find the tree node', () => {
|
||||
beforeEach(() => {
|
||||
showQueryTool(queryTool, pgBrowser, alertify, '', [{id: '10'}]);
|
||||
showQueryTool(queryTool, pgBrowser, alertify, '', [{id: '10'}], transId);
|
||||
});
|
||||
it('does not create a transaction', () => {
|
||||
expect(queryTool.create_transaction).not.toHaveBeenCalled();
|
||||
expect(queryTool.launch_grid).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('display alert', () => {
|
||||
@@ -82,8 +83,8 @@ describe('#showQueryTool', () => {
|
||||
|
||||
context('current node is not underneath a server', () => {
|
||||
it('does not create a transaction', () => {
|
||||
showQueryTool(queryTool, pgBrowser, alertify, '', [{id: 'parent'}], 'title');
|
||||
expect(queryTool.create_transaction).not.toHaveBeenCalled();
|
||||
showQueryTool(queryTool, pgBrowser, alertify, '', [{id: 'parent'}], transId);
|
||||
expect(queryTool.launch_grid).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('no alert is displayed', () => {
|
||||
@@ -94,32 +95,26 @@ describe('#showQueryTool', () => {
|
||||
context('current node is underneath a server', () => {
|
||||
context('current node is not underneath a database', () => {
|
||||
it('creates a transaction', () => {
|
||||
showQueryTool(queryTool, pgBrowser, alertify, 'http://someurl', [{id: 'server1'}]);
|
||||
expect(queryTool.create_transaction).toHaveBeenCalledWith(
|
||||
'/initialize/query_tool/1/2',
|
||||
null,
|
||||
'true',
|
||||
'pg',
|
||||
'http://someurl',
|
||||
showQueryTool(queryTool, pgBrowser, alertify, 'http://someurl', [{id: 'server1'}], transId);
|
||||
expect(queryTool.launch_grid).toHaveBeenCalledWith(
|
||||
98765432,
|
||||
'/panel/98765432?is_query_tool=true&sgid=1&sid=2&server_type=pg',
|
||||
true,
|
||||
'otherdblabel/someuser@server1',
|
||||
'',
|
||||
false
|
||||
'http://someurl'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
context('current node is underneath a database', () => {
|
||||
it('creates a transaction', () => {
|
||||
showQueryTool(queryTool, pgBrowser, alertify, 'http://someurl', [{id: 'database1'}], 'title');
|
||||
expect(queryTool.create_transaction).toHaveBeenCalledWith(
|
||||
'/initialize/query_tool/1/2/3',
|
||||
null,
|
||||
'true',
|
||||
'pg',
|
||||
'http://someurl',
|
||||
showQueryTool(queryTool, pgBrowser, alertify, 'http://someurl', [{id: 'database1'}], transId);
|
||||
expect(queryTool.launch_grid).toHaveBeenCalledWith(
|
||||
98765432,
|
||||
'/panel/98765432?is_query_tool=true&sgid=1&sid=2&server_type=pg&did=3',
|
||||
true,
|
||||
'database1/someuser@server1',
|
||||
'',
|
||||
false
|
||||
'http://someurl'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -18,5 +18,6 @@ define(function () {
|
||||
'datagrid.initialize_query_tool': '/initialize/query_tool/<int:sgid>/<int:sid>',
|
||||
'datagrid.initialize_query_tool_with_did': '/initialize/query_tool/<int:sgid>/<int:sid>/<int:did>',
|
||||
'restore.create_job': '/restore/job/<int:sid>',
|
||||
'datagrid.panel': '/panel/<int:trans_id>',
|
||||
};
|
||||
});
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import { getEpoch, getGCD, getMod, quote_ident, parseFuncParams } from 'sources/utils';
|
||||
import { getEpoch, getGCD, getMod, quote_ident, parseFuncParams, getRandomInt } from 'sources/utils';
|
||||
|
||||
describe('getEpoch', function () {
|
||||
it('should return non zero', function () {
|
||||
@@ -135,3 +135,10 @@ describe('parseFuncParams', function () {
|
||||
expect(parseFuncParams(funcLabel)).toEqual(expectedObj);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getRandomInt', function () {
|
||||
it('is between', function () {
|
||||
let id = getRandomInt(1, 9999999);
|
||||
expect(1 <= id && id <= 9999999).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -36,61 +36,5 @@ define(['sources/sqleditor_utils'],
|
||||
expect(SqlEditorUtils.calcFontSize(2)).toEqual('2em');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Remove the slashes', function () {
|
||||
it('it will remove the slashes', function () {
|
||||
expect(
|
||||
SqlEditorUtils.removeSlashInTheString('/')
|
||||
).toEqual({
|
||||
'slashLocations': '0',
|
||||
'title': '',
|
||||
});
|
||||
});
|
||||
|
||||
it('it will remove if slashes are present', function () {
|
||||
expect(
|
||||
SqlEditorUtils.removeSlashInTheString('my/test')
|
||||
).toEqual({
|
||||
'slashLocations': '2',
|
||||
'title': 'mytest',
|
||||
});
|
||||
});
|
||||
|
||||
it('it will remove all the slashes are present', function () {
|
||||
expect(
|
||||
SqlEditorUtils.removeSlashInTheString('my/test/value')
|
||||
).toEqual({
|
||||
'slashLocations': '2,7',
|
||||
'title': 'mytestvalue',
|
||||
});
|
||||
});
|
||||
|
||||
it('it will remove all the slashes are present', function () {
|
||||
expect(
|
||||
SqlEditorUtils.removeSlashInTheString('a/bb/ccc/dddd/eeeee')
|
||||
).toEqual({
|
||||
'slashLocations': '1,4,8,13',
|
||||
'title': 'abbcccddddeeeee',
|
||||
});
|
||||
});
|
||||
|
||||
it('it will not remove if slash is not present', function () {
|
||||
expect(
|
||||
SqlEditorUtils.removeSlashInTheString('mytest')
|
||||
).toEqual({
|
||||
'slashLocations': '',
|
||||
'title': 'mytest',
|
||||
});
|
||||
});
|
||||
|
||||
it('it will not remove if value is not present', function () {
|
||||
expect(
|
||||
SqlEditorUtils.removeSlashInTheString('')
|
||||
).toEqual({
|
||||
'slashLocations': '',
|
||||
'title': '',
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user