@vuu-ui/vuu-table-extras 0.13.63 → 0.13.64
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/cjs/freeze-control/FreezeControl.css.js +1 -1
- package/cjs/freeze-control/FreezeControl.js +10 -22
- package/cjs/freeze-control/FreezeControl.js.map +1 -1
- package/cjs/freeze-control/useFreezeControl.js +6 -53
- package/cjs/freeze-control/useFreezeControl.js.map +1 -1
- package/esm/freeze-control/FreezeControl.css.js +1 -1
- package/esm/freeze-control/FreezeControl.js +12 -24
- package/esm/freeze-control/FreezeControl.js.map +1 -1
- package/esm/freeze-control/useFreezeControl.js +7 -54
- package/esm/freeze-control/useFreezeControl.js.map +1 -1
- package/package.json +11 -11
- package/types/freeze-control/FreezeControl.d.ts +3 -1
- package/types/freeze-control/useFreezeControl.d.ts +1 -4
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var freezeControlCss = "\n\n.FreezeControl {\n align-items: center;\n background-color: var(--salt-container-secondary-background);\n border-radius: 6px;\n display: inline-grid;\n grid-template-columns:
|
|
3
|
+
var freezeControlCss = "\n\n.FreezeControl {\n align-items: center;\n background-color: var(--vuuFreezeControl-background, var(--salt-container-secondary-background));\n border-radius: 6px;\n display: inline-grid;\n grid-template-columns: 1fr auto 1fr;\n grid-template-rows: var(--salt-size-base);\n column-gap: var(--salt-spacing-200);\n padding: 0 var(--salt-spacing-200);\n\n .FreezeControl-label-active {\n grid-area: 1/1/2/2;\n }\n\n .saltSwitch {\n grid-area: 1/2/2/3;\n .saltSwitch-track {\n height: 24px;\n }\n }\n\n .FreezeControl-label-frozen {\n grid-area: 1/3/2/4;\n }\n\n}\n\n";
|
|
4
4
|
|
|
5
5
|
module.exports = freezeControlCss;
|
|
6
6
|
//# sourceMappingURL=FreezeControl.css.js.map
|
|
@@ -10,8 +10,10 @@ var cx = require('clsx');
|
|
|
10
10
|
|
|
11
11
|
const classBase = "FreezeControl";
|
|
12
12
|
const FreezeControl = ({
|
|
13
|
+
activeLabel = "Active",
|
|
13
14
|
dataSource,
|
|
14
15
|
className,
|
|
16
|
+
lockedLabel = "Locked",
|
|
15
17
|
...htmlAttributes
|
|
16
18
|
}) => {
|
|
17
19
|
const targetWindow = window.useWindow();
|
|
@@ -20,28 +22,14 @@ const FreezeControl = ({
|
|
|
20
22
|
css: FreezeControl$1,
|
|
21
23
|
window: targetWindow
|
|
22
24
|
});
|
|
23
|
-
const {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
children: [
|
|
32
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: `${classBase}-label`, children: label }),
|
|
33
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
34
|
-
core.Switch,
|
|
35
|
-
{
|
|
36
|
-
checked: isFrozen,
|
|
37
|
-
onChange: onSwitchChange,
|
|
38
|
-
className: "vuuLarge"
|
|
39
|
-
}
|
|
40
|
-
),
|
|
41
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: `${classBase}-lastUpdated`, children: lastUpdateMessage })
|
|
42
|
-
]
|
|
43
|
-
}
|
|
44
|
-
) });
|
|
25
|
+
const { frozen, onSwitchChange } = useFreezeControl.useFreezeControl({
|
|
26
|
+
dataSource
|
|
27
|
+
});
|
|
28
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { ...htmlAttributes, className: cx(classBase, className), children: [
|
|
29
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: `${classBase}-label-active`, children: activeLabel }),
|
|
30
|
+
/* @__PURE__ */ jsxRuntime.jsx(core.Switch, { checked: frozen, onChange: onSwitchChange, className: "vuuLarge" }),
|
|
31
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: `${classBase}-label-frozen`, children: lockedLabel })
|
|
32
|
+
] });
|
|
45
33
|
};
|
|
46
34
|
|
|
47
35
|
exports.FreezeControl = FreezeControl;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FreezeControl.js","sources":["../../../../packages/vuu-table-extras/src/freeze-control/FreezeControl.tsx"],"sourcesContent":["import { useComponentCssInjection } from \"@salt-ds/styles\";\nimport { useWindow } from \"@salt-ds/window\";\nimport {
|
|
1
|
+
{"version":3,"file":"FreezeControl.js","sources":["../../../../packages/vuu-table-extras/src/freeze-control/FreezeControl.tsx"],"sourcesContent":["import { useComponentCssInjection } from \"@salt-ds/styles\";\nimport { useWindow } from \"@salt-ds/window\";\nimport { Switch } from \"@salt-ds/core\";\nimport freezeControlCss from \"./FreezeControl.css\";\nimport { useFreezeControl, type FreezeProps } from \"./useFreezeControl\";\nimport { HTMLAttributes } from \"react\";\nimport cx from \"clsx\";\n\nconst classBase = \"FreezeControl\";\n\nexport interface FreezeControlProps\n extends HTMLAttributes<HTMLDivElement>,\n FreezeProps {\n activeLabel?: string;\n lockedLabel?: string;\n}\n\nexport const FreezeControl = ({\n activeLabel = \"Active\",\n dataSource,\n className,\n lockedLabel = \"Locked\",\n ...htmlAttributes\n}: FreezeControlProps) => {\n const targetWindow = useWindow();\n useComponentCssInjection({\n testId: \"vuu-freeze-control\",\n css: freezeControlCss,\n window: targetWindow,\n });\n\n const { frozen, onSwitchChange } = useFreezeControl({\n dataSource,\n });\n\n return (\n <div {...htmlAttributes} className={cx(classBase, className)}>\n <span className={`${classBase}-label-active`}>{activeLabel}</span>\n <Switch checked={frozen} onChange={onSwitchChange} className=\"vuuLarge\" />\n <span className={`${classBase}-label-frozen`}>{lockedLabel}</span>\n </div>\n );\n};\n"],"names":["useWindow","useComponentCssInjection","freezeControlCss","useFreezeControl","jsxs","jsx","Switch"],"mappings":";;;;;;;;;;AAQA,MAAM,SAAY,GAAA,eAAA;AASX,MAAM,gBAAgB,CAAC;AAAA,EAC5B,WAAc,GAAA,QAAA;AAAA,EACd,UAAA;AAAA,EACA,SAAA;AAAA,EACA,WAAc,GAAA,QAAA;AAAA,EACd,GAAG;AACL,CAA0B,KAAA;AACxB,EAAA,MAAM,eAAeA,gBAAU,EAAA;AAC/B,EAAyBC,+BAAA,CAAA;AAAA,IACvB,MAAQ,EAAA,oBAAA;AAAA,IACR,GAAK,EAAAC,eAAA;AAAA,IACL,MAAQ,EAAA;AAAA,GACT,CAAA;AAED,EAAA,MAAM,EAAE,MAAA,EAAQ,cAAe,EAAA,GAAIC,iCAAiB,CAAA;AAAA,IAClD;AAAA,GACD,CAAA;AAED,EACE,uBAAAC,eAAA,CAAC,SAAK,GAAG,cAAA,EAAgB,WAAW,EAAG,CAAA,SAAA,EAAW,SAAS,CACzD,EAAA,QAAA,EAAA;AAAA,oBAAAC,cAAA,CAAC,MAAK,EAAA,EAAA,SAAA,EAAW,CAAG,EAAA,SAAS,iBAAkB,QAAY,EAAA,WAAA,EAAA,CAAA;AAAA,mCAC1DC,WAAO,EAAA,EAAA,OAAA,EAAS,QAAQ,QAAU,EAAA,cAAA,EAAgB,WAAU,UAAW,EAAA,CAAA;AAAA,mCACvE,MAAK,EAAA,EAAA,SAAA,EAAW,CAAG,EAAA,SAAS,iBAAkB,QAAY,EAAA,WAAA,EAAA;AAAA,GAC7D,EAAA,CAAA;AAEJ;;;;"}
|
|
@@ -1,70 +1,23 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var vuuUtils = require('@vuu-ui/vuu-utils');
|
|
4
3
|
var react = require('react');
|
|
5
4
|
|
|
6
|
-
const timeFormatter = vuuUtils.formatDate({ time: "hh:mm:ss" });
|
|
7
|
-
const formatFreezeTime = (ts) => {
|
|
8
|
-
if (ts === void 0) {
|
|
9
|
-
throw Error("[useFreezeControl] formatFreezeTime, freezeTime undefined");
|
|
10
|
-
}
|
|
11
|
-
return timeFormatter(new Date(ts));
|
|
12
|
-
};
|
|
13
|
-
const FreezeState = (dataSource, newRecordCount) => ({
|
|
14
|
-
isFrozen: dataSource.isFrozen ?? false,
|
|
15
|
-
label: dataSource.isFrozen ? "View Frozen" : "Freeze View",
|
|
16
|
-
lastUpdateMessage: dataSource.isFrozen ? `at ${formatFreezeTime(dataSource.freezeTimestamp)}` : "",
|
|
17
|
-
newRecordCount
|
|
18
|
-
});
|
|
19
5
|
const useFreezeControl = ({ dataSource }) => {
|
|
20
|
-
const
|
|
21
|
-
const table = react.useMemo(() => {
|
|
22
|
-
if (dataSource.table === void 0) {
|
|
23
|
-
throw Error(`[useFreezeControls] dataSource must have VuuTable`);
|
|
24
|
-
}
|
|
25
|
-
return dataSource.table;
|
|
26
|
-
}, [dataSource]);
|
|
27
|
-
const [freezeState, setFreezeState] = react.useState(
|
|
28
|
-
FreezeState(dataSource, 0)
|
|
29
|
-
);
|
|
30
|
-
const [startTrackingNewRows, stopTrackingNewRows] = react.useMemo(() => {
|
|
31
|
-
let ds = void 0;
|
|
32
|
-
const dataCallback = (message) => {
|
|
33
|
-
if (vuuUtils.messageHasSize(message)) {
|
|
34
|
-
setFreezeState(FreezeState(dataSource, message.size));
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
const start = (ts) => {
|
|
38
|
-
ds = new VuuDataSource({ table });
|
|
39
|
-
ds.subscribe(
|
|
40
|
-
{
|
|
41
|
-
filterSpec: {
|
|
42
|
-
filter: `created > ${ts}`
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
dataCallback
|
|
46
|
-
);
|
|
47
|
-
};
|
|
48
|
-
const stop = () => {
|
|
49
|
-
ds?.unsubscribe();
|
|
50
|
-
};
|
|
51
|
-
return [start, stop];
|
|
52
|
-
}, [VuuDataSource, dataSource, table]);
|
|
6
|
+
const [frozen, setFrozen] = react.useState(dataSource.isFrozen);
|
|
53
7
|
const handleSwitchChange = react.useCallback(
|
|
54
8
|
(evt) => {
|
|
55
|
-
|
|
9
|
+
const isFrozen = evt.target.checked;
|
|
10
|
+
if (isFrozen) {
|
|
56
11
|
dataSource.freeze?.();
|
|
57
|
-
startTrackingNewRows(dataSource.freezeTimestamp);
|
|
58
12
|
} else {
|
|
59
13
|
dataSource.unfreeze?.();
|
|
60
|
-
stopTrackingNewRows();
|
|
61
14
|
}
|
|
62
|
-
|
|
15
|
+
setFrozen(isFrozen);
|
|
63
16
|
},
|
|
64
|
-
[dataSource
|
|
17
|
+
[dataSource]
|
|
65
18
|
);
|
|
66
19
|
return {
|
|
67
|
-
|
|
20
|
+
frozen,
|
|
68
21
|
onSwitchChange: handleSwitchChange
|
|
69
22
|
};
|
|
70
23
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFreezeControl.js","sources":["../../../../packages/vuu-table-extras/src/freeze-control/useFreezeControl.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"useFreezeControl.js","sources":["../../../../packages/vuu-table-extras/src/freeze-control/useFreezeControl.ts"],"sourcesContent":["import { DataSource } from \"@vuu-ui/vuu-data-types\";\nimport { ChangeEventHandler, useCallback, useState } from \"react\";\n\nexport interface FreezeProps {\n dataSource: DataSource;\n}\n\nexport const useFreezeControl = ({ dataSource }: FreezeProps) => {\n const [frozen, setFrozen] = useState(dataSource.isFrozen);\n\n const handleSwitchChange = useCallback<ChangeEventHandler<HTMLInputElement>>(\n (evt) => {\n const isFrozen = evt.target.checked;\n if (isFrozen) {\n dataSource.freeze?.();\n } else {\n dataSource.unfreeze?.();\n }\n setFrozen(isFrozen);\n },\n [dataSource],\n );\n\n return {\n frozen,\n onSwitchChange: handleSwitchChange,\n };\n};\n"],"names":["useState","useCallback"],"mappings":";;;;AAOO,MAAM,gBAAmB,GAAA,CAAC,EAAE,UAAA,EAA8B,KAAA;AAC/D,EAAA,MAAM,CAAC,MAAQ,EAAA,SAAS,CAAI,GAAAA,cAAA,CAAS,WAAW,QAAQ,CAAA;AAExD,EAAA,MAAM,kBAAqB,GAAAC,iBAAA;AAAA,IACzB,CAAC,GAAQ,KAAA;AACP,MAAM,MAAA,QAAA,GAAW,IAAI,MAAO,CAAA,OAAA;AAC5B,MAAA,IAAI,QAAU,EAAA;AACZ,QAAA,UAAA,CAAW,MAAS,IAAA;AAAA,OACf,MAAA;AACL,QAAA,UAAA,CAAW,QAAW,IAAA;AAAA;AAExB,MAAA,SAAA,CAAU,QAAQ,CAAA;AAAA,KACpB;AAAA,IACA,CAAC,UAAU;AAAA,GACb;AAEA,EAAO,OAAA;AAAA,IACL,MAAA;AAAA,IACA,cAAgB,EAAA;AAAA,GAClB;AACF;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var freezeControlCss = "\n\n.FreezeControl {\n align-items: center;\n background-color: var(--salt-container-secondary-background);\n border-radius: 6px;\n display: inline-grid;\n grid-template-columns:
|
|
1
|
+
var freezeControlCss = "\n\n.FreezeControl {\n align-items: center;\n background-color: var(--vuuFreezeControl-background, var(--salt-container-secondary-background));\n border-radius: 6px;\n display: inline-grid;\n grid-template-columns: 1fr auto 1fr;\n grid-template-rows: var(--salt-size-base);\n column-gap: var(--salt-spacing-200);\n padding: 0 var(--salt-spacing-200);\n\n .FreezeControl-label-active {\n grid-area: 1/1/2/2;\n }\n\n .saltSwitch {\n grid-area: 1/2/2/3;\n .saltSwitch-track {\n height: 24px;\n }\n }\n\n .FreezeControl-label-frozen {\n grid-area: 1/3/2/4;\n }\n\n}\n\n";
|
|
2
2
|
|
|
3
3
|
export { freezeControlCss as default };
|
|
4
4
|
//# sourceMappingURL=FreezeControl.css.js.map
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { useComponentCssInjection } from '@salt-ds/styles';
|
|
3
3
|
import { useWindow } from '@salt-ds/window';
|
|
4
|
-
import {
|
|
4
|
+
import { Switch } from '@salt-ds/core';
|
|
5
5
|
import freezeControlCss from './FreezeControl.css.js';
|
|
6
6
|
import { useFreezeControl } from './useFreezeControl.js';
|
|
7
7
|
import cx from 'clsx';
|
|
8
8
|
|
|
9
9
|
const classBase = "FreezeControl";
|
|
10
10
|
const FreezeControl = ({
|
|
11
|
+
activeLabel = "Active",
|
|
11
12
|
dataSource,
|
|
12
13
|
className,
|
|
14
|
+
lockedLabel = "Locked",
|
|
13
15
|
...htmlAttributes
|
|
14
16
|
}) => {
|
|
15
17
|
const targetWindow = useWindow();
|
|
@@ -18,28 +20,14 @@ const FreezeControl = ({
|
|
|
18
20
|
css: freezeControlCss,
|
|
19
21
|
window: targetWindow
|
|
20
22
|
});
|
|
21
|
-
const {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
children: [
|
|
30
|
-
/* @__PURE__ */ jsx("span", { className: `${classBase}-label`, children: label }),
|
|
31
|
-
/* @__PURE__ */ jsx(
|
|
32
|
-
Switch,
|
|
33
|
-
{
|
|
34
|
-
checked: isFrozen,
|
|
35
|
-
onChange: onSwitchChange,
|
|
36
|
-
className: "vuuLarge"
|
|
37
|
-
}
|
|
38
|
-
),
|
|
39
|
-
/* @__PURE__ */ jsx("span", { className: `${classBase}-lastUpdated`, children: lastUpdateMessage })
|
|
40
|
-
]
|
|
41
|
-
}
|
|
42
|
-
) });
|
|
23
|
+
const { frozen, onSwitchChange } = useFreezeControl({
|
|
24
|
+
dataSource
|
|
25
|
+
});
|
|
26
|
+
return /* @__PURE__ */ jsxs("div", { ...htmlAttributes, className: cx(classBase, className), children: [
|
|
27
|
+
/* @__PURE__ */ jsx("span", { className: `${classBase}-label-active`, children: activeLabel }),
|
|
28
|
+
/* @__PURE__ */ jsx(Switch, { checked: frozen, onChange: onSwitchChange, className: "vuuLarge" }),
|
|
29
|
+
/* @__PURE__ */ jsx("span", { className: `${classBase}-label-frozen`, children: lockedLabel })
|
|
30
|
+
] });
|
|
43
31
|
};
|
|
44
32
|
|
|
45
33
|
export { FreezeControl };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FreezeControl.js","sources":["../../../../packages/vuu-table-extras/src/freeze-control/FreezeControl.tsx"],"sourcesContent":["import { useComponentCssInjection } from \"@salt-ds/styles\";\nimport { useWindow } from \"@salt-ds/window\";\nimport {
|
|
1
|
+
{"version":3,"file":"FreezeControl.js","sources":["../../../../packages/vuu-table-extras/src/freeze-control/FreezeControl.tsx"],"sourcesContent":["import { useComponentCssInjection } from \"@salt-ds/styles\";\nimport { useWindow } from \"@salt-ds/window\";\nimport { Switch } from \"@salt-ds/core\";\nimport freezeControlCss from \"./FreezeControl.css\";\nimport { useFreezeControl, type FreezeProps } from \"./useFreezeControl\";\nimport { HTMLAttributes } from \"react\";\nimport cx from \"clsx\";\n\nconst classBase = \"FreezeControl\";\n\nexport interface FreezeControlProps\n extends HTMLAttributes<HTMLDivElement>,\n FreezeProps {\n activeLabel?: string;\n lockedLabel?: string;\n}\n\nexport const FreezeControl = ({\n activeLabel = \"Active\",\n dataSource,\n className,\n lockedLabel = \"Locked\",\n ...htmlAttributes\n}: FreezeControlProps) => {\n const targetWindow = useWindow();\n useComponentCssInjection({\n testId: \"vuu-freeze-control\",\n css: freezeControlCss,\n window: targetWindow,\n });\n\n const { frozen, onSwitchChange } = useFreezeControl({\n dataSource,\n });\n\n return (\n <div {...htmlAttributes} className={cx(classBase, className)}>\n <span className={`${classBase}-label-active`}>{activeLabel}</span>\n <Switch checked={frozen} onChange={onSwitchChange} className=\"vuuLarge\" />\n <span className={`${classBase}-label-frozen`}>{lockedLabel}</span>\n </div>\n );\n};\n"],"names":[],"mappings":";;;;;;;;AAQA,MAAM,SAAY,GAAA,eAAA;AASX,MAAM,gBAAgB,CAAC;AAAA,EAC5B,WAAc,GAAA,QAAA;AAAA,EACd,UAAA;AAAA,EACA,SAAA;AAAA,EACA,WAAc,GAAA,QAAA;AAAA,EACd,GAAG;AACL,CAA0B,KAAA;AACxB,EAAA,MAAM,eAAe,SAAU,EAAA;AAC/B,EAAyB,wBAAA,CAAA;AAAA,IACvB,MAAQ,EAAA,oBAAA;AAAA,IACR,GAAK,EAAA,gBAAA;AAAA,IACL,MAAQ,EAAA;AAAA,GACT,CAAA;AAED,EAAA,MAAM,EAAE,MAAA,EAAQ,cAAe,EAAA,GAAI,gBAAiB,CAAA;AAAA,IAClD;AAAA,GACD,CAAA;AAED,EACE,uBAAA,IAAA,CAAC,SAAK,GAAG,cAAA,EAAgB,WAAW,EAAG,CAAA,SAAA,EAAW,SAAS,CACzD,EAAA,QAAA,EAAA;AAAA,oBAAA,GAAA,CAAC,MAAK,EAAA,EAAA,SAAA,EAAW,CAAG,EAAA,SAAS,iBAAkB,QAAY,EAAA,WAAA,EAAA,CAAA;AAAA,wBAC1D,MAAO,EAAA,EAAA,OAAA,EAAS,QAAQ,QAAU,EAAA,cAAA,EAAgB,WAAU,UAAW,EAAA,CAAA;AAAA,wBACvE,MAAK,EAAA,EAAA,SAAA,EAAW,CAAG,EAAA,SAAS,iBAAkB,QAAY,EAAA,WAAA,EAAA;AAAA,GAC7D,EAAA,CAAA;AAEJ;;;;"}
|
|
@@ -1,68 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useMemo, useState, useCallback } from 'react';
|
|
1
|
+
import { useState, useCallback } from 'react';
|
|
3
2
|
|
|
4
|
-
const timeFormatter = formatDate({ time: "hh:mm:ss" });
|
|
5
|
-
const formatFreezeTime = (ts) => {
|
|
6
|
-
if (ts === void 0) {
|
|
7
|
-
throw Error("[useFreezeControl] formatFreezeTime, freezeTime undefined");
|
|
8
|
-
}
|
|
9
|
-
return timeFormatter(new Date(ts));
|
|
10
|
-
};
|
|
11
|
-
const FreezeState = (dataSource, newRecordCount) => ({
|
|
12
|
-
isFrozen: dataSource.isFrozen ?? false,
|
|
13
|
-
label: dataSource.isFrozen ? "View Frozen" : "Freeze View",
|
|
14
|
-
lastUpdateMessage: dataSource.isFrozen ? `at ${formatFreezeTime(dataSource.freezeTimestamp)}` : "",
|
|
15
|
-
newRecordCount
|
|
16
|
-
});
|
|
17
3
|
const useFreezeControl = ({ dataSource }) => {
|
|
18
|
-
const
|
|
19
|
-
const table = useMemo(() => {
|
|
20
|
-
if (dataSource.table === void 0) {
|
|
21
|
-
throw Error(`[useFreezeControls] dataSource must have VuuTable`);
|
|
22
|
-
}
|
|
23
|
-
return dataSource.table;
|
|
24
|
-
}, [dataSource]);
|
|
25
|
-
const [freezeState, setFreezeState] = useState(
|
|
26
|
-
FreezeState(dataSource, 0)
|
|
27
|
-
);
|
|
28
|
-
const [startTrackingNewRows, stopTrackingNewRows] = useMemo(() => {
|
|
29
|
-
let ds = void 0;
|
|
30
|
-
const dataCallback = (message) => {
|
|
31
|
-
if (messageHasSize(message)) {
|
|
32
|
-
setFreezeState(FreezeState(dataSource, message.size));
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
const start = (ts) => {
|
|
36
|
-
ds = new VuuDataSource({ table });
|
|
37
|
-
ds.subscribe(
|
|
38
|
-
{
|
|
39
|
-
filterSpec: {
|
|
40
|
-
filter: `created > ${ts}`
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
dataCallback
|
|
44
|
-
);
|
|
45
|
-
};
|
|
46
|
-
const stop = () => {
|
|
47
|
-
ds?.unsubscribe();
|
|
48
|
-
};
|
|
49
|
-
return [start, stop];
|
|
50
|
-
}, [VuuDataSource, dataSource, table]);
|
|
4
|
+
const [frozen, setFrozen] = useState(dataSource.isFrozen);
|
|
51
5
|
const handleSwitchChange = useCallback(
|
|
52
6
|
(evt) => {
|
|
53
|
-
|
|
7
|
+
const isFrozen = evt.target.checked;
|
|
8
|
+
if (isFrozen) {
|
|
54
9
|
dataSource.freeze?.();
|
|
55
|
-
startTrackingNewRows(dataSource.freezeTimestamp);
|
|
56
10
|
} else {
|
|
57
11
|
dataSource.unfreeze?.();
|
|
58
|
-
stopTrackingNewRows();
|
|
59
12
|
}
|
|
60
|
-
|
|
13
|
+
setFrozen(isFrozen);
|
|
61
14
|
},
|
|
62
|
-
[dataSource
|
|
15
|
+
[dataSource]
|
|
63
16
|
);
|
|
64
17
|
return {
|
|
65
|
-
|
|
18
|
+
frozen,
|
|
66
19
|
onSwitchChange: handleSwitchChange
|
|
67
20
|
};
|
|
68
21
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFreezeControl.js","sources":["../../../../packages/vuu-table-extras/src/freeze-control/useFreezeControl.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"useFreezeControl.js","sources":["../../../../packages/vuu-table-extras/src/freeze-control/useFreezeControl.ts"],"sourcesContent":["import { DataSource } from \"@vuu-ui/vuu-data-types\";\nimport { ChangeEventHandler, useCallback, useState } from \"react\";\n\nexport interface FreezeProps {\n dataSource: DataSource;\n}\n\nexport const useFreezeControl = ({ dataSource }: FreezeProps) => {\n const [frozen, setFrozen] = useState(dataSource.isFrozen);\n\n const handleSwitchChange = useCallback<ChangeEventHandler<HTMLInputElement>>(\n (evt) => {\n const isFrozen = evt.target.checked;\n if (isFrozen) {\n dataSource.freeze?.();\n } else {\n dataSource.unfreeze?.();\n }\n setFrozen(isFrozen);\n },\n [dataSource],\n );\n\n return {\n frozen,\n onSwitchChange: handleSwitchChange,\n };\n};\n"],"names":[],"mappings":";;AAOO,MAAM,gBAAmB,GAAA,CAAC,EAAE,UAAA,EAA8B,KAAA;AAC/D,EAAA,MAAM,CAAC,MAAQ,EAAA,SAAS,CAAI,GAAA,QAAA,CAAS,WAAW,QAAQ,CAAA;AAExD,EAAA,MAAM,kBAAqB,GAAA,WAAA;AAAA,IACzB,CAAC,GAAQ,KAAA;AACP,MAAM,MAAA,QAAA,GAAW,IAAI,MAAO,CAAA,OAAA;AAC5B,MAAA,IAAI,QAAU,EAAA;AACZ,QAAA,UAAA,CAAW,MAAS,IAAA;AAAA,OACf,MAAA;AACL,QAAA,UAAA,CAAW,QAAW,IAAA;AAAA;AAExB,MAAA,SAAA,CAAU,QAAQ,CAAA;AAAA,KACpB;AAAA,IACA,CAAC,UAAU;AAAA,GACb;AAEA,EAAO,OAAA;AAAA,IACL,MAAA;AAAA,IACA,cAAgB,EAAA;AAAA,GAClB;AACF;;;;"}
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.13.
|
|
2
|
+
"version": "0.13.64",
|
|
3
3
|
"author": "heswell",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"devDependencies": {
|
|
6
|
-
"@vuu-ui/vuu-filter-types": "0.13.
|
|
7
|
-
"@vuu-ui/vuu-protocol-types": "0.13.
|
|
6
|
+
"@vuu-ui/vuu-filter-types": "0.13.64",
|
|
7
|
+
"@vuu-ui/vuu-protocol-types": "0.13.64"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@vuu-ui/vuu-codemirror": "0.13.
|
|
11
|
-
"@vuu-ui/vuu-data-react": "0.13.
|
|
12
|
-
"@vuu-ui/vuu-data-types": "0.13.
|
|
13
|
-
"@vuu-ui/vuu-table-types": "0.13.
|
|
14
|
-
"@vuu-ui/vuu-popups": "0.13.
|
|
15
|
-
"@vuu-ui/vuu-table": "0.13.
|
|
16
|
-
"@vuu-ui/vuu-utils": "0.13.
|
|
17
|
-
"@vuu-ui/vuu-ui-controls": "0.13.
|
|
10
|
+
"@vuu-ui/vuu-codemirror": "0.13.64",
|
|
11
|
+
"@vuu-ui/vuu-data-react": "0.13.64",
|
|
12
|
+
"@vuu-ui/vuu-data-types": "0.13.64",
|
|
13
|
+
"@vuu-ui/vuu-table-types": "0.13.64",
|
|
14
|
+
"@vuu-ui/vuu-popups": "0.13.64",
|
|
15
|
+
"@vuu-ui/vuu-table": "0.13.64",
|
|
16
|
+
"@vuu-ui/vuu-utils": "0.13.64",
|
|
17
|
+
"@vuu-ui/vuu-ui-controls": "0.13.64",
|
|
18
18
|
"@lezer/lr": "1.4.2",
|
|
19
19
|
"@salt-ds/core": "1.48.0",
|
|
20
20
|
"@salt-ds/styles": "0.2.1",
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { type FreezeProps } from "./useFreezeControl";
|
|
2
2
|
import { HTMLAttributes } from "react";
|
|
3
3
|
export interface FreezeControlProps extends HTMLAttributes<HTMLDivElement>, FreezeProps {
|
|
4
|
+
activeLabel?: string;
|
|
5
|
+
lockedLabel?: string;
|
|
4
6
|
}
|
|
5
|
-
export declare const FreezeControl: ({ dataSource, className, ...htmlAttributes }: FreezeControlProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export declare const FreezeControl: ({ activeLabel, dataSource, className, lockedLabel, ...htmlAttributes }: FreezeControlProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -4,9 +4,6 @@ export interface FreezeProps {
|
|
|
4
4
|
dataSource: DataSource;
|
|
5
5
|
}
|
|
6
6
|
export declare const useFreezeControl: ({ dataSource }: FreezeProps) => {
|
|
7
|
+
frozen: boolean | undefined;
|
|
7
8
|
onSwitchChange: ChangeEventHandler<HTMLInputElement>;
|
|
8
|
-
isFrozen: boolean;
|
|
9
|
-
label: string;
|
|
10
|
-
lastUpdateMessage: string;
|
|
11
|
-
newRecordCount: number;
|
|
12
9
|
};
|