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

[RNMobile] Disable VideoPress settings for not belonged videos #30759

Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added

RNMobile: Disable Details settings if video does not belong to the site
2 changes: 1 addition & 1 deletion projects/packages/videopress/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-videopress",
"version": "0.14.3",
"version": "0.14.4-alpha",
"description": "VideoPress package",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/videopress/#readme",
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/videopress/src/class-package-version.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* The Package_Version class.
*/
class Package_Version {
const PACKAGE_VERSION = '0.14.3';
const PACKAGE_VERSION = '0.14.4-alpha';

const PACKAGE_SLUG = 'videopress';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@
*/
import { PanelBody, TextControl, BottomSheetTextControl } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import VideoNotOwnedWarning from '../video-not-owned-warning';

/**
* React component that renders the details settings panel.
*
* @param {object} props - Component properties.
* @param {object} props.attributes - Block attributes.
* @param {Function} props.setAttributes - Function to set attributes.
* @param {Function} props.videoBelongToSite - Determines if the video belongs to the current site.
* @returns {import('react').ReactElement} - Details panel component.
*/
export default function DetailsPanel( { attributes, setAttributes } ) {
export default function DetailsPanel( { attributes, setAttributes, videoBelongToSite } ) {
const { title, description } = attributes;

return (
Expand All @@ -22,13 +27,16 @@ export default function DetailsPanel( { attributes, setAttributes } ) {
onChange={ value => setAttributes( { title: value } ) }
placeholder={ __( 'Add title', 'jetpack-videopress-pkg' ) }
label={ __( 'Title', 'jetpack-videopress-pkg' ) }
disabled={ ! videoBelongToSite }
/>
<BottomSheetTextControl
initialValue={ description }
onChange={ value => setAttributes( { description: value } ) }
placeholder={ __( 'Add description', 'jetpack-videopress-pkg' ) }
label={ __( 'Description', 'jetpack-videopress-pkg' ) }
disabled={ ! videoBelongToSite }
/>
{ ! videoBelongToSite && <VideoNotOwnedWarning /> }
</PanelBody>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ import PrivacyAndRatingSettings from './privacy-and-rating-settings';
* @param {object} props.attributes - Block attributes.
* @param {Function} props.setAttributes - Function to set block attributes.
* @param {boolean} props.privateEnabledForSite - True if the site's privacy is set to Private.
* @param {boolean} props.videoBelongToSite - Determines if the video belongs to the current site.
* @returns {import('react').ReactElement} - Panel to contain privacy and ratings settings.
*/
export default function PrivacyAndRatingPanel( {
attributes,
setAttributes,
privateEnabledForSite,
videoBelongToSite,
} ) {
const [ showSubSheet, setShowSubSheet ] = useState( false );
const navigation = useNavigation();
Expand Down Expand Up @@ -58,7 +60,9 @@ export default function PrivacyAndRatingPanel( {
{ __( 'Privacy and Rating', 'jetpack-videopress-pkg' ) }
</BottomSheet.NavBar.Heading>
</BottomSheet.NavBar>
<PrivacyAndRatingSettings { ...{ attributes, setAttributes, privateEnabledForSite } } />
<PrivacyAndRatingSettings
{ ...{ attributes, setAttributes, privateEnabledForSite, videoBelongToSite } }
/>
</>
</BottomSheet.SubSheet>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
VIDEO_RATING_PG_13,
VIDEO_RATING_R_17,
} from '../../../../../state/constants';
import VideoNotOwnedWarning from '../video-not-owned-warning';

/**
* React component that renders the settings within the privacy and ratings panel.
Expand All @@ -23,12 +24,14 @@ import {
* @param {object} props.attributes - Block attributes.
* @param {Function} props.setAttributes - Function to set block attributes.
* @param {boolean} props.privateEnabledForSite - True if the site's privacy is set to Private.
* @param {boolean} props.videoBelongToSite - Determines if the video belongs to the current site.
* @returns {import('react').ReactElement} - Settings to change video's privacy and ratings.
*/
export default function PrivacyAndRatingSettings( {
attributes,
setAttributes,
privateEnabledForSite,
videoBelongToSite,
} ) {
const { privacySetting, rating, allowDownload, displayEmbed } = attributes;

Expand Down Expand Up @@ -80,6 +83,7 @@ export default function PrivacyAndRatingSettings( {
onChange={ value => {
setAttributes( { rating: value } );
} }
disabled={ ! videoBelongToSite }
/>

<SelectControl
Expand All @@ -99,6 +103,7 @@ export default function PrivacyAndRatingSettings( {
} }
value={ String( privacySetting ) }
options={ [ privacyOptionSiteDefault, privacyOptionPublic, privacyOptionPrivate ] }
disabled={ ! videoBelongToSite }
/>

<ToggleControl
Expand All @@ -107,6 +112,7 @@ export default function PrivacyAndRatingSettings( {
onChange={ value => {
setAttributes( { allowDownload: value } );
} }
disabled={ ! videoBelongToSite }
/>

<ToggleControl
Expand All @@ -119,7 +125,10 @@ export default function PrivacyAndRatingSettings( {
'Gives viewers the option to share the video link and HTML embed code',
'jetpack-videopress-pkg'
) }
disabled={ ! videoBelongToSite }
/>

{ ! videoBelongToSite && <VideoNotOwnedWarning /> }
</PanelBody>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* WordPress dependencies
*/
import { usePreferredColorSchemeStyle } from '@wordpress/compose';
import { __ } from '@wordpress/i18n';
import { Icon, warning } from '@wordpress/icons';
/**
* External dependencies
*/
import { Text, View } from 'react-native';
/**
* Internal dependencies
*/
import styles from './styles.scss';

/**
* React component that renders a warning message about the video not owned by the site.
*
* @returns {import('react').ReactElement} - Details panel component.
*/
export default function VideoNotOwnedWarning() {
const msgStyle = usePreferredColorSchemeStyle(
styles[ 'video-not-owned-notice__message' ],
styles[ 'video-not-owned-notice__message--dark' ]
);
const iconStyle = usePreferredColorSchemeStyle(
styles[ 'video-not-owned-notice__icon' ],
styles[ 'video-not-owned-notice__icon--dark' ]
);
return (
<View style={ styles[ 'video-not-owned-notice__container' ] }>
<Icon style={ iconStyle } icon={ warning } />
<Text style={ msgStyle }>
{ __(
'This video is not owned by this site. You can still embed it and customize the player, but you won’t be able to edit the video.',
'jetpack-videopress-pkg'
) }
</Text>
</View>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.video-not-owned-notice__container {
flex-direction: row;
align-items: center;
padding: 8px 0;
justify-content: space-between;
}

.video-not-owned-notice__message {
font-size: 11px;
font-weight: 500;
color: $yellow-50;
flex: 1;
}

.video-not-owned-notice__message--dark {
color: $yellow-30;
}

.video-not-owned-notice__icon {
color: $yellow-50;
margin-right: 5px;
}

.video-not-owned-notice__icon--dark {
color: $yellow-30;
}
fluiddot marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default function VideoPressEdit( {
[ setAttributes ]
);

const { videoData } = useSyncMedia( attributes, setAttributes );
const { videoData, videoBelongToSite } = useSyncMedia( attributes, setAttributes );
const { private_enabled_for_site: privateEnabledForSite } = videoData;

const handleDoneUpload = useCallback(
Expand Down Expand Up @@ -213,11 +213,13 @@ export default function VideoPressEdit( {

{ isSelected && (
<InspectorControls>
<DetailsPanel { ...{ attributes, setAttributes } } />
<DetailsPanel { ...{ attributes, setAttributes, videoBelongToSite } } />
<PanelBody title={ __( 'More', 'jetpack-videopress-pkg' ) }>
<PlaybackPanel { ...{ attributes, setAttributes } } />
<ColorPanel { ...{ attributes, setAttributes } } />
<PrivacyAndRatingPanel { ...{ attributes, setAttributes, privateEnabledForSite } } />
<PrivacyAndRatingPanel
{ ...{ attributes, setAttributes, privateEnabledForSite, videoBelongToSite } }
/>
</PanelBody>
</InspectorControls>
) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const invalidateEmbedResolutionFields = [
*/
export function useSyncMedia( attributes, setAttributes ) {
const { id, guid, isPrivate } = attributes;
const { videoData, isRequestingVideoData } = useVideoData( {
const { videoData, isRequestingVideoData, videoBelongToSite } = useVideoData( {
id,
guid,
skipRatingControl: true,
Expand Down Expand Up @@ -259,6 +259,7 @@ export function useSyncMedia( attributes, setAttributes ) {
forceInitialState: updateInitialState,
videoData,
isRequestingVideoData,
videoBelongToSite,
error,
};
}