@vuu-ui/vuu-data-react 4.3.0-beta.2 → 5.0.0-alpha.11

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/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
- "version": "4.3.0-beta.2",
2
+ "version": "5.0.0-alpha.11",
3
3
  "main": "./src/index.js",
4
4
  "author": "heswell",
5
+ "type": "module",
5
6
  "license": "Apache-2.0",
6
7
  "scripts": {
7
8
  "build": "node ../../scripts/run-build-rslib.ts",
@@ -9,25 +10,26 @@
9
10
  "type-defs": "node ../../scripts/build-type-defs.mjs"
10
11
  },
11
12
  "devDependencies": {
12
- "@vuu-ui/vuu-data-types": "4.3.0-beta.2",
13
- "@vuu-ui/vuu-filter-types": "4.3.0-beta.2",
14
- "@vuu-ui/vuu-protocol-types": "4.3.0-beta.2",
15
- "@vuu-ui/vuu-table-types": "4.3.0-beta.2"
13
+ "@vuu-ui/vuu-data-types": "5.0.0-alpha.11",
14
+ "@vuu-ui/vuu-filter-types": "5.0.0-alpha.11",
15
+ "@vuu-ui/vuu-protocol-types": "5.0.0-alpha.11",
16
+ "@vuu-ui/vuu-table-types": "5.0.0-alpha.11"
16
17
  },
17
18
  "dependencies": {
18
- "@vuu-ui/vuu-context-menu": "4.3.0-beta.2",
19
- "@vuu-ui/vuu-data-editing": "4.3.0-beta.2",
20
- "@vuu-ui/vuu-data-remote": "4.3.0-beta.2",
21
- "@vuu-ui/vuu-filter-parser": "4.3.0-beta.2",
22
- "@vuu-ui/vuu-filters": "4.3.0-beta.2",
23
- "@vuu-ui/vuu-layout": "4.3.0-beta.2",
24
- "@vuu-ui/vuu-notifications": "4.3.0-beta.2",
25
- "@vuu-ui/vuu-ui-controls": "4.3.0-beta.2",
26
- "@vuu-ui/vuu-utils": "4.3.0-beta.2",
27
- "@vuu-ui/vuu-table": "4.3.0-beta.2",
19
+ "@vuu-ui/vuu-context-menu": "5.0.0-alpha.11",
20
+ "@vuu-ui/vuu-data-editing": "5.0.0-alpha.11",
21
+ "@vuu-ui/vuu-data-remote": "5.0.0-alpha.11",
22
+ "@vuu-ui/vuu-filter-parser": "5.0.0-alpha.11",
23
+ "@vuu-ui/vuu-filters": "5.0.0-alpha.11",
24
+ "@vuu-ui/vuu-layout": "5.0.0-alpha.11",
25
+ "@vuu-ui/vuu-notifications": "5.0.0-alpha.11",
26
+ "@vuu-ui/vuu-ui-controls": "5.0.0-alpha.11",
27
+ "@vuu-ui/vuu-utils": "5.0.0-alpha.11",
28
+ "@vuu-ui/vuu-table": "5.0.0-alpha.11",
28
29
  "@salt-ds/core": "1.74.0",
29
30
  "@salt-ds/styles": "0.4.2",
30
- "@salt-ds/window": "0.1.2"
31
+ "@salt-ds/window": "0.1.2",
32
+ "@vuu-ui/core": "5.0.0-alpha.11"
31
33
  },
32
34
  "peerDependencies": {
33
35
  "clsx": "^2.0.0",
@@ -41,13 +43,12 @@
41
43
  ],
42
44
  "exports": {
43
45
  ".": {
46
+ "types": "./types/index.d.ts",
44
47
  "import": "./src/index.js",
45
- "default": "./src/index.js",
46
- "types": "./types/index.d.ts"
48
+ "default": "./src/index.js"
47
49
  }
48
50
  },
49
51
  "module": "./src/index.js",
50
52
  "name": "@vuu-ui/vuu-data-react",
51
- "type": "module",
52
53
  "types": "types/index.d.ts"
53
54
  }
@@ -1,11 +1,11 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
+ import { useModal } from "@vuu-ui/core";
2
3
  import { Range, buildColumnMap, dataSourceRowToEntity, messageHasDataRows, queryClosest } from "@vuu-ui/vuu-utils";
3
4
  import { Button } from "@salt-ds/core";
4
5
  import { useCallback, useMemo, useRef, useState } from "react";
5
6
  import { UnsavedChangesReport } from "./UnsavedChangesReport.js";
6
7
  import { buildValidationChecker, getEditValidationRules } from "./edit-rule-validation-checker.js";
7
8
  import { CLEAN_FORM, buildFormEditState } from "./form-edit-state.js";
8
- import { useModal } from "@vuu-ui/vuu-ui-controls";
9
9
  const CLEAN_VALIDATION = {
10
10
  ok: true,
11
11
  messages: {}
@@ -1,17 +1,24 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
+ import { DataProvider, useOptionalVuuConnectionId } from "@vuu-ui/core";
2
3
  import { ConnectionManager, VuuDataSource } from "@vuu-ui/vuu-data-remote";
3
- import { DataProvider } from "@vuu-ui/vuu-utils";
4
- import { useAutoLoginToVuuServer } from "./useAutoLoginToVuuServer.js";
5
- const getServerAPI = ()=>ConnectionManager.serverAPI;
6
- const VuuDataSourceProvider = ({ authenticate, autoConnect = false, autoLogin = false, children, websocketUrl })=>{
7
- useAutoLoginToVuuServer({
8
- authenticate,
9
- autoConnect,
10
- autoLogin,
11
- websocketUrl
12
- });
4
+ import { useMemo } from "react";
5
+ const VuuDataSourceProvider = ({ children })=>{
6
+ const connectionId = useOptionalVuuConnectionId() ?? "portal";
7
+ const BoundVuuDataSource = useMemo(()=>class extends VuuDataSource {
8
+ constructor(props){
9
+ super({
10
+ ...props,
11
+ connectionId
12
+ });
13
+ }
14
+ }, [
15
+ connectionId
16
+ ]);
17
+ const getServerAPI = useMemo(()=>()=>ConnectionManager.serverAPIFor(connectionId), [
18
+ connectionId
19
+ ]);
13
20
  return /*#__PURE__*/ jsx(DataProvider, {
14
- VuuDataSource: VuuDataSource,
21
+ VuuDataSource: BoundVuuDataSource,
15
22
  getServerAPI: getServerAPI,
16
23
  isLocalData: false,
17
24
  children: children
@@ -1,4 +1,5 @@
1
- import { VuuDataSource } from "@vuu-ui/vuu-data-remote";
1
+ import { useData, useOptionalVuuConnectionId } from "@vuu-ui/core";
2
+ import { DEFAULT_CONNECTION_ID } from "@vuu-ui/vuu-data-remote";
2
3
  import { Range, buildColumnMap, getSelectedOption, isLookupRenderer, isTypeDescriptor, isValueListRenderer, useShellContext } from "@vuu-ui/vuu-utils";
3
4
  import { useMemo, useState } from "react";
4
5
  const NO_VALUES = [];
@@ -7,8 +8,8 @@ const toListOption = (value)=>({
7
8
  value
8
9
  });
9
10
  const lookupValueMap = new Map();
10
- const loadLookupValues = ({ labelColumn, table, valueColumn })=>{
11
- const tableKey = `${table.module}:${table.table}`;
11
+ const loadLookupValues = (connectionId, VuuDataSource, { labelColumn, table, valueColumn })=>{
12
+ const tableKey = `${connectionId}:${table.module}:${table.table}`;
12
13
  const lookupValues = lookupValueMap.get(tableKey);
13
14
  if (lookupValues) return lookupValues;
14
15
  else {
@@ -49,6 +50,8 @@ const getLookupDetails = ({ name, type })=>{
49
50
  const useLookupValues = (column, initialValueProp)=>{
50
51
  const { type: columnType } = column;
51
52
  const { getLookupValues } = useShellContext();
53
+ const { VuuDataSource } = useData();
54
+ const connectionId = useOptionalVuuConnectionId() ?? DEFAULT_CONNECTION_ID;
52
55
  const initialState = useMemo(()=>{
53
56
  if (isTypeDescriptor(columnType) && isValueListRenderer(columnType?.renderer)) {
54
57
  const values = columnType.renderer.values.map(toListOption);
@@ -74,7 +77,7 @@ const useLookupValues = (column, initialValueProp)=>{
74
77
  useMemo(()=>{
75
78
  if (values === NO_VALUES) {
76
79
  const lookupDetails = getLookupDetails(column);
77
- loadLookupValues(lookupDetails).then((values)=>setLookupState({
80
+ loadLookupValues(connectionId, VuuDataSource, lookupDetails).then((values)=>setLookupState({
78
81
  initialValue: getSelectedOption(values, initialValueProp) ?? null,
79
82
  values
80
83
  }));
@@ -82,7 +85,9 @@ const useLookupValues = (column, initialValueProp)=>{
82
85
  }, [
83
86
  values,
84
87
  column,
85
- initialValueProp
88
+ initialValueProp,
89
+ connectionId,
90
+ VuuDataSource
86
91
  ]);
87
92
  return {
88
93
  initialValue,
@@ -1,4 +1,4 @@
1
- import { useData } from "@vuu-ui/vuu-utils";
1
+ import { useData } from "@vuu-ui/core";
2
2
  import { useCallback, useRef } from "react";
3
3
  const sessionState = new Map();
4
4
  const useSessionDataSource = (props)=>{
@@ -4,10 +4,10 @@ import { hasShowNotificationAction, isGroupMenuItemDescriptor } from "@vuu-ui/vu
4
4
  import { getFilterPredicate } from "@vuu-ui/vuu-filter-parser";
5
5
  import { NotificationType, useNotifications } from "@vuu-ui/vuu-notifications";
6
6
  import { BulkEditPanel, isTableLocation } from "@vuu-ui/vuu-table";
7
- import { getLayoutComponent, getServerNotificationStatus, isActionMessage, isCustomComponentActionMessage, isSessionTableActionMessage, useData } from "@vuu-ui/vuu-utils";
7
+ import { getLayoutComponent, getServerNotificationStatus, isActionMessage, isCustomComponentActionMessage, isSessionTableActionMessage } from "@vuu-ui/vuu-utils";
8
+ import { useData, useModal } from "@vuu-ui/core";
8
9
  import { useCallback } from "react";
9
10
  import { SessionEditingForm } from "../session-editing-form/index.js";
10
- import { useModal } from "@vuu-ui/vuu-ui-controls";
11
11
  const isRoot = (menu)=>"ROOT" === menu.name;
12
12
  const isCellMenu = (options)=>"cell" === options.context;
13
13
  const isRowMenu = (options)=>"row" === options.context;
@@ -1,16 +1,8 @@
1
- import { useData } from "@vuu-ui/vuu-utils";
2
- import { useCallback, useEffect, useState } from "react";
1
+ import { useData } from "@vuu-ui/core";
2
+ import { useEffect, useState } from "react";
3
3
  const useVuuTables = ()=>{
4
4
  const [tableSchemas, setTableSchemas] = useState();
5
5
  const { getServerAPI } = useData();
6
- const buildTables = useCallback((schemas)=>{
7
- const vuuTables = new Map();
8
- schemas.forEach((schema)=>{
9
- const { module, table } = schema.table;
10
- vuuTables.set(`${module}:${table}`, schema);
11
- });
12
- return vuuTables;
13
- }, []);
14
6
  useEffect(()=>{
15
7
  async function fetchTableMetadata() {
16
8
  try {
@@ -24,7 +16,6 @@ const useVuuTables = ()=>{
24
16
  }
25
17
  fetchTableMetadata();
26
18
  }, [
27
- buildTables,
28
19
  getServerAPI
29
20
  ]);
30
21
  return tableSchemas;
@@ -1,11 +1,13 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { ConnectionManager, isConnected } from "@vuu-ui/vuu-data-remote";
3
- import { useCallback, useMemo, useRef } from "react";
2
+ import { useOptionalVuuConnectionId } from "@vuu-ui/core";
3
+ import { ConnectionManager, DEFAULT_CONNECTION_ID, isConnected } from "@vuu-ui/vuu-data-remote";
4
+ import { useCallback, useEffect, useRef } from "react";
4
5
  import { NotificationType, useNotifications } from "@vuu-ui/vuu-notifications";
5
6
  import { LostConnectionIndicator } from "./LostConnectionIndicator.js";
6
7
  const useLostConnection = ()=>{
7
8
  const { hideNotification, showNotification } = useNotifications();
8
- const isConnectedRef = useRef(ConnectionManager.connected);
9
+ const connectionId = useOptionalVuuConnectionId() ?? DEFAULT_CONNECTION_ID;
10
+ const isConnectedRef = useRef(ConnectionManager.connectedFor(connectionId));
9
11
  const handleConnectionStatusChange = useCallback((connectionStatus)=>{
10
12
  const { current: wasConnected } = isConnectedRef;
11
13
  isConnectedRef.current = isConnected(connectionStatus);
@@ -19,9 +21,8 @@ const useLostConnection = ()=>{
19
21
  hideNotification,
20
22
  showNotification
21
23
  ]);
22
- useMemo(async ()=>{
23
- ConnectionManager.on("connection-status", handleConnectionStatusChange);
24
- }, [
24
+ useEffect(()=>ConnectionManager.onConnectionStatus(connectionId, handleConnectionStatusChange), [
25
+ connectionId,
25
26
  handleConnectionStatusChange
26
27
  ]);
27
28
  };
@@ -1,5 +1,5 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
- import { VuuDataSource } from "@vuu-ui/vuu-data-remote";
2
+ import { useData } from "@vuu-ui/core";
3
3
  import { Range, buildColumnMap, getTypedValue, queryClosest, shallowEquals } from "@vuu-ui/vuu-utils";
4
4
  import { Button, FormField, FormFieldHelperText, FormFieldLabel, Input, useIdMemo } from "@salt-ds/core";
5
5
  import { useComponentCssInjection } from "@salt-ds/styles";
@@ -30,7 +30,7 @@ const Status = {
30
30
  changed: 2,
31
31
  invalid: 3
32
32
  };
33
- const getDataSource = (dataSource, schema)=>{
33
+ const getDataSource = (VuuDataSource, dataSource, schema)=>{
34
34
  if (dataSource) return dataSource;
35
35
  else if (schema) return new VuuDataSource({
36
36
  bufferSize: 0,
@@ -52,8 +52,9 @@ const SessionEditingForm_SessionEditingForm = ({ className, config: { fields, ke
52
52
  const formContentRef = useRef(null);
53
53
  const initialDataRef = useRef(void 0);
54
54
  const dataStatusRef = useRef(Status.uninitialised);
55
+ const { VuuDataSource } = useData();
55
56
  const dataSource = useMemo(()=>{
56
- const ds = getDataSource(dataSourceProp, schema);
57
+ const ds = getDataSource(VuuDataSource, dataSourceProp, schema);
57
58
  const { columns } = ds;
58
59
  const columnMap = buildColumnMap(ds.columns);
59
60
  const applyServerData = (data)=>{
@@ -75,6 +76,7 @@ const SessionEditingForm_SessionEditingForm = ({ className, config: { fields, ke
75
76
  });
76
77
  return ds;
77
78
  }, [
79
+ VuuDataSource,
78
80
  dataSourceProp,
79
81
  schema
80
82
  ]);
@@ -1,5 +1,5 @@
1
- import { HTMLAttributes } from "react";
2
- import { EditFormHookProps } from "./useEditForm";
1
+ import type { HTMLAttributes } from "react";
2
+ import { type EditFormHookProps } from "./useEditForm";
3
3
  export interface EditFormProps extends EditFormHookProps, Omit<HTMLAttributes<HTMLDivElement>, "onSubmit"> {
4
4
  }
5
5
  export declare const EditForm: ({ className, dataSource, formFieldDescriptors, onSubmit: onSubmitProp, ...htmlAttributes }: EditFormProps) => import("react").JSX.Element;
@@ -0,0 +1,45 @@
1
+ import type { DataValueDescriptor, TableSchemaTable } from "@vuu-ui/vuu-data-types";
2
+ import { type VuuTypeaheadInputProps } from "@vuu-ui/vuu-ui-controls";
3
+ import { type CommitHandler } from "@vuu-ui/vuu-utils";
4
+ import type { InputProps } from "@salt-ds/core";
5
+ import { type ToggleFilterValue } from "@vuu-ui/vuu-filters";
6
+ /**
7
+ * variant can be used to provide a rendering hint to the filter control rendered.
8
+ * 'toggle' for A ToggleButtonGroup, only suitable for up to 3 value choices
9
+ * 'search' to render a search icon and require at least one character to be entered.
10
+ * 'pick' to show a dropdown list, even before any text is entered, best for smaller lists
11
+ */
12
+ export type FilterControlVariant = "search" | "pick" | "toggle";
13
+ export interface DataItemEditControlProps {
14
+ InputProps?: Partial<InputProps>;
15
+ TypeaheadProps?: Pick<VuuTypeaheadInputProps, "highlightFirstSuggestion" | "minCharacterCountToTriggerSuggestions" | "selectOnTab">;
16
+ className?: string;
17
+ commitOnBlur?: boolean;
18
+ commitWhenCleared?: boolean;
19
+ /**
20
+ * A table column or form field Descriptor.
21
+ */
22
+ dataDescriptor: DataValueDescriptor;
23
+ editOperation?: "insert" | "update";
24
+ errorMessage?: string;
25
+ /**
26
+ * Optional labels, only used with 'toggle' variant. If provided, must
27
+ * have same number of items as values. Defaults to values.
28
+ */
29
+ labels?: string[];
30
+ onCommit: CommitHandler<HTMLElement>;
31
+ table?: TableSchemaTable;
32
+ /**
33
+ * Where provided, only these values will be offered as suggestions.
34
+ * They will be validated against server with Typeahead service, so
35
+ * unavailable options are not offered.
36
+ * Recommended for toggle filters, not usually necessary for other
37
+ * filter variants. Boolean values are supported for toggle filters on
38
+ * boolean columns, where values default to [true, false]. A toggle filter
39
+ * on a char column requires values, which are not validated.
40
+ */
41
+ values?: ToggleFilterValue[];
42
+ variant?: FilterControlVariant;
43
+ }
44
+ export type ValidationStatus = "initial" | true | string;
45
+ export declare const getDataItemEditControl: ({ InputProps, TypeaheadProps, className, commitOnBlur, commitWhenCleared, dataDescriptor, editOperation, errorMessage, labels, onCommit, table, values, variant, }: DataItemEditControlProps) => import("react").JSX.Element;
@@ -1,5 +1,5 @@
1
1
  import type { DataSource, DataValueDescriptor } from "@vuu-ui/vuu-data-types";
2
- import { CommitHandler, Entity } from "@vuu-ui/vuu-utils";
2
+ import { type CommitHandler, type Entity } from "@vuu-ui/vuu-utils";
3
3
  import { FocusEventHandler, type ChangeEvent } from "react";
4
4
  export interface EditFormHookProps {
5
5
  dataSource?: DataSource;
@@ -1,17 +1,8 @@
1
- import { ReactNode } from "react";
1
+ import { type ReactNode } from "react";
2
2
  /**
3
- * DataSource Providers inject a DataSource constructor, made available
4
- * to clients via the useData hook. This provider offers the standard
5
- * VuuDataSource, which will source data from a remote vuu server.
6
- *
7
- * In production code, it will generally be used without props, authentication
8
- * and connection to vuu server will be handled elsewhere. The props are
9
- * useful for rendering standalone components.
3
+ * Supplies the standard VUU data-source implementation. Authentication and
4
+ * websocket lifecycle are handled by AuthenticationProvider.
10
5
  */
11
- export declare const VuuDataSourceProvider: ({ authenticate, autoConnect, autoLogin, children, websocketUrl, }: {
12
- authenticate?: boolean;
13
- autoConnect?: boolean;
14
- autoLogin?: boolean;
6
+ export declare const VuuDataSourceProvider: ({ children, }: {
15
7
  children: ReactNode;
16
- websocketUrl?: string;
17
8
  }) => import("react").JSX.Element;
@@ -0,0 +1,4 @@
1
+ import { SuggestionFetcher, TableSchemaTable } from "@vuu-ui/vuu-data-types";
2
+ import { TypeaheadParams } from "@vuu-ui/vuu-protocol-types";
3
+ export declare const getTypeaheadParams: (table: TableSchemaTable, column: string, text?: string, selectedValues?: string[]) => TypeaheadParams;
4
+ export declare const useTypeaheadSuggestions: () => SuggestionFetcher;
@@ -1,42 +0,0 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { ConnectionManager, authenticate as vuu_data_remote_authenticate } from "@vuu-ui/vuu-data-remote";
3
- import { useEffect, useState } from "react";
4
- const useAutoLoginToVuuServer = ({ authenticate = true, autoConnect = true, secure = true, token: tokenProp = "no-token", user = "steve", websocketUrl } = {})=>{
5
- const [errorMessage, setErrorMessage] = useState("");
6
- useEffect(()=>{
7
- const connect = async ()=>{
8
- try {
9
- let token = tokenProp;
10
- if (authenticate) {
11
- const response = await vuu_data_remote_authenticate(user, "xyz", "/api/authn");
12
- token = response.token;
13
- }
14
- const url = websocketUrl ?? `${secure ? "wss" : "ws"}://localhost/8090/websocket`;
15
- ConnectionManager.connect({
16
- url,
17
- token
18
- });
19
- } catch (e) {
20
- if (e instanceof Error) {
21
- console.error(e.message);
22
- setErrorMessage(e.message);
23
- }
24
- }
25
- };
26
- if (autoConnect) connect();
27
- return ()=>{
28
- if (autoConnect) ConnectionManager.disconnect();
29
- };
30
- }, [
31
- authenticate,
32
- autoConnect,
33
- secure,
34
- tokenProp,
35
- user,
36
- websocketUrl
37
- ]);
38
- if (errorMessage) return /*#__PURE__*/ jsx("p", {
39
- children: "Unable to authenticate against Vuu Server A Vuu Server instance must be running to show this example."
40
- });
41
- };
42
- export { useAutoLoginToVuuServer };
@@ -1,20 +0,0 @@
1
- export declare const useAutoLoginToVuuServer: ({ authenticate, autoConnect, secure, token: tokenProp, user, websocketUrl, }?: {
2
- /**
3
- * if true, auth url on vuuserver will be used to get token
4
- * auth url is "/api/authn"
5
- */
6
- authenticate?: boolean;
7
- /**
8
- * true by default, will go ahead and open websocket connection
9
- */
10
- autoConnect?: boolean;
11
- autoLogin?: boolean;
12
- secure?: boolean;
13
- /**
14
- * use with no authenticate step, to provide auth token.
15
- * Used when vuu server is performing no token check
16
- */
17
- token?: string;
18
- user?: string;
19
- websocketUrl?: string;
20
- }) => import("react").JSX.Element | undefined;