@sprucelabs/spruce-location-utils 9.2.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.
@@ -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;
@@ -31,4 +32,5 @@ export type LocationListCardViewControllerOptions = {
31
32
  shouldRenderDeleteButtons?: boolean;
32
33
  id?: string;
33
34
  };
35
+ export type LocationListLoadOptions = SpruceSchemas.Mercury.v2020_12_25.ListLocationsEmitTargetAndPayload;
34
36
  export {};
@@ -55,6 +55,15 @@ class LocationListCardViewController extends AbstractViewController {
55
55
  },
56
56
  },
57
57
  ];
58
+ if (!this.onClickHandler) {
59
+ cells.unshift({
60
+ id: 'checkbox',
61
+ checkboxInput: {
62
+ name: 'isSelected',
63
+ isInteractive: false,
64
+ },
65
+ });
66
+ }
58
67
  if (this.shouldRenderDeleteButtons) {
59
68
  cells.push({
60
69
  button: {
@@ -75,8 +84,19 @@ class LocationListCardViewController extends AbstractViewController {
75
84
  };
76
85
  }
77
86
  selectLocation(id) {
78
- this.selectedLocationId = id;
79
- 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
+ });
80
100
  }
81
101
  handleClickLocation(location) {
82
102
  var _a;
@@ -85,7 +105,7 @@ class LocationListCardViewController extends AbstractViewController {
85
105
  (_a = this.onClickHandler) === null || _a === void 0 ? void 0 : _a.call(this, location);
86
106
  return;
87
107
  }
88
- this.selectLocation(location.id);
108
+ yield this.selectLocation(location.id);
89
109
  });
90
110
  }
91
111
  handleDeleteLocation(location) {
@@ -130,11 +150,21 @@ class LocationListCardViewController extends AbstractViewController {
130
150
  getListVc() {
131
151
  return this.activeRecordCardVc.getListVc();
132
152
  }
133
- load() {
153
+ load(targetAndPayload) {
134
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
+ }
135
162
  yield this.activeRecordCardVc.load();
136
163
  });
137
164
  }
165
+ getIsLoaded() {
166
+ return this.activeRecordCardVc.getIsLoaded();
167
+ }
138
168
  render() {
139
169
  return this.activeRecordCardVc.render();
140
170
  }
@@ -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;
@@ -31,4 +32,5 @@ export type LocationListCardViewControllerOptions = {
31
32
  shouldRenderDeleteButtons?: boolean;
32
33
  id?: string;
33
34
  };
35
+ export type LocationListLoadOptions = SpruceSchemas.Mercury.v2020_12_25.ListLocationsEmitTargetAndPayload;
34
36
  export {};
@@ -48,6 +48,15 @@ class LocationListCardViewController extends heartwood_view_controllers_1.Abstra
48
48
  },
49
49
  },
50
50
  ];
51
+ if (!this.onClickHandler) {
52
+ cells.unshift({
53
+ id: 'checkbox',
54
+ checkboxInput: {
55
+ name: 'isSelected',
56
+ isInteractive: false,
57
+ },
58
+ });
59
+ }
51
60
  if (this.shouldRenderDeleteButtons) {
52
61
  cells.push({
53
62
  button: {
@@ -67,9 +76,18 @@ class LocationListCardViewController extends heartwood_view_controllers_1.Abstra
67
76
  cells,
68
77
  };
69
78
  }
70
- 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
+ }
71
87
  this.selectedLocationId = id;
72
88
  this.activeRecordCardVc.setSelectedRows([id]);
89
+ const rowVc = this.activeRecordCardVc.getRowVc(id);
90
+ await rowVc.setValue('isSelected', true);
73
91
  }
74
92
  async handleClickLocation(location) {
75
93
  var _a;
@@ -77,7 +95,7 @@ class LocationListCardViewController extends heartwood_view_controllers_1.Abstra
77
95
  (_a = this.onClickHandler) === null || _a === void 0 ? void 0 : _a.call(this, location);
78
96
  return;
79
97
  }
80
- this.selectLocation(location.id);
98
+ await this.selectLocation(location.id);
81
99
  }
82
100
  async handleDeleteLocation(location) {
83
101
  var _a;
@@ -119,9 +137,19 @@ class LocationListCardViewController extends heartwood_view_controllers_1.Abstra
119
137
  getListVc() {
120
138
  return this.activeRecordCardVc.getListVc();
121
139
  }
122
- 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
+ }
123
148
  await this.activeRecordCardVc.load();
124
149
  }
150
+ getIsLoaded() {
151
+ return this.activeRecordCardVc.getIsLoaded();
152
+ }
125
153
  render() {
126
154
  return this.activeRecordCardVc.render();
127
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.2.0",
4
+ "version": "9.3.0",
5
5
  "skill": {
6
6
  "namespace": "locations"
7
7
  },