Skip to content

Commit

Permalink
Merge pull request #514 from guardian/sc-20240619-spreadsheet-descrip…
Browse files Browse the repository at this point in the history
…tion

try to add description to spreadsheet tool
  • Loading branch information
itsibitzi authored Jun 20, 2024
2 parents d81b4be + 6519f76 commit b089b93
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/model/forms/SpreadSheet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ object FilterTypes extends Enum[FilterTypes] {
case object ExternalName extends FilterTypes
case object Type extends FilterTypes
case object HasFields extends FilterTypes
case object Description extends FilterTypes
}

case class SpreadSheetFilter(`type`: FilterTypes, value: String)
Expand All @@ -28,6 +29,7 @@ object GetSpreadSheet {
case "internalName" => JsSuccess(FilterTypes.InternalName)
case "externalName" => JsSuccess(FilterTypes.ExternalName)
case "type" => JsSuccess(FilterTypes.Type)
case "description" => JsSuccess(FilterTypes.Description)
case unknown: String => JsError(s"Invalid filter type: $unknown")
}
}
Expand Down
6 changes: 5 additions & 1 deletion app/repositories/TagRepository.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ case class TagSearchCriteria(
types: Option[List[String]] = None,
internalName: Option[String] = None,
externalName: Option[String] = None,
description: Option[String] = None,
referenceType: Option[String] = None,
referenceToken: Option[String] = None,
searchField: Option[String] = None,
Expand All @@ -58,6 +59,7 @@ case class TagSearchCriteria(
val filters: List[TagFilter] = Nil ++
internalName.map(v => internalNameFilter(v.toLowerCase) _) ++
externalName.map(v => externalNameFilter(v.toLowerCase) _) ++
description.map(v => descriptionFilter(v.toLowerCase) _) ++
types.map(v => typeFilter(v.map(_.toLowerCase)) _) ++
q.map(v => queryFilter(v.toLowerCase) _) ++
referenceType.map(v => referenceTypeFilter(v.toLowerCase) _) ++
Expand All @@ -83,9 +85,10 @@ case class TagSearchCriteria(
.replace("", "...")
)

private def getSearchField(t: Tag ) = {
private def getSearchField(t: Tag) = {
val field = searchField.getOrElse("internalName") match {
case "externalName" => t.externalName
case "description" => t.description.getOrElse("")
case "id" => t.id.toString
case "type" => t.`type`
case "path" => t.path
Expand Down Expand Up @@ -145,6 +148,7 @@ case class TagSearchCriteria(

private def internalNameFilter(n: String)(tags: List[Tag]) = tags.filter{ t => t.internalName.toLowerCase == n }
private def externalNameFilter(n: String)(tags: List[Tag]) = tags.filter{ t => t.externalName.toLowerCase == n }
private def descriptionFilter(n: String)(tags: List[Tag]) = tags.filter{ t => t.description.getOrElse("").toLowerCase == n }

private def referenceTypeFilter(n: String)(tags: List[Tag]) = tags.filter{ t => t.externalReferences.exists(_.`type`.toLowerCase == n) }
private def referenceTokenFilter(n: String)(tags: List[Tag]) = tags.filter{ t => t.externalReferences.exists(_.value.toLowerCase == n) }
Expand Down
5 changes: 3 additions & 2 deletions public/components/Spreadsheet/SpreadsheetBuilder.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const DEFAULT_FILTER = {
value: ""
};

const FILTER_TYPES = ["internalName", "externalName", "path", "type", "hasFields"];
const FILTER_TYPES = ["internalName", "externalName", "path", "type", "hasFields", "description"];

const DEFAULT_COLUMN = "internalName";
const AVAILABLE_COLUMNS = [
Expand All @@ -20,7 +20,8 @@ const AVAILABLE_COLUMNS = [
"section",
"path",
"type",
"hyperlink"
"hyperlink",
"description"
];

const MAX_PREVIEW_ROWS = 20;
Expand Down

0 comments on commit b089b93

Please sign in to comment.