Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix likes feature in Search Page #14709

Merged
merged 8 commits into from
Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Development
- Fix dataset search with dependent visualizations ([CartoDB/product#267](https://github.com/CartoDB/product/issues/267)))
- Fix Lockout page ([product#261](https://github.com/CartoDB/product/issues/261))
- Use .toLocaleDateString() to format date in notification page ([#14707](https://github.com/CartoDB/cartodb/pull/14707))
- Fix likes feature in Search Page ([#14709](https://github.com/CartoDB/cartodb/pull/14709))

4.25.2 (2019-02-25)
-------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
import DatasetQuickActions from 'new-dashboard/components/QuickActions/DatasetQuickActions';
import distanceInWordsStrict from 'date-fns/distance_in_words_strict';
import * as Visualization from 'new-dashboard/core/models/visualization';
import { mapActions } from 'vuex';
import FeaturesDropdown from '../Dropdowns/FeaturesDropdown';
import countCharsArray from 'new-dashboard/utils/count-chars-array';

Expand All @@ -116,6 +115,10 @@ export default {
selectMode: {
type: Boolean,
default: false
},
storeActionType: {
type: String,
default: 'datasets'
}
},
data: function () {
Expand Down Expand Up @@ -216,10 +219,6 @@ export default {
closeQuickActions () {
this.areQuickActionsOpen = false;
},
...mapActions({
likeDataset: 'datasets/like',
deleteLikeDataset: 'datasets/deleteLike'
}),
onClick (event) {
if (this.$props.selectMode) {
event.preventDefault();
Expand All @@ -228,6 +227,12 @@ export default {
},
onContentChanged (type) {
this.$emit('contentChanged', type);
},
likeDataset (dataset) {
this.$store.dispatch(`${this.storeActionType}/like`, dataset);
},
deleteLikeDataset (dataset) {
this.$store.dispatch(`${this.storeActionType}/deleteLike`, dataset);
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
:isSelected="isSelected"
:canHover="canHover"
:selectMode="selectMode"
:storeActionType="storeActionType"
@toggleSelection="toggleSelection"
@contentChanged="onContentChanged" />
</template>
Expand Down
2 changes: 1 addition & 1 deletion lib/assets/javascripts/new-dashboard/core/trackers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if (isTrackJSEnabled) {
token: store.state.config.trackjs_customer,
application: store.state.config.trackjs_app_key,
userId: store.state.user.username,
version: __ASSETS_VERSION__ // eslint-disable-line
version: __ASSETS_VERSION__ + '-nd' // eslint-disable-line
});
}

Expand Down
4 changes: 2 additions & 2 deletions lib/assets/javascripts/new-dashboard/pages/Search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

<ul class="grid grid-cell" v-if="!isFetchingMaps">
<li v-for="map in maps" :key="map.id" class="grid-cell grid-cell--col12 search-item">
<MapCard :visualization=map :canHover=false :condensed="true"></MapCard>
<MapCard :visualization=map :canHover=false :condensed="true" storeActionType="search"></MapCard>
</li>

<div class="grid-cell grid-cell--col4 grid-cell--col6--tablet grid-cell--col12--mobile is-caption text maps--empty" v-if="!hasMaps">
Expand All @@ -44,7 +44,7 @@

<ul class="grid-cell grid-cell--col12" v-if="!isFetchingDatasets">
<li v-for="dataset in datasets" :key="dataset.id" class="search-item">
<DatasetCard :dataset=dataset :canHover=false></DatasetCard>
<DatasetCard :dataset=dataset :canHover=false storeActionType="search"></DatasetCard>
</li>

<div class="is-caption text" v-if="!hasDatasets">
Expand Down
17 changes: 15 additions & 2 deletions lib/assets/javascripts/new-dashboard/store/modules/search/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import toObject from 'new-dashboard/utils/to-object';
import * as VisualizationActions from '../../actions/visualizations';

const search = {
namespaced: true,
Expand All @@ -9,7 +10,7 @@ const search = {
maps: {
isFetching: false,
isErrored: false,
results: [],
results: {},
error: {},
page: 1,
numPages: 1,
Expand All @@ -18,7 +19,7 @@ const search = {
datasets: {
isFetching: false,
isErrored: false,
results: [],
results: {},
error: {},
page: 1,
numPages: 1,
Expand Down Expand Up @@ -72,6 +73,16 @@ const search = {

state.datasets.isFetching = false;
},
updateLike (state, { visualizationId, liked }) {
const visualization = state.maps.results[visualizationId] || state.datasets.results[visualizationId];

if (visualization) {
visualization.liked = liked;
}
},
updateNumberLikes () {
// NOOP. This method avoids action not finding mutation.
},
resetState (state) {
state.searchTerm = '';
state.tag = '';
Expand All @@ -98,6 +109,8 @@ const search = {
}
},
actions: {
deleteLike: VisualizationActions.deleteLike,
like: VisualizationActions.like,
doSearch (context, searchParameters) {
context.commit('updateSearchTerm', searchParameters);
context.commit('setFetchingState', 'maps');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ export function setVisualizations (state, visualizationsData) {
}

export function updateLike (state, {visualizationId, liked}) {
state.list[visualizationId].liked = liked;
const visualization = state.list[visualizationId];

if (visualization) {
visualization.liked = liked;
}
}

export function updateNumberLikes (state, {visualizationId, liked}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ describe('DatasetCard.vue', () => {

actions = {
'datasets/deleteLike': jest.fn(),
'datasets/like': jest.fn()
'datasets/like': jest.fn(),
'search/deleteLike': jest.fn(),
'search/like': jest.fn()
};

store = new Vuex.Store({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ exports[`DatasetsList.vue should render properly 1`] = `
</div>
<ul class="grid-cell grid-cell--col12">
<li class="dataset-item">
<datasetcard-stub dataset="[object Object]" canhover="true"></datasetcard-stub>
<datasetcard-stub dataset="[object Object]" canhover="true" storeactiontype="datasets"></datasetcard-stub>
</li>
<li class="dataset-item">
<datasetcard-stub dataset="[object Object]" canhover="true"></datasetcard-stub>
<datasetcard-stub dataset="[object Object]" canhover="true" storeactiontype="datasets"></datasetcard-stub>
</li>
</ul>
<div class="grid-cell grid-cell--col12">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ exports[`Search.vue Rendering should render search results correctly 1`] = `
<!---->
<ul class="grid grid-cell">
<li class="grid-cell grid-cell--col12 search-item">
<mapcard-stub visualization="[object Object]" storeactiontype="maps" condensed="true"></mapcard-stub>
<mapcard-stub visualization="[object Object]" storeactiontype="search" condensed="true"></mapcard-stub>
</li>
<li class="grid-cell grid-cell--col12 search-item">
<mapcard-stub visualization="[object Object]" storeactiontype="maps" condensed="true"></mapcard-stub>
<mapcard-stub visualization="[object Object]" storeactiontype="search" condensed="true"></mapcard-stub>
</li>
<!---->
</ul>
Expand All @@ -115,10 +115,10 @@ exports[`Search.vue Rendering should render search results correctly 1`] = `
<div class="section-title grid-cell title is-medium">SearchPage.sections.data</div>
<ul class="grid-cell grid-cell--col12">
<li class="search-item">
<datasetcard-stub dataset="[object Object]"></datasetcard-stub>
<datasetcard-stub dataset="[object Object]" storeactiontype="search"></datasetcard-stub>
</li>
<li class="search-item">
<datasetcard-stub dataset="[object Object]"></datasetcard-stub>
<datasetcard-stub dataset="[object Object]" storeactiontype="search"></datasetcard-stub>
</li>
<!---->
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,38 @@ describe('MapsStore', () => {
});
});

it('updateLike', () => {
let state = {
list: {
'xxxx-yyyy-zzzzz': {
liked: false
describe('updateLike', () => {
it('set update liked property of a given visualization', () => {
let state = {
list: {
'xxxx-yyyy-zzzzz': {
liked: false
}
}
}
};
};

mutations.updateLike(state, { visualizationId: 'xxxx-yyyy-zzzzz', liked: true });
expect(state).toEqual({
list: {
'xxxx-yyyy-zzzzz': {
liked: true
mutations.updateLike(state, { visualizationId: 'xxxx-yyyy-zzzzz', liked: true });
expect(state).toEqual({
list: {
'xxxx-yyyy-zzzzz': {
liked: true
}
}
}
});
});

it('should not throw when passing an missing visualization id', () => {
let state = {
list: {
'xxxx-yyyy-zzzzz': {
liked: false
}
}
};

expect(() => {
mutations.updateLike(state, { visualizationId: 'unknown_id', liked: true });
}).not.toThrow();
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,29 @@ describe('SearchStore', () => {
});
});

describe('updateLike', () => {
it('should set update liked property of a given visualization', () => {
const dataset = { ...datasetVisualizationsData.visualizations[0] };
const state = {
resultsPerPage: 6,
maps: { results: {} },
datasets: {
results: {
[dataset.id]: dataset
}
}
};

const likeData = {
visualizationId: '8b2fa51d-618c-48ea-8c4c-4aa5e9a93a90',
liked: true
};

searchStore.mutations.updateLike(state, likeData);
expect(dataset.liked).toEqual(true);
});
});

describe('resetState', () => {
it('should set results, calculate pages and revert isFetching state', () => {
const state = {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cartodb-ui",
"version": "1.0.0-assets.65",
"version": "1.0.0-assets.65-likesinsearch-1",
"description": "CARTO UI frontend",
"repository": {
"type": "git",
Expand Down