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

DRAFT FEATURE: add information to dimensions menu #3597

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, {PureComponent} from 'react';
import PropTypes from 'prop-types';
import SelectBox from '@neos-project/react-ui-components/src/SelectBox/';
import style from './style.module.css';
import {$get, $transform} from 'plow-js';
import {$transform} from 'plow-js';
import mapValues from 'lodash.mapvalues';
import sortBy from 'lodash.sortby';
import {neos} from '@neos-project/neos-ui-decorators';
Expand Down Expand Up @@ -48,9 +48,11 @@ export default class DimensionSelector extends PureComponent {
(presetConfiguration, presetName) => {
return $transform(
{
label: $get('label'),
label: presetConfiguration?.label,
value: presetName,
disallowed: $get('disallowed')
disallowed: presetConfiguration?.disallowed,
existing: presetConfiguration?.existing,
url: presetConfiguration?.url
},
presetConfiguration
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,51 @@
import React, {PureComponent} from 'react';
import PropTypes from 'prop-types';
import style from './style.module.css';
// eslint-disable-next-line camelcase
import SelectBox_Option_SingleLineLink from '@neos-project/react-ui-components/src/SelectBox_Option_SingleLineLink/index';
import SelectBox_Option_SingleLine from '@neos-project/react-ui-components/src/SelectBox_Option_SingleLine/index';
import mergeClassNames from 'classnames';

export default class DimensionSelectorOption extends PureComponent {
static propTypes = {
option: PropTypes.shape({
label: PropTypes.string.isRequired,
disallowed: PropTypes.bool
disallowed: PropTypes.bool,
existing: PropTypes.bool,
url: PropTypes.string
})
};

render() {
const {option} = this.props;

const className = mergeClassNames({
[style.lighter]: !option.existing,
[style.strikethrough]: option.disallowed
});

if (option.existing) {
const linkOptions = {
className: style.whiteLink,
href: option.url,
target: '_blank',
rel: 'noopener noreferrer',
onClick: (event) => event.preventDefault()
}

return (
<SelectBox_Option_SingleLineLink
{...this.props}
className={className}
label={option.label}
linkOptions={linkOptions}
/>
);
}

return (
// eslint-disable-next-line camelcase
<SelectBox_Option_SingleLine
{...this.props}
className={option.disallowed ? style.dimmed : ''}
className={className}
label={option.label}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ SelectedPreset.propTypes = {
@connect($transform({
contentDimensions: selectors.CR.ContentDimensions.byName,
allowedPresets: selectors.CR.ContentDimensions.allowedPresets,
activePresets: selectors.CR.ContentDimensions.activePresets
activePresets: selectors.CR.ContentDimensions.activePresets,
getNodeByContextPath: selectors.CR.Nodes.nodeByContextPath,
documentNode: selectors.CR.Nodes.documentNodeSelector
}), {
selectPreset: actions.CR.ContentDimensions.selectPreset,
setAllowed: actions.CR.ContentDimensions.setAllowed
Expand Down Expand Up @@ -255,15 +257,58 @@ export default class DimensionSwitcher extends PureComponent {
return null;
}

getExistingDimensions() {
const allowed = this.props.allowedPresets
const currentDocumentNode = this.props.getNodeByContextPath(this.props.documentNode.contextPath)
const dimensionsWithVariants = currentDocumentNode?.otherNodeVariants;
if (!dimensionsWithVariants) {
return [currentDocumentNode.dimensions]
}

const existingDimensions = {};
Object.keys(allowed).forEach((dimensionName) => {
const dimensionValues = allowed[dimensionName];

existingDimensions[dimensionName] = [];
Array.from(dimensionValues).forEach((dimensionValue) => {
const result = [...dimensionsWithVariants, currentDocumentNode.dimensions].find((dimension) => {
return dimension[dimensionName] === dimensionValue;
});
if (result) {
existingDimensions[dimensionName].push(dimensionValue);
}
});
});

return existingDimensions;
}

presetsForDimension(dimensionName) {
const {contentDimensions, allowedPresets, i18nRegistry} = this.props;
const dimensionConfiguration = $get(dimensionName, contentDimensions);
const existingDimensions = this.getExistingDimensions();

return mapValues(dimensionConfiguration.presets,
(presetConfiguration, presetName) => {
// if we do not know which dimensions exist, show all as existing
let existing = existingDimensions.length === 1 && existingDimensions[0] === undefined;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue: Sometimes we do not get the existing dimensions (?switching between dimensions with overlapping defined values)
What should be displayed in this case.? (does not feel right, to mix showing and not showing the information)

(currently if we do not get the existing dimensions, all get shown as existing (white text))

for (const value of presetConfiguration.values) {
if (existingDimensions[dimensionName]?.includes(value)) {
existing = true;
}
}

const uri = new URL(window.location.href);
const contextPathWithoutDimensions = this.props.documentNode.contextPath.split(';')[0];
const uriDimension = ';' + dimensionName + '=' + presetConfiguration.values.join(',')
uri.searchParams.set('node', contextPathWithoutDimensions + uriDimension);
const url = uri.toString();

return Object.assign({}, presetConfiguration, {
label: i18nRegistry.translate(presetConfiguration.label),
disallowed: !(allowedPresets[dimensionName] && allowedPresets[dimensionName].includes(presetName))
disallowed: !(allowedPresets[dimensionName] && allowedPresets[dimensionName].includes(presetName)),
existing,
url
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,16 @@
}
}

.dimmed {
filter: opacity(50%);
.strikethrough {
text-decoration: line-through;
}

.lighter {
filter: opacity(75%);
}

.whiteLink {
color: white;
}

.selectPreset + .selectPreset {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* eslint-disable camelcase, react/jsx-pascal-case */
import SelectBox_Option_SingleLineLink from './selectBox_Option_SingleLineLink';

export default SelectBox_Option_SingleLineLink;
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* eslint-disable camelcase, react/jsx-pascal-case */
import React, {PureComponent} from 'react';
import PropTypes from 'prop-types';
import ListPreviewElement from '../ListPreviewElement';
import mergeClassNames from 'classnames';

class SelectBox_Option_SingleLineLink extends PureComponent {
static propTypes = {
option: PropTypes.shape({
label: PropTypes.string.isRequired,
icon: PropTypes.string,
disabled: PropTypes.bool
}).isRequired,

disabled: PropTypes.bool,

className: PropTypes.string
}

render() {
const {option, className, disabled, icon, linkOptions} = this.props;

const isDisabled = disabled || option.disabled;

const finalClassNames = mergeClassNames({
[className]: className
});

const previewElementIcon = option.icon ? option.icon : (icon ? icon : null);

return (
<ListPreviewElement {...this.props} icon={previewElementIcon} disabled={isDisabled} className={finalClassNames}>
<a {...linkOptions} title={option.label}>{option.label}</a>
</ListPreviewElement>
);
}
}

export default SelectBox_Option_SingleLineLink;