@sprucelabs/spruce-location-utils 2.0.16 → 2.1.3

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 +1,2 @@
1
1
  export { default as organizationAssert } from './tests/utilities/organizationAssert';
2
+ export { default as LocationListViewController } from './viewControllers/LocationListCard.vc';
@@ -1 +1,2 @@
1
1
  export { default as organizationAssert } from './tests/utilities/organizationAssert.js';
2
+ export { default as LocationListViewController } from './viewControllers/LocationListCard.vc.js';
@@ -2,15 +2,15 @@ import { SkillViewController } from '@sprucelabs/heartwood-view-controllers';
2
2
  import { OrganizationFixture, ViewFixture } from '@sprucelabs/spruce-test-fixtures';
3
3
  declare const organizationAssert: {
4
4
  assertRedirectsToAddOrgIfNoOrgExists(options: {
5
- viewFixture: ViewFixture;
6
- organizationFixture: OrganizationFixture;
5
+ views: ViewFixture;
6
+ organizations: OrganizationFixture;
7
7
  vc: SkillViewController<any>;
8
8
  didAddOrgRedirectDestination: string;
9
9
  }): Promise<void>;
10
10
  assertDoesNotRedirectToAddAOrgIfOrgExists(options: {
11
11
  vc: SkillViewController<any>;
12
- viewFixture: ViewFixture;
13
- organizationFixture: OrganizationFixture;
12
+ views: ViewFixture;
13
+ organizations: OrganizationFixture;
14
14
  }): Promise<void>;
15
15
  };
16
16
  export default organizationAssert;
@@ -15,18 +15,18 @@ const organizationAssert = {
15
15
  assertRedirectsToAddOrgIfNoOrgExists(options) {
16
16
  return __awaiter(this, void 0, void 0, function* () {
17
17
  assertOptions(options, [
18
- 'viewFixture',
18
+ 'views',
19
19
  'vc',
20
- 'organizationFixture',
20
+ 'organizations',
21
21
  'didAddOrgRedirectDestination',
22
22
  ]);
23
- const { viewFixture, vc, organizationFixture, didAddOrgRedirectDestination: redirectDestination, } = options;
24
- yield organizationFixture.deleteAllOrganizations();
23
+ const { views, vc, organizations, didAddOrgRedirectDestination: redirectDestination, } = options;
24
+ yield organizations.deleteAllOrganizations();
25
25
  TestRouter.setShouldThrowWhenRedirectingToBadSvc(false);
26
- const router = viewFixture.getRouter();
26
+ const router = views.getRouter();
27
27
  yield vcAssertUtil.assertActionRedirects({
28
28
  router,
29
- action: () => viewFixture.load(vc),
29
+ action: () => views.load(vc),
30
30
  destination: {
31
31
  id: 'organization.add',
32
32
  args: {
@@ -41,19 +41,19 @@ const organizationAssert = {
41
41
  },
42
42
  assertDoesNotRedirectToAddAOrgIfOrgExists(options) {
43
43
  return __awaiter(this, void 0, void 0, function* () {
44
- assertOptions(options, ['viewFixture', 'vc', 'organizationFixture']);
45
- const { vc, viewFixture, organizationFixture } = options;
46
- yield viewFixture.loginAsDemoPerson();
47
- const latest = yield organizationFixture.getNewestOrganization();
44
+ assertOptions(options, ['views', 'vc', 'organizations']);
45
+ const { vc, views, organizations } = options;
46
+ yield views.loginAsDemoPerson();
47
+ const latest = yield organizations.getNewestOrganization();
48
48
  if (!latest) {
49
- yield organizationFixture.seedDemoOrganization();
49
+ yield organizations.seedDemoOrganization();
50
50
  }
51
51
  let wasHit = false;
52
- yield viewFixture.getRouter().on('did-redirect', () => {
52
+ yield views.getRouter().on('did-redirect', () => {
53
53
  wasHit = true;
54
54
  });
55
55
  TestRouter.setShouldThrowWhenRedirectingToBadSvc(false);
56
- yield viewFixture.load(vc);
56
+ yield views.load(vc);
57
57
  TestRouter.setShouldThrowWhenRedirectingToBadSvc(true);
58
58
  assert.isFalse(wasHit, `I was redirected and didn't expect to be.`);
59
59
  });
@@ -0,0 +1,28 @@
1
+ import { AbstractViewController, SpruceSchemas, ViewControllerOptions, ActiveRecordCardViewController } from '@sprucelabs/heartwood-view-controllers';
2
+ declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
3
+ declare type Location = SpruceSchemas.Spruce.v2020_07_22.Location;
4
+ declare type Button = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Button;
5
+ export default class LocationListCardViewController extends AbstractViewController<Card> {
6
+ static id: string;
7
+ private onDelete?;
8
+ private selectedLocationId?;
9
+ private onEdit?;
10
+ private activeRecordCardVc;
11
+ constructor(options: ViewControllerOptions & {
12
+ onDelete?: (location: Location) => void;
13
+ onEdit?: (location: Location) => void;
14
+ currentOrganizationId: string;
15
+ selectedLocationId?: string;
16
+ footerButtons?: Button[];
17
+ });
18
+ private ActiveRecordCardVc;
19
+ private buildRow;
20
+ private handleDeleteLocation;
21
+ getCardVc(): import("@sprucelabs/heartwood-view-controllers").CardViewController;
22
+ getActiveRecordVc(): ActiveRecordCardViewController;
23
+ getSelectedLocationId(): string | undefined;
24
+ getListVc(): import("@sprucelabs/heartwood-view-controllers").ListViewController;
25
+ load(): Promise<void>;
26
+ render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
27
+ }
28
+ export {};
@@ -0,0 +1,126 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { AbstractViewController, buildActiveRecordCard, } from '@sprucelabs/heartwood-view-controllers';
11
+ import { eventResponseUtil } from '@sprucelabs/spruce-event-utils';
12
+ export default class LocationListCardViewController extends AbstractViewController {
13
+ constructor(options) {
14
+ super(options);
15
+ const { onDelete, selectedLocationId, footerButtons, currentOrganizationId, onEdit, } = options;
16
+ this.onDelete = onDelete;
17
+ this.selectedLocationId = selectedLocationId;
18
+ this.onEdit = onEdit;
19
+ this.activeRecordCardVc = this.ActiveRecordCardVc(currentOrganizationId, footerButtons);
20
+ }
21
+ ActiveRecordCardVc(currentOrganizationId, footerButtons) {
22
+ return this.Controller('activeRecordCard', buildActiveRecordCard({
23
+ header: {
24
+ title: 'Your locations',
25
+ },
26
+ eventName: 'list-locations::v2020_12_25',
27
+ target: {
28
+ organizationId: currentOrganizationId,
29
+ },
30
+ payload: {
31
+ includePrivateLocations: true,
32
+ },
33
+ responseKey: 'locations',
34
+ rowTransformer: this.buildRow.bind(this),
35
+ footer: footerButtons && {
36
+ buttons: footerButtons,
37
+ },
38
+ }));
39
+ }
40
+ buildRow(location) {
41
+ return {
42
+ id: location.id,
43
+ isSelected: this.selectedLocationId === location.id,
44
+ onClick: () => __awaiter(this, void 0, void 0, function* () {
45
+ var _a;
46
+ return (_a = this.onEdit) === null || _a === void 0 ? void 0 : _a.call(this, location);
47
+ }),
48
+ cells: [
49
+ {
50
+ text: {
51
+ content: location.name,
52
+ },
53
+ subText: {
54
+ content: `${location.address
55
+ ? `${location.address.street1}${location.address.street2
56
+ ? ` ${location.address.street2}`
57
+ : ``} ${location.address.city} ${location.address.zip}`
58
+ : ``}`,
59
+ },
60
+ },
61
+ {
62
+ button: {
63
+ id: 'delete',
64
+ lineIcon: 'delete',
65
+ type: 'destructive',
66
+ onClick: () => __awaiter(this, void 0, void 0, function* () {
67
+ return this.handleDeleteLocation(location);
68
+ }),
69
+ },
70
+ },
71
+ ].filter((c) => !!c),
72
+ };
73
+ }
74
+ handleDeleteLocation(location) {
75
+ var _a;
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ const shouldDelete = yield this.confirm({
78
+ title: `Delete ${location.name}`,
79
+ isDestructive: true,
80
+ });
81
+ if (!shouldDelete) {
82
+ return;
83
+ }
84
+ this.activeRecordCardVc.setIsBusy(true);
85
+ try {
86
+ const client = yield this.connectToApi();
87
+ const results = yield client.emit('delete-location::v2020_12_25', {
88
+ target: {
89
+ locationId: location.id,
90
+ },
91
+ });
92
+ eventResponseUtil.getFirstResponseOrThrow(results);
93
+ (_a = this.onDelete) === null || _a === void 0 ? void 0 : _a.call(this, location);
94
+ this.activeRecordCardVc.deleteRow(location.id);
95
+ }
96
+ catch (err) {
97
+ yield this.alert({
98
+ message: err.message,
99
+ style: 'error',
100
+ });
101
+ }
102
+ this.activeRecordCardVc.setIsBusy(false);
103
+ });
104
+ }
105
+ getCardVc() {
106
+ return this.activeRecordCardVc.getCardVc();
107
+ }
108
+ getActiveRecordVc() {
109
+ return this.activeRecordCardVc;
110
+ }
111
+ getSelectedLocationId() {
112
+ return this.selectedLocationId;
113
+ }
114
+ getListVc() {
115
+ return this.activeRecordCardVc.getListVc();
116
+ }
117
+ load() {
118
+ return __awaiter(this, void 0, void 0, function* () {
119
+ yield this.activeRecordCardVc.load();
120
+ });
121
+ }
122
+ render() {
123
+ return this.activeRecordCardVc.render();
124
+ }
125
+ }
126
+ LocationListCardViewController.id = 'location-list-card';
@@ -1 +1,2 @@
1
1
  export { default as organizationAssert } from './tests/utilities/organizationAssert';
2
+ export { default as LocationListViewController } from './viewControllers/LocationListCard.vc';
@@ -3,6 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.organizationAssert = void 0;
6
+ exports.LocationListViewController = exports.organizationAssert = void 0;
7
7
  var organizationAssert_1 = require("./tests/utilities/organizationAssert");
8
8
  Object.defineProperty(exports, "organizationAssert", { enumerable: true, get: function () { return __importDefault(organizationAssert_1).default; } });
9
+ var LocationListCard_vc_1 = require("./viewControllers/LocationListCard.vc");
10
+ Object.defineProperty(exports, "LocationListViewController", { enumerable: true, get: function () { return __importDefault(LocationListCard_vc_1).default; } });
@@ -2,15 +2,15 @@ import { SkillViewController } from '@sprucelabs/heartwood-view-controllers';
2
2
  import { OrganizationFixture, ViewFixture } from '@sprucelabs/spruce-test-fixtures';
3
3
  declare const organizationAssert: {
4
4
  assertRedirectsToAddOrgIfNoOrgExists(options: {
5
- viewFixture: ViewFixture;
6
- organizationFixture: OrganizationFixture;
5
+ views: ViewFixture;
6
+ organizations: OrganizationFixture;
7
7
  vc: SkillViewController<any>;
8
8
  didAddOrgRedirectDestination: string;
9
9
  }): Promise<void>;
10
10
  assertDoesNotRedirectToAddAOrgIfOrgExists(options: {
11
11
  vc: SkillViewController<any>;
12
- viewFixture: ViewFixture;
13
- organizationFixture: OrganizationFixture;
12
+ views: ViewFixture;
13
+ organizations: OrganizationFixture;
14
14
  }): Promise<void>;
15
15
  };
16
16
  export default organizationAssert;
@@ -7,18 +7,18 @@ const test_1 = require("@sprucelabs/test");
7
7
  const organizationAssert = {
8
8
  async assertRedirectsToAddOrgIfNoOrgExists(options) {
9
9
  (0, schema_1.assertOptions)(options, [
10
- 'viewFixture',
10
+ 'views',
11
11
  'vc',
12
- 'organizationFixture',
12
+ 'organizations',
13
13
  'didAddOrgRedirectDestination',
14
14
  ]);
15
- const { viewFixture, vc, organizationFixture, didAddOrgRedirectDestination: redirectDestination, } = options;
16
- await organizationFixture.deleteAllOrganizations();
15
+ const { views, vc, organizations, didAddOrgRedirectDestination: redirectDestination, } = options;
16
+ await organizations.deleteAllOrganizations();
17
17
  spruce_test_fixtures_1.TestRouter.setShouldThrowWhenRedirectingToBadSvc(false);
18
- const router = viewFixture.getRouter();
18
+ const router = views.getRouter();
19
19
  await heartwood_view_controllers_1.vcAssertUtil.assertActionRedirects({
20
20
  router,
21
- action: () => viewFixture.load(vc),
21
+ action: () => views.load(vc),
22
22
  destination: {
23
23
  id: 'organization.add',
24
24
  args: {
@@ -31,19 +31,19 @@ const organizationAssert = {
31
31
  spruce_test_fixtures_1.TestRouter.setShouldThrowWhenRedirectingToBadSvc(true);
32
32
  },
33
33
  async assertDoesNotRedirectToAddAOrgIfOrgExists(options) {
34
- (0, schema_1.assertOptions)(options, ['viewFixture', 'vc', 'organizationFixture']);
35
- const { vc, viewFixture, organizationFixture } = options;
36
- await viewFixture.loginAsDemoPerson();
37
- const latest = await organizationFixture.getNewestOrganization();
34
+ (0, schema_1.assertOptions)(options, ['views', 'vc', 'organizations']);
35
+ const { vc, views, organizations } = options;
36
+ await views.loginAsDemoPerson();
37
+ const latest = await organizations.getNewestOrganization();
38
38
  if (!latest) {
39
- await organizationFixture.seedDemoOrganization();
39
+ await organizations.seedDemoOrganization();
40
40
  }
41
41
  let wasHit = false;
42
- await viewFixture.getRouter().on('did-redirect', () => {
42
+ await views.getRouter().on('did-redirect', () => {
43
43
  wasHit = true;
44
44
  });
45
45
  spruce_test_fixtures_1.TestRouter.setShouldThrowWhenRedirectingToBadSvc(false);
46
- await viewFixture.load(vc);
46
+ await views.load(vc);
47
47
  spruce_test_fixtures_1.TestRouter.setShouldThrowWhenRedirectingToBadSvc(true);
48
48
  test_1.assert.isFalse(wasHit, `I was redirected and didn't expect to be.`);
49
49
  },
@@ -0,0 +1,28 @@
1
+ import { AbstractViewController, SpruceSchemas, ViewControllerOptions, ActiveRecordCardViewController } from '@sprucelabs/heartwood-view-controllers';
2
+ declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
3
+ declare type Location = SpruceSchemas.Spruce.v2020_07_22.Location;
4
+ declare type Button = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Button;
5
+ export default class LocationListCardViewController extends AbstractViewController<Card> {
6
+ static id: string;
7
+ private onDelete?;
8
+ private selectedLocationId?;
9
+ private onEdit?;
10
+ private activeRecordCardVc;
11
+ constructor(options: ViewControllerOptions & {
12
+ onDelete?: (location: Location) => void;
13
+ onEdit?: (location: Location) => void;
14
+ currentOrganizationId: string;
15
+ selectedLocationId?: string;
16
+ footerButtons?: Button[];
17
+ });
18
+ private ActiveRecordCardVc;
19
+ private buildRow;
20
+ private handleDeleteLocation;
21
+ getCardVc(): import("@sprucelabs/heartwood-view-controllers").CardViewController;
22
+ getActiveRecordVc(): ActiveRecordCardViewController;
23
+ getSelectedLocationId(): string | undefined;
24
+ getListVc(): import("@sprucelabs/heartwood-view-controllers").ListViewController;
25
+ load(): Promise<void>;
26
+ render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
27
+ }
28
+ export {};
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const heartwood_view_controllers_1 = require("@sprucelabs/heartwood-view-controllers");
4
+ const spruce_event_utils_1 = require("@sprucelabs/spruce-event-utils");
5
+ class LocationListCardViewController extends heartwood_view_controllers_1.AbstractViewController {
6
+ constructor(options) {
7
+ super(options);
8
+ const { onDelete, selectedLocationId, footerButtons, currentOrganizationId, onEdit, } = options;
9
+ this.onDelete = onDelete;
10
+ this.selectedLocationId = selectedLocationId;
11
+ this.onEdit = onEdit;
12
+ this.activeRecordCardVc = this.ActiveRecordCardVc(currentOrganizationId, footerButtons);
13
+ }
14
+ ActiveRecordCardVc(currentOrganizationId, footerButtons) {
15
+ return this.Controller('activeRecordCard', (0, heartwood_view_controllers_1.buildActiveRecordCard)({
16
+ header: {
17
+ title: 'Your locations',
18
+ },
19
+ eventName: 'list-locations::v2020_12_25',
20
+ target: {
21
+ organizationId: currentOrganizationId,
22
+ },
23
+ payload: {
24
+ includePrivateLocations: true,
25
+ },
26
+ responseKey: 'locations',
27
+ rowTransformer: this.buildRow.bind(this),
28
+ footer: footerButtons && {
29
+ buttons: footerButtons,
30
+ },
31
+ }));
32
+ }
33
+ buildRow(location) {
34
+ return {
35
+ id: location.id,
36
+ isSelected: this.selectedLocationId === location.id,
37
+ onClick: async () => {
38
+ var _a;
39
+ return (_a = this.onEdit) === null || _a === void 0 ? void 0 : _a.call(this, location);
40
+ },
41
+ cells: [
42
+ {
43
+ text: {
44
+ content: location.name,
45
+ },
46
+ subText: {
47
+ content: `${location.address
48
+ ? `${location.address.street1}${location.address.street2
49
+ ? ` ${location.address.street2}`
50
+ : ``} ${location.address.city} ${location.address.zip}`
51
+ : ``}`,
52
+ },
53
+ },
54
+ {
55
+ button: {
56
+ id: 'delete',
57
+ lineIcon: 'delete',
58
+ type: 'destructive',
59
+ onClick: async () => {
60
+ return this.handleDeleteLocation(location);
61
+ },
62
+ },
63
+ },
64
+ ].filter((c) => !!c),
65
+ };
66
+ }
67
+ async handleDeleteLocation(location) {
68
+ var _a;
69
+ const shouldDelete = await this.confirm({
70
+ title: `Delete ${location.name}`,
71
+ isDestructive: true,
72
+ });
73
+ if (!shouldDelete) {
74
+ return;
75
+ }
76
+ this.activeRecordCardVc.setIsBusy(true);
77
+ try {
78
+ const client = await this.connectToApi();
79
+ const results = await client.emit('delete-location::v2020_12_25', {
80
+ target: {
81
+ locationId: location.id,
82
+ },
83
+ });
84
+ spruce_event_utils_1.eventResponseUtil.getFirstResponseOrThrow(results);
85
+ (_a = this.onDelete) === null || _a === void 0 ? void 0 : _a.call(this, location);
86
+ this.activeRecordCardVc.deleteRow(location.id);
87
+ }
88
+ catch (err) {
89
+ await this.alert({
90
+ message: err.message,
91
+ style: 'error',
92
+ });
93
+ }
94
+ this.activeRecordCardVc.setIsBusy(false);
95
+ }
96
+ getCardVc() {
97
+ return this.activeRecordCardVc.getCardVc();
98
+ }
99
+ getActiveRecordVc() {
100
+ return this.activeRecordCardVc;
101
+ }
102
+ getSelectedLocationId() {
103
+ return this.selectedLocationId;
104
+ }
105
+ getListVc() {
106
+ return this.activeRecordCardVc.getListVc();
107
+ }
108
+ async load() {
109
+ await this.activeRecordCardVc.load();
110
+ }
111
+ render() {
112
+ return this.activeRecordCardVc.render();
113
+ }
114
+ }
115
+ exports.default = LocationListCardViewController;
116
+ LocationListCardViewController.id = 'location-list-card';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sprucelabs/spruce-location-utils",
3
3
  "description": "Location Utilities",
4
- "version": "2.0.16",
4
+ "version": "2.1.3",
5
5
  "skill": {
6
6
  "namespace": "locations"
7
7
  },
@@ -18,10 +18,14 @@
18
18
  "build/index-module.d.ts",
19
19
  "build/tests/utilities/organizationAssert.js",
20
20
  "build/tests/utilities/organizationAssert.d.ts",
21
+ "build/viewControllers/LocationListCard.vc.js",
22
+ "build/viewControllers/LocationListCard.vc.d.ts",
21
23
  "build/esm/index-module.js",
22
24
  "build/esm/index-module.d.ts",
23
25
  "build/esm/tests/utilities/organizationAssert.js",
24
- "build/esm/tests/utilities/organizationAssert.d.ts"
26
+ "build/esm/tests/utilities/organizationAssert.d.ts",
27
+ "build/esm/viewControllers/LocationListCard.vc.js",
28
+ "build/esm/viewControllers/LocationListCard.vc.d.ts"
25
29
  ],
26
30
  "keywords": [],
27
31
  "scripts": {
@@ -29,6 +33,7 @@
29
33
  },
30
34
  "dependencies": {
31
35
  "@sprucelabs/heartwood-view-controllers": "latest",
36
+ "@sprucelabs/spruce-event-utils": "latest",
32
37
  "@sprucelabs/spruce-test-fixtures": "latest",
33
38
  "@sprucelabs/test": "latest"
34
39
  },