Skip to content

Commit

Permalink
Moved config setting results to bottom of page (mattermost#7638)
Browse files Browse the repository at this point in the history
  • Loading branch information
cwarnermm authored Dec 4, 2024
1 parent 0e5a90a commit 6ea9300
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 68 deletions.
105 changes: 45 additions & 60 deletions source/_static/js/mattermost-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,71 +635,56 @@ class SearchClass {
}

/**
* Update the search status field with the results of the search
* Update the search status field with the results of the search.
* @param {number} numberOfResults
* @param {number} numberOfConfigSettingResults
*/
setPostSearchStatus(numberOfResults, numberOfConfigSettingResults) {
// empty the current status
this.status.innerText = '';
// If there were no results, then display an appropriate message and return
if (!numberOfResults && !numberOfConfigSettingResults) {
const searchStatusEl = document.getElementById("search-summary");
if (searchStatusEl) {
this.title.innerText = _('Search Results');
searchStatusEl.innerText = "Your search did not match any documents. Please make sure that all words are spelled correctly.";
}
return;
}
const prefixSpan = document.createElement('span');
prefixSpan.innerText = "Search finished, found ";
setPostSearchStatus(numberOfResults, numberOfConfigSettingResults) {
// Get the search status element
const searchStatusEl = document.getElementById("search-summary");

// Ensure the status element is available
if (!searchStatusEl) {
return;
}

// Clear previous contents
searchStatusEl.innerHTML = '';

// Handle the case where there are no search results or configuration settings
if (!numberOfResults && !numberOfConfigSettingResults) {
this.title.innerText = _('Search Results');
searchStatusEl.innerText = "Your search did not match any documents. Please make sure that all words are spelled correctly.";
return;
}

// Create and append the prefix span
const prefixSpan = document.createElement('span');
let prefixText = 'Search finished, found ';
if (numberOfResults) {
prefixText += `${numberOfResults} page${numberOfResults > 1 ? 's' : ''} matching your search query`;
}
if (numberOfConfigSettingResults) {
prefixText += ', and an additional ';
} else {
prefixText += '.';
}
prefixSpan.innerText = prefixText;
searchStatusEl.appendChild(prefixSpan);

// Create and append the configuration settings link and period if there are any
if (numberOfConfigSettingResults) {
const configSettingLink = document.createElement('a');
configSettingLink.href = '#config-setting-results-anchor'; // Adjust the anchor as needed
configSettingLink.innerText = `${numberOfConfigSettingResults} configuration setting${numberOfConfigSettingResults > 1 ? 's' : ''}`;

searchStatusEl.appendChild(configSettingLink);

const postfixSpan = document.createElement('span');
postfixSpan.innerText = " matching your search query. Results are sorted by relevance.";
let configSettingSpan;
let resultSpan;
if (numberOfConfigSettingResults) {
configSettingSpan = document.createElement('span');
configSettingSpan.innerText = String(numberOfConfigSettingResults) + " ";
const configSettingLink = document.createElement('a');
configSettingLink.text = "configuration setting";
if (numberOfConfigSettingResults > 1) {
configSettingLink.text += "s";
}
configSettingLink.href = "#config-setting-results-anchor";
configSettingSpan.appendChild(configSettingLink);
}
if (numberOfResults) {
resultSpan = document.createElement('span');
if (numberOfConfigSettingResults) {
resultSpan.innerText = String(numberOfResults) + " page";
resultSpan.innerText += numberOfResults > 1 ? "s of " : " of ";
const resultSpanLink = document.createElement('a');
resultSpanLink.text = "additional information";
resultSpanLink.href = "#search-results-anchor";
resultSpan.appendChild(resultSpanLink);
} else {
resultSpan.innerText = String(numberOfResults) + " document";
resultSpan.innerText += numberOfResults > 1 ? "s " : " ";
}
}
const searchStatusEl = document.getElementById("search-summary");
if (searchStatusEl) {
// prefixSpan + configSettingSpan? + " and "? + resultSpan? + postfixSpan
searchStatusEl.appendChild(prefixSpan);
if (configSettingSpan) {
searchStatusEl.appendChild(configSettingSpan);
if (resultSpan) {
const andSpan = document.createElement('span');
andSpan.innerText = " and ";
searchStatusEl.appendChild(andSpan);
}
}
if (resultSpan) {
searchStatusEl.appendChild(resultSpan);
}
searchStatusEl.appendChild(postfixSpan);
}
postfixSpan.innerText = '.';
searchStatusEl.appendChild(postfixSpan);
}
}

/**
* Display a single config setting search result item
Expand Down
14 changes: 6 additions & 8 deletions source/_templates/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,18 @@ <h2 id="search-title" style="float: left"></h2>
<h2 id="search-dots" style="float: right"></h2>
</div>
<p id="search-summary" class="search-summary"></p>
<!-- configuration setting-specific results will display here -->
<div id="config-setting-results-section" style="display: none">
<h3>Configuration settings</h3>
<a id="config-setting-results-anchor"></a>
<div class="search" id="config-setting-results-list"></div>
</div>
<!-- all other results will display here -->
<div id="search-additional-information-header" style="display: none">
<h3>Additional information</h3>
<a id="search-results-anchor"></a>
</div>
<div id="search-results">
<ul class="search" id="search-results-list"></ul>
</div>
<!-- configuration setting-specific results will display here -->
<div id="config-setting-results-section" style="display: none">
<h3>Configuration settings</h3>
<a id="config-setting-results-anchor"></a>
<div class="search" id="config-setting-results-list"></div>
</div>
{% endblock %} {% block scripts -%} {{ super() }} {# Load the search indexes
after the DOM has finished loading #}
<script lang="js">
Expand Down

0 comments on commit 6ea9300

Please sign in to comment.