@internetarchive/ia-book-actions 0.0.6-5 → 0.0.6-6
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/package.json +1 -1
- package/src/assets/styles/collapsible-action-group.js +3 -0
- package/src/core/services/actions-handler/actions-handler-service.js +3 -3
- package/src/core/services/actions-handler/actions-handler.js +12 -15
- package/src/ia-book-actions.js +19 -11
- package/test/ia-book-actions.test.js +59 -0
package/package.json
CHANGED
|
@@ -18,7 +18,7 @@ export default function ActionsHandlerService(options) {
|
|
|
18
18
|
|
|
19
19
|
let baseHost = '';
|
|
20
20
|
if (window.location.pathname === '/demo/') {
|
|
21
|
-
baseHost = `/demo
|
|
21
|
+
baseHost = `/demo/`;
|
|
22
22
|
} else {
|
|
23
23
|
baseHost = `/services/loans/loan`;
|
|
24
24
|
}
|
|
@@ -35,8 +35,8 @@ export default function ActionsHandlerService(options) {
|
|
|
35
35
|
// test changes, (won't affect you)
|
|
36
36
|
if (baseHost == '/demo/1' || baseHost == '/demo/') {
|
|
37
37
|
return {
|
|
38
|
-
error:
|
|
39
|
-
|
|
38
|
+
error:
|
|
39
|
+
'This book is not available to borrow at this time. Please try again later.',
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
|
|
@@ -88,7 +88,7 @@ export default class ActionsHandler extends LitElement {
|
|
|
88
88
|
|
|
89
89
|
handleBrowseIt() {
|
|
90
90
|
const context = 'browse_book';
|
|
91
|
-
this.
|
|
91
|
+
this.ActionError(context);
|
|
92
92
|
|
|
93
93
|
ActionsHandlerService({
|
|
94
94
|
action: context,
|
|
@@ -98,14 +98,14 @@ export default class ActionsHandler extends LitElement {
|
|
|
98
98
|
},
|
|
99
99
|
error: data => {
|
|
100
100
|
alert(data.error);
|
|
101
|
-
this.
|
|
101
|
+
this.ActionError(context, data);
|
|
102
102
|
},
|
|
103
103
|
});
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
handleReturnIt() {
|
|
107
107
|
const context = 'return_loan';
|
|
108
|
-
this.
|
|
108
|
+
this.ActionError(context);
|
|
109
109
|
|
|
110
110
|
ActionsHandlerService({
|
|
111
111
|
action: context,
|
|
@@ -116,14 +116,14 @@ export default class ActionsHandler extends LitElement {
|
|
|
116
116
|
},
|
|
117
117
|
error: data => {
|
|
118
118
|
alert(data.error);
|
|
119
|
-
this.
|
|
119
|
+
this.ActionError(context);
|
|
120
120
|
},
|
|
121
121
|
});
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
handleBorrowIt() {
|
|
125
125
|
const context = 'borrow_book';
|
|
126
|
-
this.
|
|
126
|
+
this.ActionError(context);
|
|
127
127
|
|
|
128
128
|
ActionsHandlerService({
|
|
129
129
|
action: context,
|
|
@@ -133,14 +133,14 @@ export default class ActionsHandler extends LitElement {
|
|
|
133
133
|
},
|
|
134
134
|
error: data => {
|
|
135
135
|
alert(data.error);
|
|
136
|
-
this.
|
|
136
|
+
this.ActionError(context, data);
|
|
137
137
|
},
|
|
138
138
|
});
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
handleReserveIt() {
|
|
142
142
|
const context = 'join_waitlist';
|
|
143
|
-
this.
|
|
143
|
+
this.ActionError(context);
|
|
144
144
|
|
|
145
145
|
ActionsHandlerService({
|
|
146
146
|
action: context,
|
|
@@ -150,14 +150,14 @@ export default class ActionsHandler extends LitElement {
|
|
|
150
150
|
},
|
|
151
151
|
error: data => {
|
|
152
152
|
alert(data.error);
|
|
153
|
-
this.
|
|
153
|
+
this.ActionError(context);
|
|
154
154
|
},
|
|
155
155
|
});
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
handleRemoveFromWaitingList() {
|
|
159
159
|
const context = 'leave_waitlist';
|
|
160
|
-
this.
|
|
160
|
+
this.ActionError(context);
|
|
161
161
|
|
|
162
162
|
ActionsHandlerService({
|
|
163
163
|
action: context,
|
|
@@ -167,7 +167,7 @@ export default class ActionsHandler extends LitElement {
|
|
|
167
167
|
},
|
|
168
168
|
error: data => {
|
|
169
169
|
alert(data.error);
|
|
170
|
-
this.
|
|
170
|
+
this.ActionError(context);
|
|
171
171
|
},
|
|
172
172
|
});
|
|
173
173
|
}
|
|
@@ -183,9 +183,6 @@ export default class ActionsHandler extends LitElement {
|
|
|
183
183
|
handleReadItNow(extraParam) {
|
|
184
184
|
const currentParams = new URLSearchParams(window.location.search);
|
|
185
185
|
|
|
186
|
-
// Delete the ?q= parameter just after borrow a book. see: WEBDEV-3979
|
|
187
|
-
currentParams.delete('q');
|
|
188
|
-
|
|
189
186
|
if (extraParam) {
|
|
190
187
|
// append extraParam key-value in currentParams
|
|
191
188
|
const extraParams = new URLSearchParams(extraParam);
|
|
@@ -222,9 +219,9 @@ export default class ActionsHandler extends LitElement {
|
|
|
222
219
|
document.cookie = cookie;
|
|
223
220
|
}
|
|
224
221
|
|
|
225
|
-
|
|
222
|
+
ActionError(context, data = {}) {
|
|
226
223
|
this.dispatchEvent(
|
|
227
|
-
new CustomEvent('
|
|
224
|
+
new CustomEvent('lendingActionError', {
|
|
228
225
|
detail: { context, data },
|
|
229
226
|
})
|
|
230
227
|
);
|
package/src/ia-book-actions.js
CHANGED
|
@@ -175,27 +175,35 @@ export default class IABookActions extends LitElement {
|
|
|
175
175
|
.width=${this.width}
|
|
176
176
|
.hasAdminAccess=${this.hasAdminAccess}
|
|
177
177
|
.disabled=${this.disable}
|
|
178
|
-
@
|
|
178
|
+
@lendingActionError=${this.handleLendingActionError}
|
|
179
179
|
>
|
|
180
180
|
</collapsible-action-group>
|
|
181
181
|
${this.textGroupTemplate} ${this.infoIconTemplate}
|
|
182
182
|
`;
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
-
|
|
185
|
+
handleLendingActionError(e) {
|
|
186
186
|
// toggle activity loader
|
|
187
187
|
this.disable = !this.disable;
|
|
188
188
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
189
|
+
const context = e?.detail?.context;
|
|
190
|
+
const errorMsg = e?.detail?.data?.error;
|
|
191
|
+
|
|
192
|
+
// update action bar state if book is not available to browse or borrow.
|
|
193
|
+
if (errorMsg && errorMsg.match(/not available to borrow/gm)) {
|
|
194
|
+
let currStatus = this.lendingStatus;
|
|
195
|
+
if (context === 'browse_book') {
|
|
196
|
+
currStatus = {
|
|
197
|
+
...this.lendingStatus,
|
|
198
|
+
available_to_browse: false,
|
|
199
|
+
};
|
|
200
|
+
} else if (context === 'borrow_book') {
|
|
201
|
+
currStatus = {
|
|
202
|
+
...this.lendingStatus,
|
|
203
|
+
available_to_borrow: false,
|
|
204
|
+
};
|
|
198
205
|
}
|
|
206
|
+
this.lendingStatus = currStatus;
|
|
199
207
|
}
|
|
200
208
|
}
|
|
201
209
|
|
|
@@ -106,6 +106,65 @@ describe('Primary Actions data', () => {
|
|
|
106
106
|
});
|
|
107
107
|
|
|
108
108
|
describe('Borrow status actions', () => {
|
|
109
|
+
it('Update available_to_browse key when book is not available to borrow', async () => {
|
|
110
|
+
const el = await fixture(
|
|
111
|
+
container({
|
|
112
|
+
userid: '@user1',
|
|
113
|
+
lendingStatus: {
|
|
114
|
+
is_lendable: true,
|
|
115
|
+
available_to_browse: true,
|
|
116
|
+
available_to_borrow: true,
|
|
117
|
+
},
|
|
118
|
+
})
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
const errorEvent = new CustomEvent('lendingActionError');
|
|
122
|
+
el.addEventListener('lendingActionError', () => {
|
|
123
|
+
el.handleLendingActionError({
|
|
124
|
+
detail: {
|
|
125
|
+
context: 'browse_book',
|
|
126
|
+
data: { error: 'not available to borrow' },
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
el.dispatchEvent(errorEvent);
|
|
131
|
+
await el.updateComplete;
|
|
132
|
+
|
|
133
|
+
console.log(el.lendingStatus);
|
|
134
|
+
// removed available_to_browse from lending bar
|
|
135
|
+
expect(el.lendingStatus.available_to_browse).to.be.false;
|
|
136
|
+
expect(el.primaryActions[0].text).to.equal('Borrow for 14 days');
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('Update available_to_borrow key when book is not available to borrow', async () => {
|
|
140
|
+
const el = await fixture(
|
|
141
|
+
container({
|
|
142
|
+
userid: '@user1',
|
|
143
|
+
lendingStatus: {
|
|
144
|
+
is_lendable: true,
|
|
145
|
+
available_to_browse: true,
|
|
146
|
+
available_to_borrow: true,
|
|
147
|
+
},
|
|
148
|
+
})
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
const errorEvent = new Event('lendingActionError');
|
|
152
|
+
el.addEventListener('lendingActionError', () => {
|
|
153
|
+
el.handleLendingActionError({
|
|
154
|
+
detail: {
|
|
155
|
+
context: 'borrow_book',
|
|
156
|
+
data: { error: 'not available to borrow' },
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
el.dispatchEvent(errorEvent);
|
|
161
|
+
await el.updateComplete;
|
|
162
|
+
|
|
163
|
+
// removed available_to_borrow from lending bar
|
|
164
|
+
expect(el.lendingStatus.available_to_borrow).to.be.false;
|
|
165
|
+
expect(el.primaryActions[0].text).to.equal('Borrow for 1 hour');
|
|
166
|
+
});
|
|
167
|
+
|
|
109
168
|
it('Check action for borrowable book without user', async () => {
|
|
110
169
|
const el = await fixture(
|
|
111
170
|
container({
|