mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-27 01:25:52 -05:00
Revert "Add to studio modal should only show studios user can actually change"
This commit is contained in:
parent
62ea77116c
commit
5ddb7660f6
7 changed files with 19 additions and 83 deletions
|
@ -134,14 +134,6 @@
|
|||
color: $type-gray;
|
||||
}
|
||||
|
||||
.studio-selector-button-enabled {
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.studio-selector-button-disabled {
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.studio-status-icon {
|
||||
position: absolute;
|
||||
right: .625rem;
|
||||
|
|
|
@ -26,8 +26,6 @@ const AddToStudioModalPresentation = ({
|
|||
const contentLabel = intl.formatMessage({id: 'addToStudio.title'});
|
||||
const studioButtons = studios.map(studio => (
|
||||
<StudioButton
|
||||
canAdd={studio.canAdd}
|
||||
canRemove={studio.canRemove}
|
||||
hasRequestOutstanding={studio.hasRequestOutstanding}
|
||||
id={studio.id}
|
||||
includesProject={studio.includesProject}
|
||||
|
|
|
@ -8,8 +8,6 @@ const AnimateHOC = require('./animate-hoc.jsx');
|
|||
require('./modal.scss');
|
||||
|
||||
const StudioButton = ({
|
||||
canAdd,
|
||||
canRemove,
|
||||
hasRequestOutstanding,
|
||||
includesProject,
|
||||
title,
|
||||
|
@ -40,12 +38,9 @@ const StudioButton = ({
|
|||
<div
|
||||
className={classNames(
|
||||
'studio-selector-button',
|
||||
{
|
||||
'studio-selector-button-waiting': hasRequestOutstanding,
|
||||
'studio-selector-button-selected': includesProject && !hasRequestOutstanding,
|
||||
'studio-selector-button-enabled': includesProject ? canRemove : canAdd,
|
||||
'studio-selector-button-disabled': includesProject ? !canRemove : !canAdd
|
||||
}
|
||||
{'studio-selector-button-waiting': hasRequestOutstanding},
|
||||
{'studio-selector-button-selected':
|
||||
includesProject && !hasRequestOutstanding}
|
||||
)}
|
||||
onClick={onClick}
|
||||
>
|
||||
|
@ -74,8 +69,6 @@ const StudioButton = ({
|
|||
};
|
||||
|
||||
StudioButton.propTypes = {
|
||||
canAdd: PropTypes.bool,
|
||||
canRemove: PropTypes.bool,
|
||||
hasRequestOutstanding: PropTypes.bool,
|
||||
includesProject: PropTypes.bool,
|
||||
onClick: PropTypes.func,
|
||||
|
|
|
@ -3,59 +3,26 @@ const connect = require('react-redux').connect;
|
|||
const previewActions = require('../../redux/preview.js');
|
||||
const AddToStudioModal = require('../../components/modal/addtostudio/container.jsx');
|
||||
|
||||
// user can add project to studio if studio is open to all, or user is a curator of studio
|
||||
const canAdd = (studio, userIsCurator) => (
|
||||
studio.open_to_all || userIsCurator
|
||||
);
|
||||
|
||||
// user can remove project from studio if user owns project or is admin or user is a curator of studio
|
||||
const canRemove = (userOwnsProject, isAdmin, userIsCurator) => (
|
||||
userOwnsProject || isAdmin || userIsCurator
|
||||
);
|
||||
|
||||
// include a given studio in the list to show in add to studio modal.
|
||||
// only include it if user has the ability to remove the project from this studio.
|
||||
const showStudio = (studio, currentStudioIds, userIsCurator, userOwnsProject, isAdmin) => {
|
||||
const includesProject = (currentStudioIds.indexOf(studio.id) !== -1);
|
||||
const canAddToThisStudio = canAdd(studio, userIsCurator);
|
||||
const canRemoveFromThisStudio = canRemove(userOwnsProject, isAdmin, userIsCurator);
|
||||
if (canRemoveFromThisStudio) { // power to remove matches set of studios we want to show
|
||||
// include the current status of whether the project is in the studio,
|
||||
// and what privileges the user has to change that.
|
||||
const consolidatedStudio = Object.assign({}, studio, {
|
||||
includesProject: includesProject,
|
||||
canAdd: canAddToThisStudio,
|
||||
canRemove: canRemoveFromThisStudio
|
||||
});
|
||||
return consolidatedStudio;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
// Build consolidated curatedStudios object from all studio info.
|
||||
// We add flags to indicate whether the project is currently in the studio,
|
||||
// and the status of requests to join/leave studios.
|
||||
const consolidateStudiosInfo = (userOwnsProject, isAdmin, curatedStudios, projectStudios,
|
||||
currentStudioIds, studioRequests) => {
|
||||
|
||||
const consolidateStudiosInfo = (curatedStudios, projectStudios, currentStudioIds, studioRequests) => {
|
||||
const consolidatedStudios = [];
|
||||
|
||||
// for each studio the project is in, include it if user can add or remove project from it.
|
||||
projectStudios.forEach(projectStudio => {
|
||||
const userIsCurator = curatedStudios.some(curatedStudio => (curatedStudio.id === projectStudio.id));
|
||||
const studioToShow = showStudio(projectStudio, currentStudioIds, userIsCurator, userOwnsProject, isAdmin);
|
||||
if (studioToShow) {
|
||||
consolidatedStudios.push(studioToShow);
|
||||
}
|
||||
const includesProject = (currentStudioIds.indexOf(projectStudio.id) !== -1);
|
||||
const consolidatedStudio =
|
||||
Object.assign({}, projectStudio, {includesProject: includesProject});
|
||||
consolidatedStudios.push(consolidatedStudio);
|
||||
});
|
||||
|
||||
// for each curated studio, if it was not already added to consolidatedStudios above, add it now.
|
||||
// copy the curated studios that project is not in
|
||||
curatedStudios.forEach(curatedStudio => {
|
||||
if (!projectStudios.some(projectStudio => (projectStudio.id === curatedStudio.id))) {
|
||||
const studioToShow = showStudio(curatedStudio, currentStudioIds, true, userOwnsProject, isAdmin);
|
||||
if (studioToShow) {
|
||||
consolidatedStudios.push(studioToShow);
|
||||
}
|
||||
const includesProject = (currentStudioIds.indexOf(curatedStudio.id) !== -1);
|
||||
const consolidatedStudio =
|
||||
Object.assign({}, curatedStudio, {includesProject: includesProject});
|
||||
consolidatedStudios.push(consolidatedStudio);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -71,10 +38,10 @@ const consolidateStudiosInfo = (userOwnsProject, isAdmin, curatedStudios, projec
|
|||
return consolidatedStudios;
|
||||
};
|
||||
|
||||
const mapStateToProps = (state, ownProps) => ({
|
||||
studios: consolidateStudiosInfo(ownProps.userOwnsProject, ownProps.isAdmin,
|
||||
state.preview.curatedStudios, state.preview.projectStudios,
|
||||
state.preview.currentStudioIds, state.preview.status.studioRequests)
|
||||
const mapStateToProps = state => ({
|
||||
studios: consolidateStudiosInfo(state.preview.curatedStudios,
|
||||
state.preview.projectStudios, state.preview.currentStudioIds,
|
||||
state.preview.status.studioRequests)
|
||||
});
|
||||
|
||||
const mapDispatchToProps = () => ({});
|
||||
|
|
|
@ -67,7 +67,6 @@ const PreviewPresentation = ({
|
|||
faved,
|
||||
favoriteCount,
|
||||
intl,
|
||||
isAdmin,
|
||||
isFullScreen,
|
||||
isLoggedIn,
|
||||
isNewScratcher,
|
||||
|
@ -123,7 +122,6 @@ const PreviewPresentation = ({
|
|||
showAdminPanel,
|
||||
showModInfo,
|
||||
singleCommentId,
|
||||
userOwnsProject,
|
||||
visibilityInfo
|
||||
}) => {
|
||||
const shareDate = ((projectInfo.history && projectInfo.history.shared)) ? projectInfo.history.shared : '';
|
||||
|
@ -346,11 +344,9 @@ const PreviewPresentation = ({
|
|||
<Subactions
|
||||
addToStudioOpen={addToStudioOpen}
|
||||
canReport={canReport}
|
||||
isAdmin={isAdmin}
|
||||
projectInfo={projectInfo}
|
||||
reportOpen={reportOpen}
|
||||
shareDate={shareDate}
|
||||
userOwnsProject={userOwnsProject}
|
||||
onAddToStudioClicked={onAddToStudioClicked}
|
||||
onAddToStudioClosed={onAddToStudioClosed}
|
||||
onCopyProjectLink={onCopyProjectLink}
|
||||
|
@ -473,11 +469,9 @@ const PreviewPresentation = ({
|
|||
addToStudioOpen={addToStudioOpen}
|
||||
canAddToStudio={canAddToStudio}
|
||||
canReport={canReport}
|
||||
isAdmin={isAdmin}
|
||||
projectInfo={projectInfo}
|
||||
reportOpen={reportOpen}
|
||||
shareDate={shareDate}
|
||||
userOwnsProject={userOwnsProject}
|
||||
onAddToStudioClicked={onAddToStudioClicked}
|
||||
onAddToStudioClosed={onAddToStudioClosed}
|
||||
onCopyProjectLink={onCopyProjectLink}
|
||||
|
@ -632,7 +626,6 @@ PreviewPresentation.propTypes = {
|
|||
faved: PropTypes.bool,
|
||||
favoriteCount: PropTypes.number,
|
||||
intl: intlShape,
|
||||
isAdmin: PropTypes.bool,
|
||||
isFullScreen: PropTypes.bool,
|
||||
isLoggedIn: PropTypes.bool,
|
||||
isNewScratcher: PropTypes.bool,
|
||||
|
@ -691,7 +684,6 @@ PreviewPresentation.propTypes = {
|
|||
showModInfo: PropTypes.bool,
|
||||
showUsernameBlockAlert: PropTypes.bool,
|
||||
singleCommentId: PropTypes.oneOfType([PropTypes.number, PropTypes.bool]),
|
||||
userOwnsProject: PropTypes.bool,
|
||||
visibilityInfo: PropTypes.shape({
|
||||
censored: PropTypes.bool,
|
||||
message: PropTypes.string,
|
||||
|
|
|
@ -641,7 +641,6 @@ class Preview extends React.Component {
|
|||
extensions={this.state.extensions}
|
||||
faved={this.state.clientFaved}
|
||||
favoriteCount={this.state.favoriteCount}
|
||||
isAdmin={this.props.isAdmin}
|
||||
isFullScreen={this.props.fullScreen}
|
||||
isLoggedIn={this.props.isLoggedIn}
|
||||
isNewScratcher={this.props.isNewScratcher}
|
||||
|
@ -669,7 +668,6 @@ class Preview extends React.Component {
|
|||
showModInfo={this.props.isAdmin}
|
||||
showUsernameBlockAlert={this.state.showUsernameBlockAlert}
|
||||
singleCommentId={this.state.singleCommentId}
|
||||
userOwnsProject={this.props.userOwnsProject}
|
||||
visibilityInfo={this.props.visibilityInfo}
|
||||
onAddComment={this.handleAddComment}
|
||||
onAddToStudioClicked={this.handleAddToStudioClick}
|
||||
|
|
|
@ -39,9 +39,7 @@ const Subactions = props => (
|
|||
{props.addToStudioOpen && (
|
||||
<AddToStudioModal
|
||||
isOpen
|
||||
isAdmin={props.isAdmin}
|
||||
key="add-to-studio-modal"
|
||||
userOwnsProject={props.userOwnsProject}
|
||||
onRequestClose={props.onAddToStudioClosed}
|
||||
onToggleStudio={props.onToggleStudio}
|
||||
/>
|
||||
|
@ -82,7 +80,6 @@ Subactions.propTypes = {
|
|||
addToStudioOpen: PropTypes.bool,
|
||||
canAddToStudio: PropTypes.bool,
|
||||
canReport: PropTypes.bool,
|
||||
isAdmin: PropTypes.bool,
|
||||
onAddToStudioClicked: PropTypes.func,
|
||||
onAddToStudioClosed: PropTypes.func,
|
||||
onCopyProjectLink: PropTypes.func,
|
||||
|
@ -91,8 +88,7 @@ Subactions.propTypes = {
|
|||
onReportSubmit: PropTypes.func.isRequired,
|
||||
onToggleStudio: PropTypes.func,
|
||||
reportOpen: PropTypes.bool,
|
||||
shareDate: PropTypes.string,
|
||||
userOwnsProject: PropTypes.bool
|
||||
shareDate: PropTypes.string
|
||||
};
|
||||
|
||||
module.exports = Subactions;
|
||||
|
|
Loading…
Reference in a new issue