Skip to content

Commit

Permalink
Replace querySelector in favor of form namedItems
Browse files Browse the repository at this point in the history
  • Loading branch information
Quetzacoalt91 committed Dec 19, 2024
1 parent bd38a5f commit 98899c6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions _dev/src/ts/components/LogsViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export default class LogsViewer extends ComponentAbstract implements DomLifecycl
LOG_BEFORE_SCROLL: 120 // The number of logs to process before automatically scrolling to the bottom.
};

#formId = 'form-logs-download-button';

#templateLogLine = this.queryElement<HTMLTemplateElement>(
'#log-line',
'Template log line not found'
Expand Down Expand Up @@ -247,10 +249,10 @@ export default class LogsViewer extends ComponentAbstract implements DomLifecycl

this.#logsSummary.appendChild(fragment);

const downloadlogsButtonForm = this.queryElement<HTMLFormElement>(
'.logs__download-form',
'Form to request the button to download logs cannot be found'
);
const downloadlogsButtonForm = document.forms.namedItem(this.#formId);
if (!downloadlogsButtonForm) {
throw new Error('Form to request the button to download logs cannot be found');
}
await api.post(
downloadlogsButtonForm.dataset.downloadLogsRoute!,
new FormData(downloadlogsButtonForm)
Expand Down
2 changes: 1 addition & 1 deletion _dev/tests/components/LogsViewer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('LogsViewer', () => {
container = document.createElement('div');
container.innerHTML = `
<div data-component="logs-viewer" class="logs__inner">
<form class="logs__download-form" data-download-logs-route="">
<form id="form-logs-download-button" data-download-logs-route="">
<input type="hidden" name="download-logs-type" value="" />
</form>
<div data-slot-component="scroll" class="logs__scroll" tabindex="0">
Expand Down
2 changes: 1 addition & 1 deletion views/templates/components/logs-viewer.html.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div data-component="logs-viewer" class="logs__inner">
<form class="logs__download-form" data-download-logs-route="{{ downloadLogsRoute }}">
<form id="form-logs-download-button" data-download-logs-route="{{ downloadLogsRoute }}">
<input type="hidden" name="download-logs-type" value="{{ downloadLogsType }}" />
</form>
<div class="logs__scroll">
Expand Down

0 comments on commit 98899c6

Please sign in to comment.