Skip to content

Commit

Permalink
fix conditional variables for new features (#2206)
Browse files Browse the repository at this point in the history
* fix conditional variables for new features

* simplify mr tag updates

* refine inbuild rapid editor conditions
  • Loading branch information
CollinBeczak authored Dec 13, 2023
1 parent 41b6572 commit eacc338
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 42 deletions.
10 changes: 10 additions & 0 deletions src/components/ReviewTaskControls/Messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ export default defineMessages({
defaultMessage: "Reject",
},

next: {
id: "Admin.TaskReview.controls.next",
defaultMessage: "Review next task",
},

alreadyReviewed: {
id: "Admin.TaskReview.controls.alreadyReviewed",
defaultMessage: "Task has already been reviewed",
},

approvedWithFixes: {
id: "Admin.TaskReview.controls.approvedWithFixes",
defaultMessage: "Approve (with fixes)",
Expand Down
14 changes: 3 additions & 11 deletions src/components/ReviewTaskControls/ReviewTaskControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export class ReviewTaskControls extends Component {
state = {
comment: "",
tags: null,
reviewTags: null,
loadBy: TaskReviewLoadMethod.next,
errorTags: []
}
Expand All @@ -60,7 +59,7 @@ export class ReviewTaskControls extends Component {
const errorTags = this.state.errorTags?.length ? this.state.errorTags : undefined

this.props.updateTaskReviewStatus(this.props.task, this.state.reviewStatus,
this.state.comment, this.state.reviewTags,
this.state.comment, "",
this.state.loadBy, history,
this.props.taskBundle, requestedNextTask, null, errorTags)
this.setState({ confirmingTask: false, comment: "", errorTags: [] })
Expand Down Expand Up @@ -103,6 +102,8 @@ export class ReviewTaskControls extends Component {

/** Save Review Status */
updateReviewStatus = (reviewStatus) => {
this.props.saveTaskTags(this.props.task, this.state.tags)

this.setState({reviewStatus, confirmingTask: true})
}

Expand Down Expand Up @@ -134,22 +135,13 @@ export class ReviewTaskControls extends Component {
const uniqueTagsArray = filteredTagsArray.filter((value, index, self) => self.indexOf(value) === index);
const tags = uniqueTagsArray.join(',');

const reviewTagsArray = _map(this.props.task.tags?.tagType === "review" ? this.props.task.tags : [], (tag) => tag.name);
const filteredReviewTagsArray = reviewTagsArray.filter((tag) => tag !== "");
const reviewTags = filteredReviewTagsArray.join(',');

if(tags.length > 0 && this.state.tags === null) {
this.setState({tags: tags})
}

if(reviewTags.length > 0 && this.state.reviewTags === null) {
this.setState({reviewTags: reviewTags})
}

if (prevProps.task.id !== this.props.task.id) {
// Clear tags if we are on a new task
this.setState({tags: tags ?? null})
this.setState({reviewTags: reviewTags ?? null})
}
}

Expand Down
21 changes: 15 additions & 6 deletions src/components/TaskAnalysisTable/TaskAnalysisTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import InTableTagFilter
import messages from './Messages'
import './TaskAnalysisTable.scss'
import TaskAnalysisTableHeader from './TaskAnalysisTableHeader'
import AsCooperativeWork from '../../interactions/Task/AsCooperativeWork'
import { ViewCommentsButton, StatusLabel, makeInvertable }
from './TaskTableHelpers'

Expand Down Expand Up @@ -279,16 +280,24 @@ const setupColumnTypes = (props, taskBaseRoute, manager, data, openComments) =>
columns.selected = {id: 'selected',
Header: null,
accessor: task => props.isTaskSelected(task.id),
Cell: ({value, original}) => (
Cell: ({value, original}) => {
const isMapper = props.task?.completedBy ? props.task.completedBy === props.user.id : true

const isTagFix = AsCooperativeWork(props.task).isTagType()
const enableEditForMapper = props.task?.status === 0 || (props.task?.reviewStatus === ( 2 || 4 || 5 ))
const disableSelecting = props.taskReadOnly || isTagFix || !isMapper || !enableEditForMapper

return (
props.highlightPrimaryTask && original.id === props.task.id ?
<span className="mr-text-green-lighter"></span> :
<span className="mr-text-green-lighter"></span> : !disableSelecting ?
<input
type="checkbox"
className="mr-checkbox-toggle"
checked={value}
onChange={() => props.toggleTaskSelection(original)}
/>
),
/> : ''
)
},
maxWidth: 25,
sortable: false,
resizable: false,
Expand Down Expand Up @@ -365,8 +374,8 @@ const setupColumnTypes = (props, taskBaseRoute, manager, data, openComments) =>
minWidth: 110,
Cell: ({ row }) => {
const isTaskSelected = props.taskId === row._original.id
const isTaskEditable = props.task?.status === 0 || props.task?.reviewStatus === 2
const isTaskRemovable = !props.taskReadOnly && isTaskEditable
const enableEditForMapper = props.task?.status === 0 || (props.task?.reviewStatus === ( 2 || 4 || 5 ))
const isTaskRemovable = !props.taskReadOnly && enableEditForMapper

const enableRemove = props.task?.completedBy ? props.task.completedBy === props.user.id : true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export class ActiveTaskControls extends Component {
osmComment: "",
comment: "",
tags: null,
reviewTags: null,
revisionLoadBy: TaskReviewLoadMethod.all,
doneLoadByFromHistory: false,
needsReview: this.props.challenge.reviewSetting === 1 ? true : undefined
Expand Down Expand Up @@ -155,14 +154,14 @@ export class ActiveTaskControls extends Component {

if (!_isUndefined(this.state.submitRevision)) {
this.props.updateTaskReviewStatus(this.props.task, this.state.submitRevision,
this.state.comment, this.state.reviewTags,
this.state.comment, "",
this.state.revisionLoadBy, this.props.history,
this.props.taskBundle, this.state.requestedNextTask,
taskStatus)
}
else {
this.props.completeTask(this.props.task, this.props.task.parent.id,
taskStatus, this.state.comment, this.state.tags,
taskStatus, this.state.comment, "",
revisionSubmission ? null : this.props.taskLoadBy,
this.props.user.id,
revisionSubmission || this.state.needsReview,
Expand Down Expand Up @@ -276,22 +275,13 @@ export class ActiveTaskControls extends Component {
const uniqueTagsArray = filteredTagsArray.filter((value, index, self) => self.indexOf(value) === index);
const tags = uniqueTagsArray.join(',');

const reviewTagsArray = _map(this.props.task.tags?.tagType === "review" ? this.props.task.tags : [], (tag) => tag.name);
const filteredReviewTagsArray = reviewTagsArray.filter((tag) => tag !== "");
const reviewTags = filteredReviewTagsArray.join(',');

if(tags.length > 0 && this.state.tags === null) {
this.setState({tags: tags})
}

if(reviewTags.length > 0 && this.state.reviewTags === null) {
this.setState({reviewTags: reviewTags})
}


if (prevProps.task.id !== this.props.task.id) {
// Clear tags if we are on a new task
this.setState({tags: tags ?? null})
this.setState({reviewTags: reviewTags ?? null})
}
}

Expand Down Expand Up @@ -361,7 +351,15 @@ export class ActiveTaskControls extends Component {
else if (!this.props.task) {
return null
}
const editMode = this.props.getUserAppSetting ? this.props.getUserAppSetting(this.props.user, 'isEditMode') : false;
const cooperative = AsCooperativeWork(this.props.task).isTagType() || this.props.task.cooperativeWork
const disableRapid = cooperative || this.props.taskReadOnly || (
this.props.task?.status !== 0 && (
this.props.completedBy !== this.props.user &&
this.props.task?.reviewClaimedBy !== this.props.user
)
)
const editMode = disableRapid ? false : this.props.getUserAppSetting ? this.props.getUserAppSetting(this.props.user, 'isEditMode') : false

const needsRevised = this.props.task.reviewStatus === TaskReviewStatus.rejected

const isEditingTask =
Expand All @@ -383,7 +381,7 @@ export class ActiveTaskControls extends Component {
allowedStatusProgressions(this.props.task.status, false, needsRevised)
const isComplete = isCompletionStatus(this.props.task.status)
const isFinal = isFinalStatus(this.props.task.status)

return (
<div>
{!isEditingTask && isComplete &&
Expand Down
17 changes: 13 additions & 4 deletions src/components/TaskTags/TaskTags.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,23 @@ export class TaskTags extends Component {
}

render() {
const disableEditTags = this.props.taskReadOnly || (
(this.props.task?.status !== 0 &&
(![0, 2, 4, 5].includes(this.props.task?.reviewStatus))) &&
(
this.props.task?.reviewRequestedBy !== this.props.user &&
this.props.task?.reviewClaimedBy !== this.props.user
)
)

if (this.state.edit) {
const preferredTags =
_filter(
_split(_get(this.props.task.parent, 'preferredTags'), ','),
(result) => !_isEmpty(result)
)
const limitTags = !!_get(this.props.task.parent, 'limitTags')

return (
<External>
<Modal isActive onClose={() => this.setState({edit: false})} allowOverflow>
Expand Down Expand Up @@ -96,7 +105,7 @@ export class TaskTags extends Component {
</External>
)
}
else if (this.props.tags && this.props.tags !== "") {
else if (this.props.tags && this.props.tags !== "") {
return (
<div className="mr-flex mr-justify-between mr-items-center mr-mb-2">
<div className="mr-text-sm mr-text-white mr-flex mr-items-center mr-flex-grow">
Expand All @@ -105,7 +114,7 @@ export class TaskTags extends Component {
/> {this.tagList()}
</div>

{!this.props.taskReadOnly && (this.props.completedBy === this.props.user || this.props.task.reviewClaimedBy === this.props.user) ?
{!disableEditTags ?
<div className="mr-links-green-lighter mr-flex-grow-0">
<a onClick={() => this.setState({edit: true})}>
<FormattedMessage {...messages.updateTags} />
Expand All @@ -115,7 +124,7 @@ export class TaskTags extends Component {
</div>
)
}
else if (!this.props.taskReadOnly) {
else if (!disableEditTags) {
return (
<div className="mr-links-green-lighter">
<a onClick={() => this.setState({edit: true})}>
Expand Down
17 changes: 15 additions & 2 deletions src/components/Widgets/TaskMapWidget/TaskMapWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,21 @@ export default class TaskMapWidget extends Component {
}

render() {
const disableRapid = AsCooperativeWork(this.props.task).isTagType() || this.props.task.cooperativeWork
const editMode = disableRapid ? false : this.props.getUserAppSetting ? this.props.getUserAppSetting(this.props.user, 'isEditMode') : false
const cooperative = AsCooperativeWork(this.props.task).isTagType() || this.props.task.cooperativeWork
const isReviewing = this.props.task?.reviewClaimedBy === this.props.user.id && this.props.task?.reviewStatus === 0
const disableRapid = cooperative ||
this.props.taskReadOnly || (
![0, 3, 6].includes(this.props.task?.status) &&
![2, 4, 5].includes(this.props.task?.reviewStatus)
&& !isReviewing
&& !this.props.asMetaReview
)

const editMode = disableRapid ?
false :
this.props.getUserAppSetting ?
this.props.getUserAppSetting(this.props.user, 'isEditMode') :
false

if(!this.props.task.geometries.features){
return (
Expand Down
8 changes: 4 additions & 4 deletions src/services/Editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ export const constructIdURI = function (task, mapBounds, options, taskBundle, re
encodeURIComponent(replacedComment) +
constructChangesetUrl(task) :
"comment=" +
encodeURIComponent(task.parent.checkinComment) +
encodeURIComponent(task.parent?.checkinComment) +
constructChangesetUrl(task);

const sourceComponent =
Expand Down Expand Up @@ -335,7 +335,7 @@ export const constructRapidURI = function (task, mapBounds, options, replacedCom
encodeURIComponent(replacedComment) +
constructChangesetUrl(task) :
"comment=" +
encodeURIComponent(task.parent.checkinComment) +
encodeURIComponent(task.parent?.checkinComment) +
constructChangesetUrl(task);

const sourceComponent =
Expand Down Expand Up @@ -392,7 +392,7 @@ export const constructLevel0URI = function (
encodeURIComponent(replacedComment) +
constructChangesetUrl(task) :
"comment=" +
encodeURIComponent(task.parent.checkinComment) +
encodeURIComponent(task.parent?.checkinComment) +
constructChangesetUrl(task);

const urlComponent =
Expand Down Expand Up @@ -543,7 +543,7 @@ export const josmLayerParams = function (
*/
export const josmChangesetParams = function (task) {
return `changeset_comment=${
encodeURIComponent(task.parent.checkinComment) + constructChangesetUrl(task)
encodeURIComponent(task.parent?.checkinComment) + constructChangesetUrl(task)
}&changeset_source=${encodeURIComponent(task.parent.checkinSource)}`;
};

Expand Down

0 comments on commit eacc338

Please sign in to comment.