@truedat/dd 4.43.6 → 4.44.2

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.
Files changed (72) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/package.json +6 -6
  3. package/src/api/fragments.js +10 -0
  4. package/src/api/mutations.js +28 -0
  5. package/src/api/queries.js +20 -0
  6. package/src/api.js +0 -4
  7. package/src/components/DictionaryRoutes.js +2 -10
  8. package/src/components/LinkStructureTagForm.js +2 -2
  9. package/src/components/LinkedStructureTag.js +16 -7
  10. package/src/components/StructureLinkTagButton.js +8 -11
  11. package/src/components/StructureSummary.js +1 -1
  12. package/src/components/StructureTag.js +59 -20
  13. package/src/components/StructureTagForm.js +30 -35
  14. package/src/components/StructureTags.js +7 -6
  15. package/src/components/StructureTagsCards.js +56 -59
  16. package/src/components/StructureTagsCrumbs.js +4 -4
  17. package/src/components/StructureTagsRoutes.js +33 -57
  18. package/src/components/StructuresRoutes.js +0 -3
  19. package/src/components/TagsHeader.js +14 -21
  20. package/src/components/__tests__/PendingStructureNoteRow.spec.js +5 -1
  21. package/src/components/__tests__/PendingStructureNotes.spec.js +2 -2
  22. package/src/components/__tests__/StructureTag.spec.js +4 -1
  23. package/src/components/__tests__/StructureTagForm.spec.js +40 -82
  24. package/src/components/__tests__/StructureTags.spec.js +7 -7
  25. package/src/components/__tests__/StructureTagsCards.spec.js +38 -36
  26. package/src/components/__tests__/StructuresUploadEventsTable.spec.js +36 -42
  27. package/src/components/__tests__/__snapshots__/DictionaryRoutes.spec.js.snap +3 -3
  28. package/src/components/__tests__/__snapshots__/PendingStructureNoteRow.spec.js.snap +33 -29
  29. package/src/components/__tests__/__snapshots__/StructureTag.spec.js.snap +13 -2
  30. package/src/components/__tests__/__snapshots__/StructureTagForm.spec.js.snap +7 -56
  31. package/src/components/__tests__/__snapshots__/StructureTags.spec.js.snap +32 -44
  32. package/src/components/__tests__/__snapshots__/StructureTagsCards.spec.js.snap +53 -118
  33. package/src/components/__tests__/__snapshots__/StructureTagsCrumbs.spec.js.snap +1 -1
  34. package/src/components/__tests__/__snapshots__/StructureTypes.spec.js.snap +1 -1
  35. package/src/components/__tests__/__snapshots__/StructureTypesCrumbs.spec.js.snap +1 -1
  36. package/src/components/__tests__/__snapshots__/StructureTypesTable.spec.js.snap +2 -2
  37. package/src/messages/en.js +1 -0
  38. package/src/messages/es.js +1 -0
  39. package/src/reducers/__tests__/editableStructureTags.spec.js +39 -0
  40. package/src/reducers/__tests__/structureTagsSaving.spec.js +40 -0
  41. package/src/reducers/__tests__/structuresUploadEventsLoading.spec.js +18 -4
  42. package/src/reducers/editableStructureTags.js +19 -0
  43. package/src/reducers/index.js +4 -9
  44. package/src/reducers/structureTagSaving.js +18 -0
  45. package/src/routines.js +3 -5
  46. package/src/sagas/__tests__/createStructureTag.spec.js +28 -13
  47. package/src/sagas/__tests__/deleteStructureTag.spec.js +27 -15
  48. package/src/sagas/__tests__/updateStructureTag.spec.js +26 -13
  49. package/src/sagas/createStructureTag.js +15 -13
  50. package/src/sagas/deleteStructureTag.js +13 -8
  51. package/src/sagas/index.js +0 -6
  52. package/src/sagas/updateStructureTag.js +8 -15
  53. package/src/selectors/__tests__/getStructuresUploadEventColumns.spec.js +1 -1
  54. package/src/components/StructureTagLoader.js +0 -28
  55. package/src/components/StructureTagsLoader.js +0 -26
  56. package/src/components/__tests__/StructureTagLoader.spec.js +0 -29
  57. package/src/components/__tests__/StructureTagsLoader.spec.js +0 -24
  58. package/src/components/__tests__/__snapshots__/StructureTagLoader.spec.js.snap +0 -3
  59. package/src/components/__tests__/__snapshots__/StructureTagsLoader.spec.js.snap +0 -3
  60. package/src/reducers/__tests__/structureTag.spec.js +0 -80
  61. package/src/reducers/__tests__/structureTagLoading.spec.js +0 -40
  62. package/src/reducers/__tests__/structureTags.spec.js +0 -32
  63. package/src/reducers/__tests__/structureTagsLoading.spec.js +0 -40
  64. package/src/reducers/structureTag.js +0 -38
  65. package/src/reducers/structureTagLoading.js +0 -16
  66. package/src/reducers/structureTags.js +0 -19
  67. package/src/reducers/structureTagsLoading.js +0 -16
  68. package/src/sagas/__tests__/deleteStructureType.spec.js +0 -70
  69. package/src/sagas/__tests__/fetchStructureTag.spec.js +0 -74
  70. package/src/sagas/__tests__/fetchStructureTags.spec.js +0 -72
  71. package/src/sagas/fetchStructureTag.js +0 -29
  72. package/src/sagas/fetchStructureTags.js +0 -25
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## [4.44.0] 2022-05-10
4
+
5
+ ### Added
6
+
7
+ - [TD-4723] Support for domain-specific structure tags
8
+
3
9
  ## [4.43.6] 2022-05-06
4
10
 
5
11
  ### Changed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@truedat/dd",
3
- "version": "4.43.6",
3
+ "version": "4.44.2",
4
4
  "description": "Truedat Web Data Dictionary",
5
5
  "sideEffects": false,
6
6
  "jsnext:main": "src/index.js",
@@ -34,7 +34,7 @@
34
34
  "@testing-library/jest-dom": "^5.14.1",
35
35
  "@testing-library/react": "^12.0.0",
36
36
  "@testing-library/user-event": "^13.2.1",
37
- "@truedat/test": "4.43.6",
37
+ "@truedat/test": "4.44.2",
38
38
  "babel-jest": "^27.0.6",
39
39
  "babel-plugin-dynamic-import-node": "^2.3.3",
40
40
  "babel-plugin-lodash": "^3.3.4",
@@ -84,9 +84,9 @@
84
84
  ]
85
85
  },
86
86
  "dependencies": {
87
- "@truedat/auth": "4.43.6",
88
- "@truedat/core": "4.43.6",
89
- "@truedat/df": "4.43.6",
87
+ "@truedat/auth": "4.44.2",
88
+ "@truedat/core": "4.44.2",
89
+ "@truedat/df": "4.44.2",
90
90
  "lodash": "^4.17.21",
91
91
  "path-to-regexp": "^1.7.0",
92
92
  "prop-types": "^15.7.2",
@@ -107,5 +107,5 @@
107
107
  "react-dom": ">= 16.8.6 < 17",
108
108
  "semantic-ui-react": ">= 0.88.2 < 2.1"
109
109
  },
110
- "gitHead": "848143d79486499dd9deadea6a545929b5cdb39c"
110
+ "gitHead": "ca0c5fffcba96736f7a2054f3c37789da8c30a9e"
111
111
  }
@@ -0,0 +1,10 @@
1
+ import { gql } from "@apollo/client";
2
+
3
+ export const STRUCTURE_TAG_DETAIL = gql`
4
+ fragment StructureTagDetail on StructureTag {
5
+ id
6
+ name
7
+ domainIds
8
+ structureCount
9
+ }
10
+ `;
@@ -0,0 +1,28 @@
1
+ import { gql } from "@apollo/client";
2
+ import { STRUCTURE_TAG_DETAIL } from "./fragments";
3
+
4
+ export const CREATE_STRUCTURE_TAG = gql`
5
+ mutation CreateStructureTag($structureTag: StructureTagInput!) {
6
+ createStructureTag(structureTag: $structureTag) {
7
+ ...StructureTagDetail
8
+ }
9
+ }
10
+ ${STRUCTURE_TAG_DETAIL}
11
+ `;
12
+
13
+ export const UPDATE_STRUCTURE_TAG = gql`
14
+ mutation UpdateStructureTag($structureTag: StructureTagInput!) {
15
+ updateStructureTag(structureTag: $structureTag) {
16
+ ...StructureTagDetail
17
+ }
18
+ }
19
+ ${STRUCTURE_TAG_DETAIL}
20
+ `;
21
+
22
+ export const DELETE_STRUCTURE_TAG = gql`
23
+ mutation DeleteStructureTag($id: ID!) {
24
+ deleteStructureTag(id: $id) {
25
+ id
26
+ }
27
+ }
28
+ `;
@@ -0,0 +1,20 @@
1
+ import { gql } from "@apollo/client";
2
+ import { STRUCTURE_TAG_DETAIL } from "./fragments";
3
+
4
+ export const STRUCTURE_TAG_QUERY = gql`
5
+ query StructureTag($id: ID!) {
6
+ structureTag(id: $id) {
7
+ ...StructureTagDetail
8
+ }
9
+ }
10
+ ${STRUCTURE_TAG_DETAIL}
11
+ `;
12
+
13
+ export const STRUCTURE_TAGS_QUERY = gql`
14
+ query StructureTags {
15
+ structureTags {
16
+ ...StructureTagDetail
17
+ }
18
+ }
19
+ ${STRUCTURE_TAG_DETAIL}
20
+ `;
package/src/api.js CHANGED
@@ -27,8 +27,6 @@ const API_PROFILE_GROUPS = "/api/profile_execution_groups";
27
27
  const API_SYSTEM = "/api/systems/:id";
28
28
  const API_SYSTEMS = "/api/systems";
29
29
  const API_SYSTEM_STRUCTURES = "/api/systems/:id/structures";
30
- const API_STRUCTURE_TAG = "/api/data_structure_tags/:id";
31
- const API_STRUCTURE_TAGS = "/api/data_structure_tags";
32
30
  const API_STRUCTURE_TYPE = "/api/data_structure_types/:id";
33
31
  const API_STRUCTURE_TYPES = "/api/data_structure_types";
34
32
  const API_STRUCTURES_DOMAINS_UPLOAD =
@@ -76,8 +74,6 @@ export {
76
74
  API_SYSTEM,
77
75
  API_SYSTEMS,
78
76
  API_SYSTEM_STRUCTURES,
79
- API_STRUCTURE_TAG,
80
- API_STRUCTURE_TAGS,
81
77
  API_STRUCTURE_TYPE,
82
78
  API_STRUCTURE_TYPES,
83
79
  API_USER_SEARCH_FILTERS,
@@ -72,15 +72,7 @@ export const DictionaryRoutes = () => {
72
72
  </>
73
73
  )}
74
74
  />
75
- <Route
76
- path={STRUCTURE_TAGS}
77
- render={() => (
78
- <>
79
- <StructureTypesLoader />
80
- <StructureTagsRoutes />
81
- </>
82
- )}
83
- />
75
+ <Route path={STRUCTURE_TAGS} render={() => <StructureTagsRoutes />} />
84
76
  <Route
85
77
  path={STRUCTURE_TYPES}
86
78
  render={() => (
@@ -113,7 +105,7 @@ export const DictionaryRoutes = () => {
113
105
  render={() => (
114
106
  <>
115
107
  <StructureTypesLoader />
116
- <Route render={() => <ProfileGroupLoader />} />
108
+ <ProfileGroupLoader />
117
109
  <Switch>
118
110
  <Route
119
111
  exact
@@ -142,11 +142,11 @@ LinkStructureTagForm.propTypes = {
142
142
  const mapStateToProps = ({
143
143
  linkedStructureTags,
144
144
  structure,
145
- structureTags,
145
+ editableStructureTags,
146
146
  }) => ({
147
147
  linkedStructureTags,
148
148
  structureId: _.prop("id")(structure),
149
- structureTags,
149
+ structureTags: editableStructureTags,
150
150
  });
151
151
 
152
152
  const mapDispatchToProps = {
@@ -1,3 +1,4 @@
1
+ import _ from "lodash/fp";
1
2
  import React, { useEffect, useState } from "react";
2
3
  import PropTypes from "prop-types";
3
4
  import { Icon, Label, Popup } from "semantic-ui-react";
@@ -7,9 +8,10 @@ import LinkStructureTagForm from "./LinkStructureTagForm";
7
8
  const LinkedStructureTag = ({
8
9
  id,
9
10
  _embedded,
11
+ editable,
10
12
  description,
11
13
  loading,
12
- manageTags
14
+ structureTags,
13
15
  }) => {
14
16
  const name = _embedded.data_structure_tag.name;
15
17
  const tagId = _embedded.data_structure_tag.id;
@@ -20,6 +22,8 @@ const LinkedStructureTag = ({
20
22
  if (loading) setOpenForm(false);
21
23
  }, [loading, setOpenForm]);
22
24
 
25
+ const trigger = editable ? <Icon link name="edit" /> : null;
26
+
23
27
  return (
24
28
  <Popup
25
29
  basic
@@ -32,7 +36,7 @@ const LinkedStructureTag = ({
32
36
  positionFixed
33
37
  trigger={
34
38
  <Label tag style={{ marginLeft: "1.5em" }}>
35
- {manageTags && (
39
+ {_.isEmpty(structureTags) ? null : (
36
40
  <Popup
37
41
  on="click"
38
42
  basic
@@ -53,7 +57,7 @@ const LinkedStructureTag = ({
53
57
  position="bottom center"
54
58
  size="large"
55
59
  positionFixed
56
- trigger={<Icon link name="edit" />}
60
+ trigger={trigger}
57
61
  />
58
62
  )}
59
63
 
@@ -67,14 +71,19 @@ const LinkedStructureTag = ({
67
71
  LinkedStructureTag.propTypes = {
68
72
  _embedded: PropTypes.object,
69
73
  description: PropTypes.string,
74
+ editable: PropTypes.bool,
70
75
  id: PropTypes.number,
71
76
  loading: PropTypes.bool,
72
- manageTags: PropTypes.bool
77
+ structureTags: PropTypes.array,
73
78
  };
74
79
 
75
- const mapStateToProps = state => ({
76
- loading: state.linkingStructureTags || state.deletingStructureTags,
77
- manageTags: state.userPermissions.manage_tags
80
+ const mapStateToProps = ({
81
+ editableStructureTags,
82
+ linkingStructureTags,
83
+ deletingStructureTags,
84
+ }) => ({
85
+ loading: linkingStructureTags || deletingStructureTags,
86
+ structureTags: editableStructureTags,
78
87
  });
79
88
 
80
89
  export default connect(mapStateToProps)(LinkedStructureTag);
@@ -1,19 +1,16 @@
1
- import React, { useEffect, useState } from "react";
1
+ import _ from "lodash/fp";
2
+ import React, { useState } from "react";
2
3
  import { Button, Popup } from "semantic-ui-react";
3
4
  import { useIntl } from "react-intl";
4
5
  import { connect } from "react-redux";
5
6
  import PropTypes from "prop-types";
6
7
  import LinkStructureTagForm from "./LinkStructureTagForm";
7
8
 
8
- export const StructureLinkTagButton = ({ loading }) => {
9
+ export const StructureLinkTagButton = ({ structureTags }) => {
9
10
  const { formatMessage } = useIntl();
10
11
  const [open, setOpen] = useState(false);
11
12
 
12
- useEffect(() => {
13
- if (loading) setOpen(false);
14
- }, [loading, setOpen]);
15
-
16
- return (
13
+ return _.isEmpty(structureTags) ? null : (
17
14
  <Popup
18
15
  on="click"
19
16
  basic
@@ -21,7 +18,7 @@ export const StructureLinkTagButton = ({ loading }) => {
21
18
  onOpen={() => setOpen(true)}
22
19
  onClose={() => setOpen(false)}
23
20
  open={open}
24
- content={<LinkStructureTagForm />}
21
+ content={<LinkStructureTagForm structureTags={structureTags} />}
25
22
  position="bottom center"
26
23
  size="large"
27
24
  positionFixed
@@ -40,11 +37,11 @@ export const StructureLinkTagButton = ({ loading }) => {
40
37
  };
41
38
 
42
39
  StructureLinkTagButton.propTypes = {
43
- loading: PropTypes.bool
40
+ structureTags: PropTypes.array,
44
41
  };
45
42
 
46
- const mapStateToProps = ({ deletingStructureTags, linkingStructureTags }) => ({
47
- loading: deletingStructureTags || linkingStructureTags
43
+ const mapStateToProps = ({ editableStructureTags }) => ({
44
+ structureTags: editableStructureTags,
48
45
  });
49
46
 
50
47
  export default connect(mapStateToProps)(StructureLinkTagButton);
@@ -153,7 +153,7 @@ const mapStateToProps = (state) => ({
153
153
  userPermissions: state.userPermissions,
154
154
  linkedStructureTagsLoading: state.linkedStructureTagsLoading,
155
155
  updatedAt: getStructureUpdatedAt(state),
156
- structureTags: state.structureTags,
156
+ structureTags: state.editableStructureTags,
157
157
  structureGrant: state.structureGrant,
158
158
  ...state.structure,
159
159
  isAdmin: state.authentication.role === "admin",
@@ -2,30 +2,69 @@ import React from "react";
2
2
  import PropTypes from "prop-types";
3
3
  import { Header, Icon, Container, Segment } from "semantic-ui-react";
4
4
  import { FormattedMessage } from "react-intl";
5
+ import { connect } from "react-redux";
6
+ import { Loading } from "@truedat/core/components";
7
+ import { createStructureTag, updateStructureTag } from "../routines";
8
+ import StructureTagsCrumbs from "./StructureTagsCrumbs";
5
9
  import StructureTagForm from "./StructureTagForm";
6
10
 
7
- export const StructureTag = ({ isCreate }) => (
8
- <>
9
- <Container text as={Segment}>
10
- <Header as="h2">
11
- <Icon name="tag" />
12
- <Header.Content>
13
- <FormattedMessage
14
- id={
15
- isCreate
16
- ? "structureTags.actions.create"
17
- : "structureTags.actions.update"
18
- }
11
+ const DEFAULT_VALUES = {
12
+ name: "",
13
+ domainIds: [],
14
+ };
15
+
16
+ export const StructureTag = ({
17
+ structureTag = DEFAULT_VALUES,
18
+ updateStructureTag,
19
+ createStructureTag,
20
+ loading,
21
+ saving,
22
+ id,
23
+ }) => {
24
+ const action = id
25
+ ? "structureTags.actions.edit"
26
+ : "structureTags.actions.create";
27
+ const onSubmit = id
28
+ ? (data) => updateStructureTag({ ...data, id })
29
+ : createStructureTag;
30
+ return (
31
+ <>
32
+ <StructureTagsCrumbs action={action} />
33
+ <Container text as={Segment}>
34
+ <Header as="h2">
35
+ <Icon name="tag" />
36
+ <Header.Content>
37
+ <FormattedMessage id={action} />
38
+ </Header.Content>
39
+ </Header>
40
+ {loading ? (
41
+ <Loading />
42
+ ) : (
43
+ <StructureTagForm
44
+ structureTag={structureTag}
45
+ onSubmit={onSubmit}
46
+ saving={saving}
19
47
  />
20
- </Header.Content>
21
- </Header>
22
- <StructureTagForm />
23
- </Container>
24
- </>
25
- );
48
+ )}
49
+ </Container>
50
+ </>
51
+ );
52
+ };
26
53
 
27
54
  StructureTag.propTypes = {
28
- isCreate: PropTypes.bool
55
+ structureTag: PropTypes.object,
56
+ updateStructureTag: PropTypes.func,
57
+ createStructureTag: PropTypes.func,
58
+ loading: PropTypes.bool,
59
+ saving: PropTypes.bool,
60
+ id: PropTypes.string,
29
61
  };
30
62
 
31
- export default StructureTag;
63
+ const mapStateToProps = ({ structureTagSaving }) => ({
64
+ saving: structureTagSaving,
65
+ });
66
+
67
+ export default connect(mapStateToProps, {
68
+ createStructureTag,
69
+ updateStructureTag,
70
+ })(StructureTag);
@@ -1,38 +1,28 @@
1
- import React from "react";
1
+ import _ from "lodash/fp";
2
+ import React, { useState } from "react";
2
3
  import PropTypes from "prop-types";
3
4
  import { Button, Form } from "semantic-ui-react";
4
5
  import { useForm, Controller } from "react-hook-form";
5
6
  import { useIntl } from "react-intl";
6
- import { connect } from "react-redux";
7
- import { HistoryBackButton } from "@truedat/core/components";
8
- import { createStructureTag, updateStructureTag } from "../routines";
7
+ import { HistoryBackButton, DomainSelector } from "@truedat/core/components";
9
8
 
10
9
  export const StructureTagForm = ({
11
- createStructureTag,
12
- updateStructureTag,
13
- isSubmitting,
10
+ loading,
11
+ onSubmit,
12
+ saving,
14
13
  structureTag,
15
14
  }) => {
15
+ const [domainsLoading, setDomainsLoading] = useState(true);
16
16
  const { formatMessage } = useIntl();
17
17
  const { handleSubmit, control, formState } = useForm({
18
18
  mode: "all",
19
- defaultValues: {
20
- name: "",
21
- ...structureTag,
22
- },
19
+ defaultValues: _.pick(["name", "domainIds"])(structureTag),
23
20
  });
24
21
 
25
- const onSubmit = (params) =>
26
- "id" in structureTag
27
- ? updateStructureTag({
28
- id: structureTag.id,
29
- ...params,
30
- })
31
- : createStructureTag(params);
32
22
  const { isDirty, isValid } = formState;
33
23
 
34
24
  return (
35
- <Form onSubmit={handleSubmit(onSubmit)}>
25
+ <Form onSubmit={handleSubmit(onSubmit)} loading={loading || domainsLoading}>
36
26
  <Controller
37
27
  control={control}
38
28
  name="name"
@@ -56,19 +46,32 @@ export const StructureTagForm = ({
56
46
  />
57
47
  )}
58
48
  />
49
+ <Controller
50
+ control={control}
51
+ name="domainIds"
52
+ render={({ field: { onChange, value } }) => (
53
+ <DomainSelector
54
+ action="manageTags"
55
+ value={value}
56
+ onLoad={() => setDomainsLoading(false)}
57
+ onChange={(_e, { value }) => onChange(value)}
58
+ label={formatMessage({ id: "structureTagForm.props.domains" })}
59
+ />
60
+ )}
61
+ />
59
62
  <div className="actions">
60
63
  <Button
61
64
  floated="right"
62
65
  type="submit"
63
66
  primary
64
- loading={isSubmitting}
65
- disabled={isSubmitting || !isDirty || !isValid}
67
+ loading={saving}
68
+ disabled={saving || !isDirty || !isValid}
66
69
  >
67
- {formatMessage({ id: "actions.submit" })}
70
+ {formatMessage({ id: "actions.save" })}
68
71
  </Button>
69
72
  <HistoryBackButton
70
73
  content={formatMessage({ id: "actions.cancel" })}
71
- disabled={isSubmitting}
74
+ disabled={saving}
72
75
  />
73
76
  </div>
74
77
  </Form>
@@ -76,18 +79,10 @@ export const StructureTagForm = ({
76
79
  };
77
80
 
78
81
  StructureTagForm.propTypes = {
79
- createStructureTag: PropTypes.func.isRequired,
80
- updateStructureTag: PropTypes.func.isRequired,
81
- isSubmitting: PropTypes.bool,
82
+ onSubmit: PropTypes.func.isRequired,
83
+ loading: PropTypes.bool,
84
+ saving: PropTypes.bool,
82
85
  structureTag: PropTypes.object,
83
86
  };
84
87
 
85
- const mapStateToProps = ({ structureTagCreating, structureTag }) => ({
86
- isSubmitting: structureTagCreating,
87
- structureTag,
88
- });
89
-
90
- export default connect(mapStateToProps, {
91
- createStructureTag,
92
- updateStructureTag,
93
- })(StructureTagForm);
88
+ export default StructureTagForm;
@@ -1,13 +1,13 @@
1
1
  import React from "react";
2
2
  import { Link } from "react-router-dom";
3
3
  import { Button, Header, Icon, Segment } from "semantic-ui-react";
4
- import { FormattedMessage } from "react-intl";
4
+ import { useIntl, FormattedMessage } from "react-intl";
5
5
  import { STRUCTURE_TAGS_NEW } from "@truedat/core/routes";
6
- import { useAuthorized } from "@truedat/core/hooks";
7
6
  import StructureTagsCards from "./StructureTagsCards";
8
7
 
9
- export const StructureTags = () =>
10
- useAuthorized() ? (
8
+ export const StructureTags = () => {
9
+ const { formatMessage } = useIntl();
10
+ return (
11
11
  <Segment>
12
12
  <Header as="h2">
13
13
  <Button
@@ -15,7 +15,7 @@ export const StructureTags = () =>
15
15
  primary
16
16
  as={Link}
17
17
  to={STRUCTURE_TAGS_NEW}
18
- content={<FormattedMessage id="structureTags.actions.create" />}
18
+ content={formatMessage({ id: "structureTags.actions.create" })}
19
19
  />
20
20
  <Icon name="tags" circular />
21
21
  <Header.Content>
@@ -27,6 +27,7 @@ export const StructureTags = () =>
27
27
  </Header>
28
28
  <StructureTagsCards />
29
29
  </Segment>
30
- ) : null;
30
+ );
31
+ };
31
32
 
32
33
  export default StructureTags;
@@ -5,9 +5,11 @@ import { connect } from "react-redux";
5
5
  import { Link } from "react-router-dom";
6
6
  import { Button, Card, Message, Icon } from "semantic-ui-react";
7
7
  import { FormattedMessage } from "react-intl";
8
- import { ConfirmModal } from "@truedat/core/components";
8
+ import { useQuery } from "@apollo/client";
9
+ import { ConfirmModal, Loading } from "@truedat/core/components";
9
10
  import { linkTo } from "@truedat/core/routes";
10
11
  import { accentInsensitivePathOrder } from "@truedat/core/services/sort";
12
+ import { STRUCTURE_TAGS_QUERY } from "../api/queries";
11
13
  import { deleteStructureTag } from "../routines";
12
14
 
13
15
  const EmptyMessage = () => (
@@ -21,72 +23,67 @@ const EmptyMessage = () => (
21
23
  </Message>
22
24
  );
23
25
 
24
- export const StructureTagsCards = ({
25
- deleteStructureTag,
26
- structureTags,
27
- structureTagsLoading,
28
- }) => {
29
- if (structureTagsLoading) return null;
26
+ export const StructureTagsCards = ({ deleteStructureTag, structureTags }) => {
30
27
  if (_.isEmpty(structureTags)) return <EmptyMessage />;
31
28
  return (
32
- <>
33
- <Card.Group>
34
- {structureTags.map((structureTag, i) => (
35
- <Card key={i}>
36
- <Card.Content>
37
- <Card.Header
38
- as={Link}
39
- to={linkTo.STRUCTURE_TAGS_EDIT({ id: structureTag.id })}
40
- >
41
- {_.prop("name")(structureTag)}
42
- </Card.Header>
43
- </Card.Content>
44
- <Card.Content extra>
45
- <div className="ui actions">
46
- <ConfirmModal
47
- icon="trash"
48
- trigger={<Button icon="trash" basic color="red" />}
49
- header={
50
- <FormattedMessage id="structureTags.actions.delete.confirmation.header" />
51
- }
52
- content={
53
- structureTag.structure_count > 0 ? (
54
- <FormattedMessage
55
- id="structureTags.actions.delete.confirmation.content"
56
- values={{
57
- name: <i>{`'${structureTag.name}'`}</i>,
58
- count: structureTag.structure_count,
59
- }}
60
- />
61
- ) : (
62
- <FormattedMessage
63
- id="structureTags.actions.delete.noStructures.confirmation.content"
64
- values={{ name: <i>{`'${structureTag.name}'`}</i> }}
65
- />
66
- )
67
- }
68
- onConfirm={() => deleteStructureTag({ id: structureTag.id })}
69
- />
70
- </div>
71
- </Card.Content>
72
- </Card>
73
- ))}
74
- </Card.Group>
75
- </>
29
+ <Card.Group>
30
+ {structureTags.map((structureTag) => (
31
+ <Card key={structureTag?.id}>
32
+ <Card.Content>
33
+ <Card.Header
34
+ as={Link}
35
+ to={linkTo.STRUCTURE_TAGS_EDIT({ id: structureTag.id })}
36
+ >
37
+ {_.prop("name")(structureTag)}
38
+ </Card.Header>
39
+ </Card.Content>
40
+ <Card.Content extra>
41
+ <div className="ui actions">
42
+ <ConfirmModal
43
+ icon="trash"
44
+ trigger={<Button icon="trash" basic color="red" />}
45
+ header={
46
+ <FormattedMessage id="structureTags.actions.delete.confirmation.header" />
47
+ }
48
+ content={
49
+ structureTag.structureCount > 0 ? (
50
+ <FormattedMessage
51
+ id="structureTags.actions.delete.confirmation.content"
52
+ values={{
53
+ name: <i>{`'${structureTag.name}'`}</i>,
54
+ count: structureTag.structureCount,
55
+ }}
56
+ />
57
+ ) : (
58
+ <FormattedMessage
59
+ id="structureTags.actions.delete.noStructures.confirmation.content"
60
+ values={{ name: <i>{`'${structureTag.name}'`}</i> }}
61
+ />
62
+ )
63
+ }
64
+ onConfirm={() => deleteStructureTag({ id: structureTag.id })}
65
+ />
66
+ </div>
67
+ </Card.Content>
68
+ </Card>
69
+ ))}
70
+ </Card.Group>
76
71
  );
77
72
  };
78
73
 
79
74
  StructureTagsCards.propTypes = {
80
75
  structureTags: PropTypes.array,
81
- structureTagsLoading: PropTypes.bool,
82
76
  deleteStructureTag: PropTypes.func,
83
77
  };
84
78
 
85
- const mapStateToProps = ({ structureTags, structureTagsLoading }) => ({
86
- structureTags: _.sortBy(accentInsensitivePathOrder("name"))(structureTags),
87
- structureTagsLoading,
88
- });
79
+ export const StructureTagsCardsLoader = (props) => {
80
+ const { loading, error, data } = useQuery(STRUCTURE_TAGS_QUERY);
81
+ if (error) return null;
82
+ if (loading) return <Loading />;
83
+ const structureTags = _.sortBy(accentInsensitivePathOrder("name"))(
84
+ data?.structureTags || []
85
+ );
86
+ return <StructureTagsCards structureTags={structureTags} {...props} />;
87
+ };
89
88
 
90
- export default connect(mapStateToProps, { deleteStructureTag })(
91
- StructureTagsCards
92
- );
89
+ export default connect(null, { deleteStructureTag })(StructureTagsCardsLoader);