@sprucelabs/spruce-location-utils 9.0.0 → 9.1.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
- locationListCard: LocationListCardViewController;
4
+ 'location-list-card': LocationListCardViewController;
5
5
  }
6
6
  interface ViewControllerOptionsMap {
7
- locationListCard: LocationListCardViewControllerOptions;
7
+ 'location-list-card': LocationListCardViewControllerOptions;
8
8
  }
9
9
  }
@@ -1,23 +1,17 @@
1
- import { AbstractViewController, SpruceSchemas, ViewControllerOptions, ActiveRecordCardViewController } from '@sprucelabs/heartwood-view-controllers';
2
- type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
3
- type Location = SpruceSchemas.Spruce.v2020_07_22.Location;
4
- type Button = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Button;
5
- export type LocationListCardViewControllerOptions = {
6
- onDelete?: (location: Location) => void;
7
- onEdit?: (location: Location) => void;
8
- currentOrganizationId: string;
9
- selectedLocationId?: string;
10
- footerButtons?: Button[];
11
- };
1
+ import { AbstractViewController, SpruceSchemas, ViewControllerOptions, ActiveRecordCardViewController, Button, Card } from '@sprucelabs/heartwood-view-controllers';
2
+ import { Location } from '@sprucelabs/spruce-core-schemas';
12
3
  export default class LocationListCardViewController extends AbstractViewController<Card> {
13
4
  static id: string;
14
- private onDelete?;
5
+ private onDeleteHandler?;
15
6
  private selectedLocationId?;
16
- private onEdit?;
7
+ private onClickHandler?;
17
8
  private activeRecordCardVc;
9
+ private shouldRenderDeleteButtons;
18
10
  constructor(options: LocationListCardViewControllerOptions & ViewControllerOptions);
19
11
  private ActiveRecordCardVc;
20
12
  private renderRow;
13
+ selectLocation(id: string): void;
14
+ private handleClickLocation;
21
15
  private handleDeleteLocation;
22
16
  getCardVc(): import("@sprucelabs/heartwood-view-controllers").CardViewController;
23
17
  getActiveRecordVc(): ActiveRecordCardViewController;
@@ -26,4 +20,14 @@ export default class LocationListCardViewController extends AbstractViewControll
26
20
  load(): Promise<void>;
27
21
  render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
28
22
  }
23
+ type OnDeleteHandler = (location: Location) => void;
24
+ type OnEditHandler = (location: Location) => void;
25
+ export type LocationListCardViewControllerOptions = {
26
+ onDelete?: OnDeleteHandler;
27
+ onClick?: OnEditHandler;
28
+ currentOrganizationId: string;
29
+ selectedLocationId?: string;
30
+ footerButtons?: Button[];
31
+ shouldRenderDeleteButtons?: boolean;
32
+ };
29
33
  export {};
@@ -8,15 +8,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { AbstractViewController, buildActiveRecordCard, } from '@sprucelabs/heartwood-view-controllers';
11
- import { eventResponseUtil } from '@sprucelabs/spruce-event-utils';
12
11
  import { locationRenderer } from '@sprucelabs/spruce-skill-utils';
13
12
  class LocationListCardViewController extends AbstractViewController {
14
13
  constructor(options) {
15
14
  super(options);
16
- const { onDelete, selectedLocationId, footerButtons, currentOrganizationId, onEdit, } = options;
17
- this.onDelete = onDelete;
15
+ const { onDelete, selectedLocationId, footerButtons, currentOrganizationId, onClick, shouldRenderDeleteButtons, } = options;
16
+ this.shouldRenderDeleteButtons = shouldRenderDeleteButtons !== null && shouldRenderDeleteButtons !== void 0 ? shouldRenderDeleteButtons : false;
17
+ this.onDeleteHandler = onDelete;
18
18
  this.selectedLocationId = selectedLocationId;
19
- this.onEdit = onEdit;
19
+ this.onClickHandler = onClick;
20
20
  this.activeRecordCardVc = this.ActiveRecordCardVc(currentOrganizationId, footerButtons);
21
21
  }
22
22
  ActiveRecordCardVc(currentOrganizationId, footerButtons) {
@@ -39,40 +39,54 @@ class LocationListCardViewController extends AbstractViewController {
39
39
  }
40
40
  renderRow(location) {
41
41
  const address = location.address;
42
+ const cells = [
43
+ {
44
+ text: {
45
+ content: location.name,
46
+ },
47
+ subText: {
48
+ content: locationRenderer.renderAddress(address),
49
+ },
50
+ },
51
+ ];
52
+ if (this.shouldRenderDeleteButtons) {
53
+ cells.push({
54
+ button: {
55
+ id: 'delete',
56
+ lineIcon: 'delete',
57
+ type: 'destructive',
58
+ onClick: () => __awaiter(this, void 0, void 0, function* () {
59
+ return this.handleDeleteLocation(location);
60
+ }),
61
+ },
62
+ });
63
+ }
42
64
  return {
43
65
  id: location.id,
44
66
  isSelected: this.selectedLocationId === location.id,
45
- onClick: () => __awaiter(this, void 0, void 0, function* () {
46
- var _a;
47
- return (_a = this.onEdit) === null || _a === void 0 ? void 0 : _a.call(this, location);
48
- }),
49
- cells: [
50
- {
51
- text: {
52
- content: location.name,
53
- },
54
- subText: {
55
- content: locationRenderer.renderAddress(address),
56
- },
57
- },
58
- {
59
- button: {
60
- id: 'delete',
61
- lineIcon: 'delete',
62
- type: 'destructive',
63
- onClick: () => __awaiter(this, void 0, void 0, function* () {
64
- return this.handleDeleteLocation(location);
65
- }),
66
- },
67
- },
68
- ],
67
+ onClick: () => this.handleClickLocation(location),
68
+ cells,
69
69
  };
70
70
  }
71
+ selectLocation(id) {
72
+ this.selectedLocationId = id;
73
+ this.activeRecordCardVc.setSelectedRows([id]);
74
+ }
75
+ handleClickLocation(location) {
76
+ var _a;
77
+ return __awaiter(this, void 0, void 0, function* () {
78
+ if (this.onClickHandler) {
79
+ (_a = this.onClickHandler) === null || _a === void 0 ? void 0 : _a.call(this, location);
80
+ return;
81
+ }
82
+ this.selectLocation(location.id);
83
+ });
84
+ }
71
85
  handleDeleteLocation(location) {
72
86
  var _a;
73
87
  return __awaiter(this, void 0, void 0, function* () {
74
88
  const shouldDelete = yield this.confirm({
75
- title: `Delete ${location.name}`,
89
+ title: `Delete ${location.name}?`,
76
90
  isDestructive: true,
77
91
  });
78
92
  if (!shouldDelete) {
@@ -81,13 +95,12 @@ class LocationListCardViewController extends AbstractViewController {
81
95
  this.activeRecordCardVc.setIsBusy(true);
82
96
  try {
83
97
  const client = yield this.connectToApi();
84
- const results = yield client.emit('delete-location::v2020_12_25', {
98
+ yield client.emitAndFlattenResponses('delete-location::v2020_12_25', {
85
99
  target: {
86
100
  locationId: location.id,
87
101
  },
88
102
  });
89
- eventResponseUtil.getFirstResponseOrThrow(results);
90
- (_a = this.onDelete) === null || _a === void 0 ? void 0 : _a.call(this, location);
103
+ (_a = this.onDeleteHandler) === null || _a === void 0 ? void 0 : _a.call(this, location);
91
104
  this.activeRecordCardVc.deleteRow(location.id);
92
105
  }
93
106
  catch (err) {
@@ -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
- locationListCard: LocationListCardViewController;
4
+ 'location-list-card': LocationListCardViewController;
5
5
  }
6
6
  interface ViewControllerOptionsMap {
7
- locationListCard: LocationListCardViewControllerOptions;
7
+ 'location-list-card': LocationListCardViewControllerOptions;
8
8
  }
9
9
  }
@@ -1,23 +1,17 @@
1
- import { AbstractViewController, SpruceSchemas, ViewControllerOptions, ActiveRecordCardViewController } from '@sprucelabs/heartwood-view-controllers';
2
- type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
3
- type Location = SpruceSchemas.Spruce.v2020_07_22.Location;
4
- type Button = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Button;
5
- export type LocationListCardViewControllerOptions = {
6
- onDelete?: (location: Location) => void;
7
- onEdit?: (location: Location) => void;
8
- currentOrganizationId: string;
9
- selectedLocationId?: string;
10
- footerButtons?: Button[];
11
- };
1
+ import { AbstractViewController, SpruceSchemas, ViewControllerOptions, ActiveRecordCardViewController, Button, Card } from '@sprucelabs/heartwood-view-controllers';
2
+ import { Location } from '@sprucelabs/spruce-core-schemas';
12
3
  export default class LocationListCardViewController extends AbstractViewController<Card> {
13
4
  static id: string;
14
- private onDelete?;
5
+ private onDeleteHandler?;
15
6
  private selectedLocationId?;
16
- private onEdit?;
7
+ private onClickHandler?;
17
8
  private activeRecordCardVc;
9
+ private shouldRenderDeleteButtons;
18
10
  constructor(options: LocationListCardViewControllerOptions & ViewControllerOptions);
19
11
  private ActiveRecordCardVc;
20
12
  private renderRow;
13
+ selectLocation(id: string): void;
14
+ private handleClickLocation;
21
15
  private handleDeleteLocation;
22
16
  getCardVc(): import("@sprucelabs/heartwood-view-controllers").CardViewController;
23
17
  getActiveRecordVc(): ActiveRecordCardViewController;
@@ -26,4 +20,14 @@ export default class LocationListCardViewController extends AbstractViewControll
26
20
  load(): Promise<void>;
27
21
  render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
28
22
  }
23
+ type OnDeleteHandler = (location: Location) => void;
24
+ type OnEditHandler = (location: Location) => void;
25
+ export type LocationListCardViewControllerOptions = {
26
+ onDelete?: OnDeleteHandler;
27
+ onClick?: OnEditHandler;
28
+ currentOrganizationId: string;
29
+ selectedLocationId?: string;
30
+ footerButtons?: Button[];
31
+ shouldRenderDeleteButtons?: boolean;
32
+ };
29
33
  export {};
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const heartwood_view_controllers_1 = require("@sprucelabs/heartwood-view-controllers");
4
- const spruce_event_utils_1 = require("@sprucelabs/spruce-event-utils");
5
4
  const spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils");
6
5
  class LocationListCardViewController extends heartwood_view_controllers_1.AbstractViewController {
7
6
  constructor(options) {
8
7
  super(options);
9
- const { onDelete, selectedLocationId, footerButtons, currentOrganizationId, onEdit, } = options;
10
- this.onDelete = onDelete;
8
+ const { onDelete, selectedLocationId, footerButtons, currentOrganizationId, onClick, shouldRenderDeleteButtons, } = options;
9
+ this.shouldRenderDeleteButtons = shouldRenderDeleteButtons !== null && shouldRenderDeleteButtons !== void 0 ? shouldRenderDeleteButtons : false;
10
+ this.onDeleteHandler = onDelete;
11
11
  this.selectedLocationId = selectedLocationId;
12
- this.onEdit = onEdit;
12
+ this.onClickHandler = onClick;
13
13
  this.activeRecordCardVc = this.ActiveRecordCardVc(currentOrganizationId, footerButtons);
14
14
  }
15
15
  ActiveRecordCardVc(currentOrganizationId, footerButtons) {
@@ -32,39 +32,51 @@ class LocationListCardViewController extends heartwood_view_controllers_1.Abstra
32
32
  }
33
33
  renderRow(location) {
34
34
  const address = location.address;
35
- return {
36
- id: location.id,
37
- isSelected: this.selectedLocationId === location.id,
38
- onClick: async () => {
39
- var _a;
40
- return (_a = this.onEdit) === null || _a === void 0 ? void 0 : _a.call(this, location);
41
- },
42
- cells: [
43
- {
44
- text: {
45
- content: location.name,
46
- },
47
- subText: {
48
- content: spruce_skill_utils_1.locationRenderer.renderAddress(address),
49
- },
35
+ const cells = [
36
+ {
37
+ text: {
38
+ content: location.name,
39
+ },
40
+ subText: {
41
+ content: spruce_skill_utils_1.locationRenderer.renderAddress(address),
50
42
  },
51
- {
52
- button: {
53
- id: 'delete',
54
- lineIcon: 'delete',
55
- type: 'destructive',
56
- onClick: async () => {
57
- return this.handleDeleteLocation(location);
58
- },
43
+ },
44
+ ];
45
+ if (this.shouldRenderDeleteButtons) {
46
+ cells.push({
47
+ button: {
48
+ id: 'delete',
49
+ lineIcon: 'delete',
50
+ type: 'destructive',
51
+ onClick: async () => {
52
+ return this.handleDeleteLocation(location);
59
53
  },
60
54
  },
61
- ],
55
+ });
56
+ }
57
+ return {
58
+ id: location.id,
59
+ isSelected: this.selectedLocationId === location.id,
60
+ onClick: () => this.handleClickLocation(location),
61
+ cells,
62
62
  };
63
63
  }
64
+ selectLocation(id) {
65
+ this.selectedLocationId = id;
66
+ this.activeRecordCardVc.setSelectedRows([id]);
67
+ }
68
+ async handleClickLocation(location) {
69
+ var _a;
70
+ if (this.onClickHandler) {
71
+ (_a = this.onClickHandler) === null || _a === void 0 ? void 0 : _a.call(this, location);
72
+ return;
73
+ }
74
+ this.selectLocation(location.id);
75
+ }
64
76
  async handleDeleteLocation(location) {
65
77
  var _a;
66
78
  const shouldDelete = await this.confirm({
67
- title: `Delete ${location.name}`,
79
+ title: `Delete ${location.name}?`,
68
80
  isDestructive: true,
69
81
  });
70
82
  if (!shouldDelete) {
@@ -73,13 +85,12 @@ class LocationListCardViewController extends heartwood_view_controllers_1.Abstra
73
85
  this.activeRecordCardVc.setIsBusy(true);
74
86
  try {
75
87
  const client = await this.connectToApi();
76
- const results = await client.emit('delete-location::v2020_12_25', {
88
+ await client.emitAndFlattenResponses('delete-location::v2020_12_25', {
77
89
  target: {
78
90
  locationId: location.id,
79
91
  },
80
92
  });
81
- spruce_event_utils_1.eventResponseUtil.getFirstResponseOrThrow(results);
82
- (_a = this.onDelete) === null || _a === void 0 ? void 0 : _a.call(this, location);
93
+ (_a = this.onDeleteHandler) === null || _a === void 0 ? void 0 : _a.call(this, location);
83
94
  this.activeRecordCardVc.deleteRow(location.id);
84
95
  }
85
96
  catch (err) {
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.0.0",
4
+ "version": "9.1.0",
5
5
  "skill": {
6
6
  "namespace": "locations"
7
7
  },