Ensure that default sort order should be using the primary key in View/Edit data. Fixes #5157

pull/32/head
navnath gadakh 2020-04-22 18:46:48 +05:30 committed by Akshay Joshi
parent 870bcbd932
commit c76732e3e7
6 changed files with 68 additions and 3 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 166 KiB

After

Width:  |  Height:  |  Size: 203 KiB

View File

@ -355,6 +355,11 @@ Use the fields on the *Options* panel to manage editor preferences.
*True*, the editor will prompt the user to commit or rollback changes when
exiting the Query Tool while the current transaction is not committed.
* When the *Sort View Data results by primary key columns?* If set to *True*,
data returned when using the View/Edit Data - All Rows option will be sorted
by the Primary Key columns by default. When using the First/Last 100 Rows options,
data is always sorted.
.. image:: images/preferences_sql_results_grid.png
:alt: Preferences dialog sql results grid section
:align: center

View File

@ -54,6 +54,7 @@ Bug fixes
| `Issue #4969 <https://redmine.postgresql.org/issues/4969>`_ - Fixed an issue where changing the values of columns with JSONB or JSON types to NULL.
| `Issue #5007 <https://redmine.postgresql.org/issues/5007>`_ - Ensure index dropdown should have existing indexes while creating unique constraints.
| `Issue #5053 <https://redmine.postgresql.org/issues/5053>`_ - Fixed an issue where changing the columns in the existing view throws an error.
| `Issue #5157 <https://redmine.postgresql.org/issues/5157>`_ - Ensure that default sort order should be using the primary key in View/Edit data.
| `Issue #5180 <https://redmine.postgresql.org/issues/5180>`_ - Fixed an issue where the autovacuum_enabled parameter is added automatically in the RE-SQL when the table has been created using the WITH clause.
| `Issue #5210 <https://redmine.postgresql.org/issues/5210>`_ - Ensure that text larger than underlying field size should not be truncated automatically.
| `Issue #5227 <https://redmine.postgresql.org/issues/5227>`_ - Fixed an issue where user cannot be added if many users are already exists.

View File

@ -23,6 +23,7 @@ from pgadmin.tools.sqleditor.utils.is_query_resultset_updatable \
import is_query_resultset_updatable
from pgadmin.tools.sqleditor.utils.save_changed_data import save_changed_data
from pgadmin.tools.sqleditor.utils.get_column_types import get_columns_types
from pgadmin.utils.preferences import Preferences
from config import PG_DEFAULT_DRIVER
@ -463,6 +464,11 @@ class TableCommand(GridCommand):
# call base class init to fetch the table name
super(TableCommand, self).__init__(**kwargs)
# Set the default sorting on table data by primary key if user
# preference value is set
self.data_sorting_by_pk = Preferences.module('sqleditor').preference(
'table_view_data_by_pk').get()
def get_sql(self, default_conn=None):
"""
This method is used to create a proper SQL query
@ -486,7 +492,7 @@ class TableCommand(GridCommand):
if data_sorting is None and \
not self.is_sorting_set_from_filter_dialog() \
and (self.cmd_type in (VIEW_FIRST_100_ROWS, VIEW_LAST_100_ROWS) or
(self.cmd_type == VIEW_ALL_ROWS and self.limit > 0)):
(self.cmd_type == VIEW_ALL_ROWS and self.data_sorting_by_pk)):
sorting = {'data_sorting': []}
for pk in primary_keys:
sorting['data_sorting'].append(

View File

@ -10,6 +10,7 @@
import uuid
import json
import random
import sys
from pgadmin.utils.route import BaseTestGenerator
from pgadmin.browser.server_groups.servers.databases.tests import utils as \
@ -18,6 +19,11 @@ from regression import parent_node_dict
from regression.python_test_utils import test_utils
from pgadmin.utils import server_utils, IS_PY2
if sys.version_info < (3, 3):
from mock import patch
else:
from unittest.mock import patch
class TestViewData(BaseTestGenerator):
"""
@ -36,6 +42,34 @@ class TestViewData(BaseTestGenerator):
result_data='SELECT 0',
rows_fetched_to=0
)
),
(
'Sort table data without primary key in the table',
dict(
table_sql="""Create Table <TABLE_NAME>(
id integer Not Null,
json_val json Not Null
);""",
result_data='SELECT 0',
rows_fetched_to=0
)
),
(
'Sort table data by default order with primary key in table',
dict(
table_sql="""Create Table <TABLE_NAME>(
id integer Not Null,
json_val json Not Null,
Constraint table_pk_sort Primary Key(id)
);""",
result_data='SELECT 0',
rows_fetched_to=0,
mock_data={
'function_to_be_mocked': "pgadmin.utils.preferences."
"_Preference.get",
'return_value': False
}
)
)
]
@ -71,10 +105,18 @@ class TestViewData(BaseTestGenerator):
# Initialize query tool
self.trans_id = str(random.randint(1, 9999999))
url = '/datagrid/initialize/datagrid/{0}/3/table/{1}/{2}/{3}/{4}'\
url = '/datagrid/initialize/datagrid/{0}/3/table/{1}/{2}/{3}/{4}' \
.format(self.trans_id, test_utils.SERVER_GROUP, self.server_id,
self.db_id, table_id)
response = self.tester.post(url)
if hasattr(self, 'mock_data'):
with patch(
self.mock_data['function_to_be_mocked'],
return_value=self.mock_data['return_value']
):
response = self.tester.post(url)
else:
response = self.tester.post(url)
self.assertEquals(response.status_code, 200)

View File

@ -100,6 +100,17 @@ def RegisterQueryToolPreferences(self):
)
)
self.table_view_data_by_pk = self.preference.register(
'Options', 'table_view_data_by_pk',
gettext("Sort View Data results by primary key columns?"),
'boolean', True,
category_label=gettext('Options'),
help_str=gettext("If set to True, data returned when using the "
"View/Edit Data - All Rows option will be sorted by "
"the Primary Key columns by default. When using the "
"First/Last 100 Rows options, data is always sorted.")
)
self.show_prompt_save_data_changes = self.preference.register(
'Options', 'prompt_save_data_changes',
gettext("Prompt to save unsaved data changes?"), 'boolean', True,