@sprucelabs/spruce-location-utils 9.2.0 → 9.4.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,3 +1,5 @@
1
1
  export { default as organizationAssert } from './tests/organizationAssert';
2
2
  export { default as LocationListCardViewController } from './viewControllers/LocationListCard.vc';
3
+ export { default as locationListCardAssert } from './tests/locationListCardAssert';
4
+ export * from './tests/locationListCardAssert';
3
5
  export * from './types-module';
@@ -1,3 +1,5 @@
1
1
  export { default as organizationAssert } from './tests/organizationAssert.js';
2
2
  export { default as LocationListCardViewController } from './viewControllers/LocationListCard.vc.js';
3
+ export { default as locationListCardAssert } from './tests/locationListCardAssert.js';
4
+ export * from './tests/locationListCardAssert.js';
3
5
  export * from './types-module.js';
@@ -0,0 +1,16 @@
1
+ import { Card, SpruceSchemas, ViewController, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
2
+ import { ViewFixture } from '@sprucelabs/spruce-test-fixtures';
3
+ import LocationListCardViewController, { LocationListCardViewControllerOptions as LocationListCardOptions } from '../viewControllers/LocationListCard.vc';
4
+ declare const locationListCardAssert: {
5
+ beforeEach(views: Pick<ViewFixture, 'setController'>): void;
6
+ loadsWithTargetAndPayload(options: LoadsWithTargetAndPayloadOptions): Promise<void>;
7
+ configurationEquals(vc: ViewController<Card>, options: LocationListCardOptions): void;
8
+ };
9
+ export declare class SpyLocationListCard extends LocationListCardViewController {
10
+ constructorOptions: LocationListCardOptions;
11
+ constructor(options: ViewControllerOptions & LocationListCardOptions);
12
+ }
13
+ export type LoadsWithTargetAndPayloadOptions = Partial<SpruceSchemas.Mercury.v2020_12_25.ListLocationsEmitTargetAndPayload> & {
14
+ action: () => Promise<void> | void;
15
+ };
16
+ export default locationListCardAssert;
@@ -0,0 +1,52 @@
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 { eventFaker } from '@sprucelabs/spruce-test-fixtures';
11
+ import { assert } from '@sprucelabs/test-utils';
12
+ import LocationListCardViewController from '../viewControllers/LocationListCard.vc.js';
13
+ const locationListCardAssert = {
14
+ beforeEach(views) {
15
+ views.setController('locations.list-card', SpyLocationListCard);
16
+ },
17
+ loadsWithTargetAndPayload(options) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ const { action, target, payload } = options;
20
+ let passedTarget;
21
+ let passedPayload;
22
+ yield eventFaker.on('list-locations::v2020_12_25', ({ target, payload }) => {
23
+ passedPayload = payload;
24
+ passedTarget = target;
25
+ return {
26
+ locations: [],
27
+ };
28
+ });
29
+ yield action();
30
+ if (target) {
31
+ assert.isEqualDeep(passedTarget, target, 'Target missmatch');
32
+ }
33
+ if (payload) {
34
+ assert.isEqualDeep(passedPayload, payload, 'Payload missmatch');
35
+ }
36
+ });
37
+ },
38
+ configurationEquals(vc, options) {
39
+ const spyVc = vc;
40
+ const keys = Object.keys(options);
41
+ for (const key of keys) {
42
+ assert.isEqualDeep(spyVc.constructorOptions[key], options[key], 'Missmatch on ' + key);
43
+ }
44
+ },
45
+ };
46
+ export class SpyLocationListCard extends LocationListCardViewController {
47
+ constructor(options) {
48
+ super(options);
49
+ this.constructorOptions = options;
50
+ }
51
+ }
52
+ export default locationListCardAssert;
@@ -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;
@@ -25,10 +26,11 @@ type OnEditHandler = (location: Location) => void;
25
26
  export type LocationListCardViewControllerOptions = {
26
27
  onDelete?: OnDeleteHandler;
27
28
  onClick?: OnEditHandler;
28
- currentOrganizationId: string;
29
+ currentOrganizationId?: string;
29
30
  selectedLocationId?: string;
30
31
  footerButtons?: Button[];
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
  }
@@ -1,3 +1,5 @@
1
1
  export { default as organizationAssert } from './tests/organizationAssert';
2
2
  export { default as LocationListCardViewController } from './viewControllers/LocationListCard.vc';
3
+ export { default as locationListCardAssert } from './tests/locationListCardAssert';
4
+ export * from './tests/locationListCardAssert';
3
5
  export * from './types-module';
@@ -17,9 +17,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.LocationListCardViewController = exports.organizationAssert = void 0;
20
+ exports.locationListCardAssert = exports.LocationListCardViewController = exports.organizationAssert = void 0;
21
21
  var organizationAssert_1 = require("./tests/organizationAssert");
22
22
  Object.defineProperty(exports, "organizationAssert", { enumerable: true, get: function () { return __importDefault(organizationAssert_1).default; } });
23
23
  var LocationListCard_vc_1 = require("./viewControllers/LocationListCard.vc");
24
24
  Object.defineProperty(exports, "LocationListCardViewController", { enumerable: true, get: function () { return __importDefault(LocationListCard_vc_1).default; } });
25
+ var locationListCardAssert_1 = require("./tests/locationListCardAssert");
26
+ Object.defineProperty(exports, "locationListCardAssert", { enumerable: true, get: function () { return __importDefault(locationListCardAssert_1).default; } });
27
+ __exportStar(require("./tests/locationListCardAssert"), exports);
25
28
  __exportStar(require("./types-module"), exports);
@@ -0,0 +1,16 @@
1
+ import { Card, SpruceSchemas, ViewController, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
2
+ import { ViewFixture } from '@sprucelabs/spruce-test-fixtures';
3
+ import LocationListCardViewController, { LocationListCardViewControllerOptions as LocationListCardOptions } from '../viewControllers/LocationListCard.vc';
4
+ declare const locationListCardAssert: {
5
+ beforeEach(views: Pick<ViewFixture, 'setController'>): void;
6
+ loadsWithTargetAndPayload(options: LoadsWithTargetAndPayloadOptions): Promise<void>;
7
+ configurationEquals(vc: ViewController<Card>, options: LocationListCardOptions): void;
8
+ };
9
+ export declare class SpyLocationListCard extends LocationListCardViewController {
10
+ constructorOptions: LocationListCardOptions;
11
+ constructor(options: ViewControllerOptions & LocationListCardOptions);
12
+ }
13
+ export type LoadsWithTargetAndPayloadOptions = Partial<SpruceSchemas.Mercury.v2020_12_25.ListLocationsEmitTargetAndPayload> & {
14
+ action: () => Promise<void> | void;
15
+ };
16
+ export default locationListCardAssert;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SpyLocationListCard = void 0;
7
+ const spruce_test_fixtures_1 = require("@sprucelabs/spruce-test-fixtures");
8
+ const test_utils_1 = require("@sprucelabs/test-utils");
9
+ const LocationListCard_vc_1 = __importDefault(require("../viewControllers/LocationListCard.vc"));
10
+ const locationListCardAssert = {
11
+ beforeEach(views) {
12
+ views.setController('locations.list-card', SpyLocationListCard);
13
+ },
14
+ async loadsWithTargetAndPayload(options) {
15
+ const { action, target, payload } = options;
16
+ let passedTarget;
17
+ let passedPayload;
18
+ await spruce_test_fixtures_1.eventFaker.on('list-locations::v2020_12_25', ({ target, payload }) => {
19
+ passedPayload = payload;
20
+ passedTarget = target;
21
+ return {
22
+ locations: [],
23
+ };
24
+ });
25
+ await action();
26
+ if (target) {
27
+ test_utils_1.assert.isEqualDeep(passedTarget, target, 'Target missmatch');
28
+ }
29
+ if (payload) {
30
+ test_utils_1.assert.isEqualDeep(passedPayload, payload, 'Payload missmatch');
31
+ }
32
+ },
33
+ configurationEquals(vc, options) {
34
+ const spyVc = vc;
35
+ const keys = Object.keys(options);
36
+ for (const key of keys) {
37
+ test_utils_1.assert.isEqualDeep(spyVc.constructorOptions[key], options[key], 'Missmatch on ' + key);
38
+ }
39
+ },
40
+ };
41
+ class SpyLocationListCard extends LocationListCard_vc_1.default {
42
+ constructor(options) {
43
+ super(options);
44
+ this.constructorOptions = options;
45
+ }
46
+ }
47
+ exports.SpyLocationListCard = SpyLocationListCard;
48
+ exports.default = locationListCardAssert;
@@ -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;
@@ -25,10 +26,11 @@ type OnEditHandler = (location: Location) => void;
25
26
  export type LocationListCardViewControllerOptions = {
26
27
  onDelete?: OnDeleteHandler;
27
28
  onClick?: OnEditHandler;
28
- currentOrganizationId: string;
29
+ currentOrganizationId?: string;
29
30
  selectedLocationId?: string;
30
31
  footerButtons?: Button[];
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,47 +1,51 @@
1
1
  {
2
- "name": "@sprucelabs/spruce-location-utils",
3
- "description": "Location Utilities",
4
- "version": "9.2.0",
5
- "skill": {
6
- "namespace": "locations"
7
- },
8
- "homepage": "https://github.com/sprucelabsai/spruce-locations-skill",
9
- "bugs": {
10
- "url": "https://github.com/sprucelabsai/spruce-locations-skill/issues"
11
- },
12
- "main": "./build/index-module.js",
13
- "types": "./build/index-module.d.ts",
14
- "module": "./build/esm/index-module.js",
15
- "sideEffects": false,
16
- "files": [
17
- "build/index-module.js",
18
- "build/index-module.d.ts",
19
- "build/tests/organizationAssert.js",
20
- "build/tests/organizationAssert.d.ts",
21
- "build/viewControllers/LocationListCard.vc.js",
22
- "build/viewControllers/LocationListCard.vc.d.ts",
23
- "build/esm/index-module.js",
24
- "build/esm/index-module.d.ts",
25
- "build/esm/tests/organizationAssert.js",
26
- "build/esm/tests/organizationAssert.d.ts",
27
- "build/esm/viewControllers/LocationListCard.vc.js",
28
- "build/esm/viewControllers/LocationListCard.vc.d.ts",
29
- "build/types-module.js",
30
- "build/types-module.d.ts",
31
- "build/esm/types-module.js",
32
- "build/esm/types-module.d.ts"
33
- ],
34
- "keywords": [],
35
- "scripts": {
36
- "release": "npm publish"
37
- },
38
- "dependencies": {
39
- "@sprucelabs/heartwood-view-controllers": "latest",
40
- "@sprucelabs/spruce-event-utils": "latest",
41
- "@sprucelabs/spruce-test-fixtures": "latest",
42
- "@sprucelabs/test-utils": "latest"
43
- },
44
- "engines": {
45
- "yarn": "1.x"
46
- }
47
- }
2
+ "name": "@sprucelabs/spruce-location-utils",
3
+ "description": "Location Utilities",
4
+ "version": "9.4.0",
5
+ "skill": {
6
+ "namespace": "locations"
7
+ },
8
+ "homepage": "https://github.com/sprucelabsai/spruce-locations-skill",
9
+ "bugs": {
10
+ "url": "https://github.com/sprucelabsai/spruce-locations-skill/issues"
11
+ },
12
+ "main": "./build/index-module.js",
13
+ "types": "./build/index-module.d.ts",
14
+ "module": "./build/esm/index-module.js",
15
+ "sideEffects": false,
16
+ "files": [
17
+ "build/index-module.js",
18
+ "build/index-module.d.ts",
19
+ "build/tests/organizationAssert.js",
20
+ "build/tests/organizationAssert.d.ts",
21
+ "build/esm/tests/organizationAssert.js",
22
+ "build/esm/tests/organizationAssert.d.ts",
23
+ "build/viewControllers/LocationListCard.vc.js",
24
+ "build/viewControllers/LocationListCard.vc.d.ts",
25
+ "build/esm/index-module.js",
26
+ "build/esm/index-module.d.ts",
27
+ "build/esm/viewControllers/LocationListCard.vc.js",
28
+ "build/esm/viewControllers/LocationListCard.vc.d.ts",
29
+ "build/types-module.js",
30
+ "build/types-module.d.ts",
31
+ "build/esm/types-module.js",
32
+ "build/esm/types-module.d.ts",
33
+ "build/tests/locationListCardAssert.js",
34
+ "build/tests/locationListCardAssert.d.ts",
35
+ "build/esm/tests/locationListCardAssert.js",
36
+ "build/esm/tests/locationListCardAssert.d.ts"
37
+ ],
38
+ "keywords": [],
39
+ "scripts": {
40
+ "release": "npm publish"
41
+ },
42
+ "dependencies": {
43
+ "@sprucelabs/heartwood-view-controllers": "latest",
44
+ "@sprucelabs/spruce-event-utils": "latest",
45
+ "@sprucelabs/spruce-test-fixtures": "latest",
46
+ "@sprucelabs/test-utils": "latest"
47
+ },
48
+ "engines": {
49
+ "yarn": "1.x"
50
+ }
51
+ }