mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-232 Sets | Enhancement | Pre-populate records with data taken from filters when creating new record (#2517)
This commit is contained in:
parent
e7f3f62ae9
commit
bc5c940731
9 changed files with 41 additions and 15 deletions
|
@ -423,11 +423,13 @@ class BlockDataRepository(
|
|||
override suspend fun createDataViewRecord(
|
||||
context: Id,
|
||||
target: Id,
|
||||
template: Id?
|
||||
template: Id?,
|
||||
prefilled: Map<Id, Any>
|
||||
): Map<String, Any?> = remote.createDataViewRecord(
|
||||
context = context,
|
||||
target = target,
|
||||
template = template
|
||||
template = template,
|
||||
prefilled = prefilled
|
||||
)
|
||||
|
||||
override suspend fun addDataViewRelationOption(
|
||||
|
|
|
@ -127,7 +127,7 @@ interface BlockDataStore {
|
|||
): Payload
|
||||
|
||||
suspend fun createDataViewRecord(
|
||||
context: Id, target: Id, template: Id?
|
||||
context: Id, target: Id, template: Id?, prefilled: Map<Id, Any>
|
||||
): Map<String, Any?>
|
||||
|
||||
suspend fun updateDataViewRecord(
|
||||
|
|
|
@ -132,7 +132,7 @@ interface BlockRemote {
|
|||
): Payload
|
||||
|
||||
suspend fun createDataViewRecord(
|
||||
context: Id, target: Id, template: Id?
|
||||
context: Id, target: Id, template: Id?, prefilled: Map<Id, Any>
|
||||
): Map<String, Any?>
|
||||
|
||||
suspend fun updateDataViewRecord(
|
||||
|
|
|
@ -298,11 +298,13 @@ class BlockRemoteDataStore(private val remote: BlockRemote) : BlockDataStore {
|
|||
override suspend fun createDataViewRecord(
|
||||
context: String,
|
||||
target: String,
|
||||
template: Id?
|
||||
template: Id?,
|
||||
prefilled: Map<Id, Any>
|
||||
): Map<String, Any?> = remote.createDataViewRecord(
|
||||
context = context,
|
||||
target = target,
|
||||
template = template
|
||||
template = template,
|
||||
prefilled = prefilled
|
||||
)
|
||||
|
||||
override suspend fun updateDataViewRecord(
|
||||
|
|
|
@ -187,7 +187,8 @@ interface BlockRepository {
|
|||
suspend fun createDataViewRecord(
|
||||
context: Id,
|
||||
target: Id,
|
||||
template: Id?
|
||||
template: Id?,
|
||||
prefilled: Map<Id, Any>
|
||||
): DVRecord
|
||||
|
||||
suspend fun updateDataViewRecord(
|
||||
|
|
|
@ -17,17 +17,21 @@ class CreateDataViewRecord(
|
|||
repo.createDataViewRecord(
|
||||
context = params.context,
|
||||
target = params.target,
|
||||
template = params.template
|
||||
template = params.template,
|
||||
prefilled = params.prefilled
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* @property [context] operation's context
|
||||
* @property [target] data-view's block id
|
||||
* @property [template] optional template for dv record
|
||||
* @property [prefilled] prefilled or pre-populated data for dv record
|
||||
*/
|
||||
data class Params(
|
||||
val context: Id,
|
||||
val target: Id,
|
||||
val template: Id?
|
||||
val template: Id?,
|
||||
val prefilled: Map<Id, Any> = emptyMap()
|
||||
)
|
||||
}
|
|
@ -328,11 +328,13 @@ class BlockMiddleware(
|
|||
override suspend fun createDataViewRecord(
|
||||
context: String,
|
||||
target: String,
|
||||
template: Id?
|
||||
template: Id?,
|
||||
prefilled: Map<Id, Any>
|
||||
): Map<String, Any?> = middleware.blockDataViewRecordCreate(
|
||||
context = context,
|
||||
target = target,
|
||||
template = template
|
||||
template = template,
|
||||
prefilled = prefilled
|
||||
)
|
||||
|
||||
override suspend fun updateDataViewRecord(
|
||||
|
|
|
@ -214,12 +214,14 @@ class Middleware(
|
|||
fun blockDataViewRecordCreate(
|
||||
context: String,
|
||||
target: String,
|
||||
template: Id?
|
||||
template: Id?,
|
||||
prefilled: Map<Id, Any>
|
||||
): Map<String, Any?> {
|
||||
val request = Rpc.BlockDataviewRecord.Create.Request(
|
||||
contextId = context,
|
||||
blockId = target,
|
||||
templateId = template.orEmpty()
|
||||
templateId = template.orEmpty(),
|
||||
record = prefilled
|
||||
)
|
||||
if (BuildConfig.DEBUG) logRequest(request)
|
||||
val response = service.blockDataViewRecordCreate(request)
|
||||
|
|
|
@ -10,6 +10,7 @@ import com.anytypeio.anytype.analytics.base.sendEvent
|
|||
import com.anytypeio.anytype.analytics.props.Props
|
||||
import com.anytypeio.anytype.core_models.Block
|
||||
import com.anytypeio.anytype.core_models.DV
|
||||
import com.anytypeio.anytype.core_models.DVFilterCondition
|
||||
import com.anytypeio.anytype.core_models.DVViewerRelation
|
||||
import com.anytypeio.anytype.core_models.Event
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
|
@ -726,12 +727,12 @@ class ObjectSetViewModel(
|
|||
} else {
|
||||
val startTime = System.currentTimeMillis()
|
||||
viewModelScope.launch {
|
||||
val template = resolveTemplateForNewRecord()
|
||||
createDataViewRecord(
|
||||
CreateDataViewRecord.Params(
|
||||
context = context,
|
||||
target = currentState.dataview.id,
|
||||
template = template
|
||||
template = resolveTemplateForNewRecord(),
|
||||
prefilled = resolvePrefilledRecordData(currentState)
|
||||
)
|
||||
).process(
|
||||
failure = { Timber.e(it, "Error while creating new record") },
|
||||
|
@ -763,6 +764,18 @@ class ObjectSetViewModel(
|
|||
}
|
||||
}
|
||||
|
||||
private fun resolvePrefilledRecordData(setOfObjects: ObjectSet): Map<Id, Any> = buildMap {
|
||||
val viewer = setOfObjects.viewerById(session.currentViewerId)
|
||||
viewer.filters.forEach { filter ->
|
||||
val relation = reducer.state.value.relations.find { it.key == filter.relationKey }
|
||||
if (relation != null && !relation.isReadOnly) {
|
||||
if (filter.condition == DVFilterCondition.ALL_IN || filter.condition == DVFilterCondition.IN || filter.condition == DVFilterCondition.EQUAL) {
|
||||
filter.value?.let { put(filter.relationKey, it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun resolveTemplateForNewRecord(): Id? {
|
||||
val obj = ObjectWrapper.Basic(reducer.state.value.details[context]?.map ?: emptyMap())
|
||||
val type = obj.setOf.singleOrNull()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue