-
-
Notifications
You must be signed in to change notification settings - Fork 455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a "run query" option in the profiler #1826
base: 2.13.x
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -90,6 +90,13 @@ | |||
connectionName: request.query.get('connection'), | |||
query: request.query.get('query') | |||
})) }} | |||
{% elseif 'run' == page %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like that most of the lines are duplicated now. Something like this could be done instead:
{% if page in ['explain', 'page'] %}
{{ render(controller('Doctrine\\Bundle\\DoctrineBundle\\Controller\\ProfilerController::' ~ page ~ 'Action', {
token: token,
panel: 'db',
connectionName: request.query.get('connection'),
query: request.query.get('query')
})) }}
/** | ||
* Renders the profiler panel for the given token. | ||
* | ||
* @param string $token The profiler token | ||
* @param string $connectionName | ||
* @param int $query | ||
* | ||
* @return Response A Response instance | ||
*/ | ||
public function runAction($token, $connectionName, $query) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is old school PHP 5 style code, we don't use it for new stuff
/** | |
* Renders the profiler panel for the given token. | |
* | |
* @param string $token The profiler token | |
* @param string $connectionName | |
* @param int $query | |
* | |
* @return Response A Response instance | |
*/ | |
public function runAction($token, $connectionName, $query) | |
public function runAction(string $token, string $connectionName, int $query): Response |
.sql-runnable button { align-self: end; } | ||
.sql-runnable.sf-toggle-content.sf-toggle-visible { display: flex; flex-direction: row; align-items: center} | ||
.sql-runnable pre { flex-grow: 1} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a fan of this design change. Let's have buttons next to each other, instead on top of each other
</div> | ||
{% endif %} | ||
|
||
{% if query.explainable %} | ||
<div id="explain-{{ i }}-{{ loop.parent.loop.index }}" class="sql-explain"></div> | ||
{% endif %} | ||
|
||
<div id="run-{{ i }}-{{ loop.parent.loop.index }}" class="sql-explain"></div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this be wrapped in {% if query.runnable %}
condition? Or you believe the previous condition is not necessary?
function run(link) { | ||
"use strict"; | ||
|
||
var targetId = link.getAttribute('data-target-id'); | ||
var targetElement = document.getElementById(targetId); | ||
|
||
if (targetElement.style.display != 'block') { | ||
if (targetElement.getAttribute('data-sfurl') !== link.href) { | ||
fetch(link.href, { | ||
headers: {'X-Requested-With': 'XMLHttpRequest'} | ||
}).then(async function (response) { | ||
targetElement.innerHTML = await response.text() | ||
targetElement.setAttribute('data-sfurl', link.href) | ||
}, function () { | ||
targetElement.innerHTML = 'An error occurred while loading the query explanation.'; | ||
}) | ||
} | ||
|
||
targetElement.style.display = 'block'; | ||
link.innerHTML = 'Hide query result'; | ||
} else { | ||
targetElement.style.display = 'none'; | ||
link.innerHTML = 'Run query'; | ||
} | ||
|
||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please parametrize the function that was copied instead of copying whole thing and just changing few lines
{% if result is not empty %} | ||
<table> | ||
<thead> | ||
<tr> | ||
{% for key, value in result[0] %} | ||
<th>{{ key }}</th> | ||
{% endfor %} | ||
</tr> | ||
|
||
</thead> | ||
<tbody> | ||
{% for row in result %} | ||
<tr> | ||
{% for key, value in row %} | ||
<td>{{ value }}</td> | ||
{% endfor %} | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
{% else %} | ||
Result is empty | ||
{% endif %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was also copied (explain.html.twig), please modularize through block/embed it if you believe some stuff have to be different
01c7700
to
7bfb8e8
Compare
Inside the "view runnable query" panel, a run button enables running the query and checking the results just like "explain query" does