Skip to content

Commit

Permalink
improve resource cards states (#479)
Browse files Browse the repository at this point in the history
  • Loading branch information
allyoucanmap authored Aug 27, 2021
1 parent 3196dba commit 2c8d021
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ const Cards = withResizeDetector(({
// enable allowedOptions (menu cards) only for list layout
const allowedOptions = (cardLayoutStyle === 'list' && !isProcessing) ? options
.filter((opt) => hasPermissionsTo(resource?.perms, opt?.perms, 'resource')) : [];

if (isDeleted) {
return null;
}

return (
<li
key={resource.pk}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ const Cards = withResizeDetector(({
isProcessing,
isDeleted
} = getResourceStatuses(resource);

if (isDeleted) {
return null;
}

return (
<li
key={resource?.pk}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const ResourceCard = forwardRef(({
>
<Message msgId="gnhome.author"/>: <ALink readOnly={readOnly} href={formatHref({
query: {
'filter{owner.username.in}': res.owner.username
'filter{owner.username.in}': res?.owner?.username
}
})}>{getUserName(res.owner)}</ALink>
</p>
Expand Down
5 changes: 3 additions & 2 deletions geonode_mapstore_client/client/js/epics/gnsave.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ export const gnWatchStopCopyProcessOnSave = (action$, store) =>
.switchMap((action) => {
const state = store.getState();
const resourceId = getResourceId(state);
if (resourceId !== action?.payload?.resource?.pk) {
const pathname = state?.router?.location?.pathname;
if (resourceId !== action?.payload?.resource?.pk || pathname.includes('/detail/')) {
return Observable.empty();
}
const isError = action?.payload?.error || action?.payload?.output?.status === ProcessStatus.FAILED;
Expand All @@ -268,7 +269,7 @@ export const gnWatchStopCopyProcessOnSave = (action$, store) =>
return Observable.defer(() => getResourceByUuid(newResourceUuid))
.switchMap((resource) => {
window.location.href = parseDevHostname(resource?.detail_url);
return Observable.of();
return Observable.empty();
})
.startWith(loadingResourceConfig(true));
});
Expand Down
31 changes: 20 additions & 11 deletions geonode_mapstore_client/client/js/epics/gnsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import isNil from 'lodash/isNil';
import {
getResources,
getResourceByPk,
getFeaturedResources
getFeaturedResources,
getResourceByUuid
} from '@js/api/geonode/v2';
import {
SEARCH_RESOURCES,
Expand All @@ -40,7 +41,6 @@ import {
import url from 'url';
import { getCustomMenuFilters } from '@js/selectors/config';
import { STOP_ASYNC_PROCESS } from '@js/actions/resourceservice';
import { getResourceId } from '@js/selectors/resource';
import {
ProcessTypes,
ProcessStatus
Expand Down Expand Up @@ -244,18 +244,27 @@ export const getFeaturedResourcesEpic = (action$, {getState = () => {}}) =>
export const gnWatchStopCopyProcessOnSearch = (action$, store) =>
action$.ofType(STOP_ASYNC_PROCESS)
.filter(action => action?.payload?.processType === ProcessTypes.COPY_RESOURCE)
.switchMap((action) => {
const state = store.getState();
const resourceId = getResourceId(state);
.flatMap((action) => {
const isError = action?.payload?.error || action?.payload?.output?.status === ProcessStatus.FAILED;
if (!isError && resourceId === action?.payload?.resource?.pk) {
if (isError) {
return Observable.empty();
}
const newResourceUuid = action?.payload?.output?.output_params?.output?.uuid;
if (newResourceUuid === undefined) {
return Observable.empty();
}
// reset search
return Observable.of(updateResourcesRequest({
action: 'PUSH',
location: state?.router?.location
}, true));
const pk = action?.payload?.output?.input_params?.instance;
return Observable.defer(() => getResourceByUuid(newResourceUuid))
.switchMap((resource) => {
const resources = store.getState().gnsearch?.resources || [];
const newResources = resources.reduce((acc, res) => {
if (res.pk === (pk + '')) {
return [...acc, { ...resource, '@temporary': true }, res];
}
return [...acc, res];
}, []);
return Observable.of(updateResources(newResources, true));
});
});

export default {
Expand Down
10 changes: 7 additions & 3 deletions geonode_mapstore_client/client/js/routes/Detail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import MetaTags from "@js/components/MetaTags";
import {
getThemeLayoutSize
} from '@js/utils/AppUtils';

import { getTotalResources } from '@js/selectors/search';
import ConnectedCardGrid from '@js/routes/catalogue/ConnectedCardGrid';
import DeleteResource from '@js/plugins/DeleteResource';
import SaveAs from '@js/plugins/SaveAs';
Expand Down Expand Up @@ -167,7 +167,11 @@ function Detail({
formatHref={handleFormatHref}
/>}
</div>
<DeleteResourcePlugin />
<DeleteResourcePlugin
redirectTo={handleFormatHref({
pathname: '/search/'
}).replace('#', '')}
/>
<SaveAsPlugin closeOnSave labelId="gnviewer.clone"/>
</>
);
Expand Down Expand Up @@ -203,7 +207,7 @@ const ConnectedDetail = connect(
state => state?.gnresource?.data || null,
state => state?.controls?.gnFiltersPanel?.enabled || null,
getParsedGeoNodeConfiguration,
state => state?.gnsearch?.total || 0,
getTotalResources,
state => state?.gnsettings?.siteName || "Geonode"
], (params, user, resource, isFiltersPanelEnabled, config, totalResources, siteName) => ({
params,
Expand Down
6 changes: 3 additions & 3 deletions geonode_mapstore_client/client/js/routes/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
} from '@js/utils/AppUtils';

import ConnectedCardGrid from '@js/routes/catalogue/ConnectedCardGrid';
import { getFeaturedResults } from '@js/selectors/search';
import { getFeaturedResults, getTotalResources } from '@js/selectors/search';
import DeleteResource from '@js/plugins/DeleteResource';
import SaveAs from '@js/plugins/SaveAs';
const { DeleteResourcePlugin } = DeleteResource;
Expand Down Expand Up @@ -145,7 +145,7 @@ function Home({
</ConnectedCardGrid>
</div>
</div>
<DeleteResourcePlugin />
<DeleteResourcePlugin redirectTo={false} />
<SaveAsPlugin closeOnSave labelId="gnviewer.clone"/>
</div>
);
Expand Down Expand Up @@ -174,7 +174,7 @@ const ConnectedHome = connect(
state => state?.gnsearch?.params || DEFAULT_PARAMS,
userSelector,
getParsedGeoNodeConfiguration,
state => state?.gnsearch?.total || 0
getTotalResources
], (params, user, config, totalResources) => ({
params,
user,
Expand Down
6 changes: 3 additions & 3 deletions geonode_mapstore_client/client/js/routes/Search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import MetaTags from "@js/components/MetaTags";
import {
getThemeLayoutSize
} from '@js/utils/AppUtils';

import { getTotalResources } from '@js/selectors/search';
import ConnectedCardGrid from '@js/routes/catalogue/ConnectedCardGrid';
import DeleteResource from '@js/plugins/DeleteResource';
import SaveAs from '@js/plugins/SaveAs';
Expand Down Expand Up @@ -225,7 +225,7 @@ function Search({
</ConnectedCardGrid>
</div>
</div>
<DeleteResourcePlugin />
<DeleteResourcePlugin redirectTo={false} />
<SaveAsPlugin closeOnSave labelId="gnviewer.clone"/>
</>
);
Expand Down Expand Up @@ -261,7 +261,7 @@ const ConnectedSearch = connect(
state => state?.gnresource?.data || null,
state => state?.controls?.gnFiltersPanel?.enabled || null,
getParsedGeoNodeConfiguration,
state => state?.gnsearch?.total || 0,
getTotalResources,
state => state?.gnsettings?.siteName || "Geonode"
], (params, user, resource, isFiltersPanelEnabled, config, totalResources, siteName) => ({
params,
Expand Down
9 changes: 9 additions & 0 deletions geonode_mapstore_client/client/js/selectors/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/

import { getResourceStatuses } from '@js/utils/ResourceUtils';

export const getSearchResults = (state) => {
const resources = state?.gnsearch?.resources || [];
const processes = state?.resourceservice?.processes || [];
Expand All @@ -29,3 +31,10 @@ export const getFeaturedResults = (state) => {
return resource;
});
};

export const getTotalResources = (state) => {
const resources = getSearchResults(state);
const deletedResourcesCount = resources.filter(resource => getResourceStatuses(resource).isDeleted).length;
const temporaryResourcesCount = resources.filter(resource => resource['@temporary']).length;
return (state?.gnsearch?.total || 0) - deletedResourcesCount + temporaryResourcesCount;
};

0 comments on commit 2c8d021

Please sign in to comment.