Skip to content

Commit a2ed03b

Browse files
Show auto-complete column names in filtered rows dialog of table and filter options of view/edit data tool. #3751
1 parent da53082 commit a2ed03b

File tree

8 files changed

+578
-552
lines changed

8 files changed

+578
-552
lines changed

web/pgadmin/static/js/SchemaView/FormView.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ export default function FormView({
260260
let contentClassName = [
261261
isSingleCollection() ? 'FormView-singleCollectionPanelContent' :
262262
'FormView-nonTabPanelContent',
263-
(schemaState.errors?.message ? 'FormView-errorMargin' : null)
263+
(schemaState.errors?.message ? 'FormView-errorMargin' : null),
264+
(finalGroups.some((g)=>g.isFullTab) ? 'FormView-fullControl' : ''),
264265
];
265266
return (
266267
<>
@@ -275,7 +276,8 @@ export default function FormView({
275276
classNameRoot={[
276277
isSingleCollection() ?
277278
'FormView-singleCollectionPanel' : 'FormView-nonTabPanel',
278-
className
279+
className,
280+
(finalGroups.some((g)=>g.isFullTab) ? 'FormView-fullSpace' : ''),
279281
].join(' ')}
280282
className={contentClassName.join(' ')}>
281283
{

web/pgadmin/static/js/SchemaView/StyledComponents.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,17 @@ export const FormContentBox = styled(Box)(({theme}) => ({
144144
'& .FormView-fullControl': {
145145
display: 'flex',
146146
flexDirection: 'column',
147-
'& .FormView-sqlTabInput': {
147+
'& .FormView-sqlTabInput, & .Form-sql': {
148148
border: 0,
149149
},
150150
}
151151
},
152152
'& .FormView-nonTabPanel': {
153153
...theme.mixins.tabPanel,
154154
'& .FormView-nonTabPanelContent': {
155-
height: 'unset',
155+
'&:not(.FormView-fullControl)': {
156+
height: 'unset',
157+
},
156158
'& .FormView-controlRow': {
157159
marginBottom: theme.spacing(1),
158160
},

web/pgadmin/static/js/UtilityView.jsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default function UtilityView({dockerObj}) {
4141
<UtilityViewContent
4242
docker={docker.current}
4343
panelId={panelId}
44-
schema={dialogProps.schema}
44+
{...dialogProps}
4545
treeNodeInfo={treeNodeInfo}
4646
actionType={dialogProps.actionType??'create'}
4747
formType='dialog'
@@ -60,10 +60,6 @@ export default function UtilityView({dockerObj}) {
6060
onClose();
6161
})}
6262
extraData={dialogProps.extraData??{}}
63-
saveBtnName={dialogProps.saveBtnName}
64-
urlBase={dialogProps.urlBase}
65-
sqlHelpUrl={dialogProps.sqlHelpUrl}
66-
helpUrl={dialogProps.helpUrl}
6763
/>
6864
</ErrorBoundary>
6965
)

web/pgadmin/static/js/components/FormComponents.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,20 +192,26 @@ FormInput.propTypes = {
192192
export function InputSQL({ value, options, onChange, className, controlProps, inputRef, ...props }) {
193193

194194
const editor = useRef();
195+
const { autocompleteProvider, autocompleteOnKeyPress } = options;
195196

196197
return (
197198
<Root style={{height: '100%'}}>
198199
<CodeMirror
199200
currEditor={(obj) => {
200201
editor.current = obj;
201202
inputRef?.(obj);
203+
if(autocompleteProvider) {
204+
editor.current.registerAutocomplete(autocompleteProvider);
205+
}
202206
}}
203207
value={value || ''}
204208
options={{
205-
...options,
209+
..._.omit(options, ['autocompleteProvider', 'autocompleteOnKeyPress']),
206210
}}
207211
className={'Form-sql ' + className}
208212
onChange={onChange}
213+
autocomplete={true}
214+
autocompleteOnKeyPress={autocompleteOnKeyPress}
209215
{...controlProps}
210216
{...props}
211217
/>

web/pgadmin/static/js/components/ReactCodeMirror/components/Editor.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ const defaultExtensions = [
165165

166166
export default function Editor({
167167
currEditor, name, value, options, onCursorActivity, onChange, readonly,
168-
disabled, autocomplete = false, breakpoint = false, onBreakPointChange,
168+
disabled, autocomplete = false, autocompleteOnKeyPress, breakpoint = false, onBreakPointChange,
169169
showActiveLine=false, keepHistory = true, cid, helpid, labelledBy,
170170
customKeyMap, language='pgsql'
171171
}) {
@@ -331,7 +331,7 @@ export default function Editor({
331331
}],
332332
};
333333
if (autocomplete) {
334-
if (pref.autocomplete_on_key_press) {
334+
if (pref.autocomplete_on_key_press || autocompleteOnKeyPress) {
335335
newConfigExtn.push(autocompletion({
336336
...autoCompOptions,
337337
activateOnTyping: true,

web/pgadmin/tools/sqleditor/static/js/components/dialogs/FilterDialog.jsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,23 @@ class FilterSchema extends BaseUISchema {
6262
options: {
6363
lineWrapping: true,
6464
},
65+
autocompleteOnKeyPress: true,
66+
autocompleteProvider: (context, onAvailable)=>{
67+
return new Promise((resolve)=>{
68+
const word = context.matchBefore(/\w*/);
69+
const fullSql = context.state.doc.toString();
70+
onAvailable();
71+
resolve({
72+
from: word.from,
73+
options: (this.sortingCollObj.columnOptions??[]).map((col)=>({
74+
label: col.label, type: 'property',
75+
})),
76+
validFor: (text, from)=>{
77+
return text.startsWith(fullSql.slice(from));
78+
}
79+
});
80+
});
81+
}
6582
}
6683
},
6784
{

web/pgadmin/tools/sqleditor/static/js/show_view_data.js

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,47 @@ import _ from 'lodash';
1414
import { isEmptyString } from 'sources/validators';
1515
import usePreferences from '../../../../preferences/static/js/store';
1616
import pgAdmin from 'sources/pgadmin';
17+
import { getNodeListByName } from '../../../../browser/static/js/node_ajax';
1718

1819
export default class DataFilterSchema extends BaseUISchema {
19-
constructor(fieldOptions = {}) {
20+
constructor(getColumns) {
2021
super({
2122
filter_sql: ''
2223
});
2324

24-
this.fieldOptions = {
25-
...fieldOptions,
26-
};
25+
this.getColumns = getColumns;
2726
}
2827

2928
get baseFields() {
3029
return [{
3130
id: 'filter_sql',
3231
label: gettext('Data Filter'),
3332
type: 'sql', isFullTab: true, cell: 'text',
33+
controlProps: {
34+
autocompleteOnKeyPress: true,
35+
autocompleteProvider: (context, onAvailable)=>{
36+
return new Promise((resolve, reject)=>{
37+
const word = context.matchBefore(/\w*/);
38+
const fullSql = context.state.doc.toString();
39+
this.getColumns().then((columns) => {
40+
onAvailable();
41+
resolve({
42+
from: word.from,
43+
options: (columns??[]).map((col)=>({
44+
label: col.label, type: 'property',
45+
})),
46+
validFor: (text, from)=>{
47+
return text.startsWith(fullSql.slice(from));
48+
}
49+
});
50+
})
51+
.catch((err) => {
52+
onAvailable();
53+
reject(err instanceof Error ? err : Error(gettext('Something went wrong')));
54+
});
55+
});
56+
}
57+
}
3458
}];
3559
}
3660

@@ -64,8 +88,7 @@ export function showViewData(
6488
return;
6589
}
6690

67-
const parentData = pgBrowser.tree.getTreeNodeHierarchy( treeIdentifier
68-
);
91+
const parentData = pgBrowser.tree.getTreeNodeHierarchy(treeIdentifier);
6992

7093
if (hasServerOrDatabaseConfiguration(parentData)
7194
|| !hasSchemaOrCatalogOrViewInformation(parentData)) {
@@ -157,7 +180,11 @@ function generateFilterValidateUrl(nodeData, parentData) {
157180
function showFilterDialog(pgBrowser, item, queryToolMod, transId,
158181
gridUrl, queryToolTitle, validateUrl) {
159182

160-
let schema = new DataFilterSchema();
183+
const treeNodeInfo = pgBrowser.tree.getTreeNodeHierarchy(item);
184+
const itemNodeData = pgBrowser.tree.findNodeByDomElement(item).getData();
185+
let schema = new DataFilterSchema(
186+
()=>getNodeListByName('column', treeNodeInfo, itemNodeData),
187+
);
161188
let helpUrl = url_for('help.static', {'filename': 'viewdata_filter.html'});
162189

163190
let okCallback = function() {
@@ -168,7 +195,7 @@ function showFilterDialog(pgBrowser, item, queryToolMod, transId,
168195
gettext('Data Filter - %s', queryToolTitle),{
169196
schema, urlBase: validateUrl, helpUrl, saveBtnName: gettext('OK'), isTabView: false,
170197
onSave: okCallback,
171-
}, pgBrowser.stdW.md, pgBrowser.stdH.sm
198+
}, pgBrowser.stdW.md, pgBrowser.stdH.md
172199
);
173200
}
174201

0 commit comments

Comments
 (0)