Skip to content

Commit 3378a24

Browse files
Refactor core component to use html_attributes, add default to collection order
1 parent 015c434 commit 3378a24

File tree

11 files changed

+29
-25
lines changed

11 files changed

+29
-25
lines changed

app/concepts/matestack/ui/core/collection/order/order.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const componentDef = {
1616
this.ordering[key] = "asc"
1717
} else if (this.ordering[key] == "asc") {
1818
this.ordering[key] = "desc"
19-
} else if (this.ordering[key] = "desc") {
19+
} else if (this.ordering[key] == "desc") {
2020
this.ordering[key] = undefined
2121
}
2222
var url;

app/concepts/matestack/ui/core/collection/order/order.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def setup
88

99
def response
1010
components {
11-
div @tag_attributes do
11+
div html_attributes do
1212
yield_components
1313
end
1414
}

app/concepts/matestack/ui/core/collection/order/toggle/indicator/indicator.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ class Indicator < Matestack::Ui::Core::Component::Static
33

44
def response
55
components {
6-
span @tag_attributes do
7-
plain "{{orderIndicator( '#{@component_config[:key]}', {asc: '#{@component_config[:asc]}', desc: '#{@component_config[:desc]}'} ) }}"
6+
span html_attributes do
7+
span attributes: {"v-if": "ordering['#{@component_config[:key]}'] === undefined"}, text: @component_config[:default]
8+
plain "{{
9+
orderIndicator('#{@component_config[:key]}', { asc: '#{@component_config[:asc]}', desc: '#{@component_config[:desc]}'})
10+
}}"
811
end
912
}
1013
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
%a{@tag_attributes, "@click": "toggleOrder(\"#{@component_config[:key]}\")"}
1+
%a{ html_attributes, "@click": "toggleOrder(\"#{@component_config[:key]}\")" }
22
- if block_given?
33
= yield
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
module Matestack::Ui::Core::Collection::Order::Toggle
22
class Toggle < Matestack::Ui::Core::Component::Static
3-
43
end
54
end

spec/0.8/components/dynamic/collection/complete_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def ordering
7272
end
7373

7474
def content
75-
async rerender_on: "my-first-collection-update" do
75+
async id: 'my-collection', rerender_on: "my-first-collection-update" do
7676
collection_content @my_collection.config do
7777
ul do
7878
@my_collection.paginated_data.each do |dummy|
@@ -259,7 +259,7 @@ def ordering_1
259259
end
260260

261261
def content_1
262-
async rerender_on: "my-first-collection-update" do
262+
async id: 'my-collection-1', rerender_on: "my-first-collection-update" do
263263
collection_content @my_first_collection.config do
264264
ul do
265265
@my_first_collection.paginated_data.each do |dummy|
@@ -318,7 +318,7 @@ def ordering_2
318318
end
319319

320320
def content_2
321-
async rerender_on: "my-second-collection-update" do
321+
async id: 'my-collection-2', rerender_on: "my-second-collection-update" do
322322
collection_content @my_second_collection.config do
323323
ul do
324324
@my_second_collection.paginated_data.each do |dummy|
@@ -502,7 +502,7 @@ def response
502502
end
503503

504504
def content
505-
async rerender_on: "my-first-collection-update" do
505+
async id: 'my-collection', rerender_on: "my-first-collection-update" do
506506
collection_content @my_collection.config do
507507
ul do
508508
@my_collection.paginated_data.each do |dummy|
@@ -540,4 +540,4 @@ def my_action_config id
540540
expect(page).not_to have_content("some-title-3")
541541
end
542542

543-
end
543+
end

spec/0.8/components/dynamic/collection/filter_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def filter
5858
end
5959

6060
def content
61-
async rerender_on: "my-first-collection-update" do
61+
async id: 'my-colletion', rerender_on: "my-first-collection-update" do
6262
collection_content @my_collection.config do
6363
ul do
6464
@my_collection.data.each do |dummy|
@@ -126,4 +126,4 @@ def content
126126

127127
end
128128

129-
end
129+
end

spec/0.8/components/dynamic/collection/order_spec.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,16 @@ def ordering
4848
collection_order_toggle key: :title do
4949
button do
5050
plain "title"
51-
collection_order_toggle_indicator key: :title, asc: ' asc', desc: ' desc'
51+
collection_order_toggle_indicator key: :title, default: ' created_at', asc: ' asc', desc: ' desc'
52+
# try line below
53+
# collection_order_toggle_indicator default: ' created_at', asc: ' asc', desc: ' desc'
5254
end
5355
end
5456
end
5557
end
5658

5759
def content
58-
async rerender_on: "my-first-collection-update" do
60+
async id: 'my-collection', rerender_on: "my-first-collection-update" do
5961
collection_content @my_collection.config do
6062
ul do
6163
@my_collection.paginated_data.each do |dummy|
@@ -72,11 +74,11 @@ def content
7274
end
7375

7476
visit "/example"
75-
expect(page).to have_button("title")
77+
expect(page).to have_button("title created_at")
7678
expect(all(".item").first.text).to eq "some-title-1 some-description-1"
7779
expect(all(".item").last.text).to eq "some-title-11 some-description-11"
7880

79-
click_button "title"
81+
click_button "title created_at"
8082
sleep 0.2 # otherwise getting stale element error, quick fix
8183
expect(page).to have_button("title asc")
8284
expect(all(".item").first.text).to eq "some-title-1 some-description-1"
@@ -90,16 +92,16 @@ def content
9092

9193
click_button "title desc"
9294
sleep 0.2 # otherwise getting stale element error, quick fix
93-
expect(page).to have_button("title")
95+
expect(page).to have_button("title created_at")
9496
expect(all(".item").first.text).to eq "some-title-1 some-description-1"
9597
expect(all(".item").last.text).to eq "some-title-11 some-description-11"
9698

9799
# test persistent state
98100
page.driver.browser.navigate.refresh
99101
sleep 0.2 # otherwise getting stale element error, quick fix
100-
expect(page).to have_button("title")
102+
expect(page).to have_button("title created_at")
101103
expect(all(".item").first.text).to eq "some-title-1 some-description-1"
102104
expect(all(".item").last.text).to eq "some-title-11 some-description-11"
103105
end
104106
end
105-
end
107+
end

spec/0.8/components/dynamic/collection/pagination_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def response
4343
end
4444

4545
def content
46-
async rerender_on: "my-first-collection-update" do
46+
async id: 'my-collection', rerender_on: "my-first-collection-update" do
4747
collection_content @my_collection.config do
4848
ul do
4949
@my_collection.paginated_data.each do |dummy|
@@ -175,7 +175,7 @@ def response
175175
end
176176

177177
def content
178-
async rerender_on: "my-first-collection-update" do
178+
async id: 'my-collection', rerender_on: "my-first-collection-update" do
179179
collection_content @my_collection.config do
180180
ul do
181181
@my_collection.paginated_data.each do |dummy|
@@ -238,4 +238,4 @@ def my_action_config id
238238

239239
end
240240

241-
end
241+
end

vendor/assets/javascripts/dist/matestack-ui-core.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)