@xeplr/ui-utils 1.1.8 → 1.1.9

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
@@ -328,6 +328,8 @@ configureUpload({ url: API_BASE + '/imports/files', getHeaders }) // once, at
328
328
  |---|---|---|
329
329
  | `basePath` | `string` | Where the app mounted the router, as the browser sees it (default `'/imports'`) |
330
330
  | `pollMs` | `number` | How often a running import is asked how far it has got (default 1000) |
331
+ | `upload` | `(file, onProgress(percent), { standard }) => Promise<{ filePath }>` | Optional: the app's own way to send a file. It decides per file — `standard(file, onProgress)` is the usual one request to `/files`; a file too big for one request can be sent another way (in pieces, say) into the tenant's `uploads/` folder, and the answer's `filePath` is imported like any other. Xeplr BI sends files over 200 MB in chunks this way, on Pro and up (`importsApi.js` `uploaderFor`) |
332
+ | `accept` | `string` | The file input's `accept` (default `ACCEPT`: `.csv,.json,.xlsx,.xls,.parquet`) |
331
333
 
332
334
  It shows three things:
333
335
 
@@ -338,7 +340,7 @@ It shows three things:
338
340
  Requests carry the headers `configureUpload` was given (`uploadHeaders()`), so sign-in and tenancy need no second setup. The model is `importsApi.js`:
339
341
 
340
342
  - `createImportsApi(basePath)` makes every route call.
341
- - Pure helpers: `importProgressText`, `runResults`, `historyJob`, `databasesOf`, `fileNameOf`.
343
+ - Pure helpers: `importProgressText`, `runResults`, `historyJob`, `databasesOf`, `fileNameOf`, `uploaderFor(api, upload)` (how a picked file is sent), `ACCEPT` (exported as `IMPORT_ACCEPT`: the files it reads, Parquet among them).
342
344
 
343
345
  A custom design receives the controller's values plus `importSection` and `historySection` as elements.
344
346
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xeplr/ui-utils",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
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",
@@ -7,6 +7,22 @@
7
7
 
8
8
  import { uploadFile, uploadHeaders } from '../fileUpload/uploadFile.js';
9
9
 
10
+ /**
11
+ * How a picked file is sent: the app's own `upload` when it gives one —
12
+ * handed the file, the progress callback and the standard sender, so it can
13
+ * keep the standard one for most files and send a big one its own way (in
14
+ * pieces, say) — else the standard: one request to /files. Either answers
15
+ * { filePath } inside the tenant's uploads/ folder, which is all the import
16
+ * needs.
17
+ */
18
+ export function uploaderFor(api, upload) {
19
+ if (typeof upload !== 'function') return function(file, onProgress) { return api.upload(file, onProgress); };
20
+ return function(file, onProgress) { return upload(file, onProgress, { standard: api.upload }); };
21
+ }
22
+
23
+ /** The files the import reads, for the file input. */
24
+ export var ACCEPT = '.csv,.json,.xlsx,.xls,.parquet';
25
+
10
26
  /** The import routes under one base path. Every call rejects with the server's own `error`. */
11
27
  export function createImportsApi(basePath) {
12
28
  var base = String(basePath || '/imports').replace(/\/+$/, '');
@@ -1,4 +1,5 @@
1
1
  import { useImportsController } from './useImportsController.js';
2
+ import { ACCEPT } from './importsApi.js';
2
3
  import ImportsSample from './designs/ImportsSample.jsx';
3
4
  import { IMPORTS_RULES } from './validateDesign.js';
4
5
  import { useDesignValidator } from '../dataImport/validateDesign.js';
@@ -17,7 +18,7 @@ export function ImportsPage(props) {
17
18
  return (
18
19
  <div ref={ref}>
19
20
  <ImportsSample {...c}
20
- importSection={<DataImportPage accept=".csv,.json,.xlsx,.xls" targetLabel="Table name" {...c.importProps} />}
21
+ importSection={<DataImportPage accept={props.accept || ACCEPT} targetLabel="Table name" {...c.importProps} />}
21
22
  historySection={<ImportHistoryPage key={c.historyVersion} {...c.historyProps} />} />
22
23
  </div>
23
24
  );
@@ -1,5 +1,5 @@
1
1
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
- import { createImportsApi, importProgressText, runResults, historyJob, databasesOf } from './importsApi.js';
2
+ import { createImportsApi, importProgressText, runResults, historyJob, databasesOf, uploaderFor } from './importsApi.js';
3
3
 
4
4
  /**
5
5
  * The whole import screen against @xeplr/imports' routes: which database,
@@ -10,6 +10,7 @@ import { createImportsApi, importProgressText, runResults, historyJob, databases
10
10
  * @param {object} props
11
11
  * @param {string} [props.basePath='/imports'] - where the app mounted the router, as the browser sees it
12
12
  * @param {number} [props.pollMs=1000] - how often a running import is asked how far it has got
13
+ * @param {(file, onProgress, { standard }) => Promise<{ filePath }>} [props.upload] - the app's own way to send a file (see uploaderFor)
13
14
  */
14
15
  export function useImportsController(props = {}) {
15
16
  var api = useMemo(function() { return createImportsApi(props.basePath); }, [props.basePath]);
@@ -42,7 +43,8 @@ export function useImportsController(props = {}) {
42
43
  setDbInfoId((databasesOf(targets, id)[0] || {}).id || '');
43
44
  }
44
45
 
45
- var onUpload = useCallback(function(file, onProgress) { return api.upload(file, onProgress); }, [api]);
46
+ var upload = props.upload;
47
+ var onUpload = useMemo(function() { return uploaderFor(api, upload); }, [api, upload]);
46
48
 
47
49
  var onInspect = useCallback(async function(filePath) {
48
50
  var found = await api.inspect(filePath);
package/src/index.js CHANGED
@@ -59,7 +59,7 @@ export { DroppedRowsPage } from './dataImport/pages.jsx';
59
59
  // Imports — the whole import screen against @xeplr/imports' routes: database
60
60
  // picker, import (DataImportPage), progress with ✕, history (ImportHistoryPage).
61
61
  // <ImportsPage basePath="/api/imports" /> is all an app adds.
62
- export { createImportsApi, importProgressText, runResults, historyJob, databasesOf, fileNameOf } from './imports/importsApi.js';
62
+ export { createImportsApi, importProgressText, runResults, historyJob, databasesOf, fileNameOf, uploaderFor, ACCEPT as IMPORT_ACCEPT } from './imports/importsApi.js';
63
63
  export { useImportsController } from './imports/useImportsController.js';
64
64
  export { IMPORTS_RULES } from './imports/validateDesign.js';
65
65
  export { ImportsSample } from './imports/designs/index.js';