OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Make turbo requests for filters are opt-in
Aaron Contreras34c6151d9c5d
diff --git a/app/components/projects/index_sub_header_component.html.erb b/app/components/projects/index_sub_header_component.html.erbindex d19afc97ce0..464fadc021e 100644--- a/app/components/projects/index_sub_header_component.html.erb+++ b/app/components/projects/index_sub_header_component.html.erb@@ -1,6 +1,7 @@<%= component_wrapper(tag: 'turbo-frame') do %><%= render(Primer::OpenProject::SubHeader.new(data: {controller: "filter--filters-form",+ 'filter--filters-form-perform-turbo-requests-value': true,"application-target": "dynamic",})) do |subheader|subheader.with_filter_component dodiff --git a/app/components/projects/projects_filters_component.rb b/app/components/projects/projects_filters_component.rbindex 058bb1cd7ad..a8a7f1fadef 100644--- a/app/components/projects/projects_filters_component.rb+++ b/app/components/projects/projects_filters_component.rb@@ -37,6 +37,10 @@ class Projects::ProjectsFiltersComponent < Filter::FilterComponent.sort_by(&:human_name)end+ def turbo_requests?+ true+ end+privatedef allowed_filter?(filter)diff --git a/app/views/filters/_autocomplete.html.erb b/app/views/filters/_autocomplete.html.erbindex e10bec695b7..551098352ab 100644--- a/app/views/filters/_autocomplete.html.erb+++ b/app/views/filters/_autocomplete.html.erb@@ -5,7 +5,7 @@multiple: true,multipleAsSeparateInputs: false,inputValue: filter.values,- hiddenFieldAction: "change->filter--filters-form#sendForm"+ hiddenFieldAction: "change->filter--filters-form#autocompleteSendForm"# Set on the template as there is a timing issue where the# angular component is not yet ready in the DOM and hence# the action can't be registered on the input field at the timediff --git a/frontend/src/stimulus/controllers/dynamic/filter/filters-form.controller.ts b/frontend/src/stimulus/controllers/dynamic/filter/filters-form.controller.tsindex bacd2cc7cbb..a67d0601462 100644--- a/frontend/src/stimulus/controllers/dynamic/filter/filters-form.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/filter/filters-form.controller.ts@@ -70,10 +70,12 @@ export default class FiltersFormController extends Controller {static values = {displayFilters: { type: Boolean, default: false },outputFormat: { type: String, default: 'params' },+ performTurboRequests: { type: Boolean, default: false },};declare displayFiltersValue:boolean;declare outputFormatValue:string;+ declare performTurboRequestsValue:boolean;connect() {const urlParams = new URLSearchParams(window.location.search);@@ -81,57 +83,61 @@ export default class FiltersFormController extends Controller {// Auto-register change event listeners for all fields// to keep DOM cleaner.- this.simpleValueTargets.forEach((simpleValue) => {- simpleValue.addEventListener('change', this.sendForm.bind(this));- });+ if (this.performTurboRequestsValue) {+ this.simpleValueTargets.forEach((simpleValue) => {+ simpleValue.addEventListener('change', this.sendForm.bind(this));+ });- this.operatorTargets.forEach((operator) => {- operator.addEventListener('change', this.sendForm.bind(this));- });+ this.operatorTargets.forEach((operator) => {+ operator.addEventListener('change', this.sendForm.bind(this));+ });- this.filterValueSelectTargets.forEach((select) => {- select.addEventListener('change', this.sendForm.bind(this));- });+ this.filterValueSelectTargets.forEach((select) => {+ select.addEventListener('change', this.sendForm.bind(this));+ });- this.filterValueContainerTargets.forEach((container) => {- container.addEventListener('change', this.sendForm.bind(this));- });+ this.filterValueContainerTargets.forEach((container) => {+ container.addEventListener('change', this.sendForm.bind(this));+ });- this.singleDayTargets.forEach((singleDay) => {- singleDay.addEventListener('change', this.sendForm.bind(this));- });+ this.singleDayTargets.forEach((singleDay) => {+ singleDay.addEventListener('change', this.sendForm.bind(this));+ });- this.daysTargets.forEach((days) => {- days.addEventListener('change', this.sendForm.bind(this));- });+ this.daysTargets.forEach((days) => {+ days.addEventListener('change', this.sendForm.bind(this));+ });+ }}disconnect() {// Auto-deregister change event listeners for all fields// to keep DOM cleaner.- this.simpleValueTargets.forEach((simpleValue) => {- simpleValue.removeEventListener('change', this.sendForm.bind(this));- });+ if (this.performTurboRequestsValue) {+ this.simpleValueTargets.forEach((simpleValue) => {+ simpleValue.removeEventListener('change', this.sendForm.bind(this));+ });- this.operatorTargets.forEach((operator) => {- operator.removeEventListener('change', this.sendForm.bind(this));- });+ this.operatorTargets.forEach((operator) => {+ operator.removeEventListener('change', this.sendForm.bind(this));+ });- this.filterValueSelectTargets.forEach((select) => {- select.removeEventListener('change', this.sendForm.bind(this));- });+ this.filterValueSelectTargets.forEach((select) => {+ select.removeEventListener('change', this.sendForm.bind(this));+ });- this.filterValueContainerTargets.forEach((container) => {- container.removeEventListener('change', this.sendForm.bind(this));- });+ this.filterValueContainerTargets.forEach((container) => {+ container.removeEventListener('change', this.sendForm.bind(this));+ });- this.singleDayTargets.forEach((singleDay) => {- singleDay.removeEventListener('change', this.sendForm.bind(this));- });+ this.singleDayTargets.forEach((singleDay) => {+ singleDay.removeEventListener('change', this.sendForm.bind(this));+ });- this.daysTargets.forEach((days) => {- days.removeEventListener('change', this.sendForm.bind(this));- });+ this.daysTargets.forEach((days) => {+ days.removeEventListener('change', this.sendForm.bind(this));+ });+ }}toggleDisplayFilters() {@@ -191,7 +197,9 @@ export default class FiltersFormController extends Controller {this.reselectPlaceholderOption();this.setSpacerVisibility();- this.sendForm();+ if (this.performTurboRequestsValue) {+ this.sendForm();+ }}private disableSelection() {@@ -211,7 +219,9 @@ export default class FiltersFormController extends Controller {removedFilterOption?.removeAttribute('disabled');this.setSpacerVisibility();- this.sendForm();+ if (this.performTurboRequestsValue) {+ this.sendForm();+ }}private setSpacerVisibility() {@@ -257,6 +267,12 @@ export default class FiltersFormController extends Controller {}}+ autocompleteSendForm() {+ if (this.performTurboRequestsValue) {+ this.sendForm();+ }+ }+sendForm() {const ajaxIndicator = document.querySelector('#ajax-indicator') as HTMLElement;ajaxIndicator.style.display = '';@@ -274,20 +290,24 @@ export default class FiltersFormController extends Controller {const url = `${window.location.pathname}?${params.toString()}`;- fetch(url, {- headers: {- Accept: 'text/vnd.turbo-stream.html',- },- })- .then((response:Response) => response.text())- .then((html:string) => {- renderStreamMessage(html);- ajaxIndicator.style.display = 'none';+ if (this.performTurboRequestsValue) {+ fetch(url, {+ headers: {+ Accept: 'text/vnd.turbo-stream.html',+ },})- .catch((error:Error) => {- console.error('Error:', error);- ajaxIndicator.style.display = 'none';- });+ .then((response:Response) => response.text())+ .then((html:string) => {+ renderStreamMessage(html);+ ajaxIndicator.style.display = 'none';+ })+ .catch((error:Error) => {+ console.error('Error:', error);+ ajaxIndicator.style.display = 'none';+ });+ } else {+ window.location.href = url;+ }}private parseFilters():InternalFilterValue[] {