Skip to content

Commit

Permalink
WIP: Fix further occurrences of server resources
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Jul 8, 2024
1 parent b59545e commit aea8e7c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
30 changes: 26 additions & 4 deletions packages/neos-ui-editors/src/EditorEnvelope/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ import I18n from '@neos-project/neos-ui-i18n';
import {neos} from '@neos-project/neos-ui-decorators';

import style from './style.module.css';
import {ResourceIconContext} from '@neos-project/react-ui-components/src/Icon/resourceIcon';

@neos(globalRegistry => ({
editorRegistry: globalRegistry.get('inspector').get('editors'),
i18nRegistry: globalRegistry.get('i18n')
}))
export default class EditorEnvelope extends PureComponent {
static contextType = ResourceIconContext;

state = {
showHelpMessage: false
};
Expand Down Expand Up @@ -118,11 +121,30 @@ export default class EditorEnvelope extends PureComponent {
};

getThumbnailSrc(thumbnail) {
if (thumbnail.substr(0, 11) === 'resource://') {
thumbnail = '/_Resources/Static/Packages/' + thumbnail.substr(11);
const regex = /^resource:\/\/([^\\/]+)\/(.*)/;

const matches = thumbnail?.match(regex);

if (!matches) {
return thumbnail;
}

if (!this.context) {
console.error('ResourceIconContext missing! Cannot resolve uri: ', thumbnail);
return null;
}

return thumbnail;
const [_, packageName, rawPath] = matches;

Check failure on line 137 in packages/neos-ui-editors/src/EditorEnvelope/index.js

View workflow job for this annotation

GitHub Actions / Code style

'_' is assigned a value but never used

let publicPath = rawPath;
if (!rawPath.startsWith('Public/')) {
// legacy syntax not including the "Public" segment see https://github.com/neos/neos-ui/issues/2092#issuecomment-1606055787
publicPath = `Public/${rawPath}`;
}

const resourcePath = `resource://${packageName}/${publicPath}`;

return this.context.createFromResourcePath(resourcePath);
}

renderHelpMessage() {
Expand All @@ -134,7 +156,7 @@ export default class EditorEnvelope extends PureComponent {
return (
<Tooltip renderInline className={style.envelope__helpmessage}>
{helpMessage ? <ReactMarkdown children={translatedHelpMessage} linkTarget="_blank" /> : ''}
{helpThumbnail ? <img alt={label} src={helpThumbnailSrc} className={style.envelope__helpThumbnail} /> : ''}
{helpThumbnailSrc ? <img alt={label} src={helpThumbnailSrc} className={style.envelope__helpThumbnail} /> : ''}
</Tooltip>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import {AssetUpload} from '../../../../Library/index';
import {Thumbnail} from '../../Utils/index';
import {Icon} from '@neos-project/react-ui-components';
import style from './style.module.css';
import {ResourceIconContext} from '@neos-project/react-ui-components/src/Icon/resourceIcon';

export default class PreviewScreen extends PureComponent {
static contextType = ResourceIconContext;

static propTypes = {
className: PropTypes.string,
propertyName: PropTypes.string,
Expand Down Expand Up @@ -52,7 +55,7 @@ export default class PreviewScreen extends PureComponent {
</div>
<img
className={(thumbnail ? style.cropArea__image : style['cropArea__image--placeholder'])}
src={thumbnail ? thumbnail.uri : '/_Resources/Static/Packages/Neos.Neos/Images/dummy-image.svg'}
src={thumbnail ? thumbnail.uri : this.context.createFromResourcePath('resource://Neos.Neos/Public/Images/dummy-image.svg')}
style={thumbnail ? thumbnail.styles.thumbnail : {}}
alt={propertyName}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import CropConfiguration, {CustomAspectRatioOption, LockedAspectRatioStrategy} f
import style from './style.module.css';

import './react_crop.vanilla-css';
import {ResourceIconContext} from '@neos-project/react-ui-components/src/Icon/resourceIcon';

/**
* Calculates the greatest common divisor for given numbers a, b
Expand Down Expand Up @@ -74,6 +75,8 @@ class AspectRatioItem extends PureComponent {
i18nRegistry: globalRegistry.get('i18n')
}))
export default class ImageCropper extends PureComponent {
static contextType = ResourceIconContext;

state = {
cropConfiguration: CropConfiguration.fromNeosConfiguration(
this.props.sourceImage,
Expand Down Expand Up @@ -176,7 +179,7 @@ export default class ImageCropper extends PureComponent {
const aspectRatioLocked = cropConfiguration.aspectRatioStrategy instanceof LockedAspectRatioStrategy;
const allowCustomRatios = cropConfiguration.aspectRatioOptions.some(option => option instanceof CustomAspectRatioOption);
const {sourceImage, i18nRegistry} = this.props;
const src = sourceImage.previewUri || '/_Resources/Static/Packages/Neos.Neos/Images/dummy-image.svg';
const src = sourceImage.previewUri || this.context.createFromResourcePath('resource://Neos.Neos/Public/Images/dummy-image.svg');

const toolbarRef = el => {
this.toolbarNode = el;
Expand Down
3 changes: 1 addition & 2 deletions packages/react-ui-components/src/Icon/resourceIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ class ResourceIcon extends PureComponent<ResourceIconProps> {
public render(): JSX.Element | null {
const {padded, theme, label, icon, className, color, size} = this.props;



if (!this.context) {
console.error('ResourceIconContext missing! Cannot resolve uri: ', icon);
return null;
Expand All @@ -43,6 +41,7 @@ class ResourceIcon extends PureComponent<ResourceIconProps> {

let publicPath = rawPath;
if (!rawPath.startsWith('Public/')) {
// legacy syntax not including the "Public" segment see https://github.com/neos/neos-ui/issues/2092#issuecomment-1606055787
publicPath = `Public/${rawPath}`;
}

Expand Down

0 comments on commit aea8e7c

Please sign in to comment.