@truedat/core 4.48.7 → 4.48.8

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [4.48.8] 2022-07-18
4
+
5
+ ### Added
6
+
7
+ - [TD-5001] Added `columnPredicate` helper to determine whether a table column
8
+ contains a non-empty value
9
+
3
10
  ## [4.48.3] 2022-07-11
4
11
 
5
12
  ### Changed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@truedat/core",
3
- "version": "4.48.7",
3
+ "version": "4.48.8",
4
4
  "description": "Truedat Web Core",
5
5
  "sideEffects": false,
6
6
  "jsnext:main": "src/index.js",
@@ -112,5 +112,5 @@
112
112
  "react-dom": ">= 16.8.6 < 17",
113
113
  "semantic-ui-react": ">= 0.88.2 < 2.1"
114
114
  },
115
- "gitHead": "f4a20ecf51eb101c2c25facfec48ee8cd0e621a3"
115
+ "gitHead": "e49b195088068688520a1cb02c64127e140615e6"
116
116
  }
@@ -0,0 +1,40 @@
1
+ import _ from "lodash/fp";
2
+ import { isValue, columnPredicate } from "../columnPredicate";
3
+
4
+ describe("isValue", () => {
5
+ it("returns false for 'empty' values", () => {
6
+ expect(isValue(null)).toBe(false);
7
+ expect(isValue(undefined)).toBe(false);
8
+ expect(isValue({ a: null })).toBe(false);
9
+ expect(isValue([])).toBe(false);
10
+ });
11
+
12
+ it("returns true for 'non-empty' values", () => {
13
+ expect(isValue("a")).toBe(true);
14
+ expect(isValue(1)).toBe(true);
15
+ expect(isValue(false)).toBe(true);
16
+ expect(isValue([1])).toBe(true);
17
+ expect(isValue({ a: 1 })).toBe(true);
18
+ });
19
+ });
20
+
21
+ describe("columnPredicate", () => {
22
+ it("returns a function to check whether a column value is 'empty'", () => {
23
+ const pred = columnPredicate({ name: "foo" });
24
+ expect(pred({ foo: 1 })).toBe(true);
25
+ expect(pred({ foo: false })).toBe(true);
26
+ expect(pred({ bar: 1 })).toBe(false);
27
+ });
28
+
29
+ it("uses fieldSelector as a function", () => {
30
+ const pred = columnPredicate({ fieldSelector: _.pick(["foo"]) });
31
+ expect(pred({ foo: 1 })).toBe(true);
32
+ expect(pred({ foo: null })).toBe(false);
33
+ });
34
+
35
+ it("uses fieldSelector as a path", () => {
36
+ const pred = columnPredicate({ fieldSelector: "foo.bar" });
37
+ expect(pred({ foo: { bar: 1 } })).toBe(true);
38
+ expect(pred({ foo: { bar: null } })).toBe(false);
39
+ });
40
+ });
@@ -0,0 +1,23 @@
1
+ import _ from "lodash/fp";
2
+
3
+ const notEmpty = _.negate(_.isEmpty);
4
+
5
+ export const isValue = _.cond([
6
+ [_.isBoolean, _.stubTrue],
7
+ [_.isNumber, _.stubTrue],
8
+ [
9
+ _.isObject,
10
+ _.flow(_.values, _.some(_.overSome([_.isBoolean, _.isNumber, notEmpty]))),
11
+ ],
12
+ [_.stubTrue, notEmpty],
13
+ ]);
14
+
15
+ export const columnPredicate = ({ name, fieldSelector }) =>
16
+ _.flow(
17
+ _.isFunction(fieldSelector)
18
+ ? fieldSelector
19
+ : _.path(_.defaultTo(name)(fieldSelector)),
20
+ isValue
21
+ );
22
+
23
+ export default columnPredicate;
@@ -7,12 +7,14 @@ import * as sort from "./sort";
7
7
  import * as format from "./format";
8
8
  import columnDecorator from "./columnDecorator";
9
9
  import columnDecoratorComponent from "./columnDecoratorComponent";
10
+ import columnPredicate from "./columnPredicate";
10
11
 
11
12
  export {
12
13
  api,
13
14
  arrays,
14
15
  columnDecorator,
15
16
  columnDecoratorComponent,
17
+ columnPredicate,
16
18
  fieldType,
17
19
  filters,
18
20
  format,