terrazzo 0.7.6 → 0.7.7
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7598c68c1691318c48e26a9b47176857414e6b1d0b72df96215941bd6f809ea5
|
|
4
|
+
data.tar.gz: e6f744d7131f5481d2b4a2c8c25db6a0547e96d9417eddc6edad0192805ad223
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2b50169a5535e19fe88c591f4d6f44881f1e7923fb6559d3f50ef6091e5addf971eb789a30d2c8fb92a09eb2180ee1bec7d89bb824a6783bf2244560e17b7d40
|
|
7
|
+
data.tar.gz: 91a647284864eddc2f1d3ba22e658a02b4800415008720256b3e1d868fe62e50af20d05d8ed54cf4064e9267fdaab13480688f4de9236be8f59321bc0fa74362
|
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Terrazzo
|
|
2
2
|
|
|
3
|
-
Association forms load selected values first. `HasMany` and `BelongsTo` use
|
|
3
|
+
Association forms load selected values first. `HasMany` and `BelongsTo` use typeahead search with at most 10 matches. Upgrade the gem and npm package together. Custom association form components must use the new option query contract; see [custom fields](docs/customizing-fields.md).
|
|
4
4
|
|
|
5
5
|
A drop-in admin panel for Rails apps. Uses the [Administrate](https://github.com/thoughtbot/administrate) dashboard DSL with a React SPA frontend powered by [Superglue](https://github.com/thoughtbot/superglue).
|
|
6
6
|
|
|
@@ -282,7 +282,7 @@ module Terrazzo
|
|
|
282
282
|
return head :not_found unless field.association_options?
|
|
283
283
|
|
|
284
284
|
response.headers["Cache-Control"] = "no-store"
|
|
285
|
-
render json: field.association_options(search: params[:search]
|
|
285
|
+
render json: field.association_options(search: params[:search])
|
|
286
286
|
end
|
|
287
287
|
|
|
288
288
|
def resolver
|
|
@@ -24,8 +24,7 @@ export function AssociationSelect({
|
|
|
24
24
|
);
|
|
25
25
|
const [open, setOpen] = useState(false);
|
|
26
26
|
const [search, setSearch] = useState("");
|
|
27
|
-
const [
|
|
28
|
-
const [result, setResult] = useState({ resourceOptions: [], hasMore: false });
|
|
27
|
+
const [result, setResult] = useState({ resourceOptions: [] });
|
|
29
28
|
const [loading, setLoading] = useState(false);
|
|
30
29
|
const [error, setError] = useState("");
|
|
31
30
|
const [retry, setRetry] = useState(0);
|
|
@@ -40,7 +39,6 @@ export function AssociationSelect({
|
|
|
40
39
|
try {
|
|
41
40
|
const url = new URL(options.optionsUrl, window.location.origin);
|
|
42
41
|
url.searchParams.set("search", search);
|
|
43
|
-
url.searchParams.set("page", String(page));
|
|
44
42
|
const response = await window.fetch(url, {
|
|
45
43
|
headers: { Accept: "application/json" },
|
|
46
44
|
signal: controller.signal,
|
|
@@ -61,7 +59,7 @@ export function AssociationSelect({
|
|
|
61
59
|
clearTimeout(timer);
|
|
62
60
|
controller.abort();
|
|
63
61
|
};
|
|
64
|
-
}, [open, search,
|
|
62
|
+
}, [open, search, options.optionsUrl, retry]);
|
|
65
63
|
|
|
66
64
|
const select = (option) => {
|
|
67
65
|
const id = option[1];
|
|
@@ -150,7 +148,6 @@ export function AssociationSelect({
|
|
|
150
148
|
className="w-full rounded border px-2 py-1"
|
|
151
149
|
onChange={(event) => {
|
|
152
150
|
setSearch(event.target.value);
|
|
153
|
-
setPage(1);
|
|
154
151
|
setLoading(true);
|
|
155
152
|
}}
|
|
156
153
|
/>
|
|
@@ -187,29 +184,6 @@ export function AssociationSelect({
|
|
|
187
184
|
))}
|
|
188
185
|
</div>
|
|
189
186
|
)}
|
|
190
|
-
<div className="flex items-center justify-between">
|
|
191
|
-
<button
|
|
192
|
-
type="button"
|
|
193
|
-
disabled={loading || page === 1}
|
|
194
|
-
onClick={() => {
|
|
195
|
-
setPage(page - 1);
|
|
196
|
-
setLoading(true);
|
|
197
|
-
}}
|
|
198
|
-
>
|
|
199
|
-
Previous
|
|
200
|
-
</button>
|
|
201
|
-
<span>Page {page}</span>
|
|
202
|
-
<button
|
|
203
|
-
type="button"
|
|
204
|
-
disabled={loading || !!error || !result.hasMore}
|
|
205
|
-
onClick={() => {
|
|
206
|
-
setPage(page + 1);
|
|
207
|
-
setLoading(true);
|
|
208
|
-
}}
|
|
209
|
-
>
|
|
210
|
-
Next
|
|
211
|
-
</button>
|
|
212
|
-
</div>
|
|
213
187
|
</PopoverContent>
|
|
214
188
|
</Popover>
|
|
215
189
|
{!multiple && selectedIds.length > 0 && (
|
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
module Terrazzo
|
|
2
2
|
module Field
|
|
3
3
|
class Associative < Base
|
|
4
|
-
|
|
4
|
+
OPTION_LIMIT = 10
|
|
5
5
|
|
|
6
|
-
def association_options(search
|
|
7
|
-
page = [page.to_i, 1].max
|
|
6
|
+
def association_options(search:)
|
|
8
7
|
scope = candidate_scope
|
|
9
8
|
columns = options[:searchable_fields] || (%w[name title email slug code original_filename id] &
|
|
10
9
|
(associated_class.column_names + associated_class.stored_attributes.values.flatten.map(&:to_s)))
|
|
11
10
|
scope = Terrazzo::Search.new(scope, nil, search).run_for_columns(columns)
|
|
12
11
|
scope = scope.reorder(options[:order] || association_primary_key).order(association_primary_key)
|
|
13
|
-
records = scope.
|
|
12
|
+
records = scope.limit(OPTION_LIMIT).to_a
|
|
14
13
|
{
|
|
15
|
-
resourceOptions: records.
|
|
16
|
-
page: page,
|
|
17
|
-
hasMore: records.length > OPTION_PAGE_SIZE
|
|
14
|
+
resourceOptions: records.map { |record| option_for(record) }
|
|
18
15
|
}
|
|
19
16
|
end
|
|
20
17
|
|
data/lib/terrazzo/version.rb
CHANGED