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-118100 Update SelectField if value prop is updated #2955

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,33 @@ public FragmentConfigurationField(JSONObject fieldJSONObject) {
_name = fieldJSONObject.getString("name");
_dataType = fieldJSONObject.getString("dataType");
_defaultValue = fieldJSONObject.getString("defaultValue");
_localizable = fieldJSONObject.getBoolean("localizable");
_type = fieldJSONObject.getString("type");
}

public FragmentConfigurationField(
String name, String dataType, String defaultValue, boolean localizable,
String type) {

_name = name;
_dataType = dataType;
_defaultValue = defaultValue;
_localizable = localizable;
_type = type;
}

/**
* @deprecated As of Cavanaugh (7.4.x), replaced by {@link
* #FragmentConfigurationField(String, String, String, boolean, String)}
*/
@Deprecated
public FragmentConfigurationField(
String name, String dataType, String defaultValue, String type) {

_name = name;
_dataType = dataType;
_defaultValue = defaultValue;
_localizable = false;
_type = type;
}

Expand Down Expand Up @@ -83,6 +101,10 @@ public String getType() {
return _type;
}

public boolean isLocalizable() {
return _localizable;
}

private String _getColorPaletteDefaultValue() {
JSONObject defaultValueJSONObject = JSONUtil.put(
"cssClass", StringPool.BLANK
Expand Down Expand Up @@ -167,6 +189,7 @@ private String _getItemSelectorDefaultValue() {

private final String _dataType;
private final String _defaultValue;
private final boolean _localizable;
private final String _name;
private final String _type;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.liferay.portal.kernel.json.JSONObject;

import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;

Expand All @@ -32,10 +33,19 @@ public interface FragmentEntryConfigurationParser {
public JSONObject getConfigurationDefaultValuesJSONObject(
String configuration);

/**
* @deprecated As of Cavanaugh (7.4.x), replaced by {@link
* #getConfigurationJSONObject(String, String, Locale)}
*/
@Deprecated
public JSONObject getConfigurationJSONObject(
String configuration, String editableValues)
throws JSONException;

public JSONObject getConfigurationJSONObject(
String configuration, String editableValues, Locale locale)
throws JSONException;

/**
* @deprecated As of Athanasius (7.3.x), replaced by {@link
* #getConfigurationJSONObject(String, String)}
Expand All @@ -58,9 +68,22 @@ public Map<String, Object> getContextObjects(
JSONObject configurationValuesJSONObject, String configuration,
long[] segmentsExperienceIds);

public Object getFieldValue(
FragmentConfigurationField fragmentConfigurationField, Locale locale,
String value);

/**
* @deprecated As of Cavanaugh (7.4.x), replaced by {@link
* #getFieldValue(FragmentConfigurationField, Locale, String)}
*/
@Deprecated
public Object getFieldValue(
FragmentConfigurationField fragmentConfigurationField, String value);

public Object getFieldValue(
String configuration, String editableValues, Locale locale,
String name);

/**
* @deprecated As of Athanasius (7.3.x), with no direct replacement
*/
Expand All @@ -69,6 +92,11 @@ public Object getFieldValue(
String configuration, String editableValues,
long[] segmentsExperienceIds, String name);

/**
* @deprecated As of Cavanaugh (7.4.x), replaced by {@link
* #getFieldValue(String, String, Locale, String)}
*/
@Deprecated
public Object getFieldValue(
String configuration, String editableValues, String name);

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version 1.3.0
version 1.4.0
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ public String processFragmentEntryLinkHTML(
JSONObject configurationValuesJSONObject =
_fragmentEntryConfigurationParser.getConfigurationJSONObject(
fragmentEntryLink.getConfiguration(),
fragmentEntryLink.getEditableValues());
fragmentEntryLink.getEditableValues(),
fragmentEntryProcessorContext.getLocale());

template.putAll(
HashMapBuilder.<String, Object>put(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
import com.liferay.portal.kernel.json.JSONException;
import com.liferay.portal.kernel.json.JSONFactoryUtil;
import com.liferay.portal.kernel.json.JSONObject;
import com.liferay.portal.kernel.json.JSONUtil;
import com.liferay.portal.kernel.language.LanguageUtil;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.LocaleUtil;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.kernel.util.Validator;

Expand All @@ -42,6 +44,7 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.ResourceBundle;
Expand Down Expand Up @@ -76,11 +79,25 @@ public JSONObject getConfigurationDefaultValuesJSONObject(
return defaultValuesJSONObject;
}

/**
* @deprecated As of Cavanaugh (7.4.x), replaced by {@link
* #getConfigurationJSONObject(String, String, Locale)}
*/
@Deprecated
@Override
public JSONObject getConfigurationJSONObject(
String configuration, String editableValues)
throws JSONException {

return getConfigurationJSONObject(
configuration, editableValues, LocaleUtil.getMostRelevantLocale());
}

@Override
public JSONObject getConfigurationJSONObject(
String configuration, String editableValues, Locale locale)
throws JSONException {

JSONObject configurationDefaultValuesJSONObject =
getConfigurationDefaultValuesJSONObject(configuration);

Expand Down Expand Up @@ -116,7 +133,7 @@ public JSONObject getConfigurationJSONObject(
configurationDefaultValuesJSONObject.put(
name,
getFieldValue(
configurationField,
configurationField, locale,
configurationValuesJSONObject.getString(name)));
}

Expand Down Expand Up @@ -197,10 +214,30 @@ public Map<String, Object> getContextObjects(

@Override
public Object getFieldValue(
FragmentConfigurationField fragmentConfigurationField, String value) {
FragmentConfigurationField fragmentConfigurationField, Locale locale,
String value) {

value = GetterUtil.getString(
value, fragmentConfigurationField.getDefaultValue());
value = GetterUtil.getString(value);

if (fragmentConfigurationField.isLocalizable() &&
JSONUtil.isValid(value)) {

try {
JSONObject valueJSONObject = JSONFactoryUtil.createJSONObject(
value);

value = valueJSONObject.getString(
LocaleUtil.toLanguageId(locale),
fragmentConfigurationField.getDefaultValue());
}
catch (JSONException jsonException) {
_log.error(
"Unable to parse configuration value JSON", jsonException);
}
}
else if (Validator.isNull(value)) {
value = fragmentConfigurationField.getDefaultValue();
}

if (StringUtil.equalsIgnoreCase(
fragmentConfigurationField.getType(), "checkbox")) {
Expand Down Expand Up @@ -247,20 +284,23 @@ else if (StringUtil.equalsIgnoreCase(
}

/**
* @deprecated As of Athanasius (7.3.x), with no direct replacement
* @deprecated As of Cavanaugh (7.4.x), replaced by {@link
* #getFieldValue(String, String, Locale, String)}
*/
@Deprecated
@Override
public Object getFieldValue(
String configuration, String editableValues,
long[] segmentsExperienceIds, String name) {
FragmentConfigurationField fragmentConfigurationField, String value) {

return getFieldValue(configuration, editableValues, name);
return getFieldValue(
fragmentConfigurationField, LocaleUtil.getMostRelevantLocale(),
value);
}

@Override
public Object getFieldValue(
String configuration, String editableValues, String name) {
String configuration, String editableValues, Locale locale,
String name) {

JSONObject editableValuesJSONObject = null;

Expand Down Expand Up @@ -290,12 +330,40 @@ public Object getFieldValue(
continue;
}

return configurationValuesJSONObject.get(name);
return getFieldValue(
fragmentConfigurationField, locale,
configurationValuesJSONObject.getString(name));
}

return null;
}

/**
* @deprecated As of Athanasius (7.3.x), with no direct replacement
*/
@Deprecated
@Override
public Object getFieldValue(
String configuration, String editableValues,
long[] segmentsExperienceIds, String name) {

return getFieldValue(configuration, editableValues, name);
}

/**
* @deprecated As of Cavanaugh (7.4.x), replaced by {@link
* #getFieldValue(String, String, Locale, String)}
*/
@Deprecated
@Override
public Object getFieldValue(
String configuration, String editableValues, String name) {

return getFieldValue(
configuration, editableValues, LocaleUtil.getMostRelevantLocale(),
name);
}

@Override
public List<FragmentConfigurationField> getFragmentConfigurationFields(
String configuration) {
Expand Down Expand Up @@ -473,6 +541,10 @@ private JSONObject _getInfoDisplayObjectEntryJSONObject(String value) {
JSONObject configurationValueJSONObject =
JSONFactoryUtil.createJSONObject(value);

if (configurationValueJSONObject.length() == 0) {
return null;
}

JSONObject jsonObject = JSONFactoryUtil.createJSONObject(
JSONFactoryUtil.looseSerialize(
_getInfoDisplayObjectEntry(value)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@
"title": "The Label Schema",
"type": "string"
},
"localizable": {
"default": false,
"title": "The Localizable Schema",
"type": "boolean"
},
"name": {
"minLength": 1,
"pattern": "^[A-Za-z0-9]+$",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.liferay.portal.kernel.portlet.bridges.mvc.MVCResourceCommand;
import com.liferay.portal.kernel.servlet.SessionErrors;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.LocaleUtil;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.Portal;
import com.liferay.portal.kernel.util.Validator;
Expand Down Expand Up @@ -81,14 +82,18 @@ protected void doServeResource(
JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

if (fragmentEntryLink != null) {
DefaultFragmentRendererContext defaultFragmentRendererContext =
new DefaultFragmentRendererContext(fragmentEntryLink);

ThemeDisplay themeDisplay =
(ThemeDisplay)resourceRequest.getAttribute(
WebKeys.THEME_DISPLAY);

defaultFragmentRendererContext.setLocale(themeDisplay.getLocale());
String languageId = ParamUtil.getString(
resourceRequest, "languageId", themeDisplay.getLanguageId());

DefaultFragmentRendererContext defaultFragmentRendererContext =
new DefaultFragmentRendererContext(fragmentEntryLink);

defaultFragmentRendererContext.setLocale(
LocaleUtil.fromLanguageId(languageId));

defaultFragmentRendererContext.setMode(
FragmentEntryLinkConstants.EDIT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import com.liferay.portal.kernel.portlet.PortletIdCodec;
import com.liferay.portal.kernel.service.PortletLocalServiceUtil;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.LocaleUtil;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.PortalUtil;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.kernel.util.WebKeys;
Expand Down Expand Up @@ -159,7 +161,12 @@ public static JSONObject getFragmentEntryLinkJSONObject(
DefaultFragmentRendererContext defaultFragmentRendererContext =
new DefaultFragmentRendererContext(fragmentEntryLink);

defaultFragmentRendererContext.setLocale(themeDisplay.getLocale());
String languageId = ParamUtil.getString(
portletRequest, "languageId", themeDisplay.getLanguageId());

defaultFragmentRendererContext.setLocale(
LocaleUtil.fromLanguageId(languageId));

defaultFragmentRendererContext.setMode(
FragmentEntryLinkConstants.EDIT);
defaultFragmentRendererContext.setSegmentsExperienceIds(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {StyleBookContextProvider} from '../../plugins/page-design-options/hooks/
import {INIT} from '../actions/types';
import {config} from '../config/index';
import {reducer} from '../reducers/index';
import selectLanguageId from '../selectors/selectLanguageId';
import {StoreContextProvider, useSelector} from '../store/index';
import {DragAndDropContextProvider} from '../utils/dragAndDrop/useDragAndDrop';
import {CollectionActiveItemContextProvider} from './CollectionActiveItemContext';
Expand Down Expand Up @@ -75,7 +76,7 @@ App.propTypes = {
};

const LanguageDirection = () => {
const languageId = useSelector((state) => state.languageId);
const languageId = useSelector(selectLanguageId);

useEffect(() => {
const currentLanguageDirection = config.languageDirection[languageId];
Expand Down