Skip to content

Commit 97c9bda

Browse files
authored
Merge pull request solidusio#6238 from chaimann/admin-fix-table-sorting
[Admin] fix table sorting
2 parents df50e6a + 246ccc3 commit 97c9bda

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

admin/app/components/solidus_admin/ui/table/component.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ export default class extends Controller {
3232
}
3333

3434
// Determine if sortable should be enabled
35-
modeValueChanged() {
35+
modeValueChanged(_current, previous) {
36+
this.previousMode = previous;
37+
3638
const shouldSetSortable = this.sortableValue && this.modeValue !== "batch" && this.modeValue !== "search"
3739

3840
if (shouldSetSortable) {
@@ -69,27 +71,19 @@ export default class extends Controller {
6971

7072
selectRow(event) {
7173
if (this.checkboxTargets.some((checkbox) => checkbox.checked)) {
72-
this.modeValue = "batch"
73-
} else if (this.hasSearchFieldTarget && this.searchFieldTarget.value !== "") {
74-
this.modeValue = "search"
75-
} else if (this.hasScopesToolbarTarget) {
76-
this.modeValue = "scopes"
74+
this.modeValue = "batch";
7775
} else {
78-
this.modeValue = "search"
76+
this.modeValue = this.previousMode;
7977
}
8078

8179
this.render()
8280
}
8381

8482
selectAllRows(event) {
8583
if (event.target.checked) {
86-
this.modeValue = "batch"
87-
} else if (this.hasSearchFieldTarget && this.searchFieldTarget.value !== "") {
88-
this.modeValue = "search"
89-
} else if (this.hasScopesToolbarTarget) {
90-
this.modeValue = "scopes"
84+
this.modeValue = "batch";
9185
} else {
92-
this.modeValue = "search"
86+
this.modeValue = this.previousMode;
9387
}
9488

9589
this.checkboxTargets.forEach((checkbox) => (checkbox.checked = event.target.checked))

admin/app/components/solidus_admin/ui/table/component.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ def initial_mode
185185
end
186186

187187
def should_enable_sortable?
188-
@sortable && @search&.on_default_scope?
188+
return false if @sortable.nil?
189+
return true if @search.nil?
190+
@search.on_default_scope?
189191
end
190192
end

admin/app/javascript/solidus_admin/controllers/sortable_controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { patch } from '@rails/request.js'
44

55
export default class extends Controller {
66
static values = {
7-
param: { type: String, default: 'postion' },
7+
param: { type: String, default: 'position' },
88
handle: { type: String, default: null },
99
animation: { type: Number, default: 150 },
1010
}

0 commit comments

Comments
 (0)