From c5d5fbdafd211bf2f2b3c9fe526de2e232f3f587 Mon Sep 17 00:00:00 2001 From: Aditya Toshniwal Date: Thu, 14 Nov 2024 16:56:03 +0530 Subject: [PATCH] Fixed an issue where Ctrl/Cmd + A was not selecting all data in query tool data grid. #5099 --- docs/en_US/release_notes_8_14.rst | 1 + .../js/components/QueryToolConstants.js | 1 + .../js/components/QueryToolDataGrid/index.jsx | 40 ++++++++++++------- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/docs/en_US/release_notes_8_14.rst b/docs/en_US/release_notes_8_14.rst index dfb654ddd..44cc1db73 100644 --- a/docs/en_US/release_notes_8_14.rst +++ b/docs/en_US/release_notes_8_14.rst @@ -29,4 +29,5 @@ Housekeeping Bug fixes ********* + | `Issue #5099 `_ - Fixed an issue where Ctrl/Cmd + A was not selecting all data in query tool data grid. diff --git a/web/pgadmin/tools/sqleditor/static/js/components/QueryToolConstants.js b/web/pgadmin/tools/sqleditor/static/js/components/QueryToolConstants.js index fc48540f2..57ce1f449 100644 --- a/web/pgadmin/tools/sqleditor/static/js/components/QueryToolConstants.js +++ b/web/pgadmin/tools/sqleditor/static/js/components/QueryToolConstants.js @@ -28,6 +28,7 @@ export const QUERY_TOOL_EVENTS = { TRIGGER_SET_LIMIT: 'TRIGGER_SET_LIMIT', TRIGGER_FORMAT_SQL: 'TRIGGER_FORMAT_SQL', TRIGGER_GRAPH_VISUALISER: 'TRIGGER_GRAPH_VISUALISER', + TRIGGER_SELECT_ALL: 'TRIGGER_SELECT_ALL', COPY_DATA: 'COPY_DATA', SET_LIMIT_VALUE: 'SET_LIMIT_VALUE', diff --git a/web/pgadmin/tools/sqleditor/static/js/components/QueryToolDataGrid/index.jsx b/web/pgadmin/tools/sqleditor/static/js/components/QueryToolDataGrid/index.jsx index 780e4bf5f..513f338d5 100644 --- a/web/pgadmin/tools/sqleditor/static/js/components/QueryToolDataGrid/index.jsx +++ b/web/pgadmin/tools/sqleditor/static/js/components/QueryToolDataGrid/index.jsx @@ -22,6 +22,7 @@ import { QueryToolEventsContext } from '../QueryToolComponent'; import PropTypes from 'prop-types'; import gettext from 'sources/gettext'; import PgReactDataGrid from '../../../../../../static/js/components/PgReactDataGrid'; +import { isMac } from '../../../../../../static/js/keyboard_shortcuts'; export const ROWNUM_KEY = '$_pgadmin_rownum_key_$'; export const GRID_ROW_SELECT_KEY = '$_pgadmin_gridrowselect_key_$'; @@ -88,15 +89,6 @@ const StyledPgReactDataGrid = styled(PgReactDataGrid)(({theme})=>({ export const RowInfoContext = React.createContext(); export const DataGridExtrasContext = React.createContext(); -function getCopyShortcutHandler(handleCopy) { - return (e)=>{ - if((e.ctrlKey || e.metaKey) && e.key !== 'Control' && e.keyCode == 67) { - e.preventDefault(); - handleCopy(); - } - }; -} - function CustomRow(props) { const rowRef = useRef(); const dataGridExtras = useContext(DataGridExtrasContext); @@ -113,9 +105,7 @@ function CustomRow(props) { dataGridExtras.onSelectedCellChange?.(null); } const handleKeyDown = (e)=>{ - const handleCopyShortcut = getCopyShortcutHandler(dataGridExtras.handleCopy); - // Invokes the copy handler. - handleCopyShortcut(e); + dataGridExtras.handleShortcuts(e); if(e.code === 'Enter' && !props.isRowSelected && props.selectedCellIdx > 0) { props.selectCell(props.row, props.viewportColumns?.find(columns => columns.idx === props.selectedCellIdx), true); } @@ -160,8 +150,13 @@ function SelectAllHeaderRenderer({isCellSelected}) { }; }, []); + useEffect(()=>{ + const unregSelect = eventBus.registerListener(QUERY_TOOL_EVENTS.TRIGGER_SELECT_ALL, ()=>!isRowSelected && onClick()); + return unregSelect; + }, [isRowSelected]); + return
; + tabIndex="0" onKeyDown={dataGridExtras.handleShortcuts}>; } SelectAllHeaderRenderer.propTypes = { onAllRowsSelectionChange: PropTypes.func, @@ -196,7 +191,7 @@ function SelectableHeaderRenderer({column, selectedColumns, onSelectedColumnsCha return ( + onKeyDown={dataGridExtras.handleShortcuts} data-column-key={column.key}> {(column.column_type_internal == 'geometry' || column.column_type_internal == 'geography') && } size="small" style={{marginRight: '0.25rem'}} onClick={(e)=>{ @@ -398,12 +393,27 @@ export default function QueryToolDataGrid({columns, rows, totalRowCount, dataCha eventBus.fireEvent(QUERY_TOOL_EVENTS.TRIGGER_COPY_DATA); } + function handleShortcuts(e) { + // Handle Copy shortcut Cmd/Ctrl + c + if((e.ctrlKey || e.metaKey) && e.key !== 'Control' && e.keyCode == 67) { + e.preventDefault(); + handleCopy(); + } + + // Handle Select All Cmd + A(mac) / Ctrl + a (others) + if((isMac() && e.metaKey) || (!isMac() && e.ctrlKey) && e.key === 'a') { + e.preventDefault(); + onSelectedColumnsChangeWrapped(new Set()); + eventBus.fireEvent(QUERY_TOOL_EVENTS.TRIGGER_SELECT_ALL); + } + } + const renderCustomRow = useCallback((key, props) => { return ; }, []); const dataGridExtras = useMemo(()=>({ - onSelectedCellChange, handleCopy, startRowNum + onSelectedCellChange, handleShortcuts, startRowNum }), [onSelectedCellChange]); useEffect(()=>{