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 +4 -4
- data/app/views/terrazzo/application/index.json.props +0 -1
- data/app/views/terrazzo/application/show.json.props +0 -1
- data/lib/generators/terrazzo/views/templates/fields/has_many/ShowField.jsx +14 -2
- data/lib/terrazzo/field/has_many.rb +8 -1
- data/lib/terrazzo/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8912409821769ce6f2303842822a9d33696bef4a24c9fdc9974411a99dccc7b0
|
|
4
|
+
data.tar.gz: a171f982161da734439ac15c77cafa831ace5f8f9b8f87b43d93aa3107cf67d1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
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
|
|
data/lib/terrazzo/version.rb
CHANGED