terrazzo 0.5.4 → 0.6.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 100223520cc1a1dbedef6413a2ba4e1b45691f4773abddd9ee27d123e735c64d
4
- data.tar.gz: eeee21e64365ca82bc7c6f11c2f80dd813b2960d96e1e3aa80839fd7acb2b2cf
3
+ metadata.gz: 6030a4b97c39b154729b26996275571d8a6ffba864d84a0bff348257c308ce16
4
+ data.tar.gz: 82edfaa39bd26353f4c56a2e96b22739620033d527d3c3fb57f6fcde45ec4b7c
5
5
  SHA512:
6
- metadata.gz: f44edde4138e7348cfaa6abd5c790c8d295f40ed57fd7391c6e1af6a97a2f334bf73e147e4322e37138b5a72ef4743be7c0346448defef4c8d0becaf1daf8d17
7
- data.tar.gz: 344144b82879ebe42857dbf048b9737e429fba63d06a06aa5ef5b2aa1ff3accef8633efb11c12835fca3a384ef06b162cf5c78892db4ffbc8e046598b2eaf311
6
+ metadata.gz: cdc8552e4cf480b5dee699776ef5d1337eb7e1d92d387328d379b634165bf941774f4263ef0f0f8159ba8ae5fccb7d827b00425fed500b173f03325efddd908f
7
+ data.tar.gz: c7ff22f7872258e527a0558ef9a54df140a481aa76f8fc906250b16fd7b1210dc7f1a8293a6677398888461e26dd5b82ad967c6463eefd44df3e3d312591c9e6
@@ -46,7 +46,7 @@ module Terrazzo
46
46
  @resource = find_resource(params[:id])
47
47
  @page = Terrazzo::Page::Show.new(
48
48
  dashboard, @resource,
49
- has_many_params: Terrazzo::HasManyPagination.extract(params)
49
+ has_many_params: Terrazzo::HasManyPagination.extract(params, dashboard.has_many_attributes)
50
50
  )
51
51
  end
52
52
 
@@ -16,7 +16,8 @@ module Terrazzo
16
16
  controller: controller_path,
17
17
  action: :show,
18
18
  id: resource.to_param,
19
- format: nil
19
+ format: nil,
20
+ props_at: "data.attributes.#{field.attribute}"
20
21
  )
21
22
  {
22
23
  prevPagePath: (field.current_page > 1 ? url_for(base.merge(param_key => field.current_page - 1)) : nil),
@@ -25,13 +25,17 @@ show_field_json = ->(json, field) do
25
25
  end
26
26
 
27
27
  json.attributes do
28
+ @page.grouped_attributes.flat_map { |g| g[:fields] }.each do |field|
29
+ json.set!(field.attribute.to_s) do
30
+ show_field_json.call(json, field)
31
+ end
32
+ end
33
+ end
34
+
35
+ json.attributeGroups do
28
36
  json.array! @page.grouped_attributes do |group|
29
37
  json.name group[:name]
30
- json.attributes do
31
- json.array! group[:fields] do |field|
32
- show_field_json.call(json, field)
33
- end
34
- end
38
+ json.attributeKeys group[:fields].map { |f| f.attribute.to_s }
35
39
  end
36
40
  end
37
41
 
@@ -10,6 +10,7 @@ export default function AdminShow() {
10
10
  const {
11
11
  pageTitle,
12
12
  attributes,
13
+ attributeGroups,
13
14
  editPath,
14
15
  deletePath,
15
16
  indexPath,
@@ -54,7 +55,7 @@ export default function AdminShow() {
54
55
  </div>
55
56
  }>
56
57
 
57
- {attributes.map((group, groupIndex) =>
58
+ {attributeGroups.map((group, groupIndex) =>
58
59
  <Card key={groupIndex}>
59
60
  {group.name && (
60
61
  <CardHeader>
@@ -63,22 +64,25 @@ export default function AdminShow() {
63
64
  )}
64
65
  <CardContent className={group.name ? "" : "pt-6"}>
65
66
  <dl className="divide-y">
66
- {group.attributes.map((attr) =>
67
- <div key={attr.attribute} className="py-4 grid grid-cols-3 gap-4">
68
- <dt className="text-sm font-medium text-muted-foreground">
69
- {attr.label}
70
- </dt>
71
- <dd className="col-span-2 text-sm">
72
- {attr.showPath ? (
73
- <a href={attr.showPath} data-sg-visit className="hover:underline">
67
+ {group.attributeKeys.map((key) => {
68
+ const attr = attributes[key];
69
+ return (
70
+ <div key={key} className="py-4 grid grid-cols-3 gap-4">
71
+ <dt className="text-sm font-medium text-muted-foreground">
72
+ {attr.label}
73
+ </dt>
74
+ <dd className="col-span-2 text-sm">
75
+ {attr.showPath ? (
76
+ <a href={attr.showPath} data-sg-visit className="hover:underline">
77
+ <FieldRenderer mode="show" {...attr} />
78
+ </a>
79
+ ) : (
74
80
  <FieldRenderer mode="show" {...attr} />
75
- </a>
76
- ) : (
77
- <FieldRenderer mode="show" {...attr} />
78
- )}
79
- </dd>
80
- </div>
81
- )}
81
+ )}
82
+ </dd>
83
+ </div>
84
+ );
85
+ })}
82
86
  </dl>
83
87
  </CardContent>
84
88
  </Card>
@@ -58,6 +58,10 @@ module Terrazzo
58
58
  attribute_types.select { |_attr, type| type.searchable? }.keys
59
59
  end
60
60
 
61
+ def has_many_attributes
62
+ attribute_types.select { |_attr, type| type.field_type == "has_many" }.keys
63
+ end
64
+
61
65
  def display_resource(resource)
62
66
  "#{resource.class.name} ##{resource.id}"
63
67
  end
@@ -1,24 +1,19 @@
1
1
  module Terrazzo
2
2
  module HasManyPagination
3
- PARAM_PREFIX = "hm_".freeze
4
3
  PARAM_SUFFIX = "_page".freeze
5
4
 
6
5
  module_function
7
6
 
8
- def extract(params)
9
- result = {}
10
- params.each do |key, value|
11
- key_s = key.to_s
12
- next unless key_s.start_with?(PARAM_PREFIX) && key_s.end_with?(PARAM_SUFFIX)
13
- attr = key_s[PARAM_PREFIX.length...-PARAM_SUFFIX.length]
14
- next if attr.empty?
7
+ def extract(params, attributes)
8
+ attributes.each_with_object({}) do |attr, result|
9
+ value = params[param_key(attr)] || params[param_key(attr).to_sym]
10
+ next if value.nil?
15
11
  result[attr.to_sym] = { _page: value.to_i }
16
12
  end
17
- result
18
13
  end
19
14
 
20
15
  def param_key(attribute)
21
- "#{PARAM_PREFIX}#{attribute}#{PARAM_SUFFIX}"
16
+ "#{attribute}#{PARAM_SUFFIX}"
22
17
  end
23
18
  end
24
19
  end
@@ -1,3 +1,3 @@
1
1
  module Terrazzo
2
- VERSION = "0.5.4"
2
+ VERSION = "0.6.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terrazzo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Terrazzo Contributors