@sprucelabs/spruce-location-utils 2.1.0 → 2.1.4

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.
@@ -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
  });
@@ -4,7 +4,7 @@ declare type Location = SpruceSchemas.Spruce.v2020_07_22.Location;
4
4
  declare type Button = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Button;
5
5
  export default class LocationListCardViewController extends AbstractViewController<Card> {
6
6
  static id: string;
7
- private onDeleteHandler?;
7
+ private onDelete?;
8
8
  private selectedLocationId?;
9
9
  private onEdit?;
10
10
  private activeRecordCardVc;
@@ -15,6 +15,7 @@ export default class LocationListCardViewController extends AbstractViewControll
15
15
  selectedLocationId?: string;
16
16
  footerButtons?: Button[];
17
17
  });
18
+ private ActiveRecordCardVc;
18
19
  private buildRow;
19
20
  private handleDeleteLocation;
20
21
  getCardVc(): import("@sprucelabs/heartwood-view-controllers").CardViewController;
@@ -13,10 +13,13 @@ export default class LocationListCardViewController extends AbstractViewControll
13
13
  constructor(options) {
14
14
  super(options);
15
15
  const { onDelete, selectedLocationId, footerButtons, currentOrganizationId, onEdit, } = options;
16
- this.onDeleteHandler = onDelete;
16
+ this.onDelete = onDelete;
17
17
  this.selectedLocationId = selectedLocationId;
18
18
  this.onEdit = onEdit;
19
- this.activeRecordCardVc = this.Controller('activeRecordCard', buildActiveRecordCard({
19
+ this.activeRecordCardVc = this.ActiveRecordCardVc(currentOrganizationId, footerButtons);
20
+ }
21
+ ActiveRecordCardVc(currentOrganizationId, footerButtons) {
22
+ return this.Controller('activeRecordCard', buildActiveRecordCard({
20
23
  header: {
21
24
  title: 'Your locations',
22
25
  },
@@ -37,6 +40,11 @@ export default class LocationListCardViewController extends AbstractViewControll
37
40
  buildRow(location) {
38
41
  return {
39
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
+ }),
40
48
  cells: [
41
49
  {
42
50
  text: {
@@ -50,16 +58,6 @@ export default class LocationListCardViewController extends AbstractViewControll
50
58
  : ``}`,
51
59
  },
52
60
  },
53
- this.selectedLocationId !== location.id && {
54
- button: {
55
- id: 'edit',
56
- lineIcon: 'edit-box',
57
- onClick: () => __awaiter(this, void 0, void 0, function* () {
58
- var _a;
59
- return (_a = this.onEdit) === null || _a === void 0 ? void 0 : _a.call(this, location);
60
- }),
61
- },
62
- },
63
61
  {
64
62
  button: {
65
63
  id: 'delete',
@@ -92,7 +90,7 @@ export default class LocationListCardViewController extends AbstractViewControll
92
90
  },
93
91
  });
94
92
  eventResponseUtil.getFirstResponseOrThrow(results);
95
- (_a = this.onDeleteHandler) === null || _a === void 0 ? void 0 : _a.call(this, location);
93
+ (_a = this.onDelete) === null || _a === void 0 ? void 0 : _a.call(this, location);
96
94
  this.activeRecordCardVc.deleteRow(location.id);
97
95
  }
98
96
  catch (err) {
@@ -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
  },
@@ -4,7 +4,7 @@ declare type Location = SpruceSchemas.Spruce.v2020_07_22.Location;
4
4
  declare type Button = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Button;
5
5
  export default class LocationListCardViewController extends AbstractViewController<Card> {
6
6
  static id: string;
7
- private onDeleteHandler?;
7
+ private onDelete?;
8
8
  private selectedLocationId?;
9
9
  private onEdit?;
10
10
  private activeRecordCardVc;
@@ -15,6 +15,7 @@ export default class LocationListCardViewController extends AbstractViewControll
15
15
  selectedLocationId?: string;
16
16
  footerButtons?: Button[];
17
17
  });
18
+ private ActiveRecordCardVc;
18
19
  private buildRow;
19
20
  private handleDeleteLocation;
20
21
  getCardVc(): import("@sprucelabs/heartwood-view-controllers").CardViewController;
@@ -6,10 +6,13 @@ class LocationListCardViewController extends heartwood_view_controllers_1.Abstra
6
6
  constructor(options) {
7
7
  super(options);
8
8
  const { onDelete, selectedLocationId, footerButtons, currentOrganizationId, onEdit, } = options;
9
- this.onDeleteHandler = onDelete;
9
+ this.onDelete = onDelete;
10
10
  this.selectedLocationId = selectedLocationId;
11
11
  this.onEdit = onEdit;
12
- this.activeRecordCardVc = this.Controller('activeRecordCard', (0, heartwood_view_controllers_1.buildActiveRecordCard)({
12
+ this.activeRecordCardVc = this.ActiveRecordCardVc(currentOrganizationId, footerButtons);
13
+ }
14
+ ActiveRecordCardVc(currentOrganizationId, footerButtons) {
15
+ return this.Controller('activeRecordCard', (0, heartwood_view_controllers_1.buildActiveRecordCard)({
13
16
  header: {
14
17
  title: 'Your locations',
15
18
  },
@@ -30,6 +33,11 @@ class LocationListCardViewController extends heartwood_view_controllers_1.Abstra
30
33
  buildRow(location) {
31
34
  return {
32
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
+ },
33
41
  cells: [
34
42
  {
35
43
  text: {
@@ -43,16 +51,6 @@ class LocationListCardViewController extends heartwood_view_controllers_1.Abstra
43
51
  : ``}`,
44
52
  },
45
53
  },
46
- this.selectedLocationId !== location.id && {
47
- button: {
48
- id: 'edit',
49
- lineIcon: 'edit-box',
50
- onClick: async () => {
51
- var _a;
52
- return (_a = this.onEdit) === null || _a === void 0 ? void 0 : _a.call(this, location);
53
- },
54
- },
55
- },
56
54
  {
57
55
  button: {
58
56
  id: 'delete',
@@ -84,7 +82,7 @@ class LocationListCardViewController extends heartwood_view_controllers_1.Abstra
84
82
  },
85
83
  });
86
84
  spruce_event_utils_1.eventResponseUtil.getFirstResponseOrThrow(results);
87
- (_a = this.onDeleteHandler) === null || _a === void 0 ? void 0 : _a.call(this, location);
85
+ (_a = this.onDelete) === null || _a === void 0 ? void 0 : _a.call(this, location);
88
86
  this.activeRecordCardVc.deleteRow(location.id);
89
87
  }
90
88
  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": "2.1.0",
4
+ "version": "2.1.4",
5
5
  "skill": {
6
6
  "namespace": "locations"
7
7
  },