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: f2485c82e85ed664ba929d42f7aba8b3fd05d06c0c98f0e72cdf023108827c9b
4
- data.tar.gz: 936dc1c90978c9e5a034ad1a99994eca021d09494bde07ffa08b452bf99b6641
3
+ metadata.gz: 7598c68c1691318c48e26a9b47176857414e6b1d0b72df96215941bd6f809ea5
4
+ data.tar.gz: e6f744d7131f5481d2b4a2c8c25db6a0547e96d9417eddc6edad0192805ad223
5
5
  SHA512:
6
- metadata.gz: 2526b14b6bcd42a5d4eaee4ed9d3c6ce95a98f345a6e67ede0935e7fcdf7d455ce5afa1f012b52b26c9930706dcbd32dacb6062860f8a5cffac466045274db5e
7
- data.tar.gz: 69b436459fb552a8569b1b9250f50335b9383c2bc7490d0ec9ce0c8c366c99b57f3c6d6fa9d44de21d5bb306192d6e80ae5ba6ab1cd4d25da4eb0b9e85046171
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 server search with pages of 25 options. 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).
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], page: params[:page])
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 [page, setPage] = useState(1);
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, page, options.optionsUrl, retry]);
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
- OPTION_PAGE_SIZE = 25
4
+ OPTION_LIMIT = 10
5
5
 
6
- def association_options(search:, page:)
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.offset((page - 1) * OPTION_PAGE_SIZE).limit(OPTION_PAGE_SIZE + 1).to_a
12
+ records = scope.limit(OPTION_LIMIT).to_a
14
13
  {
15
- resourceOptions: records.first(OPTION_PAGE_SIZE).map { |record| option_for(record) },
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
 
@@ -1,3 +1,3 @@
1
1
  module Terrazzo
2
- VERSION = "0.7.6"
2
+ VERSION = "0.7.7"
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.7.6
4
+ version: 0.7.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Terrazzo Contributors