katalyst-tables 2.1.0 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/app/components/concerns/katalyst/tables/turbo_replaceable.rb +4 -4
- data/app/components/katalyst/tables/pagy_nav_component.rb +3 -1
- data/app/models/concerns/katalyst/tables/collection/core.rb +2 -6
- data/app/models/concerns/katalyst/tables/collection/pagination.rb +3 -3
- data/app/models/concerns/katalyst/tables/collection/reducers.rb +67 -0
- data/app/models/concerns/katalyst/tables/collection/sorting.rb +0 -2
- data/app/models/katalyst/tables/collection.rb +1 -1
- data/lib/katalyst/tables/backend.rb +5 -0
- data/lib/katalyst/tables/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ddd6b87989959fe3bea80d3d061984ace8fbaa918033ae6d40f1fb41fa752a4f
|
4
|
+
data.tar.gz: c1fcff810e0c6e76ae8ae8df7a92f26d0badd1601b6fd091748249eaeebdc262
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39a50df893890ed53a0d54acc7ab5d23a0292c9e98ec82b4e6286325713e115d718cfcdaf8caf6c0b2ce211ec20ea514eb53b5dc275dfe04bf253ee00d094aa5
|
7
|
+
data.tar.gz: 919db4197193d5c4d2be8ea6c15642ff309819757c32ae6cb99266412029e0d250156220584442d048b97a40bcc9c5cce7660d141ac9fb157d12d8468b6fd268
|
data/README.md
CHANGED
@@ -281,8 +281,8 @@ def index
|
|
281
281
|
table = Katalyst::Turbo::TableComponent.new(collection:, id: "people")
|
282
282
|
|
283
283
|
respond_to do |format|
|
284
|
+
format.turbo_stream { render table } if self_referred?
|
284
285
|
format.html { render locals: { table: table } }
|
285
|
-
format.turbo_stream { render table }
|
286
286
|
end
|
287
287
|
end
|
288
288
|
```
|
@@ -47,10 +47,10 @@ module Katalyst
|
|
47
47
|
component_class.alias_method(:vc_render_template_for, :render_template_for)
|
48
48
|
component_class.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
49
49
|
def render_template_for(variant = nil)
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
if turbo? && response.media_type.eql?("text/vnd.turbo-stream.html")
|
51
|
+
turbo_stream.replace(id, vc_render_template_for(variant))
|
52
|
+
else
|
53
|
+
vc_render_template_for(variant)
|
54
54
|
end
|
55
55
|
end
|
56
56
|
RUBY
|
@@ -3,7 +3,9 @@
|
|
3
3
|
module Katalyst
|
4
4
|
module Tables
|
5
5
|
class PagyNavComponent < ViewComponent::Base # :nodoc:
|
6
|
-
|
6
|
+
# Pagy is not a required gem unless you're using pagination
|
7
|
+
# Expect to see NoMethodError failures if pagy is not available
|
8
|
+
"Pagy::Frontend".safe_constantize&.tap { |pagy| include(pagy) }
|
7
9
|
|
8
10
|
attr_reader :pagy_options
|
9
11
|
|
@@ -11,13 +11,9 @@ module Katalyst
|
|
11
11
|
include ActiveModel::Dirty
|
12
12
|
include ActiveSupport::Configurable
|
13
13
|
|
14
|
-
|
15
|
-
class_attribute :reducers, default: ActionDispatch::MiddlewareStack.new
|
16
|
-
|
17
|
-
class << self
|
18
|
-
delegate :use, :before, to: :reducers
|
19
|
-
end
|
14
|
+
include Reducers
|
20
15
|
|
16
|
+
included do
|
21
17
|
attr_accessor :items
|
22
18
|
|
23
19
|
delegate :model, :to_model, :each, :count, :empty?, to: :items, allow_nil: true
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "pagy/backend"
|
4
|
-
|
5
3
|
module Katalyst
|
6
4
|
module Tables
|
7
5
|
module Collection
|
@@ -41,7 +39,9 @@ module Katalyst
|
|
41
39
|
end
|
42
40
|
|
43
41
|
class Paginate # :nodoc:
|
44
|
-
|
42
|
+
# Pagy is not a required gem unless you're using pagination
|
43
|
+
# Expect to see NoMethodError failures if pagy is not available
|
44
|
+
"Pagy::Backend".safe_constantize&.tap { |pagy| include(pagy) }
|
45
45
|
|
46
46
|
def initialize(app)
|
47
47
|
@app = app
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Katalyst
|
4
|
+
module Tables
|
5
|
+
module Collection
|
6
|
+
# Adds stackable reducers to a collection.
|
7
|
+
# Inspired by ActiveDispatch::MiddlewareStack which unfortunately can't
|
8
|
+
# be used due to monkey patches from gems such as NewRelic which assume
|
9
|
+
# it is only used for Rack middleware.
|
10
|
+
module Reducers
|
11
|
+
extend ActiveSupport::Concern
|
12
|
+
|
13
|
+
included do
|
14
|
+
class_attribute :reducers, default: Stack.new
|
15
|
+
end
|
16
|
+
|
17
|
+
class_methods do
|
18
|
+
delegate :use, :insert, to: :reducers
|
19
|
+
end
|
20
|
+
|
21
|
+
class Stack # :nodoc:
|
22
|
+
def initialize
|
23
|
+
@stack = []
|
24
|
+
end
|
25
|
+
|
26
|
+
def use(klass)
|
27
|
+
@stack << Reducer.new(klass) unless index(klass)
|
28
|
+
end
|
29
|
+
|
30
|
+
def insert(other, klass)
|
31
|
+
@stack.insert(index(other), Reducer.new(klass))
|
32
|
+
end
|
33
|
+
|
34
|
+
def index(klass)
|
35
|
+
@stack.index(Reducer.new(klass))
|
36
|
+
end
|
37
|
+
|
38
|
+
def build(&block)
|
39
|
+
@stack.freeze.reduce(block) do |app, reducer|
|
40
|
+
reducer.build(app)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class Reducer # :nodoc:
|
46
|
+
attr_reader :klass
|
47
|
+
|
48
|
+
def initialize(klass)
|
49
|
+
@klass = klass
|
50
|
+
end
|
51
|
+
|
52
|
+
def build(app)
|
53
|
+
klass.new(app)
|
54
|
+
end
|
55
|
+
|
56
|
+
def ==(other)
|
57
|
+
klass.name == other.klass.name
|
58
|
+
end
|
59
|
+
|
60
|
+
def inspect
|
61
|
+
"#<#{self.class.name} #{klass.name}>"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -27,6 +27,11 @@ module Katalyst
|
|
27
27
|
.apply(collection)
|
28
28
|
end
|
29
29
|
|
30
|
+
def self_referred?
|
31
|
+
request.referer.present? && URI.parse(request.referer).path == request.path
|
32
|
+
end
|
33
|
+
alias self_refered? self_referred?
|
34
|
+
|
30
35
|
included do
|
31
36
|
class_attribute :_default_table_component, instance_accessor: false
|
32
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: katalyst-tables
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Katalyst Interactive
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-07-
|
11
|
+
date: 2023-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: html-attributes-utils
|
@@ -68,6 +68,7 @@ files:
|
|
68
68
|
- app/components/katalyst/turbo/table_component.rb
|
69
69
|
- app/models/concerns/katalyst/tables/collection/core.rb
|
70
70
|
- app/models/concerns/katalyst/tables/collection/pagination.rb
|
71
|
+
- app/models/concerns/katalyst/tables/collection/reducers.rb
|
71
72
|
- app/models/concerns/katalyst/tables/collection/sorting.rb
|
72
73
|
- app/models/katalyst/tables/collection.rb
|
73
74
|
- config/importmap.rb
|