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

LPS-127308 [TS] [Bug: 7.3.x, master] LPS-127308 Category Filters are removed when doing a text search in Content Dashboard #99019

Expand Up @@ -44,6 +44,7 @@
import com.liferay.portal.kernel.service.UserLocalService;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.ListUtil;
import com.liferay.portal.kernel.util.SetUtil;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.kernel.workflow.WorkflowConstants;

Expand Down Expand Up @@ -372,6 +373,46 @@ public PortletURL getPortletURL() {
public String getSearchActionURL() {
PortletURL portletURL = liferayPortletResponse.createRenderURL();

List<Long> assetCategoryIds =
_contentDashboardAdminDisplayContext.getAssetCategoryIds();

if (!ListUtil.isEmpty(assetCategoryIds)) {
Stream<Long> stream = assetCategoryIds.stream();

portletURL.setParameter(
"assetCategoryId",
stream.map(
String::valueOf
).toArray(
String[]::new
));
}

Set<String> assetTagIds =
_contentDashboardAdminDisplayContext.getAssetTagIds();

if (!SetUtil.isEmpty(assetTagIds)) {
Stream<String> stream = assetTagIds.stream();

portletURL.setParameter(
"assetTagId", stream.toArray(String[]::new));
}

List<Long> authorIds =
_contentDashboardAdminDisplayContext.getAuthorIds();

if (!ListUtil.isEmpty(authorIds)) {
Stream<Long> stream = authorIds.stream();

portletURL.setParameter(
"authorIds",
stream.map(
String::valueOf
).toArray(
String[]::new
));
}

List<? extends ContentDashboardItemType> contentDashboardItemTypes =
_contentDashboardAdminDisplayContext.getContentDashboardItemTypes();

Expand Down
@@ -0,0 +1,170 @@
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/

import {
ItemSelectorDialog,
addParams,
navigate,
openSelectionModal,
} from 'frontend-js-web';

export default function propsTransformer({portletNamespace, ...otherProps}) {
const selectAuthor = (itemData) => {
openSelectionModal({
buttonAddLabel: Liferay.Language.get('select'),
multiple: true,
onSelect(selectedItem) {
if (selectedItem) {
let redirectURL = itemData.redirectURL;

selectedItem.forEach((item) => {
redirectURL = addParams(
`${portletNamespace}authorIds=${item.id}`,
redirectURL
);
});

navigate(redirectURL);
}
},
selectEventName: `${portletNamespace}selectedAuthorItem`,
title: itemData.dialogTitle,
url: itemData.selectAuthorURL,
});
};

const selectAssetCategory = (itemData) => {
const itemSelectorDialog = new ItemSelectorDialog({
buttonAddLabel: Liferay.Language.get('select'),
eventName: `${portletNamespace}selectedAssetCategory`,
title: itemData.dialogTitle,
url: itemData.selectAssetCategoryURL,
});

itemSelectorDialog.on('selectedItemChange', (event) => {
const selectedItem = event.selectedItem;

if (selectedItem) {
const assetCategories = Object.keys(selectedItem).filter(
(key) => !selectedItem[key].unchecked
);

let redirectURL = itemData.redirectURL;

assetCategories.forEach((assetCategory) => {
redirectURL = addParams(
`${portletNamespace}assetCategoryId=${selectedItem[assetCategory].categoryId}`,
redirectURL
);
});

navigate(redirectURL);
}
});

itemSelectorDialog.open();
};

const selectAssetTag = (itemData) => {
openSelectionModal({
buttonAddLabel: Liferay.Language.get('select'),
multiple: true,
onSelect(selectedItem) {
if (selectedItem) {
const assetTags = selectedItem['items'].split(',');

let redirectURL = itemData.redirectURL;

assetTags.forEach((assetTag) => {
redirectURL = addParams(
`${portletNamespace}assetTagId=${assetTag}`,
redirectURL
);
});

navigate(redirectURL);
}
},
selectEventName: `${portletNamespace}selectedAssetTag`,
title: itemData.dialogTitle,
url: itemData.selectTagURL,
});
};

const selectContentDashboardItemType = (itemData) => {
openSelectionModal({
buttonAddLabel: Liferay.Language.get('select'),
multiple: true,
onSelect(selectedItem) {
if (selectedItem) {
let redirectURL = itemData.redirectURL;

selectedItem.forEach((item) => {
redirectURL = addParams(
`${portletNamespace}contentDashboardItemTypePayload=${JSON.stringify(
item
)}`,
redirectURL
);
});

navigate(redirectURL);
}
},
selectEventName: `${portletNamespace}selectedContentDashboardItemTypeItem`,
title: itemData.dialogTitle,
url: itemData.selectContentDashboardItemTypeURL,
});
};

const selectScope = (itemData) => {
openSelectionModal({
id: `${portletNamespace}selectedScopeIdItem`,
onSelect(selectedItem) {
navigate(
addParams(
`${portletNamespace}scopeId=${selectedItem.groupid}`,
itemData.redirectURL
)
);
},
selectEventName: `${portletNamespace}selectedScopeIdItem`,
title: itemData.dialogTitle,
url: itemData.selectScopeURL,
});
};

return {
...otherProps,
onFilterDropdownItemClick(event, {item}) {
const action = item.data?.action;

if (action === 'selectAssetCategory') {
selectAssetCategory(item.data);
}
else if (action === 'selectAssetTag') {
selectAssetTag(item.data);
}
else if (action === 'selectAuthor') {
selectAuthor(item.data);
}
else if (action === 'selectContentDashboardItemType') {
selectContentDashboardItemType(item.data);
}
else if (action === 'selectScope') {
selectScope(item.data);
}
},
};
}
Expand Up @@ -18,8 +18,6 @@

<%
ContentDashboardAdminDisplayContext contentDashboardAdminDisplayContext = (ContentDashboardAdminDisplayContext)request.getAttribute(ContentDashboardWebKeys.CONTENT_DASHBOARD_ADMIN_DISPLAY_CONTEXT);

ContentDashboardAdminManagementToolbarDisplayContext contentDashboardAdminManagementToolbarDisplayContext = (ContentDashboardAdminManagementToolbarDisplayContext)request.getAttribute(ContentDashboardWebKeys.CONTENT_DASHBOARD_ADMIN_MANAGEMENT_TOOLBAR_DISPLAY_CONTEXT);
%>

<div class="sidebar-wrapper">
Expand Down Expand Up @@ -96,9 +94,10 @@ ContentDashboardAdminManagementToolbarDisplayContext contentDashboardAdminManage
</span>
</h2>

<clay:management-toolbar-v2
displayContext="<%= contentDashboardAdminManagementToolbarDisplayContext %>"
elementClasses="content-dashboard-management-toolbar"
<clay:management-toolbar
cssClass="content-dashboard-management-toolbar"
managementToolbarDisplayContext="<%= (ContentDashboardAdminManagementToolbarDisplayContext)request.getAttribute(ContentDashboardWebKeys.CONTENT_DASHBOARD_ADMIN_MANAGEMENT_TOOLBAR_DISPLAY_CONTEXT) %>"
propsTransformer="js/ContentDashboardManagementToolbarPropsTransformer"
/>

<liferay-ui:search-container
Expand Down Expand Up @@ -268,9 +267,4 @@ ContentDashboardAdminManagementToolbarDisplayContext contentDashboardAdminManage
</liferay-ui:search-container>
</clay:sheet>
</clay:container-fluid>
</div>

<liferay-frontend:component
componentId="<%= contentDashboardAdminManagementToolbarDisplayContext.getDefaultEventHandler() %>"
module="js/ContentDashboardManagementToolbarDefaultEventHandler"
/>
</div>
Expand Up @@ -22,8 +22,8 @@ ContentDashboardItemTypeItemSelectorViewManagementToolbarDisplayContext contentD
ContentDashboardItemTypeItemSelectorViewDisplayContext contentDashboardItemTypeItemSelectorViewDisplayContext = (ContentDashboardItemTypeItemSelectorViewDisplayContext)request.getAttribute(ContentDashboardItemTypeItemSelectorViewDisplayContext.class.getName());
%>

<clay:management-toolbar-v2
displayContext="<%= contentDashboardItemTypeItemSelectorViewManagementToolbarDisplayContext %>"
<clay:management-toolbar
managementToolbarDisplayContext="<%= contentDashboardItemTypeItemSelectorViewManagementToolbarDisplayContext %>"
/>

<clay:container-fluid>
Expand Down
Expand Up @@ -32,6 +32,7 @@
import com.liferay.taglib.util.TagResourceBundleUtil;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
Expand Down Expand Up @@ -1067,8 +1068,8 @@ protected int processStartTag() throws Exception {
return SKIP_BODY;
}

private Map<String, String> _getParamsMap(String url) {
Map<String, String> searchData = new HashMap<>();
private Map<String, List<String>> _getParamsMap(String url) {
Map<String, List<String>> searchData = new HashMap<>();

String[] parameters = StringUtil.split(
HttpUtil.getQueryString(url), CharPool.AMPERSAND);
Expand All @@ -1095,7 +1096,15 @@ private Map<String, String> _getParamsMap(String url) {

parameterValue = HttpUtil.decodeURL(parameterValue);

searchData.put(parameterName, parameterValue);
List<String> parameterValues = searchData.get(parameterName);

if (parameterValues == null) {
parameterValues = new LinkedList<>();

searchData.put(parameterName, parameterValues);
}

parameterValues.add(parameterValue);
}

return searchData;
Expand Down
Expand Up @@ -34,6 +34,7 @@
import com.liferay.portal.kernel.util.Validator;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -463,8 +464,8 @@ private String _getPlaceholder(String id) {
return sb.toString();
}

private Map<String, Object> _getSearchData(String searchActionURL) {
Map<String, Object> searchData = new HashMap<>();
private Map<String, List<Object>> _getSearchData(String searchActionURL) {
Map<String, List<Object>> searchData = new HashMap<>();

String[] parameters = StringUtil.split(
HttpUtil.getQueryString(searchActionURL), CharPool.AMPERSAND);
Expand All @@ -491,7 +492,15 @@ private Map<String, Object> _getSearchData(String searchActionURL) {

parameterValue = HttpUtil.decodeURL(parameterValue);

searchData.put(parameterName, parameterValue);
List<Object> parameterValues = searchData.get(parameterName);

if (parameterValues == null) {
parameterValues = new LinkedList<>();

searchData.put(parameterName, parameterValues);
}

parameterValues.add(parameterValue);
}

return searchData;
Expand Down
Expand Up @@ -20,13 +20,32 @@ import React from 'react';

import LinkOrButton from './LinkOrButton';

const FilterOrderControls = ({disabled, filterDropdownItems, sortingURL}) => {
const FilterOrderControls = ({
disabled,
filterDropdownItems,
onFilterDropdownItemClick,
sortingURL,
}) => {
return (
<>
{filterDropdownItems && (
<ClayManagementToolbar.Item>
<ClayDropDownWithItems
items={filterDropdownItems}
items={filterDropdownItems.map((item) => {
return {
...item,
items: item.items.map((childItem) => {
return {
...childItem,
onClick(event) {
onFilterDropdownItemClick(event, {
item: childItem,
});
},
};
}),
};
})}
trigger={
<ClayButton
className="nav-link"
Expand Down
Expand Up @@ -45,6 +45,7 @@ function ManagementToolbar({
onCreateButtonClick = () => {},
onCreationMenuItemClick = () => {},
onInfoButtonClick = () => {},
onFilterDropdownItemClick = () => {},
onSelectAllButtonClick = () => {},
onShowMoreButtonClick,
searchActionURL,
Expand Down Expand Up @@ -101,6 +102,9 @@ function ManagementToolbar({
<FilterOrderControls
disabled={disabled}
filterDropdownItems={filterDropdownItems}
onFilterDropdownItemClick={
onFilterDropdownItemClick
}
sortingURL={sortingURL}
/>
)}
Expand Down