Skip to content

Commit

Permalink
Handle taskWidgetLayout as JSON object in ChallengeController and MRS…
Browse files Browse the repository at this point in the history
…chemaTypes (#1068)

Modified the `ChallengeController` to store `taskWidgetLayout` as an empty JSON
object instead of an empty string when the field is not provided in the request.

Updated `MRSchemaTypes` in the GraphQL schema to handle `taskWidgetLayout` as an
optional JSON value, defaulting to an empty JSON object when not present.
  • Loading branch information
ljdelight authored Oct 28, 2023
1 parent d9239b7 commit 3efabc3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ class ChallengeController @Inject() (
Utils.insertIntoJson(jsonBody, "reviewSetting", Challenge.REVIEW_SETTING_NOT_REQUIRED)(
IntWrites
)
jsonBody = Utils.insertIntoJson(jsonBody, "taskWidgetLayout", "")(StringWrites)
jsonBody = Utils.insertIntoJson(jsonBody, "taskWidgetLayout", JsObject.empty)(jsValueWrites)
jsonBody = Utils.insertIntoJson(jsonBody, "updateTasks", false)(BooleanWrites)
jsonBody = Utils.insertIntoJson(jsonBody, "changesetUrl", false)(BooleanWrites)
// if we can't find the parent ID, just use the user's default project instead
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package org.maproulette.framework.graphql.schemas

import play.api.libs.json._

import org.joda.time.DateTime
import org.maproulette.framework.model._
import org.maproulette.framework.graphql.fetchers._
Expand Down Expand Up @@ -169,6 +171,7 @@ trait MRSchemaTypes {
deriveObjectType[Unit, ChallengeCreation](ObjectTypeName("ChallengeCreation"))
implicit val ChallengePriorityType: ObjectType[Unit, ChallengePriority] =
deriveObjectType[Unit, ChallengePriority](ObjectTypeName("ChallengePriority"))

implicit val ChallengeExtraType: ObjectType[Unit, ChallengeExtra] =
deriveObjectType[Unit, ChallengeExtra](
ObjectTypeName("ChallengeExtra"),
Expand All @@ -177,7 +180,11 @@ trait MRSchemaTypes {
Field(
"taskWidgetLayout",
StringType,
resolve = _.value.taskWidgetLayout.getOrElse("").toString
resolve = ctx =>
ctx.value.taskWidgetLayout match {
case Some(jsValue) => Json.stringify(jsValue)
case None => "{}"
}
)
)
)
Expand Down

0 comments on commit 3efabc3

Please sign in to comment.