@sprucelabs/spruce-location-utils 9.0.1 → 9.2.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.
- package/build/esm/types-module.d.ts +2 -2
- package/build/esm/viewControllers/LocationListCard.vc.d.ts +18 -13
- package/build/esm/viewControllers/LocationListCard.vc.js +53 -34
- package/build/types-module.d.ts +2 -2
- package/build/viewControllers/LocationListCard.vc.d.ts +18 -13
- package/build/viewControllers/LocationListCard.vc.js +51 -34
- package/package.json +1 -1
|
@@ -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
|
-
|
|
4
|
+
'locations.list-card': LocationListCardViewController;
|
|
5
5
|
}
|
|
6
6
|
interface ViewControllerOptionsMap {
|
|
7
|
-
|
|
7
|
+
'locations.list-card': LocationListCardViewControllerOptions;
|
|
8
8
|
}
|
|
9
9
|
}
|
|
@@ -1,23 +1,17 @@
|
|
|
1
|
-
import { AbstractViewController, SpruceSchemas, ViewControllerOptions, ActiveRecordCardViewController } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
-
|
|
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
|
|
5
|
+
private onDeleteHandler?;
|
|
15
6
|
private selectedLocationId?;
|
|
16
|
-
private
|
|
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,15 @@ 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
|
+
id?: string;
|
|
33
|
+
};
|
|
29
34
|
export {};
|
|
@@ -8,19 +8,25 @@ 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,
|
|
17
|
-
this.
|
|
15
|
+
const { id, 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.
|
|
20
|
-
this.activeRecordCardVc = this.ActiveRecordCardVc(
|
|
19
|
+
this.onClickHandler = onClick;
|
|
20
|
+
this.activeRecordCardVc = this.ActiveRecordCardVc({
|
|
21
|
+
id,
|
|
22
|
+
currentOrganizationId,
|
|
23
|
+
footerButtons,
|
|
24
|
+
});
|
|
21
25
|
}
|
|
22
|
-
ActiveRecordCardVc(
|
|
26
|
+
ActiveRecordCardVc(options) {
|
|
27
|
+
const { currentOrganizationId, footerButtons, id } = options;
|
|
23
28
|
return this.Controller('activeRecordCard', buildActiveRecordCard({
|
|
29
|
+
id,
|
|
24
30
|
header: {
|
|
25
31
|
title: 'Your locations',
|
|
26
32
|
},
|
|
@@ -39,40 +45,54 @@ class LocationListCardViewController extends AbstractViewController {
|
|
|
39
45
|
}
|
|
40
46
|
renderRow(location) {
|
|
41
47
|
const address = location.address;
|
|
48
|
+
const cells = [
|
|
49
|
+
{
|
|
50
|
+
text: {
|
|
51
|
+
content: location.name,
|
|
52
|
+
},
|
|
53
|
+
subText: {
|
|
54
|
+
content: locationRenderer.renderAddress(address),
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
];
|
|
58
|
+
if (this.shouldRenderDeleteButtons) {
|
|
59
|
+
cells.push({
|
|
60
|
+
button: {
|
|
61
|
+
id: 'delete',
|
|
62
|
+
lineIcon: 'delete',
|
|
63
|
+
type: 'destructive',
|
|
64
|
+
onClick: () => __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
return this.handleDeleteLocation(location);
|
|
66
|
+
}),
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
}
|
|
42
70
|
return {
|
|
43
71
|
id: location.id,
|
|
44
72
|
isSelected: this.selectedLocationId === location.id,
|
|
45
|
-
onClick: () =>
|
|
46
|
-
|
|
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
|
-
],
|
|
73
|
+
onClick: () => this.handleClickLocation(location),
|
|
74
|
+
cells,
|
|
69
75
|
};
|
|
70
76
|
}
|
|
77
|
+
selectLocation(id) {
|
|
78
|
+
this.selectedLocationId = id;
|
|
79
|
+
this.activeRecordCardVc.setSelectedRows([id]);
|
|
80
|
+
}
|
|
81
|
+
handleClickLocation(location) {
|
|
82
|
+
var _a;
|
|
83
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
if (this.onClickHandler) {
|
|
85
|
+
(_a = this.onClickHandler) === null || _a === void 0 ? void 0 : _a.call(this, location);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
this.selectLocation(location.id);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
71
91
|
handleDeleteLocation(location) {
|
|
72
92
|
var _a;
|
|
73
93
|
return __awaiter(this, void 0, void 0, function* () {
|
|
74
94
|
const shouldDelete = yield this.confirm({
|
|
75
|
-
title: `Delete ${location.name}
|
|
95
|
+
title: `Delete ${location.name}?`,
|
|
76
96
|
isDestructive: true,
|
|
77
97
|
});
|
|
78
98
|
if (!shouldDelete) {
|
|
@@ -81,13 +101,12 @@ class LocationListCardViewController extends AbstractViewController {
|
|
|
81
101
|
this.activeRecordCardVc.setIsBusy(true);
|
|
82
102
|
try {
|
|
83
103
|
const client = yield this.connectToApi();
|
|
84
|
-
|
|
104
|
+
yield client.emitAndFlattenResponses('delete-location::v2020_12_25', {
|
|
85
105
|
target: {
|
|
86
106
|
locationId: location.id,
|
|
87
107
|
},
|
|
88
108
|
});
|
|
89
|
-
|
|
90
|
-
(_a = this.onDelete) === null || _a === void 0 ? void 0 : _a.call(this, location);
|
|
109
|
+
(_a = this.onDeleteHandler) === null || _a === void 0 ? void 0 : _a.call(this, location);
|
|
91
110
|
this.activeRecordCardVc.deleteRow(location.id);
|
|
92
111
|
}
|
|
93
112
|
catch (err) {
|
package/build/types-module.d.ts
CHANGED
|
@@ -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
|
-
|
|
4
|
+
'locations.list-card': LocationListCardViewController;
|
|
5
5
|
}
|
|
6
6
|
interface ViewControllerOptionsMap {
|
|
7
|
-
|
|
7
|
+
'locations.list-card': LocationListCardViewControllerOptions;
|
|
8
8
|
}
|
|
9
9
|
}
|
|
@@ -1,23 +1,17 @@
|
|
|
1
|
-
import { AbstractViewController, SpruceSchemas, ViewControllerOptions, ActiveRecordCardViewController } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
-
|
|
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
|
|
5
|
+
private onDeleteHandler?;
|
|
15
6
|
private selectedLocationId?;
|
|
16
|
-
private
|
|
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,15 @@ 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
|
+
id?: string;
|
|
33
|
+
};
|
|
29
34
|
export {};
|
|
@@ -1,19 +1,25 @@
|
|
|
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,
|
|
10
|
-
this.
|
|
8
|
+
const { id, 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.
|
|
13
|
-
this.activeRecordCardVc = this.ActiveRecordCardVc(
|
|
12
|
+
this.onClickHandler = onClick;
|
|
13
|
+
this.activeRecordCardVc = this.ActiveRecordCardVc({
|
|
14
|
+
id,
|
|
15
|
+
currentOrganizationId,
|
|
16
|
+
footerButtons,
|
|
17
|
+
});
|
|
14
18
|
}
|
|
15
|
-
ActiveRecordCardVc(
|
|
19
|
+
ActiveRecordCardVc(options) {
|
|
20
|
+
const { currentOrganizationId, footerButtons, id } = options;
|
|
16
21
|
return this.Controller('activeRecordCard', (0, heartwood_view_controllers_1.buildActiveRecordCard)({
|
|
22
|
+
id,
|
|
17
23
|
header: {
|
|
18
24
|
title: 'Your locations',
|
|
19
25
|
},
|
|
@@ -32,39 +38,51 @@ class LocationListCardViewController extends heartwood_view_controllers_1.Abstra
|
|
|
32
38
|
}
|
|
33
39
|
renderRow(location) {
|
|
34
40
|
const address = location.address;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
cells: [
|
|
43
|
-
{
|
|
44
|
-
text: {
|
|
45
|
-
content: location.name,
|
|
46
|
-
},
|
|
47
|
-
subText: {
|
|
48
|
-
content: spruce_skill_utils_1.locationRenderer.renderAddress(address),
|
|
49
|
-
},
|
|
41
|
+
const cells = [
|
|
42
|
+
{
|
|
43
|
+
text: {
|
|
44
|
+
content: location.name,
|
|
45
|
+
},
|
|
46
|
+
subText: {
|
|
47
|
+
content: spruce_skill_utils_1.locationRenderer.renderAddress(address),
|
|
50
48
|
},
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
},
|
|
50
|
+
];
|
|
51
|
+
if (this.shouldRenderDeleteButtons) {
|
|
52
|
+
cells.push({
|
|
53
|
+
button: {
|
|
54
|
+
id: 'delete',
|
|
55
|
+
lineIcon: 'delete',
|
|
56
|
+
type: 'destructive',
|
|
57
|
+
onClick: async () => {
|
|
58
|
+
return this.handleDeleteLocation(location);
|
|
59
59
|
},
|
|
60
60
|
},
|
|
61
|
-
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
id: location.id,
|
|
65
|
+
isSelected: this.selectedLocationId === location.id,
|
|
66
|
+
onClick: () => this.handleClickLocation(location),
|
|
67
|
+
cells,
|
|
62
68
|
};
|
|
63
69
|
}
|
|
70
|
+
selectLocation(id) {
|
|
71
|
+
this.selectedLocationId = id;
|
|
72
|
+
this.activeRecordCardVc.setSelectedRows([id]);
|
|
73
|
+
}
|
|
74
|
+
async handleClickLocation(location) {
|
|
75
|
+
var _a;
|
|
76
|
+
if (this.onClickHandler) {
|
|
77
|
+
(_a = this.onClickHandler) === null || _a === void 0 ? void 0 : _a.call(this, location);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
this.selectLocation(location.id);
|
|
81
|
+
}
|
|
64
82
|
async handleDeleteLocation(location) {
|
|
65
83
|
var _a;
|
|
66
84
|
const shouldDelete = await this.confirm({
|
|
67
|
-
title: `Delete ${location.name}
|
|
85
|
+
title: `Delete ${location.name}?`,
|
|
68
86
|
isDestructive: true,
|
|
69
87
|
});
|
|
70
88
|
if (!shouldDelete) {
|
|
@@ -73,13 +91,12 @@ class LocationListCardViewController extends heartwood_view_controllers_1.Abstra
|
|
|
73
91
|
this.activeRecordCardVc.setIsBusy(true);
|
|
74
92
|
try {
|
|
75
93
|
const client = await this.connectToApi();
|
|
76
|
-
|
|
94
|
+
await client.emitAndFlattenResponses('delete-location::v2020_12_25', {
|
|
77
95
|
target: {
|
|
78
96
|
locationId: location.id,
|
|
79
97
|
},
|
|
80
98
|
});
|
|
81
|
-
|
|
82
|
-
(_a = this.onDelete) === null || _a === void 0 ? void 0 : _a.call(this, location);
|
|
99
|
+
(_a = this.onDeleteHandler) === null || _a === void 0 ? void 0 : _a.call(this, location);
|
|
83
100
|
this.activeRecordCardVc.deleteRow(location.id);
|
|
84
101
|
}
|
|
85
102
|
catch (err) {
|