@spokane-folio/security-incident 1.0.28

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 (188) hide show
  1. package/.eslintrc +32 -0
  2. package/.github/workflows/CODEOWNERS +8 -0
  3. package/.github/workflows/pr-validation.yml +44 -0
  4. package/.github/workflows/release.yml +64 -0
  5. package/.prettierrc +6 -0
  6. package/.stripesclirc +4 -0
  7. package/CHANGELOG.md +8 -0
  8. package/CONTRIBUTING.md +4 -0
  9. package/LICENSE +201 -0
  10. package/README.md +16 -0
  11. package/administrator-documentation/roles-and-permissions.md +65 -0
  12. package/administrator-documentation/track-settings-admin-guide-sketch.md +192 -0
  13. package/administrator-documentation/using-the-application.md +192 -0
  14. package/icons/app.png +0 -0
  15. package/icons/app.svg +1 -0
  16. package/icons/playButton.png +0 -0
  17. package/icons/profilePicThumbnail.png +0 -0
  18. package/jest.config.js +10 -0
  19. package/module-descriptor.json +75 -0
  20. package/output/service-worker.js +0 -0
  21. package/package.json +146 -0
  22. package/src/components/incidents/ColumnChooser.js +37 -0
  23. package/src/components/incidents/CreateMedia.js +132 -0
  24. package/src/components/incidents/CreatePane.js +1215 -0
  25. package/src/components/incidents/CreatePane.test.js +138 -0
  26. package/src/components/incidents/CreateReport.js +102 -0
  27. package/src/components/incidents/DetailsPane.js +1267 -0
  28. package/src/components/incidents/DetailsPane.test.js +150 -0
  29. package/src/components/incidents/EditPane.js +2334 -0
  30. package/src/components/incidents/EditPane.test.js +187 -0
  31. package/src/components/incidents/GetDetails.js +55 -0
  32. package/src/components/incidents/GetListDQLinkIncident.js +81 -0
  33. package/src/components/incidents/GetListDynamicQuery.js +66 -0
  34. package/src/components/incidents/GetLocations.js +57 -0
  35. package/src/components/incidents/GetMedia.js +98 -0
  36. package/src/components/incidents/GetName.js +111 -0
  37. package/src/components/incidents/GetNameCreatedBy.js +94 -0
  38. package/src/components/incidents/GetOrgLocaleSettings.js +61 -0
  39. package/src/components/incidents/GetPatronGroups.js +52 -0
  40. package/src/components/incidents/GetSelf.js +65 -0
  41. package/src/components/incidents/GetSummary.js +110 -0
  42. package/src/components/incidents/IncidentTypeCard.js +53 -0
  43. package/src/components/incidents/IncidentTypeCard.test.js +133 -0
  44. package/src/components/incidents/IncidentsPaneset.js +810 -0
  45. package/src/components/incidents/IncidentsPaneset.test.js +128 -0
  46. package/src/components/incidents/LinkedIncident.js +86 -0
  47. package/src/components/incidents/ModalAddMedia.js +262 -0
  48. package/src/components/incidents/ModalAddMedia.test.js +97 -0
  49. package/src/components/incidents/ModalAttentionDecOfService.js +111 -0
  50. package/src/components/incidents/ModalCustomWitness.js +469 -0
  51. package/src/components/incidents/ModalCustomWitness.test.js +147 -0
  52. package/src/components/incidents/ModalCustomerDetails.js +480 -0
  53. package/src/components/incidents/ModalCustomerDetails.test.js +116 -0
  54. package/src/components/incidents/ModalDescribeCustomer.js +361 -0
  55. package/src/components/incidents/ModalDescribeCustomer.test.js +156 -0
  56. package/src/components/incidents/ModalDirtyFormWarn.js +62 -0
  57. package/src/components/incidents/ModalLinkIncident.js +1213 -0
  58. package/src/components/incidents/ModalLinkIncidentStyle.css +32 -0
  59. package/src/components/incidents/ModalSelectIncidentTypes.js +178 -0
  60. package/src/components/incidents/ModalSelectIncidentTypes.test.js +273 -0
  61. package/src/components/incidents/ModalSelectKnownCustomer.js +395 -0
  62. package/src/components/incidents/ModalSelectWitness.js +406 -0
  63. package/src/components/incidents/ModalSelectWitness.test.js +308 -0
  64. package/src/components/incidents/ModalStyle.css +44 -0
  65. package/src/components/incidents/ModalTrespass.js +741 -0
  66. package/src/components/incidents/ModalViewCustomerDetails.js +241 -0
  67. package/src/components/incidents/ModalViewMedia.js +86 -0
  68. package/src/components/incidents/ModalViewTrespass.js +210 -0
  69. package/src/components/incidents/ResultsPane.js +437 -0
  70. package/src/components/incidents/ResultsPane.test.js +120 -0
  71. package/src/components/incidents/SearchCustomerOrWitness.js +108 -0
  72. package/src/components/incidents/Thumbnail.js +72 -0
  73. package/src/components/incidents/ThumbnailMarkRemoval.js +38 -0
  74. package/src/components/incidents/ThumbnailSkeleton.js +30 -0
  75. package/src/components/incidents/ThumbnailStyles.js +49 -0
  76. package/src/components/incidents/ThumbnailTempPreSave.js +71 -0
  77. package/src/components/incidents/UpdateReport.js +84 -0
  78. package/src/components/incidents/__snapshots__/CreatePane.test.js.snap +3 -0
  79. package/src/components/incidents/__snapshots__/DetailsPane.test.js.snap +3 -0
  80. package/src/components/incidents/__snapshots__/EditPane.test.js.snap +3 -0
  81. package/src/components/incidents/__snapshots__/IncidentTypeCard.test.js.snap +3 -0
  82. package/src/components/incidents/__snapshots__/IncidentsPaneset.test.js.snap +3 -0
  83. package/src/components/incidents/__snapshots__/ModalAddMedia.test.js.snap +3 -0
  84. package/src/components/incidents/__snapshots__/ModalCustomerDetails.test.js.snap +3 -0
  85. package/src/components/incidents/__snapshots__/ModalSelectWitness.test.js.snap +3 -0
  86. package/src/components/incidents/__snapshots__/ResultsPane.test.js.snap +3 -0
  87. package/src/components/incidents/helpers/ProfilePicture/ProfilePicture.css +5 -0
  88. package/src/components/incidents/helpers/ProfilePicture/ProfilePicture.js +51 -0
  89. package/src/components/incidents/helpers/ProfilePicture/isAValidURL.js +3 -0
  90. package/src/components/incidents/helpers/ProfilePicture/useProfilePicture.js +127 -0
  91. package/src/components/incidents/helpers/buildQueryString.js +28 -0
  92. package/src/components/incidents/helpers/cleanFormValues.js +53 -0
  93. package/src/components/incidents/helpers/computeEditedCustomers.js +124 -0
  94. package/src/components/incidents/helpers/convertDateIgnoringTZ.js +8 -0
  95. package/src/components/incidents/helpers/convertUTCISOToLocalePrettyTime.js +15 -0
  96. package/src/components/incidents/helpers/convertUTCISOToPrettyDate.js +19 -0
  97. package/src/components/incidents/helpers/decodeParamsToForm.js +20 -0
  98. package/src/components/incidents/helpers/deepNormalizeForComparison.js +39 -0
  99. package/src/components/incidents/helpers/extractFilterString.js +12 -0
  100. package/src/components/incidents/helpers/formatDateAndTimeToUTCISO.js +14 -0
  101. package/src/components/incidents/helpers/formatDateToUTCISO.js +14 -0
  102. package/src/components/incidents/helpers/formatTimeToUTCISO.js +28 -0
  103. package/src/components/incidents/helpers/getCurrentTime.js +20 -0
  104. package/src/components/incidents/helpers/getTodayDate.js +12 -0
  105. package/src/components/incidents/helpers/handlebarsHelpers.js +148 -0
  106. package/src/components/incidents/helpers/hasFormChangedAtCreate.js +50 -0
  107. package/src/components/incidents/helpers/hasTopLevelChangeAffectedDeclaration.js +90 -0
  108. package/src/components/incidents/helpers/hasTopLevelFormChanged.js +111 -0
  109. package/src/components/incidents/helpers/identifyCurrentTrespassDocs.js +109 -0
  110. package/src/components/incidents/helpers/isSameHtml.js +13 -0
  111. package/src/components/incidents/helpers/isValidDateFormat.js +14 -0
  112. package/src/components/incidents/helpers/isValidTimeInput.js +11 -0
  113. package/src/components/incidents/helpers/isValidUTCTimeFormat.js +14 -0
  114. package/src/components/incidents/helpers/parseMMDDYYYY.js +7 -0
  115. package/src/components/incidents/helpers/parseQueryString.js +16 -0
  116. package/src/components/incidents/helpers/sortTrespassDocuments.js +44 -0
  117. package/src/components/incidents/helpers/stripHTML.js +11 -0
  118. package/src/components/incidents/helpers/trespassDocUtils.js +197 -0
  119. package/src/components/incidents/helpers/validateTrespassDetails.js +37 -0
  120. package/src/components/incidents/usePersistedColModalLink.js +70 -0
  121. package/src/components/incidents/usePersistedColumns.js +70 -0
  122. package/src/components/incidents/usePersistedSort.js +23 -0
  123. package/src/components/incidents/usePersistedSortModalLink.js +23 -0
  124. package/src/contexts/IncidentContext.js +433 -0
  125. package/src/index.js +61 -0
  126. package/src/routes/Application.js +13 -0
  127. package/src/settings/GetIncidentCategories.js +56 -0
  128. package/src/settings/GetIncidentTypesDetails.js +88 -0
  129. package/src/settings/GetIncidentTypesIds.js +74 -0
  130. package/src/settings/GetLocationsInService.js +54 -0
  131. package/src/settings/GetSingleCustomLocationDetails.js +60 -0
  132. package/src/settings/GetSingleIncidentTypeDetails.js +60 -0
  133. package/src/settings/GetTrespassReasons.js +67 -0
  134. package/src/settings/GetTrespassTemplates.js +51 -0
  135. package/src/settings/IncidentCategoriesPane.js +285 -0
  136. package/src/settings/IncidentCategoriesPane.test.js +229 -0
  137. package/src/settings/IncidentTypeDetailsPane.js +215 -0
  138. package/src/settings/IncidentTypeDetailsPane.test.js +220 -0
  139. package/src/settings/IncidentTypeEditPane.js +211 -0
  140. package/src/settings/IncidentTypeEditPane.test.js +170 -0
  141. package/src/settings/IncidentTypesPaneset.js +167 -0
  142. package/src/settings/IncidentTypesPaneset.test.js +124 -0
  143. package/src/settings/LocationInServiceEditPane.js +320 -0
  144. package/src/settings/LocationsPaneset.js +415 -0
  145. package/src/settings/LocationsPaneset.test.js +106 -0
  146. package/src/settings/ModalDeleteCategory.js +47 -0
  147. package/src/settings/ModalDeleteIncidentType.js +49 -0
  148. package/src/settings/ModalDeleteLocationInService.js +49 -0
  149. package/src/settings/ModalDeleteTrespassReason.js +49 -0
  150. package/src/settings/ModalPreviewTrespassDoc.js +65 -0
  151. package/src/settings/ModalTrespassDocTokens.js +83 -0
  152. package/src/settings/NewIncidentTypePane.js +182 -0
  153. package/src/settings/PutIncidentType.js +60 -0
  154. package/src/settings/PutLocationsInService.js +52 -0
  155. package/src/settings/PutTrespassReasons.js +61 -0
  156. package/src/settings/PutTrespassTemplate.js +50 -0
  157. package/src/settings/TrespassDoc.css +17 -0
  158. package/src/settings/TrespassDocDetailsPane.js +215 -0
  159. package/src/settings/TrespassDocEditPane.js +538 -0
  160. package/src/settings/TrespassDocPaneset.js +581 -0
  161. package/src/settings/TrespassReasonDetailsPane.js +171 -0
  162. package/src/settings/TrespassReasonEditPane.js +221 -0
  163. package/src/settings/TrespassReasonsPaneset.js +282 -0
  164. package/src/settings/__snapshots__/IncidentCategoriesPane.test.js.snap +3 -0
  165. package/src/settings/__snapshots__/IncidentTypeDetailsPane.test.js.snap +3 -0
  166. package/src/settings/__snapshots__/IncidentTypeEditPane.test.js.snap +3 -0
  167. package/src/settings/__snapshots__/IncidentTypesPaneset.test.js.snap +3 -0
  168. package/src/settings/__snapshots__/LocationsPaneset.test.js.snap +3 -0
  169. package/src/settings/data/exampleJSON.json +92 -0
  170. package/src/settings/data/templateTokens.js +396 -0
  171. package/src/settings/helpers/alphabetize.js +18 -0
  172. package/src/settings/helpers/getCategoryTitleById.js +13 -0
  173. package/src/settings/helpers/makeId.js +15 -0
  174. package/src/settings/index.js +48 -0
  175. package/stripes.config.js +10 -0
  176. package/test/jest/__mock__/index.js +8 -0
  177. package/test/jest/__mock__/intl.mock.js +27 -0
  178. package/test/jest/__mock__/stripes.mock.js +26 -0
  179. package/test/jest/__mock__/stripesComponents.mock.js +151 -0
  180. package/test/jest/__mock__/stripesConfig.mock.js +1 -0
  181. package/test/jest/__mock__/stripesCore.mock.js +9 -0
  182. package/test/jest/__mock__/stripesIcon.mock.js +5 -0
  183. package/test/jest/__mock__/stripesSmartComponents.mock.js +7 -0
  184. package/test/jest/__mock__/stripesUtils.mock.js +3 -0
  185. package/test/jest/eslintrc.js +12 -0
  186. package/test/jest/setupFiles.js +5 -0
  187. package/translations/ui-security-incident/en_US.json +542 -0
  188. package/ui-module-acceptance-criteria.md +34 -0
@@ -0,0 +1,88 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { stripesConnect } from '@folio/stripes/core';
4
+ import { IncidentContext } from '../contexts/IncidentContext';
5
+
6
+ class GetIncidentTypesDetails extends React.Component {
7
+ static contextType = IncidentContext;
8
+ static manifest = Object.freeze({
9
+ incidentTypes: {
10
+ type: 'okapi',
11
+ path: 'incidents/configurations/incident-types',
12
+ records: 'data.value.incidentTypes',
13
+ throwErrors: false // prevent error modal if empty on first pass
14
+ },
15
+ });
16
+
17
+ static propTypes = {
18
+ resources: PropTypes.object.isRequired,
19
+ context: PropTypes.oneOf(['incidents', 'settings']).isRequired,
20
+ handleIncidentTypes: PropTypes.func, //only passed in 'settings' context
21
+ };
22
+
23
+ componentDidMount() {
24
+ // console.log("@GetIncidentTypesDetails - componentDidMount")
25
+ this.fetchRecords();
26
+ };
27
+
28
+ componentDidUpdate(prevProps) {
29
+ const resourceChanged =
30
+ this.props.resources.incidentTypes !==
31
+ prevProps.resources.incidentTypes;
32
+
33
+ if (resourceChanged) {
34
+ // console.log("@GetIncidentTypesDetails - componentDidUPDATE")
35
+ this.fetchRecords();
36
+ };
37
+ };
38
+
39
+ fetchRecords() {
40
+ const incidentTypesBody = this.props.resources.incidentTypes;
41
+ if (!incidentTypesBody?.hasLoaded) return;
42
+
43
+ const types = incidentTypesBody?.records;
44
+
45
+ if (!Array.isArray(types) || !types.length) return;
46
+
47
+ // make shape for id, title shape list
48
+ const incTypes = [...types];
49
+ const titlesAndIds = incTypes.map((type) => ({
50
+ id: type.id,
51
+ title: type.title,
52
+ }));
53
+
54
+ if (titlesAndIds) {
55
+ // set inc types names, ids list for ready use at
56
+ // <IncidentsPaneset /> (app), < IncidentTypesPaneset/> (Settings)
57
+ this.context.setIncidentTypesNamesIdsList(titlesAndIds);
58
+ }
59
+
60
+
61
+ if (this.props.context === 'incidents') {
62
+ // set incident types for general application
63
+ this.context.setIncidentTypesList(types);
64
+
65
+ } else if (this.props.context === 'settings') {
66
+ /*
67
+ set full-shape incidentTypes for Settings
68
+ <IncidentTypeDetailsPane />, <IncidentTypeEditPane />,
69
+ and <NewIncidentTypePane />. They pass handleIncidentTypes()
70
+ via props.
71
+ */
72
+ if (typeof this.props.handleIncidentTypes === 'function') {
73
+ this.props.handleIncidentTypes(types);
74
+ }
75
+ };
76
+ };
77
+
78
+ render() {
79
+ return null;
80
+ };
81
+ };
82
+
83
+ GetIncidentTypesDetails.contextType = IncidentContext;
84
+
85
+ export default stripesConnect(
86
+ GetIncidentTypesDetails,
87
+ '@spokane-folio/security-incident'
88
+ );
@@ -0,0 +1,74 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { stripesConnect } from '@folio/stripes/core';
4
+ import { IncidentContext } from '../contexts/IncidentContext';
5
+
6
+ class GetIncidentTypesIds extends React.Component {
7
+ static contextType = IncidentContext;
8
+ /*
9
+ 'incTypesIds' named manifest key so no collision with 'incidentTypes' manifest key at GetIncidentTypesDetails.
10
+ GetIncidentTypesIds requests at the same /incident-types endpoint that
11
+ GetIncidentTypesDetails utilizes. GetIncidentTypesIds is for convenience.
12
+ */
13
+ static manifest = Object.freeze({
14
+ incTypesIds: {
15
+ type: 'okapi',
16
+ path: 'incidents/configurations/incident-types'
17
+ },
18
+ });
19
+
20
+ static propTypes = {
21
+ resources: PropTypes.object.isRequired,
22
+ // not required, used in context of <IncidentTypesPaneset />
23
+ handleGetTypesList: PropTypes.func,
24
+ // leave use of oneOf for future addition
25
+ contextTypeProp: PropTypes.oneOf(['incident-types-paneset'])
26
+ };
27
+
28
+ componentDidMount() {
29
+ this.fetchRecords();
30
+ };
31
+
32
+ componentDidUpdate(prevProps) {
33
+ const resourceChanged =
34
+ this.props.resources.incTypesIds !==
35
+ prevProps.resources.incTypesIds;
36
+ if (resourceChanged) {
37
+ this.fetchRecords();
38
+ };
39
+ };
40
+
41
+ fetchRecords() {
42
+ // console.log("this.props.resources --> ", JSON.stringify(this.props.resources, null, 2))
43
+ const incTypesIdsBody = this.props.resources.incTypesIds;
44
+ // console.log("incTypesIdsBody --> ", JSON.stringify(incTypesIdsBody, null, 2))
45
+ if (!incTypesIdsBody?.hasLoaded) return;
46
+
47
+ const incTypes = incTypesIdsBody?.records[0]?.data?.value?.incidentTypes;
48
+ // console.log("incTypes --> ", JSON.stringify(incTypes, null, 2));
49
+
50
+ if (incTypes) {
51
+ const types = incTypes;
52
+ const titlesAndIds = types.map((type) => ({
53
+ id: type.id,
54
+ title: type.title,
55
+ }));
56
+
57
+ // console.log("titlesAndIds --> ", JSON.stringify(titlesAndIds, null, 2));
58
+
59
+ if (this.props.contextTypeProp === 'incident-types-paneset') {
60
+ this.props.handleGetTypesList(titlesAndIds);
61
+ };
62
+
63
+ this.context.setIncidentTypesNamesIdsList(titlesAndIds);
64
+ };
65
+ };
66
+
67
+ render() {
68
+ return null;
69
+ };
70
+ };
71
+
72
+ GetIncidentTypesIds.contextType = IncidentContext;
73
+
74
+ export default stripesConnect(GetIncidentTypesIds, '@spokane-folio/security-incident');
@@ -0,0 +1,54 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { stripesConnect } from '@folio/stripes/core';
4
+ import { IncidentContext } from '../contexts/IncidentContext';
5
+ import alphabetize from './helpers/alphabetize';
6
+
7
+ class GetLocationsInService extends React.Component {
8
+ static contextType = IncidentContext;
9
+ static manifest = Object.freeze({
10
+ locationsInService: {
11
+ type: 'okapi',
12
+ path: 'incidents/configurations/locations-in-service',
13
+ records: 'data.value.locationsInService',
14
+ throwErrors: false // prevent error modal if empty on first pass
15
+ },
16
+ });
17
+
18
+ static propTypes = {
19
+ resources: PropTypes.object.isRequired,
20
+ handleFetchedLocationsInService: PropTypes.func,
21
+ };
22
+
23
+ componentDidMount() {
24
+ this.fetchRecords();
25
+ };
26
+
27
+ componentDidUpdate(prevProps) {
28
+ const resourceChanged =
29
+ this.props.resources.locationsInService !==
30
+ prevProps.resources.locationsInService;
31
+
32
+ if (resourceChanged) {
33
+ this.fetchRecords();
34
+ };
35
+ };
36
+
37
+ fetchRecords() {
38
+ const res = this.props.resources.locationsInService;
39
+ if (!res?.hasLoaded) return;
40
+
41
+ const locationsInServiceList = res?.records;
42
+ if (!Array.isArray(locationsInServiceList)) return;
43
+
44
+ this.context.setLocationsInService(alphabetize(locationsInServiceList))
45
+ };
46
+
47
+ render() {
48
+ return null;
49
+ };
50
+ };
51
+
52
+ GetLocationsInService.contextType = IncidentContext;
53
+
54
+ export default stripesConnect(GetLocationsInService, '@spokane-folio/security-incident');
@@ -0,0 +1,60 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { stripesConnect } from '@folio/stripes/core';
4
+
5
+ class GetSingleCustomLocationDetails extends React.Component {
6
+ static manifest = Object.freeze({
7
+ customLocations: {
8
+ type: 'okapi',
9
+ path: 'configurations/entries?query=module==security-incident and configName=custom-locations and enabled=true',
10
+ accumulate: true,
11
+ },
12
+ });
13
+
14
+ static propTypes = {
15
+ customLocations: PropTypes.shape({
16
+ records: PropTypes.arrayOf(PropTypes.object),
17
+ }),
18
+ detailsId: PropTypes.string.isRequired,
19
+ handleFetchedDetails: PropTypes.func.isRequired,
20
+ mutator: PropTypes.shape({
21
+ customLocations: PropTypes.shape({
22
+ GET: PropTypes.func.isRequired,
23
+ }).isRequired,
24
+ }).isRequired,
25
+ };
26
+
27
+ componentDidMount() {
28
+ this.fetchCustomLocationDetails(this.props.detailsId);
29
+ }
30
+
31
+ componentDidUpdate(prevProps) {
32
+ if (this.props.detailsId !== prevProps.detailsId) {
33
+ this.fetchCustomLocationDetails(this.props.detailsId);
34
+ }
35
+ }
36
+
37
+ fetchCustomLocationDetails(id) {
38
+ this.props.mutator.customLocations
39
+ .GET({ path: 'configurations/entries?query=module==security-incident and configName=custom-locations and enabled=true' })
40
+ .then((records) => {
41
+ const valueObject = JSON.parse(records.configs[0].value);
42
+ const locations = valueObject.customLocations;
43
+ const singleLocation = locations.find((loc) => loc.id === id);
44
+ this.props.handleFetchedDetails(singleLocation);
45
+ })
46
+ .catch((error) => {
47
+ // placeholder
48
+ console.log('error fetching single custom location: ', error.message);
49
+ });
50
+ }
51
+
52
+ render() {
53
+ return <></>;
54
+ }
55
+ }
56
+
57
+ export default stripesConnect(
58
+ GetSingleCustomLocationDetails,
59
+ '@spokane-folio/security-incident'
60
+ );
@@ -0,0 +1,60 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { stripesConnect } from '@folio/stripes/core';
4
+ class GetSingleIncidentTypeDetails extends React.Component {
5
+ static manifest = Object.freeze({
6
+ incidentTypes: {
7
+ type: 'okapi',
8
+ path: 'incidents/configurations/incident-types',
9
+ records: 'data.value.incidentTypes',
10
+ throwErrors: false
11
+ },
12
+ });
13
+
14
+ static propTypes = {
15
+ resources: PropTypes.object.isRequired,
16
+ detailsId: PropTypes.string.isRequired,
17
+ handleFetchedDetails: PropTypes.func.isRequired,
18
+ };
19
+
20
+ componentDidMount() {
21
+ this.fetchRecord(this.props.detailsId);
22
+ };
23
+
24
+ componentDidUpdate(prevProps) {
25
+ const resourceChanged =
26
+ this.props.resources.incidentTypes !==
27
+ prevProps.resources.incidentTypes;
28
+ const idChanged = this.props.detailsId !== prevProps.detailsId;
29
+
30
+ if (idChanged || resourceChanged) {
31
+ this.fetchRecord(this.props.detailsId);
32
+ };
33
+ };
34
+
35
+ fetchRecord(id) {
36
+ const res = this.props.resources.incidentTypes;
37
+ console.log("res --> ", JSON.stringify(res, null, 2))
38
+ if (!res?.hasLoaded) return;
39
+
40
+ const incTypesRecords = res?.records;
41
+ console.log("incTypesRecords --> ", JSON.stringify(incTypesRecords, null, 2));
42
+
43
+
44
+ const singleType = incTypesRecords.find((type) => type.id === id);
45
+ this.props.handleFetchedDetails(singleType);
46
+ if (singleType) {
47
+ console.log("singleType --> ", JSON.stringify(singleType, null, 2));
48
+ this.props.handleFetchedDetails(singleType);
49
+ }
50
+ };
51
+
52
+ render() {
53
+ return null;
54
+ };
55
+ };
56
+
57
+ export default stripesConnect(
58
+ GetSingleIncidentTypeDetails,
59
+ '@spokane-folio/security-incident'
60
+ );
@@ -0,0 +1,67 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { stripesConnect } from '@folio/stripes/core';
4
+ import { IncidentContext } from '../contexts/IncidentContext';
5
+
6
+ class GetTrespassReasons extends React.Component {
7
+ static contextType = IncidentContext;
8
+ static manifest = Object.freeze({
9
+ trespassReasons: {
10
+ type: 'okapi',
11
+ path: 'incidents/configurations/trespass-reasons',
12
+ records: 'data.value.trespassReasons',
13
+ throwErrors: false
14
+ },
15
+ });
16
+
17
+ static propTypes = {
18
+ resources: PropTypes.object.isRequired,
19
+ handleFetchedTrespassReasons: PropTypes.func,
20
+ reloadKey: PropTypes.number // not required (invoked by Settings <TrespassReasonsPaneset> on new tr)
21
+ };
22
+
23
+ componentDidMount() {
24
+ this.fetchRecords();
25
+ };
26
+
27
+ componentDidUpdate(prevProps) {
28
+ // if parent bumped reloadKey make stripes refetch now
29
+ if (this.props.reloadKey !== prevProps.reloadKey) {
30
+ this.props.mutator.trespassReasons.reset?.();
31
+ this.props.mutator.trespassReasons.GET?.();
32
+ return;
33
+ }
34
+ const resourceChanged =
35
+ this.props.resources.trespassReasons !==
36
+ prevProps.resources.trespassReasons;
37
+
38
+ if (resourceChanged) {
39
+ this.fetchRecords();
40
+ };
41
+ };
42
+
43
+ fetchRecords = () => {
44
+ const trBody = this.props.resources.trespassReasons;
45
+ if (!trBody?.hasLoaded || trBody?.isPending) return; // don't hit trespassReasons context value w/ partial
46
+
47
+ const reasons = trBody?.records;
48
+ if (Array.isArray(reasons)) {
49
+ this.context.setTrespassReasons(reasons)
50
+ } else {
51
+ console.error(
52
+ `Error: skip setter, records not array`
53
+ );
54
+ }
55
+ };
56
+
57
+ render() {
58
+ return null;
59
+ };
60
+ };
61
+
62
+ GetTrespassReasons.contextType = IncidentContext;
63
+
64
+ export default stripesConnect(
65
+ GetTrespassReasons,
66
+ '@spokane-folio/security-incident'
67
+ );
@@ -0,0 +1,51 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { stripesConnect } from '@folio/stripes/core';
4
+ import { IncidentContext } from '../contexts/IncidentContext';
5
+
6
+ class GetTrespassTemplates extends React.Component {
7
+ static contextType = IncidentContext;
8
+ static manifest = Object.freeze({
9
+ trespassTemplates: {
10
+ type: 'okapi',
11
+ path: 'incidents/configurations/trespass-templates',
12
+ records: 'data.value.templates',
13
+ throwErrors: false // prevent error modal if empty on first pass
14
+ },
15
+ });
16
+
17
+ static propTypes = {
18
+ resources: PropTypes.object.isRequired,
19
+ handleFetchedTrespassTemplates: PropTypes.func,
20
+ };
21
+
22
+ componentDidMount() {
23
+ this.fetchRecords();
24
+ };
25
+
26
+ componentDidUpdate(prevProps) {
27
+ const resourceChanged =
28
+ this.props.resources.trespassTemplates !==
29
+ prevProps.resources.trespassTemplates;
30
+
31
+ if (resourceChanged) {
32
+ this.fetchRecords();
33
+ };
34
+ };
35
+
36
+ fetchRecords = () => {
37
+ const res = this.props.resources.trespassTemplates;
38
+ if (!res?.hasLoaded) return;
39
+
40
+ const trespassTemplatesList = res?.records;
41
+ if (!Array.isArray(trespassTemplatesList)) return;
42
+
43
+ this.context.setTrespassTemplates(trespassTemplatesList);
44
+ };
45
+
46
+ render() {
47
+ return null;
48
+ };
49
+ };
50
+
51
+ export default stripesConnect(GetTrespassTemplates, '@spokane-folio/security-incident');