feat: trim main_key_id before creating new one / fix clearing_form pipeline

This commit is contained in:
2026-04-11 16:15:07 +03:00
parent 1f0b0c2a64
commit a1bc8dd9fa
2 changed files with 14 additions and 6 deletions

12
app.R
View File

@@ -586,7 +586,7 @@ server <- function(input, output, session) {
} }
values$nested_key <- input[[schm$get_key_id(values$nested_form_id)]] values$nested_key <- input[[schm$get_key_id(values$nested_form_id)]]
utils$clean_forms(values$nested_id_and_types, NS(values$nested_form_id)) utils$clean_forms(values$nested_form_id, schm, NS(values$nested_form_id))
removeModal() removeModal()
show_modal_for_nested_form(con) show_modal_for_nested_form(con)
@@ -646,10 +646,12 @@ server <- function(input, output, session) {
con <- db$make_db_connection("confirm_create_new_main_key") con <- db$make_db_connection("confirm_create_new_main_key")
on.exit(db$close_db_connection(con, "confirm_create_new_key"), add = TRUE) on.exit(db$close_db_connection(con, "confirm_create_new_key"), add = TRUE)
new_main_key <- trimws(input[[schm$get_main_key_id]])
existed_key <- db$get_keys_from_table("main", schm, con) existed_key <- db$get_keys_from_table("main", schm, con)
# если введенный ключ уже есть в базе # если введенный ключ уже есть в базе
if (input[[schm$get_main_key_id]] %in% existed_key) { if (new_main_key %in% existed_key) {
showNotification( showNotification(
sprintf("В базе уже запись с данным ключем."), sprintf("В базе уже запись с данным ключем."),
type = "error" type = "error"
@@ -657,8 +659,8 @@ server <- function(input, output, session) {
return() return()
} }
values$main_key <- input[[schm$get_main_key_id]] values$main_key <- new_main_key
utils$clean_forms(schm$get_id_type_list("main")) utils$clean_forms("main", schm)
removeModal() removeModal()
}) })
@@ -681,7 +683,7 @@ server <- function(input, output, session) {
observeEvent(input$clean_all_action, { observeEvent(input$clean_all_action, {
# rewrite all inputs with empty data # rewrite all inputs with empty data
utils$clean_forms(schm$get_id_type_list("main")) utils$clean_forms("main", schm)
values$main_key <- NULL values$main_key <- NULL
removeModal() removeModal()

View File

@@ -318,10 +318,15 @@ update_forms_with_data <- function(
} }
#' @export #' @export
clean_forms <- function(id_and_types_list, ns) { clean_forms <- function(
table_name,
schm,
ns
) {
# если передана ns() функция то подмеяем id для каждой формы в соответствии с пространством имен # если передана ns() функция то подмеяем id для каждой формы в соответствии с пространством имен
if (missing(ns)) ns <- NULL if (missing(ns)) ns <- NULL
id_and_types_list <- schm$get_id_type_list(table_name)
purrr::walk2( purrr::walk2(
.x = id_and_types_list, .x = id_and_types_list,
@@ -333,6 +338,7 @@ clean_forms <- function(id_and_types_list, ns) {
form_id = x_id, form_id = x_id,
form_type = x_type, form_type = x_type,
value = get_empty_data(x_type), value = get_empty_data(x_type),
scheme = schm$get_schema(table_name),
ns = ns ns = ns
) )
} }