@jobber/hooks 1.10.0 → 1.12.0

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
@@ -8,6 +8,28 @@ menu: Changelog
8
8
  All notable changes to this project will be documented in this file.
9
9
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
10
10
 
11
+ # [1.12.0](https://github.com/GetJobber/atlantis/compare/@jobber/hooks@1.11.0...@jobber/hooks@1.12.0) (2022-08-24)
12
+
13
+
14
+ ### Features
15
+
16
+ * **hooks:** allow totalCount to be optional -- (Minor) Feature Release ([#916](https://github.com/GetJobber/atlantis/issues/916)) ([0c11138](https://github.com/GetJobber/atlantis/commit/0c111384378d7b4512f54047683646512fe2b9f9))
17
+
18
+
19
+
20
+
21
+
22
+ # [1.11.0](https://github.com/GetJobber/atlantis/compare/@jobber/hooks@1.10.0...@jobber/hooks@1.11.0) (2022-01-28)
23
+
24
+
25
+ ### Features
26
+
27
+ * Announce chip deletion and addition JOB-41252 ([#848](https://github.com/GetJobber/atlantis/issues/848)) ([f251b42](https://github.com/GetJobber/atlantis/commit/f251b42c5aa98ee07f7e16d3605a6bd965a8231b))
28
+
29
+
30
+
31
+
32
+
11
33
  # [1.10.0](https://github.com/GetJobber/atlantis/compare/@jobber/hooks@1.9.1...@jobber/hooks@1.10.0) (2022-01-21)
12
34
 
13
35
 
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export * from "./useAssert";
2
2
  export * from "./useCollectionQuery";
3
3
  export * from "./useFormState";
4
4
  export * from "./useIsMounted";
5
+ export * from "./useLiveAnnounce";
5
6
  export * from "./useOnKeyDown";
6
7
  export * from "./usePasswordStrength";
7
8
  export * from "./useRefocusOnActivator";
package/dist/index.js CHANGED
@@ -7,6 +7,7 @@ __export(require("./useAssert"));
7
7
  __export(require("./useCollectionQuery"));
8
8
  __export(require("./useFormState"));
9
9
  __export(require("./useIsMounted"));
10
+ __export(require("./useLiveAnnounce"));
10
11
  __export(require("./useOnKeyDown"));
11
12
  __export(require("./usePasswordStrength"));
12
13
  __export(require("./useRefocusOnActivator"));
@@ -15,7 +15,7 @@ export interface ListQueryType {
15
15
  };
16
16
  cursor: string;
17
17
  }>;
18
- totalCount: number;
18
+ totalCount?: number;
19
19
  };
20
20
  }
21
21
  export declare const LIST_QUERY: import("@apollo/client").DocumentNode;
@@ -5,7 +5,7 @@ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cook
5
5
  };
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  var client_1 = require("@apollo/client");
8
- exports.LIST_QUERY = client_1.gql(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n query ListQuery($cursor: String) {\n allPlanets(first: 4, after: $cursor) {\n pageInfo {\n hasNextPage\n endCursor\n }\n edges {\n node {\n name\n id\n }\n cursor\n }\n totalCount\n }\n }\n"], ["\n query ListQuery($cursor: String) {\n allPlanets(first: 4, after: $cursor) {\n pageInfo {\n hasNextPage\n endCursor\n }\n edges {\n node {\n name\n id\n }\n cursor\n }\n totalCount\n }\n }\n"])));
8
+ exports.LIST_QUERY = client_1.gql(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n query ListQuery($cursor: String) {\n allPlanets(first: 4, after: $cursor) {\n pageInfo {\n hasNextPage\n endCursor\n }\n edges {\n node {\n name\n id\n }\n cursor\n }\n }\n }\n"], ["\n query ListQuery($cursor: String) {\n allPlanets(first: 4, after: $cursor) {\n pageInfo {\n hasNextPage\n endCursor\n }\n edges {\n node {\n name\n id\n }\n cursor\n }\n }\n }\n"])));
9
9
  exports.apolloClient = new client_1.ApolloClient({
10
10
  uri: "https://swapi-graphql.netlify.app/.netlify/functions/index",
11
11
  cache: new client_1.InMemoryCache(),
@@ -1,8 +1,35 @@
1
1
  /// <reference types="jest" />
2
+ import { DocumentNode } from "@apollo/client";
2
3
  import { MockedResponse } from "@apollo/react-testing";
3
4
  import React from "react";
4
5
  export declare function wrapper(mocks: MockedResponse[]): React.FunctionComponent<{}>;
5
6
  export declare const listQueryResponseMock: jest.Mock<{
7
+ data: {
8
+ conversation: {
9
+ __typename: string;
10
+ smsMessages: {
11
+ __typename: string;
12
+ edges: {
13
+ __typename: string;
14
+ node: {
15
+ __typename: string;
16
+ id: any;
17
+ };
18
+ }[];
19
+ nodes: {
20
+ __typename: string;
21
+ id: any;
22
+ }[];
23
+ pageInfo: {
24
+ __typename: string;
25
+ endCursor: string;
26
+ hasNextPage: boolean;
27
+ };
28
+ };
29
+ };
30
+ };
31
+ }, [any]>;
32
+ export declare const listQueryWithTotalCountResponseMock: jest.Mock<{
6
33
  data: {
7
34
  conversation: {
8
35
  __typename: string;
@@ -41,44 +68,18 @@ export declare const subscriptionQueryMock: jest.Mock<{
41
68
  };
42
69
  };
43
70
  }, [any]>;
44
- export declare function buildListRequestMock(id?: string | undefined, searchTerm?: string | undefined): {
71
+ export declare function buildListRequestMock(query: DocumentNode, responseMock: jest.Mock, id?: string | undefined, searchTerm?: string | undefined): {
45
72
  request: {
46
- query: import("graphql").DocumentNode;
73
+ query: DocumentNode;
47
74
  variables: {
48
75
  searchTerm: string | undefined;
49
76
  };
50
77
  };
51
- result: () => {
52
- data: {
53
- conversation: {
54
- __typename: string;
55
- smsMessages: {
56
- __typename: string;
57
- edges: {
58
- __typename: string;
59
- node: {
60
- __typename: string;
61
- id: any;
62
- };
63
- }[];
64
- nodes: {
65
- __typename: string;
66
- id: any;
67
- }[];
68
- pageInfo: {
69
- __typename: string;
70
- endCursor: string;
71
- hasNextPage: boolean;
72
- };
73
- totalCount: number;
74
- };
75
- };
76
- };
77
- };
78
+ result: () => any;
78
79
  };
79
80
  export declare function buildSubscriptionRequestMock(id?: string | undefined): {
80
81
  request: {
81
- query: import("graphql").DocumentNode;
82
+ query: DocumentNode;
82
83
  };
83
84
  result: () => {
84
85
  data: {
@@ -94,39 +95,13 @@ export declare function buildSubscriptionRequestMock(id?: string | undefined): {
94
95
  };
95
96
  delay: number;
96
97
  };
97
- export declare function buildListRequestMockForNextPage(id?: string | undefined): {
98
+ export declare function buildListRequestMockForNextPage(query: DocumentNode, responseMock: jest.Mock, id?: string | undefined): {
98
99
  request: {
99
- query: import("graphql").DocumentNode;
100
+ query: DocumentNode;
100
101
  variables: {
101
102
  cursor: string;
102
103
  };
103
104
  };
104
- result: () => {
105
- data: {
106
- conversation: {
107
- __typename: string;
108
- smsMessages: {
109
- __typename: string;
110
- edges: {
111
- __typename: string;
112
- node: {
113
- __typename: string;
114
- id: any;
115
- };
116
- }[];
117
- nodes: {
118
- __typename: string;
119
- id: any;
120
- }[];
121
- pageInfo: {
122
- __typename: string;
123
- endCursor: string;
124
- hasNextPage: boolean;
125
- };
126
- totalCount: number;
127
- };
128
- };
129
- };
130
- };
105
+ result: () => any;
131
106
  };
132
107
  export declare function setListQueryMockHasNextPage(hasNextPage: boolean): void;
@@ -17,6 +17,38 @@ function wrapper(mocks) {
17
17
  exports.wrapper = wrapper;
18
18
  var listQueryHasNextPage = true;
19
19
  exports.listQueryResponseMock = jest.fn(function (id) {
20
+ return {
21
+ data: {
22
+ conversation: {
23
+ __typename: "Conversation",
24
+ smsMessages: {
25
+ __typename: "SMSMessageConnection",
26
+ edges: [
27
+ {
28
+ __typename: "SMSMessageEdge",
29
+ node: {
30
+ __typename: "SMSMessage",
31
+ id: id || uuid_1.v1(),
32
+ },
33
+ },
34
+ ],
35
+ nodes: [
36
+ {
37
+ __typename: "SMSMessage",
38
+ id: id || uuid_1.v1(),
39
+ },
40
+ ],
41
+ pageInfo: {
42
+ __typename: "PageInfo",
43
+ endCursor: "MZ",
44
+ hasNextPage: listQueryHasNextPage,
45
+ },
46
+ },
47
+ },
48
+ },
49
+ };
50
+ });
51
+ exports.listQueryWithTotalCountResponseMock = jest.fn(function (id) {
20
52
  return {
21
53
  data: {
22
54
  conversation: {
@@ -63,13 +95,13 @@ exports.subscriptionQueryMock = jest.fn(function (id) {
63
95
  },
64
96
  };
65
97
  });
66
- function buildListRequestMock(id, searchTerm) {
98
+ function buildListRequestMock(query, responseMock, id, searchTerm) {
67
99
  return {
68
100
  request: {
69
- query: queries_1.LIST_QUERY,
101
+ query: query,
70
102
  variables: { searchTerm: searchTerm },
71
103
  },
72
- result: function () { return exports.listQueryResponseMock(id); },
104
+ result: function () { return responseMock(id); },
73
105
  };
74
106
  }
75
107
  exports.buildListRequestMock = buildListRequestMock;
@@ -83,13 +115,13 @@ function buildSubscriptionRequestMock(id) {
83
115
  };
84
116
  }
85
117
  exports.buildSubscriptionRequestMock = buildSubscriptionRequestMock;
86
- function buildListRequestMockForNextPage(id) {
118
+ function buildListRequestMockForNextPage(query, responseMock, id) {
87
119
  return {
88
120
  request: {
89
- query: queries_1.LIST_QUERY,
121
+ query: query,
90
122
  variables: { cursor: "MZ" },
91
123
  },
92
- result: function () { return exports.listQueryResponseMock(id); },
124
+ result: function () { return responseMock(id); },
93
125
  };
94
126
  }
95
127
  exports.buildListRequestMockForNextPage = buildListRequestMockForNextPage;
@@ -1,4 +1,5 @@
1
1
  export declare const LIST_QUERY: import("@apollo/client").DocumentNode;
2
+ export declare const LIST_QUERY_WITH_TOTAL_COUNT: import("@apollo/client").DocumentNode;
2
3
  export interface ListQueryType {
3
4
  __typename?: "Query";
4
5
  conversation?: {
@@ -20,7 +21,7 @@ export interface ListQueryType {
20
21
  endCursor: string;
21
22
  hasNextPage: boolean;
22
23
  };
23
- totalCount: number;
24
+ totalCount?: number;
24
25
  };
25
26
  };
26
27
  }
@@ -5,6 +5,7 @@ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cook
5
5
  };
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  var client_1 = require("@apollo/client");
8
- exports.LIST_QUERY = client_1.gql(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n query ConversationMessages($cursor: string, $searchTerm: string) {\n conversation(id: \"MQ==\") {\n smsMessages(first: 1, after: $cursor, searchTerm: $searchTerm) {\n edges {\n node {\n __typename\n id\n }\n }\n nodes {\n __typename\n id\n }\n pageInfo {\n endCursor\n hasNextPage\n }\n totalCount\n }\n }\n }\n"], ["\n query ConversationMessages($cursor: string, $searchTerm: string) {\n conversation(id: \"MQ==\") {\n smsMessages(first: 1, after: $cursor, searchTerm: $searchTerm) {\n edges {\n node {\n __typename\n id\n }\n }\n nodes {\n __typename\n id\n }\n pageInfo {\n endCursor\n hasNextPage\n }\n totalCount\n }\n }\n }\n"])));
9
- exports.SUBSCRIPTION_QUERY = client_1.gql(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n subscription ConversationMessage($conversationId: EncodedId!) {\n conversationMessage(conversationId: $conversationId) {\n smsMessage {\n __typename\n id\n }\n }\n }\n"], ["\n subscription ConversationMessage($conversationId: EncodedId!) {\n conversationMessage(conversationId: $conversationId) {\n smsMessage {\n __typename\n id\n }\n }\n }\n"])));
10
- var templateObject_1, templateObject_2;
8
+ exports.LIST_QUERY = client_1.gql(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n query ConversationMessages($cursor: string, $searchTerm: string) {\n conversation(id: \"MQ==\") {\n smsMessages(first: 1, after: $cursor, searchTerm: $searchTerm) {\n edges {\n node {\n __typename\n id\n }\n }\n nodes {\n __typename\n id\n }\n pageInfo {\n endCursor\n hasNextPage\n }\n }\n }\n }\n"], ["\n query ConversationMessages($cursor: string, $searchTerm: string) {\n conversation(id: \"MQ==\") {\n smsMessages(first: 1, after: $cursor, searchTerm: $searchTerm) {\n edges {\n node {\n __typename\n id\n }\n }\n nodes {\n __typename\n id\n }\n pageInfo {\n endCursor\n hasNextPage\n }\n }\n }\n }\n"])));
9
+ exports.LIST_QUERY_WITH_TOTAL_COUNT = client_1.gql(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n query ConversationMessages($cursor: string, $searchTerm: string) {\n conversation(id: \"MQ==\") {\n smsMessages(first: 1, after: $cursor, searchTerm: $searchTerm) {\n edges {\n node {\n __typename\n id\n }\n }\n nodes {\n __typename\n id\n }\n pageInfo {\n endCursor\n hasNextPage\n }\n totalCount\n }\n }\n }\n"], ["\n query ConversationMessages($cursor: string, $searchTerm: string) {\n conversation(id: \"MQ==\") {\n smsMessages(first: 1, after: $cursor, searchTerm: $searchTerm) {\n edges {\n node {\n __typename\n id\n }\n }\n nodes {\n __typename\n id\n }\n pageInfo {\n endCursor\n hasNextPage\n }\n totalCount\n }\n }\n }\n"])));
10
+ exports.SUBSCRIPTION_QUERY = client_1.gql(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n subscription ConversationMessage($conversationId: EncodedId!) {\n conversationMessage(conversationId: $conversationId) {\n smsMessage {\n __typename\n id\n }\n }\n }\n"], ["\n subscription ConversationMessage($conversationId: EncodedId!) {\n conversationMessage(conversationId: $conversationId) {\n smsMessage {\n __typename\n id\n }\n }\n }\n"])));
11
+ var templateObject_1, templateObject_2, templateObject_3;
@@ -52,7 +52,7 @@ interface Collection {
52
52
  hasNextPage: boolean;
53
53
  [otherProperties: string]: unknown;
54
54
  };
55
- totalCount: number;
55
+ totalCount?: number;
56
56
  [otherProperties: string]: unknown;
57
57
  }
58
58
  interface CollectionQueryResult<TQuery> {
@@ -165,10 +165,7 @@ function fetchMoreUpdateQueryHandler(prev, fetchMoreResult, getCollectionByPath)
165
165
  if (outputCollection.edges && nextCollection.edges) {
166
166
  outputCollection.edges = getUpdatedEdges(outputCollection.edges, nextCollection.edges);
167
167
  }
168
- Object.assign(outputCollection, {
169
- pageInfo: lodash_1.cloneDeep(nextCollection.pageInfo),
170
- totalCount: nextCollection.totalCount,
171
- });
168
+ Object.assign(outputCollection, __assign({ pageInfo: lodash_1.cloneDeep(nextCollection.pageInfo) }, getTotalCount(nextCollection.totalCount)));
172
169
  return output;
173
170
  }
174
171
  function subscribeToMoreHandler(isSearching, prev, getCollectionByPath, subscriptionData, getNodeByPath) {
@@ -186,12 +183,15 @@ function subscribeToMoreHandler(isSearching, prev, getCollectionByPath, subscrip
186
183
  if (outputCollection.edges) {
187
184
  outputCollection.edges = getUpdatedEdges(outputCollection.edges, [uniqueEdges_1.createEdge(node)], false);
188
185
  }
189
- Object.assign(outputCollection, {
190
- pageInfo: lodash_1.cloneDeep(outputCollection.pageInfo),
191
- totalCount: outputCollection.totalCount + 1,
192
- });
186
+ Object.assign(outputCollection, __assign({ pageInfo: lodash_1.cloneDeep(outputCollection.pageInfo) }, getTotalCount(outputCollection.totalCount, 1)));
193
187
  return output;
194
188
  }
189
+ function getTotalCount(totalCount, additionalCount) {
190
+ if (additionalCount === void 0) { additionalCount = 0; }
191
+ return totalCount !== undefined
192
+ ? { totalCount: totalCount + additionalCount }
193
+ : {};
194
+ }
195
195
  function isAlreadyUpdated(outputCollection, newNode) {
196
196
  var edgesAlreadyUpdated = true;
197
197
  var nodesAlreadyUpdated = true;