Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
de1682ce
Unverified
Commit
de1682ce
authored
3 years ago
by
Gustavo Saiani
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Small readability improvements to NativeQueryEditor (#18585)
parent
5d350be7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
frontend/src/metabase/query_builder/components/NativeQueryEditor.jsx
+15
-12
15 additions, 12 deletions
...c/metabase/query_builder/components/NativeQueryEditor.jsx
with
15 additions
and
12 deletions
frontend/src/metabase/query_builder/components/NativeQueryEditor.jsx
+
15
−
12
View file @
de1682ce
...
@@ -133,7 +133,7 @@ export default class NativeQueryEditor extends Component {
...
@@ -133,7 +133,7 @@ export default class NativeQueryEditor extends Component {
const
lines
=
Math
.
max
(
const
lines
=
Math
.
max
(
Math
.
min
(
Math
.
min
(
this
.
maxAutoSizeLines
(),
this
.
maxAutoSizeLines
(),
(
props
.
query
&&
props
.
query
.
lineCount
()
)
||
this
.
maxAutoSizeLines
(),
props
.
query
?
.
lineCount
()
||
this
.
maxAutoSizeLines
(),
),
),
MIN_HEIGHT_LINES
,
MIN_HEIGHT_LINES
,
);
);
...
@@ -143,7 +143,7 @@ export default class NativeQueryEditor extends Component {
...
@@ -143,7 +143,7 @@ export default class NativeQueryEditor extends Component {
isSelectedTextPopoverOpen
:
false
,
isSelectedTextPopoverOpen
:
false
,
};
};
// Ace sometimes fires mu
t
liple "change" events in rapid succession
// Ace sometimes fires mul
t
iple "change" events in rapid succession
// e.x. https://github.com/metabase/metabase/issues/2801
// e.x. https://github.com/metabase/metabase/issues/2801
this
.
onChange
=
_
.
debounce
(
this
.
onChange
.
bind
(
this
),
1
);
this
.
onChange
=
_
.
debounce
(
this
.
onChange
.
bind
(
this
),
1
);
...
@@ -220,6 +220,7 @@ export default class NativeQueryEditor extends Component {
...
@@ -220,6 +220,7 @@ export default class NativeQueryEditor extends Component {
}
}
const
editorElement
=
this
.
editor
.
current
;
const
editorElement
=
this
.
editor
.
current
;
if
(
query
.
hasWritePermission
())
{
if
(
query
.
hasWritePermission
())
{
this
.
_editor
.
setReadOnly
(
false
);
this
.
_editor
.
setReadOnly
(
false
);
editorElement
.
classList
.
remove
(
"
read-only
"
);
editorElement
.
classList
.
remove
(
"
read-only
"
);
...
@@ -227,8 +228,10 @@ export default class NativeQueryEditor extends Component {
...
@@ -227,8 +228,10 @@ export default class NativeQueryEditor extends Component {
this
.
_editor
.
setReadOnly
(
true
);
this
.
_editor
.
setReadOnly
(
true
);
editorElement
.
classList
.
add
(
"
read-only
"
);
editorElement
.
classList
.
add
(
"
read-only
"
);
}
}
const
aceMode
=
query
.
aceMode
();
const
aceMode
=
query
.
aceMode
();
const
session
=
this
.
_editor
.
getSession
();
const
session
=
this
.
_editor
.
getSession
();
if
(
session
.
$modeId
!==
aceMode
)
{
if
(
session
.
$modeId
!==
aceMode
)
{
session
.
setMode
(
aceMode
);
session
.
setMode
(
aceMode
);
if
(
aceMode
.
indexOf
(
"
sql
"
)
>=
0
)
{
if
(
aceMode
.
indexOf
(
"
sql
"
)
>=
0
)
{
...
@@ -278,12 +281,14 @@ export default class NativeQueryEditor extends Component {
...
@@ -278,12 +281,14 @@ export default class NativeQueryEditor extends Component {
const
{
query
,
runQuestionQuery
}
=
this
.
props
;
const
{
query
,
runQuestionQuery
}
=
this
.
props
;
// if any text is selected, just run that
// if any text is selected, just run that
const
selectedText
=
this
.
_editor
&&
this
.
_editor
.
getSelectedText
();
const
selectedText
=
this
.
_editor
?.
getSelectedText
();
if
(
selectedText
)
{
if
(
selectedText
)
{
const
temporaryCard
=
query
const
temporaryCard
=
query
.
setQueryText
(
selectedText
)
.
setQueryText
(
selectedText
)
.
question
()
.
question
()
.
card
();
.
card
();
runQuestionQuery
({
runQuestionQuery
({
overrideWithCard
:
temporaryCard
,
overrideWithCard
:
temporaryCard
,
shouldUpdateUrl
:
false
,
shouldUpdateUrl
:
false
,
...
@@ -334,7 +339,7 @@ export default class NativeQueryEditor extends Component {
...
@@ -334,7 +339,7 @@ export default class NativeQueryEditor extends Component {
};
};
// initialize the content
// initialize the content
this
.
_editor
.
setValue
(
query
?
query
.
queryText
()
:
""
);
this
.
_editor
.
setValue
(
query
?
.
queryText
()
??
""
);
this
.
_editor
.
renderer
.
setScrollMargin
(
SCROLL_MARGIN
,
SCROLL_MARGIN
);
this
.
_editor
.
renderer
.
setScrollMargin
(
SCROLL_MARGIN
,
SCROLL_MARGIN
);
...
@@ -462,7 +467,7 @@ export default class NativeQueryEditor extends Component {
...
@@ -462,7 +467,7 @@ export default class NativeQueryEditor extends Component {
// TODO: push more of this into metabase-lib?
// TODO: push more of this into metabase-lib?
const
{
query
}
=
this
.
props
;
const
{
query
}
=
this
.
props
;
const
table
=
query
.
metadata
().
table
(
tableId
);
const
table
=
query
.
metadata
().
table
(
tableId
);
if
(
table
&&
table
.
name
!==
query
.
collection
())
{
if
(
table
?
.
name
!==
query
.
collection
())
{
query
.
setCollectionName
(
table
.
name
).
update
(
this
.
props
.
setDatasetQuery
);
query
.
setCollectionName
(
table
.
name
).
update
(
this
.
props
.
setDatasetQuery
);
}
}
};
};
...
@@ -496,10 +501,8 @@ export default class NativeQueryEditor extends Component {
...
@@ -496,10 +501,8 @@ export default class NativeQueryEditor extends Component {
// hide the snippet sidebar if there aren't any visible snippets/collections and the root collection isn't writable
// hide the snippet sidebar if there aren't any visible snippets/collections and the root collection isn't writable
const
showSnippetSidebarButton
=
!
(
const
showSnippetSidebarButton
=
!
(
snippets
&&
snippets
?.
length
===
0
&&
snippets
.
length
===
0
&&
snippetCollections
?.
length
===
1
&&
snippetCollections
&&
snippetCollections
.
length
===
1
&&
snippetCollections
[
0
].
can_write
===
false
snippetCollections
[
0
].
can_write
===
false
);
);
...
@@ -517,7 +520,7 @@ export default class NativeQueryEditor extends Component {
...
@@ -517,7 +520,7 @@ export default class NativeQueryEditor extends Component {
>
>
<
DatabaseDataSelector
<
DatabaseDataSelector
databases
=
{
databases
}
databases
=
{
databases
}
selectedDatabaseId
=
{
database
&&
database
.
id
}
selectedDatabaseId
=
{
database
?
.
id
}
setDatabaseFn
=
{
this
.
setDatabaseId
}
setDatabaseFn
=
{
this
.
setDatabaseId
}
isInitiallyOpen
=
{
database
==
null
}
isInitiallyOpen
=
{
database
==
null
}
readOnly
=
{
this
.
props
.
readOnly
}
readOnly
=
{
this
.
props
.
readOnly
}
...
@@ -539,8 +542,8 @@ export default class NativeQueryEditor extends Component {
...
@@ -539,8 +542,8 @@ export default class NativeQueryEditor extends Component {
className
=
"GuiBuilder-section GuiBuilder-data flex align-center ml2"
className
=
"GuiBuilder-section GuiBuilder-data flex align-center ml2"
>
>
<
SchemaAndTableDataSelector
<
SchemaAndTableDataSelector
selectedTableId
=
{
selectedTable
?
selectedTable
.
id
:
null
}
selectedTableId
=
{
selectedTable
?
.
id
||
null
}
selectedDatabaseId
=
{
database
&&
database
.
id
}
selectedDatabaseId
=
{
database
?
.
id
}
databases
=
{
[
database
]
}
databases
=
{
[
database
]
}
setSourceTableFn
=
{
this
.
setTableId
}
setSourceTableFn
=
{
this
.
setTableId
}
isInitiallyOpen
=
{
false
}
isInitiallyOpen
=
{
false
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment