@@ -1647,13 +1647,13 @@ createCloneButtonHTML <- function(
16471647
16481648#' Re-usable documentation
16491649#' @param canEditRow can be either of the following:
1650- #' - `logical`, e.g. TRUE or FALSE
1650+ #' - `logical`, e.g. TRUE or FALSE. In case of `FALSE`, buttons will not be visible except for new rows.
16511651#' - `function`. Needs as input an argument `row` which accepts a single row `tibble` and as output TRUE/FALSE.
16521652#' @param canCloneRow can be either of the following:
1653- #' - `logical`, e.g. TRUE or FALSE
1653+ #' - `logical`, e.g. TRUE or FALSE. In case of `FALSE`, buttons will not be visible except for new rows.
16541654#' - `function`. Needs as input an argument `row` which accepts a single row `tibble` and as output TRUE/FALSE.
16551655#' @param canDeleteRow can be either of the following:
1656- #' - `logical`, e.g. TRUE or FALSE
1656+ #' - `logical`, e.g. TRUE or FALSE. In case of `FALSE`, buttons will not be visible except for new rows.
16571657#' - `function`. Needs as input an argument `row` which accepts a single row `tibble` and as output TRUE/FALSE.
16581658#' @keywords internal
16591659canXXXRowTemplate <- function(canEditRow, canCloneRow, canDeleteRow){
@@ -1679,19 +1679,45 @@ createButtons <- function(
16791679 canCloneRow = TRUE,
16801680 statusCol = '_editbl_status'
16811681){
1682- deleteButton <- createDeleteButtonHTML(
1683- ns=ns,
1684- suffix=suffix,
1685- disabled = !evalCanDeleteRow(row=row, canDeleteRow=canDeleteRow, statusCol=statusCol))
1686- editButton <- createEditButtonHTML(
1687- ns=ns,
1688- suffix=suffix,
1689- disabled = !evalCanEditRow(row=row, canEditRow=canEditRow, statusCol=statusCol))
1690- cloneButton <- createCloneButtonHTML(
1691- ns = ns,
1692- suffix = suffix,
1693- disabled = !evalCanCloneRow(row = row, canCloneRow = canCloneRow, statusCol = statusCol))
1694-
1682+ # Hide delete completely if canDeleteRow = FALSE. With the exception of newly created rows.
1683+ if(is.logical(canDeleteRow)
1684+ && !canDeleteRow
1685+ && (is.null(statusCol) || row[[statusCol]] != 'inserted')
1686+ ){
1687+ deleteButton <- " "
1688+ } else {
1689+ deleteButton <- createDeleteButtonHTML(
1690+ ns=ns,
1691+ suffix=suffix,
1692+ disabled = !evalCanDeleteRow(row=row, canDeleteRow=canDeleteRow, statusCol=statusCol))
1693+ }
1694+
1695+ # Hide edit completely if canEditRow = FALSE. With the exception of newly created rows.
1696+ if(is.logical(canEditRow)
1697+ && !canEditRow
1698+ && (is.null(statusCol) || row[[statusCol]] != 'inserted')
1699+ ){
1700+ editButton <- " "
1701+ } else {
1702+ editButton <- createEditButtonHTML(
1703+ ns=ns,
1704+ suffix=suffix,
1705+ disabled = !evalCanEditRow(row=row, canEditRow=canEditRow, statusCol=statusCol))
1706+ }
1707+
1708+ # Hide clone button completely if canCloneRow = FALSE. With the exception of newly created rows.
1709+ if(is.logical(canCloneRow)
1710+ && !canCloneRow
1711+ && (is.null(statusCol) || row[[statusCol]] != 'inserted')
1712+ ){
1713+ cloneButton <- " "
1714+ } else {
1715+ cloneButton <- createCloneButtonHTML(
1716+ ns = ns,
1717+ suffix = suffix,
1718+ disabled = !evalCanCloneRow(row = row, canCloneRow = canCloneRow, statusCol = statusCol))
1719+ }
1720+
16951721 result <- sprintf('<div class=" btn - group " >%1$s%2$s%3$s</div>',
16961722 deleteButton,
16971723 editButton,
0 commit comments