katalyst-tables 3.4.6 → 3.5.0

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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/builds/katalyst/tables.esm.js +15 -3
  3. data/app/assets/builds/katalyst/tables.js +15 -3
  4. data/app/assets/builds/katalyst/tables.min.js +1 -1
  5. data/app/assets/builds/katalyst/tables.min.js.map +1 -1
  6. data/app/assets/stylesheets/katalyst/tables/_query.scss +20 -20
  7. data/app/components/katalyst/tables/query/input_component.html.erb +7 -6
  8. data/app/components/katalyst/tables/query/input_component.rb +23 -7
  9. data/app/components/katalyst/tables/query/modal_component.html.erb +7 -17
  10. data/app/components/katalyst/tables/query/modal_component.rb +7 -62
  11. data/app/components/katalyst/tables/query/suggestion_component.html.erb +3 -0
  12. data/app/components/katalyst/tables/query/suggestion_component.rb +35 -0
  13. data/app/components/katalyst/tables/query_component.rb +0 -1
  14. data/app/javascript/tables/query_controller.js +10 -3
  15. data/app/javascript/tables/query_input_controller.js +5 -0
  16. data/app/models/concerns/katalyst/tables/collection/query/array_value_parser.rb +19 -1
  17. data/app/models/concerns/katalyst/tables/collection/query/parser.rb +12 -11
  18. data/app/models/concerns/katalyst/tables/collection/query/single_value_parser.rb +10 -0
  19. data/app/models/concerns/katalyst/tables/collection/query/untagged_literal.rb +36 -0
  20. data/app/models/concerns/katalyst/tables/collection/query/value_parser.rb +11 -2
  21. data/app/models/concerns/katalyst/tables/collection/query.rb +11 -26
  22. data/app/models/concerns/katalyst/tables/collection/suggestions.rb +120 -0
  23. data/app/models/katalyst/tables/suggestions/attribute.rb +13 -0
  24. data/app/models/katalyst/tables/suggestions/base.rb +31 -0
  25. data/app/models/katalyst/tables/suggestions/constant_value.rb +28 -0
  26. data/app/models/katalyst/tables/suggestions/custom_value.rb +26 -0
  27. data/app/models/katalyst/tables/suggestions/database_value.rb +36 -0
  28. data/app/models/katalyst/tables/suggestions/search_value.rb +13 -0
  29. data/config/locales/tables.en.yml +9 -1
  30. data/lib/katalyst/tables/collection/type/boolean.rb +10 -2
  31. data/lib/katalyst/tables/collection/type/date.rb +7 -5
  32. data/lib/katalyst/tables/collection/type/enum.rb +4 -4
  33. data/lib/katalyst/tables/collection/type/helpers/extensions.rb +1 -11
  34. data/lib/katalyst/tables/collection/type/value.rb +14 -12
  35. metadata +12 -3
  36. data/lib/katalyst/tables/collection/type/example.rb +0 -30
@@ -2,7 +2,15 @@ en:
2
2
  katalyst:
3
3
  tables:
4
4
  query:
5
- placeholder: "Filter %{name}"
5
+ input_component:
6
+ placeholder: "Filter %{name}"
7
+ modal_component:
8
+ suggestions_title: "Search options"
6
9
  orderable:
7
10
  value:
8
11
  "⠿"
12
+ errors:
13
+ attributes:
14
+ query:
15
+ unknown_key: "The field '%{input}' isn’t searchable here. Please check your input."
16
+ no_untagged_search: "'%{input}' isn't searchable here. Please choose a field to search."
@@ -22,8 +22,16 @@ module Katalyst
22
22
  end
23
23
  end
24
24
 
25
- def examples_for(...)
26
- [example(true), example(false)]
25
+ def suggestions(scope, attribute)
26
+ _, model, column = model_and_column_for(scope, attribute)
27
+
28
+ values = %w[true false]
29
+
30
+ if attribute.value_before_type_cast.present?
31
+ values = values.select { |value| value.include?(attribute.value_before_type_cast) }
32
+ end
33
+
34
+ values.map { |v| constant_suggestion(attribute:, model:, column:, value: deserialize(v)) }
27
35
  end
28
36
  end
29
37
  end
@@ -22,13 +22,15 @@ module Katalyst
22
22
  end
23
23
  end
24
24
 
25
- def examples_for(scope, attribute)
25
+ def suggestions(scope, attribute)
26
+ _, model, column = model_and_column_for(scope, attribute)
27
+
26
28
  [
27
29
  *super(scope, attribute, limit: 6, order: :desc),
28
- example(::Date.current.beginning_of_week.., "this week"),
29
- example(::Date.current.beginning_of_month.., "this month"),
30
- example(1.month.ago.all_month, "last month"),
31
- example(1.year.ago.all_year, "last year"),
30
+ database_suggestion(attribute:, model:, column:, value: ::Date.current.beginning_of_week..),
31
+ database_suggestion(attribute:, model:, column:, value: ::Date.current.beginning_of_month..),
32
+ database_suggestion(attribute:, model:, column:, value: 1.month.ago.all_month),
33
+ database_suggestion(attribute:, model:, column:, value: 1.year.ago.all_year),
32
34
  ]
33
35
  end
34
36
 
@@ -15,18 +15,18 @@ module Katalyst
15
15
  :enum
16
16
  end
17
17
 
18
- def examples_for(scope, attribute)
18
+ def suggestions(scope, attribute)
19
19
  _, model, column = model_and_column_for(scope, attribute)
20
20
 
21
21
  raise ArgumentError, "Unknown enum #{column} for #{model}" unless model.defined_enums.has_key?(column)
22
22
 
23
- keys = model.defined_enums[column].keys
23
+ values = model.defined_enums[column].keys
24
24
 
25
25
  if attribute.value_before_type_cast.present?
26
- keys = keys.select { |key| key.include?(attribute.value_before_type_cast.last) }
26
+ values = values.select { |key| key.include?(attribute.value_before_type_cast) }
27
27
  end
28
28
 
29
- keys.map { |key| example(key, describe_key(model, attribute, key)) }
29
+ values.map { |value| constant_suggestion(attribute:, model:, column:, value:) }
30
30
  end
31
31
 
32
32
  private
@@ -20,20 +20,10 @@ module Katalyst
20
20
  false
21
21
  end
22
22
 
23
- def examples_for(...)
23
+ def suggestions(...)
24
24
  []
25
25
  end
26
26
  end
27
-
28
- refine(::ActiveModel::Attribute) do
29
- def query_range=(range)
30
- @query_range = range
31
- end
32
-
33
- def query_range
34
- @query_range
35
- end
36
- end
37
27
  end
38
28
  end
39
29
  end
@@ -30,9 +30,7 @@ module Katalyst
30
30
  end
31
31
  end
32
32
 
33
- def filter(scope, attribute)
34
- value = filter_value(attribute)
35
-
33
+ def filter(scope, attribute, value: filter_value(attribute))
36
34
  return scope unless filter?(attribute, value)
37
35
 
38
36
  scope, model, column = model_and_column_for(scope, attribute)
@@ -45,29 +43,33 @@ module Katalyst
45
43
  serialize(value)
46
44
  end
47
45
 
48
- def examples_for(scope, attribute, limit: 10, order: :asc)
46
+ def suggestions(scope, attribute, limit: 10, order: :asc)
49
47
  scope, model, column = model_and_column_for(scope, attribute)
50
48
 
51
49
  unless model.attribute_types.has_key?(column)
52
50
  raise(ArgumentError, "Unknown column '#{column}' for #{model}. " \
53
- "Consider defining '#{attribute.name.parameterize.underscore}_examples'")
51
+ "Consider defining '#{attribute.name.parameterize.underscore}_suggestions'")
54
52
  end
55
53
 
56
- column = model.arel_table[column]
54
+ arel_column = model.arel_table[column]
57
55
 
58
56
  filter(scope, attribute)
59
- .group(column)
57
+ .group(arel_column)
60
58
  .distinct
61
59
  .limit(limit)
62
- .reorder(column => order)
63
- .pluck(column)
64
- .map { |v| example(deserialize(v)) }
60
+ .reorder(arel_column => order)
61
+ .pluck(arel_column)
62
+ .map { |v| database_suggestion(attribute:, model:, column:, value: deserialize(v)) }
65
63
  end
66
64
 
67
65
  private
68
66
 
69
- def example(value, description = "")
70
- Example.new(to_param(value), description)
67
+ def constant_suggestion(attribute:, model:, column:, value:)
68
+ Tables::Suggestions::ConstantValue.new(name: attribute.name, type: attribute.type, model:, column:, value:)
69
+ end
70
+
71
+ def database_suggestion(attribute:, model:, column:, value:)
72
+ Tables::Suggestions::DatabaseValue.new(name: attribute.name, type: attribute.type, model:, column:, value:)
71
73
  end
72
74
 
73
75
  def filter_value(attribute)
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: 3.4.6
4
+ version: 3.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katalyst Interactive
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-15 00:00:00.000000000 Z
11
+ date: 2024-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: katalyst-html-attributes
@@ -101,6 +101,8 @@ files:
101
101
  - app/components/katalyst/tables/query/input_component.rb
102
102
  - app/components/katalyst/tables/query/modal_component.html.erb
103
103
  - app/components/katalyst/tables/query/modal_component.rb
104
+ - app/components/katalyst/tables/query/suggestion_component.html.erb
105
+ - app/components/katalyst/tables/query/suggestion_component.rb
104
106
  - app/components/katalyst/tables/query_component.html.erb
105
107
  - app/components/katalyst/tables/query_component.rb
106
108
  - app/components/katalyst/tables/selectable/form_component.html.erb
@@ -130,12 +132,20 @@ files:
130
132
  - app/models/concerns/katalyst/tables/collection/query/array_value_parser.rb
131
133
  - app/models/concerns/katalyst/tables/collection/query/parser.rb
132
134
  - app/models/concerns/katalyst/tables/collection/query/single_value_parser.rb
135
+ - app/models/concerns/katalyst/tables/collection/query/untagged_literal.rb
133
136
  - app/models/concerns/katalyst/tables/collection/query/value_parser.rb
134
137
  - app/models/concerns/katalyst/tables/collection/reducers.rb
135
138
  - app/models/concerns/katalyst/tables/collection/sorting.rb
139
+ - app/models/concerns/katalyst/tables/collection/suggestions.rb
136
140
  - app/models/katalyst/tables/collection/array.rb
137
141
  - app/models/katalyst/tables/collection/base.rb
138
142
  - app/models/katalyst/tables/collection/filter.rb
143
+ - app/models/katalyst/tables/suggestions/attribute.rb
144
+ - app/models/katalyst/tables/suggestions/base.rb
145
+ - app/models/katalyst/tables/suggestions/constant_value.rb
146
+ - app/models/katalyst/tables/suggestions/custom_value.rb
147
+ - app/models/katalyst/tables/suggestions/database_value.rb
148
+ - app/models/katalyst/tables/suggestions/search_value.rb
139
149
  - config/importmap.rb
140
150
  - config/locales/tables.en.yml
141
151
  - lib/katalyst/tables.rb
@@ -144,7 +154,6 @@ files:
144
154
  - lib/katalyst/tables/collection/type/boolean.rb
145
155
  - lib/katalyst/tables/collection/type/date.rb
146
156
  - lib/katalyst/tables/collection/type/enum.rb
147
- - lib/katalyst/tables/collection/type/example.rb
148
157
  - lib/katalyst/tables/collection/type/float.rb
149
158
  - lib/katalyst/tables/collection/type/helpers/delegate.rb
150
159
  - lib/katalyst/tables/collection/type/helpers/extensions.rb
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Katalyst
4
- module Tables
5
- module Collection
6
- module Type
7
- class Example
8
- attr_reader :value, :description
9
-
10
- def initialize(value, description = "")
11
- @value = value
12
- @description = description
13
- end
14
-
15
- def hash
16
- value.hash
17
- end
18
-
19
- def eql?(other)
20
- value.eql?(other.value)
21
- end
22
-
23
- def to_s
24
- value.to_s
25
- end
26
- end
27
- end
28
- end
29
- end
30
- end