Skip to content

Commit

Permalink
Merge pull request #1214 from carloslancha/issue-1213-events-manageme…
Browse files Browse the repository at this point in the history
…nt-toolbar

Fixes #1213 - Emit all events consistently
  • Loading branch information
julien authored Oct 3, 2018
2 parents 081a017 + d2e2d4c commit 13d4a4d
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 54 deletions.
33 changes: 27 additions & 6 deletions packages/clay-dataset-display/src/ClayDatasetDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,13 @@ class ClayDatasetDisplay extends ClayComponent {
* Continues the propagation of the plus button clicked event
* @param {!Event} event
* @private
* @return {Boolean} If the event has been prevented or not.
*/
_handleCreationButtonClicked(event) {
this.emit('creationButtonClicked', event);
return !this.emit({
name: 'creationButtonClicked',
originalEvent: event,
});
}

/**
Expand All @@ -128,18 +132,26 @@ class ClayDatasetDisplay extends ClayComponent {
* Continues the propagation of the creation menu more button clicked event
* @param {!Event} event
* @private
* @return {Boolean} If the event has been prevented or not.
*/
_handleCreationMenuMoreButtonClicked(event) {
this.emit('creationMenuMoreButtonClicked', event);
return !this.emit({
name: 'creationMenuMoreButtonClicked',
originalEvent: event,
});
}

/**
* Continues the propagation of the filter done clicked event
* @param {!Event} event
* @private
* @return {Boolean} If the event has been prevented or not.
*/
_handleFilterDoneClicked(event) {
this.emit('filterDoneClicked', event);
return !this.emit({
name: 'filterDoneClicked',
originalEvent: event,
});
}

/**
Expand Down Expand Up @@ -235,18 +247,27 @@ class ClayDatasetDisplay extends ClayComponent {
* Continues the propagation of the search event
* @param {!Event} event
* @private
* @return {Boolean} If the event has been prevented or not.
*/
_handleSearch(event) {
this.emit('search', event);
return !this.emit({
name: 'search',
originalEvent: event,
});
}

/**
* Continues the propagation of the sorting button clicked event
* @param {!Event} event
* @private
* @return {Boolean} If the event has been prevented or not.
*/
_handleSortingButtonClicked(event) {
this.emit('sortingButtonClicked', event);
return !this.emit({
data: event.data,
name: 'sortingButtonClicked',
originalEvent: event,
});
}

/**
Expand All @@ -256,7 +277,7 @@ class ClayDatasetDisplay extends ClayComponent {
* @private
*/
_handleSelectPageCheckboxChanged(event) {
let checkboxStatus = event.target.checked;
let checkboxStatus = event.data.checked;

if (checkboxStatus) {
this._selectAllItems();
Expand Down
33 changes: 25 additions & 8 deletions packages/clay-dataset-display/src/__tests__/ClayDatasetDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,12 @@ describe('ClayDatasetDisplay', function() {
jest.runAllTimers();

expect(spy).toHaveBeenCalled();
expect(spy).toHaveBeenCalledWith('filterDoneClicked', expect.any(Object));
expect(spy).toHaveBeenCalledWith(
expect.objectContaining({
name: 'filterDoneClicked',
originalEvent: expect.any(Object),
})
);
});

it('should render a ClayDatasetDisplay and emit an event on management toolbar creation menu button click', () => {
Expand All @@ -592,8 +597,10 @@ describe('ClayDatasetDisplay', function() {

expect(spy).toHaveBeenCalled();
expect(spy).toHaveBeenCalledWith(
'creationButtonClicked',
expect.any(Object)
expect.objectContaining({
name: 'creationButtonClicked',
originalEvent: expect.any(Object),
})
);
});

Expand Down Expand Up @@ -648,8 +655,10 @@ describe('ClayDatasetDisplay', function() {

expect(spy).toHaveBeenCalled();
expect(spy).toHaveBeenCalledWith(
'creationMenuMoreButtonClicked',
expect.any(Object)
expect.objectContaining({
name: 'creationMenuMoreButtonClicked',
originalEvent: expect.any(Object),
})
);
});

Expand All @@ -663,7 +672,12 @@ describe('ClayDatasetDisplay', function() {
jest.runAllTimers();

expect(spy).toHaveBeenCalled();
expect(spy).toHaveBeenCalledWith('search', expect.any(Object));
expect(spy).toHaveBeenCalledWith(
expect.objectContaining({
name: 'search',
originalEvent: expect.any(Object),
})
);
});

it('should render a ClayDatasetDisplay and emit an event on management toolbar sorting button click', () => {
Expand All @@ -677,8 +691,11 @@ describe('ClayDatasetDisplay', function() {

expect(spy).toHaveBeenCalled();
expect(spy).toHaveBeenCalledWith(
'sortingButtonClicked',
expect.any(Object)
expect.objectContaining({
data: expect.any(Object),
name: 'sortingButtonClicked',
originalEvent: expect.any(Object),
})
);
});

Expand Down
62 changes: 51 additions & 11 deletions packages/clay-management-toolbar/src/ClayManagementToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ class ClayManagementToolbar extends ClayComponent {
* Continues the propagation of the clear button clicked event
* @param {!Event} event
* @private
* @return {Boolean} If the event has been prevented or not.
*/
_handleClearResultsClick(event) {
this.emit('clearButtonClicked', event);
return !this.emit({
name: 'clearButtonClicked',
originalEvent: event,
});
}

/**
Expand All @@ -63,9 +67,13 @@ class ClayManagementToolbar extends ClayComponent {
* Continues the propagation of the plus button clicked event
* @param {!Event} event
* @private
* @return {Boolean} If the event has been prevented or not.
*/
_handleCreationButtonClicked(event) {
this.emit('creationButtonClicked', event);
return !this.emit({
name: 'creationButtonClicked',
originalEvent: event,
});
}

/**
Expand All @@ -86,18 +94,26 @@ class ClayManagementToolbar extends ClayComponent {
* Continues the propagation of the creation menu more button clicked event
* @param {!Event} event
* @private
* @return {Boolean} If the event has been prevented or not.
*/
_handleCreationMenuMoreButtonClicked(event) {
this.emit('creationMenuMoreButtonClicked', event);
return !this.emit({
name: 'creationMenuMoreButtonClicked',
originalEvent: event,
});
}

/**
* Continues the propagation of the checkbox changed event
* @param {!Event} event
* @private
* @return {Boolean} If the event has been prevented or not.
*/
_handleFilterDoneButtonClick(event) {
this.emit('filterDoneClicked', event);
return !this.emit({
name: 'filterDoneClicked',
originalEvent: event,
});
}

/**
Expand All @@ -118,18 +134,26 @@ class ClayManagementToolbar extends ClayComponent {
* Continues the propagation of the filter label close clicked event
* @param {!Event} event
* @private
* @return {Boolean} If the event has been prevented or not.
*/
_handleFilterLabelCloseClicked(event) {
this.emit('filterLabelCloseClicked', event);
return !this.emit({
name: 'filterLabelCloseClicked',
originalEvent: event,
});
}

/**
* Continues the propagation of the Info button clicked event
* @param {!Event} event
* @private
* @return {Boolean} If the event has been prevented or not.
*/
_handleInfoButtonClicked(event) {
this.emit('infoButtonClicked', event);
return !this.emit({
name: 'infoButtonClicked',
originalEvent: event,
});
}

/**
Expand Down Expand Up @@ -167,25 +191,41 @@ class ClayManagementToolbar extends ClayComponent {
* @return {Boolean} If the event has been prevented or not.
*/
_handleSearchSearchClick(event) {
return !this.emit('search', event);
return !this.emit({
name: 'search',
originalEvent: event,
});
}

/**
* Continues the propagation of the checkbox changed event
* @param {!Event} event
* @private
* @return {Boolean} If the event has been prevented or not.
*/
_handleSelectPageCheckboxChanged(event) {
this.emit('selectPageCheckboxChanged', event);
return !this.emit({
data: {
checked: event.target.checked,
},
name: 'selectPageCheckboxChanged',
originalEvent: event,
});
}

/**
* Continues the propagation of the sorting button clicked event
* @param {!Event} event
* @private
* @return {Boolean} If the event has been prevented or not.
*/
_handleSortingButtonClicked() {
this.emit('sortingButtonClicked', {
sortingOrder: this.sortingOrder,
_handleSortingButtonClicked(event) {
return !this.emit({
data: {
sortingOrder: this.sortingOrder,
},
name: 'sortingButtonClicked',
originalEvent: event,
});
}

Expand Down
12 changes: 10 additions & 2 deletions packages/clay-management-toolbar/src/ClayResultsBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,26 @@ class ClayResultsBar extends ClayComponent {
* Continues the propagation of the clear button clicked event
* @param {!Event} event
* @private
* @return {Boolean} If the event has been prevented or not.
*/
_handleClearResultsClick(event) {
this.emit('clearButtonClicked', event);
return !this.emit({
name: 'clearButtonClicked',
originalEvent: event,
});
}

/**
* Continues the propagation of the filter label close clicked event
* @param {!Event} event
* @private
* @return {Boolean} If the event has been prevented or not.
*/
_handleFilterLabelCloseClicked(event) {
this.emit('filterLabelCloseClicked', event);
return !this.emit({
name: 'filterLabelCloseClicked',
originalEvent: event,
});
}
}

Expand Down
Loading

0 comments on commit 13d4a4d

Please sign in to comment.