@sprucelabs/spruce-location-utils 9.1.0 → 9.3.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.
@@ -1,9 +1,9 @@
1
1
  import LocationListCardViewController, { LocationListCardViewControllerOptions } from './viewControllers/LocationListCard.vc';
2
2
  declare module '@sprucelabs/heartwood-view-controllers/build/types/heartwood.types' {
3
3
  interface ViewControllerMap {
4
- 'location-list-card': LocationListCardViewController;
4
+ 'locations.list-card': LocationListCardViewController;
5
5
  }
6
6
  interface ViewControllerOptionsMap {
7
- 'location-list-card': LocationListCardViewControllerOptions;
7
+ 'locations.list-card': LocationListCardViewControllerOptions;
8
8
  }
9
9
  }
@@ -10,14 +10,15 @@ export default class LocationListCardViewController extends AbstractViewControll
10
10
  constructor(options: LocationListCardViewControllerOptions & ViewControllerOptions);
11
11
  private ActiveRecordCardVc;
12
12
  private renderRow;
13
- selectLocation(id: string): void;
13
+ selectLocation(id: string): Promise<void>;
14
14
  private handleClickLocation;
15
15
  private handleDeleteLocation;
16
16
  getCardVc(): import("@sprucelabs/heartwood-view-controllers").CardViewController;
17
17
  getActiveRecordVc(): ActiveRecordCardViewController;
18
18
  getSelectedLocationId(): string | undefined;
19
19
  getListVc(): import("@sprucelabs/heartwood-view-controllers").ListViewController;
20
- load(): Promise<void>;
20
+ load(targetAndPayload?: LocationListLoadOptions): Promise<void>;
21
+ getIsLoaded(): boolean;
21
22
  render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
22
23
  }
23
24
  type OnDeleteHandler = (location: Location) => void;
@@ -29,5 +30,7 @@ export type LocationListCardViewControllerOptions = {
29
30
  selectedLocationId?: string;
30
31
  footerButtons?: Button[];
31
32
  shouldRenderDeleteButtons?: boolean;
33
+ id?: string;
32
34
  };
35
+ export type LocationListLoadOptions = SpruceSchemas.Mercury.v2020_12_25.ListLocationsEmitTargetAndPayload;
33
36
  export {};
@@ -12,15 +12,21 @@ import { locationRenderer } from '@sprucelabs/spruce-skill-utils';
12
12
  class LocationListCardViewController extends AbstractViewController {
13
13
  constructor(options) {
14
14
  super(options);
15
- const { onDelete, selectedLocationId, footerButtons, currentOrganizationId, onClick, shouldRenderDeleteButtons, } = options;
15
+ const { id, onDelete, selectedLocationId, footerButtons, currentOrganizationId, onClick, shouldRenderDeleteButtons, } = options;
16
16
  this.shouldRenderDeleteButtons = shouldRenderDeleteButtons !== null && shouldRenderDeleteButtons !== void 0 ? shouldRenderDeleteButtons : false;
17
17
  this.onDeleteHandler = onDelete;
18
18
  this.selectedLocationId = selectedLocationId;
19
19
  this.onClickHandler = onClick;
20
- this.activeRecordCardVc = this.ActiveRecordCardVc(currentOrganizationId, footerButtons);
20
+ this.activeRecordCardVc = this.ActiveRecordCardVc({
21
+ id,
22
+ currentOrganizationId,
23
+ footerButtons,
24
+ });
21
25
  }
22
- ActiveRecordCardVc(currentOrganizationId, footerButtons) {
26
+ ActiveRecordCardVc(options) {
27
+ const { currentOrganizationId, footerButtons, id } = options;
23
28
  return this.Controller('activeRecordCard', buildActiveRecordCard({
29
+ id,
24
30
  header: {
25
31
  title: 'Your locations',
26
32
  },
@@ -49,6 +55,15 @@ class LocationListCardViewController extends AbstractViewController {
49
55
  },
50
56
  },
51
57
  ];
58
+ if (!this.onClickHandler) {
59
+ cells.unshift({
60
+ id: 'checkbox',
61
+ checkboxInput: {
62
+ name: 'isSelected',
63
+ isInteractive: false,
64
+ },
65
+ });
66
+ }
52
67
  if (this.shouldRenderDeleteButtons) {
53
68
  cells.push({
54
69
  button: {
@@ -69,8 +84,19 @@ class LocationListCardViewController extends AbstractViewController {
69
84
  };
70
85
  }
71
86
  selectLocation(id) {
72
- this.selectedLocationId = id;
73
- this.activeRecordCardVc.setSelectedRows([id]);
87
+ return __awaiter(this, void 0, void 0, function* () {
88
+ if (this.selectedLocationId === id) {
89
+ return;
90
+ }
91
+ if (this.selectedLocationId) {
92
+ const rowVc = this.activeRecordCardVc.getRowVc(this.selectedLocationId);
93
+ yield rowVc.setValue('isSelected', false);
94
+ }
95
+ this.selectedLocationId = id;
96
+ this.activeRecordCardVc.setSelectedRows([id]);
97
+ const rowVc = this.activeRecordCardVc.getRowVc(id);
98
+ yield rowVc.setValue('isSelected', true);
99
+ });
74
100
  }
75
101
  handleClickLocation(location) {
76
102
  var _a;
@@ -79,7 +105,7 @@ class LocationListCardViewController extends AbstractViewController {
79
105
  (_a = this.onClickHandler) === null || _a === void 0 ? void 0 : _a.call(this, location);
80
106
  return;
81
107
  }
82
- this.selectLocation(location.id);
108
+ yield this.selectLocation(location.id);
83
109
  });
84
110
  }
85
111
  handleDeleteLocation(location) {
@@ -124,11 +150,21 @@ class LocationListCardViewController extends AbstractViewController {
124
150
  getListVc() {
125
151
  return this.activeRecordCardVc.getListVc();
126
152
  }
127
- load() {
153
+ load(targetAndPayload) {
128
154
  return __awaiter(this, void 0, void 0, function* () {
155
+ const { target, payload } = targetAndPayload !== null && targetAndPayload !== void 0 ? targetAndPayload : {};
156
+ if (target) {
157
+ this.activeRecordCardVc.setTarget(target);
158
+ }
159
+ if (payload) {
160
+ this.activeRecordCardVc.setPayload(payload);
161
+ }
129
162
  yield this.activeRecordCardVc.load();
130
163
  });
131
164
  }
165
+ getIsLoaded() {
166
+ return this.activeRecordCardVc.getIsLoaded();
167
+ }
132
168
  render() {
133
169
  return this.activeRecordCardVc.render();
134
170
  }
@@ -1,9 +1,9 @@
1
1
  import LocationListCardViewController, { LocationListCardViewControllerOptions } from './viewControllers/LocationListCard.vc';
2
2
  declare module '@sprucelabs/heartwood-view-controllers/build/types/heartwood.types' {
3
3
  interface ViewControllerMap {
4
- 'location-list-card': LocationListCardViewController;
4
+ 'locations.list-card': LocationListCardViewController;
5
5
  }
6
6
  interface ViewControllerOptionsMap {
7
- 'location-list-card': LocationListCardViewControllerOptions;
7
+ 'locations.list-card': LocationListCardViewControllerOptions;
8
8
  }
9
9
  }
@@ -10,14 +10,15 @@ export default class LocationListCardViewController extends AbstractViewControll
10
10
  constructor(options: LocationListCardViewControllerOptions & ViewControllerOptions);
11
11
  private ActiveRecordCardVc;
12
12
  private renderRow;
13
- selectLocation(id: string): void;
13
+ selectLocation(id: string): Promise<void>;
14
14
  private handleClickLocation;
15
15
  private handleDeleteLocation;
16
16
  getCardVc(): import("@sprucelabs/heartwood-view-controllers").CardViewController;
17
17
  getActiveRecordVc(): ActiveRecordCardViewController;
18
18
  getSelectedLocationId(): string | undefined;
19
19
  getListVc(): import("@sprucelabs/heartwood-view-controllers").ListViewController;
20
- load(): Promise<void>;
20
+ load(targetAndPayload?: LocationListLoadOptions): Promise<void>;
21
+ getIsLoaded(): boolean;
21
22
  render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
22
23
  }
23
24
  type OnDeleteHandler = (location: Location) => void;
@@ -29,5 +30,7 @@ export type LocationListCardViewControllerOptions = {
29
30
  selectedLocationId?: string;
30
31
  footerButtons?: Button[];
31
32
  shouldRenderDeleteButtons?: boolean;
33
+ id?: string;
32
34
  };
35
+ export type LocationListLoadOptions = SpruceSchemas.Mercury.v2020_12_25.ListLocationsEmitTargetAndPayload;
33
36
  export {};
@@ -5,15 +5,21 @@ const spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils");
5
5
  class LocationListCardViewController extends heartwood_view_controllers_1.AbstractViewController {
6
6
  constructor(options) {
7
7
  super(options);
8
- const { onDelete, selectedLocationId, footerButtons, currentOrganizationId, onClick, shouldRenderDeleteButtons, } = options;
8
+ const { id, onDelete, selectedLocationId, footerButtons, currentOrganizationId, onClick, shouldRenderDeleteButtons, } = options;
9
9
  this.shouldRenderDeleteButtons = shouldRenderDeleteButtons !== null && shouldRenderDeleteButtons !== void 0 ? shouldRenderDeleteButtons : false;
10
10
  this.onDeleteHandler = onDelete;
11
11
  this.selectedLocationId = selectedLocationId;
12
12
  this.onClickHandler = onClick;
13
- this.activeRecordCardVc = this.ActiveRecordCardVc(currentOrganizationId, footerButtons);
13
+ this.activeRecordCardVc = this.ActiveRecordCardVc({
14
+ id,
15
+ currentOrganizationId,
16
+ footerButtons,
17
+ });
14
18
  }
15
- ActiveRecordCardVc(currentOrganizationId, footerButtons) {
19
+ ActiveRecordCardVc(options) {
20
+ const { currentOrganizationId, footerButtons, id } = options;
16
21
  return this.Controller('activeRecordCard', (0, heartwood_view_controllers_1.buildActiveRecordCard)({
22
+ id,
17
23
  header: {
18
24
  title: 'Your locations',
19
25
  },
@@ -42,6 +48,15 @@ class LocationListCardViewController extends heartwood_view_controllers_1.Abstra
42
48
  },
43
49
  },
44
50
  ];
51
+ if (!this.onClickHandler) {
52
+ cells.unshift({
53
+ id: 'checkbox',
54
+ checkboxInput: {
55
+ name: 'isSelected',
56
+ isInteractive: false,
57
+ },
58
+ });
59
+ }
45
60
  if (this.shouldRenderDeleteButtons) {
46
61
  cells.push({
47
62
  button: {
@@ -61,9 +76,18 @@ class LocationListCardViewController extends heartwood_view_controllers_1.Abstra
61
76
  cells,
62
77
  };
63
78
  }
64
- selectLocation(id) {
79
+ async selectLocation(id) {
80
+ if (this.selectedLocationId === id) {
81
+ return;
82
+ }
83
+ if (this.selectedLocationId) {
84
+ const rowVc = this.activeRecordCardVc.getRowVc(this.selectedLocationId);
85
+ await rowVc.setValue('isSelected', false);
86
+ }
65
87
  this.selectedLocationId = id;
66
88
  this.activeRecordCardVc.setSelectedRows([id]);
89
+ const rowVc = this.activeRecordCardVc.getRowVc(id);
90
+ await rowVc.setValue('isSelected', true);
67
91
  }
68
92
  async handleClickLocation(location) {
69
93
  var _a;
@@ -71,7 +95,7 @@ class LocationListCardViewController extends heartwood_view_controllers_1.Abstra
71
95
  (_a = this.onClickHandler) === null || _a === void 0 ? void 0 : _a.call(this, location);
72
96
  return;
73
97
  }
74
- this.selectLocation(location.id);
98
+ await this.selectLocation(location.id);
75
99
  }
76
100
  async handleDeleteLocation(location) {
77
101
  var _a;
@@ -113,9 +137,19 @@ class LocationListCardViewController extends heartwood_view_controllers_1.Abstra
113
137
  getListVc() {
114
138
  return this.activeRecordCardVc.getListVc();
115
139
  }
116
- async load() {
140
+ async load(targetAndPayload) {
141
+ const { target, payload } = targetAndPayload !== null && targetAndPayload !== void 0 ? targetAndPayload : {};
142
+ if (target) {
143
+ this.activeRecordCardVc.setTarget(target);
144
+ }
145
+ if (payload) {
146
+ this.activeRecordCardVc.setPayload(payload);
147
+ }
117
148
  await this.activeRecordCardVc.load();
118
149
  }
150
+ getIsLoaded() {
151
+ return this.activeRecordCardVc.getIsLoaded();
152
+ }
119
153
  render() {
120
154
  return this.activeRecordCardVc.render();
121
155
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sprucelabs/spruce-location-utils",
3
3
  "description": "Location Utilities",
4
- "version": "9.1.0",
4
+ "version": "9.3.0",
5
5
  "skill": {
6
6
  "namespace": "locations"
7
7
  },