Best way to refresh a table after a button action?

Product: PowerShell Universal
Version: 1.4.6

I have a UDTable that within it has a UDButton that resets a user with a click action. I want to refresh the table after it is successful and remove the user so that it is no longer visible in the table after the refresh (because they are now unlocked)

Here, Data is set to Get-SDMLockedOutUsers which in turn references a $CACHE:LockedOutUsers variable. Basically, I want to after Invoke-ButtonAction to invalidate the cache and re-run the query. Do I need to do a sync-udelement to the table ID? Will that refresh it? Or do I have to wrap it in a dynamic or something?

I’m also open to “better” approaches

New-UDTab -Text 'Locked Out' -Content {
  $UDTableParams = @{
    Data    = Get-SDMLockedOutUsers
    Columns = @(
      New-UDTableColumn -IncludeInSearch -Property SamAccountName -Title 'User'
      New-UDTableColumn -IncludeInSearch -Property UserPrincipalName -Title 'Login'
      New-UDTableColumn -IncludeInSearch -Property LastLogonDate -Title 'Last Logon Date'
      New-UDTableColumn -Property Unlock -Title 'Action' -Render {
        $buttonId = 'UnlockBtn-' + $EventData.SamAccountName
        $buttonAction = {
          param($userInfo)
          Unlock-SDMUser -SamAccountName $userInfo.SamAccountName -ErrorAction Stop
        }
        New-UDButton -Id $buttonId -Icon (New-UDIcon -Icon unlock) -Text 'Unlock' -OnClick {
          $buttonActionParams = @{
            ButtonId   = $buttonId
            Title      = "Unlocking $($EventData.UserPrincipalName) ($($EventData.SamAccountName)):"
            Action     = $buttonAction
            ActionArgs = $EventData
          }
          Invoke-ButtonAction @buttonActionParams
          #Invalidate the cache
          $CACHE:SDMLockedOutUsers = $null
          
        }
      }
    )
  }
  New-UDTable @UDTableParams -Search -Sort -Dense
}

I’d wrap it in a UDDynamic and sync that. You could use the LoadingComponent parameter to show some progress if it takes a second to reload the table.

1 Like