Skip to content

Commit 7fc6582

Browse files
authored
Add extra button for search page manage UI (#414)
* Add extra button for search page manage UI
1 parent 0bcc4bb commit 7fc6582

File tree

6 files changed

+120
-28
lines changed

6 files changed

+120
-28
lines changed

src/app-root.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,14 @@ export class AppRoot extends LitElement {
327327
/>
328328
<label for="enable-management">Enable manage mode</label>
329329
</div>
330+
<div class="checkbox-control indent">
331+
<input
332+
type="checkbox"
333+
id="enable-search-management"
334+
@click=${this.SearchManageModeCheckboxChanged}
335+
/>
336+
<label for="enable-search-management">Search</label>
337+
</div>
330338
<div class="checkbox-control">
331339
<input
332340
type="checkbox"
@@ -476,10 +484,15 @@ export class AppRoot extends LitElement {
476484
.loggedIn=${this.loggedIn}
477485
.modalManager=${this.modalManager}
478486
.analyticsHandler=${this.analyticsHandler}
487+
.pageContext=${'search'}
479488
@visiblePageChanged=${this.visiblePageChanged}
480489
@baseQueryChanged=${this.baseQueryChanged}
481490
@searchTypeChanged=${this.searchTypeChanged}
482491
@manageModeChanged=${this.manageModeChanged}
492+
@itemRemovalRequested=${(e: CustomEvent) =>
493+
console.log(e.detail.items)}
494+
@itemManagerRequested=${(e: CustomEvent) =>
495+
console.log(e.detail.items)}
483496
>
484497
${this.toggleSlots
485498
? html`<div slot="sortbar-left-slot">Sort Slot</div>`
@@ -704,6 +717,16 @@ export class AppRoot extends LitElement {
704717
'Select items to remove (customizable texts)';
705718
}
706719

720+
/**
721+
* Handler when the dev panel's "Enable manage mode -> Search" checkbox is changed.
722+
*/
723+
private SearchManageModeCheckboxChanged(e: Event) {
724+
const target = e.target as HTMLInputElement;
725+
this.collectionBrowser.pageContext = target.checked
726+
? 'search'
727+
: 'collection';
728+
}
729+
707730
/**
708731
* Handler for when the dev panel's "Enable smart facet bar" checkbox is changed.
709732
*/

src/collection-browser.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,10 +777,12 @@ export class CollectionBrowser
777777
return html`
778778
<manage-bar
779779
.label=${this.manageViewLabel}
780+
.pageContext=${this.pageContext}
780781
showSelectAll
781782
showUnselectAll
782783
?removeAllowed=${this.dataSource.checkedTileModels.length !== 0}
783784
@removeItems=${this.handleRemoveItems}
785+
@itemsManager=${this.handleItemsManager}
784786
@selectAll=${() => this.dataSource.checkAllTiles()}
785787
@unselectAll=${() => this.dataSource.uncheckAllTiles()}
786788
@cancel=${() => {
@@ -809,6 +811,22 @@ export class CollectionBrowser
809811
);
810812
}
811813

814+
/**
815+
* Handler when user request to bulk edit from /search/ page
816+
*/
817+
private handleItemsManager(): void {
818+
this.dispatchEvent(
819+
new CustomEvent('itemManagerRequested', {
820+
detail: {
821+
items: this.dataSource.checkedTileModels
822+
.map(item => item.identifier)
823+
.filter(Boolean)
824+
.join(','),
825+
},
826+
})
827+
);
828+
}
829+
812830
/**
813831
* Removes all tile models that are currently checked & adjusts the paging
814832
* of the data source to account for any new gaps in the data.

src/manage/manage-bar.ts

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ export class ManageBar extends LitElement {
1717
*/
1818
@property({ type: String }) label = msg('Select items to remove');
1919

20+
/**
21+
* Specifies the context in which the collection browser is being used
22+
*/
23+
@property({ type: String }) pageContext?: string;
24+
2025
/**
2126
* Whether to show the "Select All" button (default false)
2227
*/
@@ -47,11 +52,22 @@ export class ManageBar extends LitElement {
4752
>
4853
${msg('Remove selected items')}
4954
</button>
55+
${this.pageContext === 'search'
56+
? html`
57+
<button
58+
class="ia-button warning"
59+
?disabled=${!this.removeAllowed}
60+
@click=${this.itemsManagerClicked}
61+
>
62+
${msg('Item Manager the items')}
63+
</button>
64+
`
65+
: ''}
5066
<div class="selection-buttons">
5167
${when(
5268
this.showSelectAll,
5369
() => html` <button
54-
class="link-styled select-all-btn"
70+
class="ia-button link select-all-btn"
5571
@click=${this.selectAllClicked}
5672
>
5773
${msg('Select all')}
@@ -60,7 +76,7 @@ export class ManageBar extends LitElement {
6076
${when(
6177
this.showUnselectAll,
6278
() => html` <button
63-
class="link-styled unselect-all-btn"
79+
class="ia-button link unselect-all-btn"
6480
@click=${this.unselectAllClicked}
6581
>
6682
${msg('Unselect all')}
@@ -80,6 +96,10 @@ export class ManageBar extends LitElement {
8096
this.dispatchEvent(new CustomEvent('removeItems'));
8197
}
8298

99+
private itemsManagerClicked(): void {
100+
this.dispatchEvent(new CustomEvent('itemsManager'));
101+
}
102+
83103
private selectAllClicked(): void {
84104
this.dispatchEvent(new CustomEvent('selectAll'));
85105
}
@@ -108,33 +128,20 @@ export class ManageBar extends LitElement {
108128
109129
.manage-buttons {
110130
display: flex;
131+
flex-wrap: wrap;
111132
align-items: center;
112133
column-gap: 5px;
113134
}
114135
136+
.selection-buttons {
137+
display: inherit;
138+
}
139+
115140
.ia-button,
116141
button {
117142
padding: 6px 12px;
118143
font-size: 1.4rem;
119-
}
120-
121-
.ia-button.danger:disabled {
122-
opacity: 0.5;
123-
}
124-
125-
button.link-styled {
126-
margin: 0;
127-
padding: 6px;
128-
border: 0;
129-
appearance: none;
130-
background: none;
131-
color: var(--ia-theme-link-color, #4b64ff);
132-
font: inherit;
133-
text-decoration: none;
134-
cursor: pointer;
135-
}
136-
button.link-styled:hover {
137-
text-decoration: underline;
144+
margin: 3px 0;
138145
}
139146
`;
140147
}

src/models.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,9 @@ export type TileDisplayMode =
236236
/**
237237
* This is mainly used to set the cookies for the collection display mode.
238238
*
239-
* It allows the user to set different modes for different contexts (collection page, search page, etc).
239+
* It allows the user to set different modes for different contexts (collection page, search page, profile page etc).
240240
*/
241-
export type CollectionBrowserContext = 'collection' | 'search';
241+
export type CollectionBrowserContext = 'collection' | 'search' | 'profile';
242242

243243
/**
244244
* The sort fields shown in the sort filter bar

src/styles/ia-button.ts

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ const darkButtonFillColor = css`var(--secondaryCTAFill, #333)`;
1616
const darkButtonFillColorRGB = css`var(--secondaryCTAFillRGB, 51, 51, 51)`; // RBG format of --secondaryCTAFill
1717
const darkButtonBorderColor = css`var(--primaryCTABorder, #979797)`;
1818

19-
const warningButtonBGColor = css`#ee8950`;
20-
const warningButtonBorderColor = css`#ec7939`;
19+
const warningButtonFillColor = css`var(---primaryWarningFill, #ee8950)`;
20+
const warningButtonFillColorRGB = css`var(--primaryWarningFillRGB, 238, 137, 80)`; // RBG format of --primaryWarningFill
21+
const warningButtonBorderColor = css`var(--primaryWarningBorder, #ec7939)`;
2122

2223
export default css`
2324
.ia-button {
@@ -58,9 +59,12 @@ export default css`
5859
.ia-button.transparent {
5960
background-color: transparent;
6061
}
61-
.ia-button.warning {
62-
background-color: ${warningButtonBGColor}
63-
border-color: ${warningButtonBorderColor};
62+
63+
.ia-button.primary:disabled,
64+
.ia-button.danger:disabled,
65+
.ia-button.warning:disabled,
66+
.ia-button.dark:disabled {
67+
opacity: 0.5;
6468
}
6569
6670
.ia-button.primary {
@@ -91,6 +95,20 @@ export default css`
9195
background-color: rgba(${dangerButtonFillColorRGB}, 0.7);
9296
}
9397
98+
.ia-button.warning {
99+
background-color: ${warningButtonFillColor};
100+
border-color: ${warningButtonBorderColor};
101+
}
102+
.ia-button.warning:hover {
103+
background-color: rgba(${warningButtonFillColorRGB}, 0.9);
104+
}
105+
.ia-button.warning:focus-visible {
106+
background-color: rgba(${warningButtonFillColorRGB}, 0.8);
107+
}
108+
.ia-button.warning:active {
109+
background-color: rgba(${warningButtonFillColorRGB}, 0.7);
110+
}
111+
94112
.ia-button.dark {
95113
background-color: ${darkButtonFillColor};
96114
border-color: ${darkButtonBorderColor};
@@ -104,4 +122,18 @@ export default css`
104122
.ia-button.dark:active {
105123
background-color: rgba(${darkButtonFillColorRGB}, 0.7);
106124
}
125+
126+
.ia-button.link {
127+
margin: 0;
128+
padding: 6px;
129+
border: 0;
130+
appearance: none;
131+
background: none;
132+
color: var(--ia-theme-link-color, #4b64ff);
133+
text-decoration: none;
134+
cursor: pointer;
135+
}
136+
.ia-button.link:hover {
137+
text-decoration: underline;
138+
}
107139
`;

test/manage/manage-bar.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ describe('Manage bar', () => {
3131
expect(el.shadowRoot?.querySelector('.unselect-all-btn')).not.to.exist;
3232
});
3333

34+
it('does not render item manager button except /search/ page', async () => {
35+
const el = await fixture<ManageBar>(html`<manage-bar></manage-bar>`);
36+
expect(el.shadowRoot?.querySelector('.ia-button.warning')).not.to.exist;
37+
});
38+
39+
it('render item manager button for /search/ page', async () => {
40+
const el = await fixture<ManageBar>(
41+
html`<manage-bar .pageContext=${'search'}></manage-bar>`
42+
);
43+
expect(el.shadowRoot?.querySelector('.ia-button.warning')).to.exist;
44+
});
45+
3446
it('includes Select All button when requested', async () => {
3547
const el = await fixture<ManageBar>(
3648
html`<manage-bar showSelectAll></manage-bar>`

0 commit comments

Comments
 (0)