diff --git a/explore/src/main/scala/explore/validations/ObservationValidationsTableBody.scala b/explore/src/main/scala/explore/validations/ObservationValidationsTableBody.scala index bb4234ebc..f6599b2df 100644 --- a/explore/src/main/scala/explore/validations/ObservationValidationsTableBody.scala +++ b/explore/src/main/scala/explore/validations/ObservationValidationsTableBody.scala @@ -106,7 +106,7 @@ object ObservationValidationsTableBody { "Request Approval", onClick = props.observations.mod( // this also gets rid of any buttons on "affected" observations - _.unsafeMapValues(_.updateToPendingIfConfigurationApplies(config)) + _.mapValues(Observation.id)(_.updateToPendingIfConfigurationApplies(config)) ) >> ObsQueries.createConfigurationRequest[IO](row.id).void.runAsync ).tiny.compact.some diff --git a/model/shared/src/main/scala/explore/data/KeyedIndexedList.scala b/model/shared/src/main/scala/explore/data/KeyedIndexedList.scala index 846ec131b..ed40fa7ed 100644 --- a/model/shared/src/main/scala/explore/data/KeyedIndexedList.scala +++ b/model/shared/src/main/scala/explore/data/KeyedIndexedList.scala @@ -99,9 +99,15 @@ case class KeyedIndexedList[K, A] private (private val list: TreeSeqMap[K, (A, N def updatedValueWith(key: K, f: A => A): KeyedIndexedList[K, A] = updatedWith(key, (v, i) => (f(v), i)) - // WARNING - Do not use to update the part of the value used as a key - def unsafeMapValues(f: A => A): KeyedIndexedList[K, A] = - KeyedIndexedList(TreeSeqMap.from(list.map { case (k, (a, idx)) => (k, (f(a), idx)) })) + def mapValues(keyLens: Lens[A, K])(f: A => A): KeyedIndexedList[K, A] = + KeyedIndexedList( + TreeSeqMap.from( + list.map { case (_, (a, idx)) => + val newA = f(a) + (keyLens.get(newA), (newA, idx)) + } + ) + ) object KeyedIndexedList: def empty[K, A]: KeyedIndexedList[K, A] = KeyedIndexedList[K, A](TreeSeqMap.empty)