@truedat/auth 4.51.2 → 4.51.3

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,11 @@
1
1
  # Changelog
2
2
 
3
+ ## [4.51.3] 2022-09-16
4
+
5
+ ### Changed
6
+
7
+ - [TD-4794] Use `DomainSelector` in `UserDomainsFilter`
8
+
3
9
  ## [4.51.2] 2022-09-15
4
10
 
5
11
  ### Added
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@truedat/auth",
3
- "version": "4.51.2",
3
+ "version": "4.51.3",
4
4
  "description": "Truedat Web Auth",
5
5
  "sideEffects": false,
6
6
  "jsnext:main": "src/index.js",
@@ -34,7 +34,7 @@
34
34
  "@testing-library/jest-dom": "^5.16.4",
35
35
  "@testing-library/react": "^12.0.0",
36
36
  "@testing-library/user-event": "^13.2.1",
37
- "@truedat/test": "4.47.9",
37
+ "@truedat/test": "4.51.3",
38
38
  "babel-jest": "^28.1.0",
39
39
  "babel-plugin-dynamic-import-node": "^2.3.3",
40
40
  "babel-plugin-lodash": "^3.3.4",
@@ -87,7 +87,7 @@
87
87
  ]
88
88
  },
89
89
  "dependencies": {
90
- "@truedat/core": "4.51.2",
90
+ "@truedat/core": "4.51.3",
91
91
  "auth0-js": "^9.12.2",
92
92
  "immutable": "^4.0.0-rc.12",
93
93
  "jwt-decode": "^2.2.0",
@@ -109,5 +109,5 @@
109
109
  "react-dom": ">= 16.8.6 < 17",
110
110
  "semantic-ui-react": ">= 0.88.2 < 2.1"
111
111
  },
112
- "gitHead": "9bdc76f3ee59a6e28fb2312e26d0cba2807f069b"
112
+ "gitHead": "69d6cf8f7379eb2ef5744a4fdd357a7dd662b115"
113
113
  }
@@ -1,69 +1,65 @@
1
1
  import _ from "lodash/fp";
2
- import React, { useState, useEffect } from "react";
2
+ import React, { useState } from "react";
3
3
  import { connect } from "react-redux";
4
4
  import { Form } from "semantic-ui-react";
5
5
  import { setDashboardDomains } from "@truedat/core/routines";
6
6
  import { useIntl } from "react-intl";
7
7
  import PropTypes from "prop-types";
8
- import { DomainMenuSelector } from "@truedat/bg/taxonomy/components";
9
- import { getDomainSelectorOptions } from "@truedat/bg/selectors";
8
+ import { DomainSelector } from "@truedat/core/components";
10
9
 
11
10
  export const UserDomainsFilter = ({
12
- domainOptions,
13
- domainsLoading,
11
+ action = "viewDomain",
14
12
  setDashboardDomains,
15
13
  }) => {
16
- const [domainsFilter, setDomainsFilter] = useState([]);
14
+ const [domainIds, setDomainIds] = useState("loading");
15
+ const [selectedDomainIds, setSelectedDomainIds] = useState([]);
17
16
  const { formatMessage } = useIntl();
18
17
 
19
- useEffect(() => {
20
- setDashboardDomains(_.map("id")(domainOptions));
21
- }, [domainOptions, setDashboardDomains]);
22
-
23
- const handleChange = (_e, data) => {
24
- const { value } = data;
25
- setDomainsFilter(value);
18
+ const handleDomainsLoaded = ({ domains }) => {
19
+ const domainIds = _.map(({ id }) => _.toInteger(id))(domains);
20
+ setDomainIds(domainIds);
26
21
  };
27
22
 
28
23
  const onClick = (_e) => {
29
- _.isEmpty(domainsFilter)
30
- ? setDashboardDomains(_.map("id")(domainOptions))
31
- : setDashboardDomains(domainsFilter);
24
+ _.isEmpty(selectedDomainIds)
25
+ ? setDashboardDomains(domainIds)
26
+ : setDashboardDomains(_.map(_.toInteger)(selectedDomainIds));
32
27
  };
33
28
 
34
29
  return (
35
- !domainsLoading && (
36
- <Form>
37
- <Form.Group inline>
38
- <DomainMenuSelector
39
- domainOptions={domainOptions}
40
- onChange={handleChange}
41
- />
42
- <Form.Field>
43
- <Form.Button name="applyFilter" onClick={onClick}>
44
- {formatMessage({
45
- id: "userDomainsFilter.button",
46
- defaultMessage: "Aplicar filtros",
47
- })}
48
- </Form.Button>
49
- </Form.Field>
50
- </Form.Group>
51
- </Form>
52
- )
30
+ <Form loading={domainIds === "loading"}>
31
+ <Form.Group inline>
32
+ <DomainSelector
33
+ action={action}
34
+ placeholder={formatMessage({ id: "domain.multiple.placeholder" })}
35
+ labels
36
+ multiple
37
+ onChange={(_e, { value }) => setSelectedDomainIds(value)}
38
+ onLoad={handleDomainsLoaded}
39
+ value={selectedDomainIds}
40
+ />
41
+ <Form.Field>
42
+ <Form.Button
43
+ name="applyFilter"
44
+ disabled={domainIds === "loading"}
45
+ onClick={onClick}
46
+ >
47
+ {formatMessage({
48
+ id: "userDomainsFilter.button",
49
+ defaultMessage: "Apply filters",
50
+ })}
51
+ </Form.Button>
52
+ </Form.Field>
53
+ </Form.Group>
54
+ </Form>
53
55
  );
54
56
  };
55
57
 
56
58
  UserDomainsFilter.propTypes = {
57
- domainOptions: PropTypes.array,
58
- domainsLoading: PropTypes.bool,
59
+ action: PropTypes.string,
59
60
  setDashboardDomains: PropTypes.func,
60
61
  };
61
62
 
62
- const mapStateToProps = (state) => ({
63
- domainOptions: getDomainSelectorOptions(state),
64
- domainsLoading: state.domainsLoading,
65
- });
66
-
67
63
  const mapDispatchToProps = { setDashboardDomains };
68
64
 
69
- export default connect(mapStateToProps, mapDispatchToProps)(UserDomainsFilter);
65
+ export default connect(null, mapDispatchToProps)(UserDomainsFilter);
@@ -2,54 +2,45 @@ import React from "react";
2
2
  import userEvent from "@testing-library/user-event";
3
3
  import { waitFor } from "@testing-library/react";
4
4
  import { render } from "@truedat/test/render";
5
- import { intl } from "@truedat/test/intl-stub";
5
+ import { domainsMock } from "@truedat/test/mocks";
6
6
  import { UserDomainsFilter } from "../UserDomainsFilter";
7
7
 
8
- // workaround for enzyme issue with React.useContext
9
- // see https://github.com/airbnb/enzyme/issues/2176#issuecomment-532361526
10
- jest.spyOn(React, "useContext").mockImplementation(() => intl);
11
-
12
8
  describe("<UserDomainsFilter />", () => {
13
- const setDashboardDomains = jest.fn();
14
- const formatMessage = jest.fn();
15
- const intl = { formatMessage };
16
- const domains = [
17
- { id: 1, name: "d1", level: 0 },
18
- { id: 2, name: "d2", level: 0 },
19
- ];
20
- const props = {
21
- intl,
22
- setDashboardDomains,
23
- domainsLoading: false,
24
- domainOptions: domains,
25
- };
26
-
27
- it("matches the latest snapshot", () => {
28
- const { container } = render(<UserDomainsFilter {...props} />, {
29
- state: { domains },
9
+ const props = { setDashboardDomains: jest.fn() };
10
+ const mocks = [domainsMock({ action: "viewDomain" })];
11
+
12
+ it("matches the latest snapshot", async () => {
13
+ const { container, queryByText } = render(
14
+ <UserDomainsFilter {...props} />,
15
+ { mocks }
16
+ );
17
+ await waitFor(() => {
18
+ expect(queryByText(/fooDomain/)).toBeInTheDocument();
30
19
  });
31
20
  expect(container).toMatchSnapshot();
32
21
  });
33
22
 
34
23
  it("calls setDashboardDomains when clicking button", async () => {
35
- const { getByRole } = render(<UserDomainsFilter {...props} />, {
36
- state: { domains },
37
- });
24
+ const { queryByText, findByText } = render(
25
+ <UserDomainsFilter {...props} />,
26
+ { mocks }
27
+ );
38
28
 
39
- const button = getByRole("button", { name: /userDomainsFilter/i });
40
- const option = getByRole("option", { name: /d1/i });
29
+ await waitFor(() => {
30
+ expect(queryByText(/fooDomain/)).toBeInTheDocument();
31
+ });
41
32
 
42
- userEvent.click(button);
33
+ userEvent.click(await findByText("Filter"));
43
34
 
44
35
  await waitFor(() => {
45
- expect(setDashboardDomains).toHaveBeenCalledWith([1, 2]);
36
+ expect(props.setDashboardDomains).toHaveBeenCalledWith([1, 2, 3, 33]);
46
37
  });
47
38
 
48
- userEvent.click(option);
49
- userEvent.click(button);
39
+ userEvent.click(await findByText("fooDomain"));
40
+ userEvent.click(await findByText("Filter"));
50
41
 
51
42
  await waitFor(() => {
52
- expect(setDashboardDomains).toHaveBeenCalledWith([1]);
43
+ expect(props.setDashboardDomains).toHaveBeenCalledWith([1]);
53
44
  });
54
45
  });
55
46
  });
@@ -19,7 +19,7 @@ exports[`<UserDomainsFilter /> matches the latest snapshot 1`] = `
19
19
  tabindex="0"
20
20
  >
21
21
  <label>
22
- domain.multiple.placeholder
22
+ Select domains
23
23
  </label>
24
24
  <i
25
25
  aria-hidden="true"
@@ -42,6 +42,21 @@ exports[`<UserDomainsFilter /> matches the latest snapshot 1`] = `
42
42
  <div
43
43
  class="scrolling menu transition"
44
44
  >
45
+ <div
46
+ aria-selected="false"
47
+ class="item"
48
+ role="option"
49
+ >
50
+ <div
51
+ style="margin-left: 0px;"
52
+ >
53
+ <i
54
+ aria-hidden="true"
55
+ class="plus icon"
56
+ />
57
+ barDomain
58
+ </div>
59
+ </div>
45
60
  <div
46
61
  aria-selected="false"
47
62
  class="item"
@@ -54,7 +69,7 @@ exports[`<UserDomainsFilter /> matches the latest snapshot 1`] = `
54
69
  aria-hidden="true"
55
70
  class="icon"
56
71
  />
57
- d1
72
+ bazDomain
58
73
  </div>
59
74
  </div>
60
75
  <div
@@ -69,7 +84,7 @@ exports[`<UserDomainsFilter /> matches the latest snapshot 1`] = `
69
84
  aria-hidden="true"
70
85
  class="icon"
71
86
  />
72
- d2
87
+ fooDomain
73
88
  </div>
74
89
  </div>
75
90
  </div>
@@ -86,7 +101,7 @@ exports[`<UserDomainsFilter /> matches the latest snapshot 1`] = `
86
101
  class="ui button"
87
102
  name="applyFilter"
88
103
  >
89
- userDomainsFilter.button
104
+ Filter
90
105
  </button>
91
106
  </div>
92
107
  </div>