terrazzo 0.2.2 → 0.2.3

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: b55338dd365f9ad475e3892c34a4a5ca706625b50bd331dd6793bbd756ec75e7
4
- data.tar.gz: a5193fda7a10ca72103816e0f47a58ba7facf375003a4af22efa0385914378b2
3
+ metadata.gz: 8912409821769ce6f2303842822a9d33696bef4a24c9fdc9974411a99dccc7b0
4
+ data.tar.gz: a171f982161da734439ac15c77cafa831ace5f8f9b8f87b43d93aa3107cf67d1
5
5
  SHA512:
6
- metadata.gz: d048907fe5b71cee9100ce4cd7a1b606e666972be105a39f15c24f3119531deccc4bc7cb85144b65623faf933dbebfd1f78d61b841909872046afe754c3ea71f
7
- data.tar.gz: 6eb4e86c0a06cd790094cc0829313894f2c9d7b6ce232327a5c46610d9d507c5215b87ec81c3a136c0e5ac2b6841c22de4f81b0544a46aba2846a1f8e762f009
6
+ metadata.gz: 1394dab4447f66fbda0801d3b60a74ddd8f0325b6927562c4f8cf7b33212491b029efc78b12d5d8eb887496fed9261b8abb3b75f4e5f2148d74a80061951643a
7
+ data.tar.gz: f16c4e076d8f693b789622073df1fd9ccb5bedf36afb4eaa1032c4da09e8d87cc69b5a4929c8dcea28d0228c2ef53fc7476e71c8e12eee1e98a8b057982bad4a
@@ -42,7 +42,6 @@ json.table do
42
42
  json.attribute attr.to_s
43
43
  json.fieldType field.field_type
44
44
  json.value field.serialize_value(:index)
45
- json.options field.serializable_options
46
45
 
47
46
  if field.class.associative? && field.data.present?
48
47
  json.showPath polymorphic_path([namespace, field.data]) rescue nil
@@ -5,7 +5,6 @@ show_field_json = ->(json, field) do
5
5
  json.label field.attribute.to_s.humanize
6
6
  json.fieldType field.field_type
7
7
  json.value field.serialize_value(:show)
8
- json.options field.serializable_options
9
8
 
10
9
  if field.class.associative? && field.data.present?
11
10
  if field.is_a?(Terrazzo::Field::HasMany)
@@ -1,4 +1,5 @@
1
- import React, { useState } from "react";
1
+ import React, { useState, useContext } from "react";
2
+ import { NavigationContext } from "@thoughtbot/superglue";
2
3
 
3
4
  import {
4
5
  Table,
@@ -17,6 +18,7 @@ export function ShowField({ value, itemShowPaths }) {
17
18
 
18
19
  const { items, headers, total, initialLimit } = value;
19
20
  const [expanded, setExpanded] = useState(false);
21
+ const { visit } = useContext(NavigationContext);
20
22
 
21
23
  if (!items || items.length === 0) {
22
24
  return <span className="text-muted-foreground">None</span>;
@@ -26,6 +28,13 @@ export function ShowField({ value, itemShowPaths }) {
26
28
  const hasMore = initialLimit && initialLimit > 0 && total > initialLimit;
27
29
  const visibleItems = expanded || !hasMore ? items : items.slice(0, initialLimit);
28
30
 
31
+ const handleRowClick = (e, showPath) => {
32
+ if (!showPath) return;
33
+ if (e.target.closest("a, button, form")) return;
34
+ if (window.getSelection().toString()) return;
35
+ visit(showPath, {});
36
+ };
37
+
29
38
  // Table mode: collection_attributes specified
30
39
  if (headers) {
31
40
  return (
@@ -43,7 +52,10 @@ export function ShowField({ value, itemShowPaths }) {
43
52
  {visibleItems.map((item) => {
44
53
  const showPath = pathFor(item.id);
45
54
  return (
46
- <TableRow key={item.id}>
55
+ <TableRow
56
+ key={item.id}
57
+ className={showPath ? "cursor-pointer" : ""}
58
+ onClick={(e) => handleRowClick(e, showPath)}>
47
59
  {item.columns.map((col, colIndex) =>
48
60
  <TableCell key={col.attribute}>
49
61
  {showPath && colIndex === 0 ? (
@@ -44,7 +44,7 @@ module Terrazzo
44
44
  limit = options.fetch(:limit, 5)
45
45
  all_records = data.to_a
46
46
  total = all_records.size
47
- col_attrs = options[:collection_attributes]
47
+ col_attrs = options[:collection_attributes] || resolve_default_collection_attributes
48
48
 
49
49
  if col_attrs
50
50
  serialize_with_collection_attributes(all_records, col_attrs, total, limit)
@@ -57,6 +57,13 @@ module Terrazzo
57
57
  end
58
58
  end
59
59
 
60
+ def resolve_default_collection_attributes
61
+ dashboard_class = find_associated_dashboard
62
+ dashboard_class.new.collection_attributes
63
+ rescue NameError
64
+ nil
65
+ end
66
+
60
67
  def serialize_with_collection_attributes(records, col_attrs, total, limit)
61
68
  dashboard_class = find_associated_dashboard
62
69
 
@@ -1,3 +1,3 @@
1
1
  module Terrazzo
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
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.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Terrazzo Contributors