@xeplr/ui-utils 1.1.11 → 1.1.13

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.
package/README.md CHANGED
@@ -342,8 +342,8 @@ It shows three things:
342
342
  Requests carry the headers `configureUpload` was given (`uploadHeaders()`), so sign-in and tenancy need no second setup. The model is `importsApi.js`:
343
343
 
344
344
  - `createImportsApi(basePath)` makes every route call.
345
- - `createRunWatcher({ api, events?, pollMs? })` → `{ wait(runId, onProgress) → Promise<run>, close() }`: waits for a check or an import as described under `events`, without React. A run whose `GET /runs/:id` fails (with several API processes it may be held by another one) is still heard ending on the stream.
346
- - Pure helpers: `importProgressText`, `checkProgressText`, `runResults`, `checkResult` (a finished check in `onInspect`'s shape, or its error), `historyJob`, `databasesOf`, `fileNameOf`, `uploaderFor(api, upload)` (how a picked file is sent), `ACCEPT` (exported as `IMPORT_ACCEPT`: the files it reads, Parquet among them).
345
+ - `createRunWatcher({ api, events?, pollMs? })` → `{ wait(runId, onProgress) → Promise<run>, open(), close() }`: waits for a check or an import as described under `events`, without React. `open()` undoes `close()` — `useImportsController` calls it on every mount, because React's StrictMode (development) mounts, cleans up and mounts again, and a watcher closed by that cleanup never heard a run finish ("Checking the file…" forever although the server had finished). A run whose `GET /runs/:id` fails (with several API processes it may be held by another one) is still heard ending on the stream.
346
+ - Pure helpers: `importProgressText`, `checkProgressText`, `runResults`, `checkResult` (a finished check in `onInspect`'s shape — `{ format, parts, checks, rows }`, `rows` each part's `{ rows, over }` count from @xeplr/imports 2.0.6+, else null — or its error), `historyJob`, `databasesOf`, `fileNameOf`, `uploaderFor(api, upload)` (how a picked file is sent), `ACCEPT` (exported as `IMPORT_ACCEPT`: the files it reads, Parquet among them).
347
347
 
348
348
  A custom design receives the controller's values plus `importSection` and `historySection` as elements.
349
349
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xeplr/ui-utils",
3
- "version": "1.1.11",
3
+ "version": "1.1.13",
4
4
  "description": "UI utility components: file upload with progress, snackbar, static data (countries/states)",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -109,9 +109,14 @@ export function createRunWatcher(opts) {
109
109
  if (run.status === 'running') { if (w.onProgress) w.onProgress(run.progress || null); return; }
110
110
  w.done(run);
111
111
  }
112
- var unsubscribe = events ? events.subscribe(function(e) {
113
- if (e && e.type === 'import-run' && e.runId) heard(e);
114
- }) : null;
112
+ var unsubscribe = null;
113
+ function listen() {
114
+ if (!events || unsubscribe) return;
115
+ unsubscribe = events.subscribe(function(e) {
116
+ if (e && e.type === 'import-run' && e.runId) heard(e);
117
+ });
118
+ }
119
+ listen();
115
120
 
116
121
  function live() {
117
122
  if (!events) return false;
@@ -158,9 +163,18 @@ export function createRunWatcher(opts) {
158
163
 
159
164
  return {
160
165
  wait: wait,
166
+ // Open again after close(). React's StrictMode (development) mounts,
167
+ // cleans up and mounts again: closed for good on the cleanup, the watcher
168
+ // never asked about a run again and a check sat on "Checking the file…"
169
+ // although the server had finished it. The hook re-opens it on each mount.
170
+ open: function() {
171
+ closed = false;
172
+ listen();
173
+ },
161
174
  close: function() {
162
175
  closed = true;
163
176
  if (unsubscribe) { try { unsubscribe(); } catch (e) { /* gone already */ } }
177
+ unsubscribe = null;
164
178
  waiting.clear();
165
179
  }
166
180
  };
@@ -171,7 +185,8 @@ export function checkResult(run) {
171
185
  if (run.status === 'error') throw new Error(run.error || 'The check failed');
172
186
  if (run.status === 'stopped') throw new Error(run.error === 'Stopped' || !run.error ? 'The check was stopped.' : run.error);
173
187
  var found = run.result || {};
174
- return { format: found.format, parts: found.sheets, checks: found.checks };
188
+ // rows: each part's row count ({ rows, over }) — @xeplr/imports 2.0.6+.
189
+ return { format: found.format, parts: found.sheets, checks: found.checks, rows: found.rows || null };
175
190
  }
176
191
 
177
192
  /** "Checking the file · 1.2 GB of 3.0 GB (40%) · 412,000 rows" — how far a check has got. */
@@ -22,7 +22,9 @@ export function useImportsController(props = {}) {
22
22
  var pollMs = props.pollMs || 1000;
23
23
  var events = props.events;
24
24
  var watcher = useMemo(function() { return createRunWatcher({ api: api, events: events, pollMs: pollMs }); }, [api, events, pollMs]);
25
- useEffect(function() { return function() { watcher.close(); }; }, [watcher]);
25
+ // open() on every mount: StrictMode's mount → cleanup → mount would
26
+ // otherwise leave it closed and no run would ever be heard finishing.
27
+ useEffect(function() { watcher.open(); return function() { watcher.close(); }; }, [watcher]);
26
28
 
27
29
  var [targets, setTargets] = useState([]);
28
30
  var [targetsError, setTargetsError] = useState('');
@@ -71,7 +73,7 @@ export function useImportsController(props = {}) {
71
73
  // at once, without a run.
72
74
  var onInspect = useCallback(async function(filePath) {
73
75
  var found = await api.inspect(filePath);
74
- if (!found.runId) return { format: found.format, parts: found.sheets, checks: found.checks };
76
+ if (!found.runId) return { format: found.format, parts: found.sheets, checks: found.checks, rows: found.rows || null };
75
77
  return checkResult(await follow(found.runId, 'check'));
76
78
  }, [api, follow]);
77
79