Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First pass into workspace UI/server #124

Merged
merged 18 commits into from
Jan 12, 2024
Merged

First pass into workspace UI/server #124

merged 18 commits into from
Jan 12, 2024

Conversation

DivadNojnarg
Copy link
Collaborator

@DivadNojnarg DivadNojnarg commented Dec 8, 2023

TO DO:

  • add tests.
  • add way to edit stacks: pass blocks.
  • Important: Cleanup stack inputs? observers and output (like for blocks). Below is how input looks like after stacks are added, cleared and reset (OUT OF THE SCOPE OF THIS PR).
<ReactiveValues> 
  Values:    myworkspace-add_stack, myworkspace-clear_stacks, myworkspace-mystack-1-jgnzeezgtmhotlp-dataset, myworkspace-mystack-1-jgnzeezgtmhotlp-remove, myworkspace-mystack-1-jgnzeezgtmhotlp-res_cell_clicked, myworkspace-mystack-1-jgnzeezgtmhotlp-res_cells_selected, myworkspace-mystack-1-jgnzeezgtmhotlp-res_columns_selected, myworkspace-mystack-1-jgnzeezgtmhotlp-res_rows_all, myworkspace-mystack-1-jgnzeezgtmhotlp-res_rows_current, myworkspace-mystack-1-jgnzeezgtmhotlp-res_rows_selected, myworkspace-mystack-1-jgnzeezgtmhotlp-res_search, myworkspace-mystack-1-jgnzeezgtmhotlp-res_state, myworkspace-mystack-1-last_changed, myworkspace-mystack-1-remove, myworkspace-mystack-1-title, myworkspace-mystack-2-last_changed, myworkspace-mystack-2-remove, myworkspace-mystack-2-title, myworkspace-mystack-2-wpmbppudytffvdu-dataset, myworkspace-mystack-2-wpmbppudytffvdu-remove, myworkspace-mystack-2-wpmbppudytffvdu-res_cell_clicked, myworkspace-mystack-2-wpmbppudytffvdu-res_cells_selected, myworkspace-mystack-2-wpmbppudytffvdu-res_columns_selected, myworkspace-mystack-2-wpmbppudytffvdu-res_rows_all, myworkspace-mystack-2-wpmbppudytffvdu-res_rows_current, myworkspace-mystack-2-wpmbppudytffvdu-res_rows_selected, myworkspace-mystack-2-wpmbppudytffvdu-res_search, myworkspace-mystack-2-wpmbppudytffvdu-res_state, myworkspace-mystack-3-last_changed, myworkspace-mystack-3-remove, myworkspace-mystack-3-title, myworkspace-mystack-3-uozygoqqaknabbd-dataset, myworkspace-mystack-3-uozygoqqaknabbd-remove, myworkspace-mystack-3-uozygoqqaknabbd-res_cell_clicked, myworkspace-mystack-3-uozygoqqaknabbd-res_cells_selected, myworkspace-mystack-3-uozygoqqaknabbd-res_columns_selected, myworkspace-mystack-3-uozygoqqaknabbd-res_rows_all, myworkspace-mystack-3-uozygoqqaknabbd-res_rows_current, myworkspace-mystack-3-uozygoqqaknabbd-res_rows_selected, myworkspace-mystack-3-uozygoqqaknabbd-res_search, myworkspace-mystack-3-uozygoqqaknabbd-res_state 
  Readonly:  TRUE 

Copy link

codecov bot commented Dec 8, 2023

Codecov Report

Attention: 125 lines in your changes are missing coverage. Please review.

Comparison is base (f1dddf9) 64.90% compared to head (a1c4c93) 75.66%.

Files Patch % Lines
R/server.R 8.33% 66 Missing ⚠️
R/ui.R 10.60% 59 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main     #124       +/-   ##
===========================================
+ Coverage   64.90%   75.66%   +10.76%     
===========================================
  Files          16       16               
  Lines        1681     1796      +115     
===========================================
+ Hits         1091     1359      +268     
+ Misses        590      437      -153     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -12,7 +12,7 @@ set_workspace <- function(..., title = "", settings = NULL, force = FALSE) {

set_workspace_title(title)
set_workspace_settings(settings)
set_workpsace_stacks(list(...))
set_workspace_stacks(list(...))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor typo fixed

R/ui.R Outdated

ns <- NS(id)

stacks <- get_workspace_stacks()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this feels actually a bit weird to have to get the stacks this way since workspace is not a structure like new_stack or new_block. I can make it work but this does not feel super in line with the rest of our API.

R/ui.R Outdated
div(
class = "d-flex justify-content-between stacks",
lapply(seq_along(stacks), \(i) {
generate_ui(stacks[[i]], id = ns(sprintf("mystack-%s", i)))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above. I would have expected to loop over x (the workspace) and not over the result of get_workspace_stacks.

@DivadNojnarg
Copy link
Collaborator Author

Note: #119 is needed to cleanup module server after being removed (cc @nbenn)

@DivadNojnarg
Copy link
Collaborator Author

DivadNojnarg commented Jan 10, 2024

Still to do:

  • maybe add the "Add block button" within the stack card DONE.
  • improve layout DONE.

Screenshot 2024-01-10 at 14 55 48

@DivadNojnarg DivadNojnarg marked this pull request as ready for review January 10, 2024 22:52
@DivadNojnarg DivadNojnarg requested a review from nbenn as a code owner January 10, 2024 22:52
@DivadNojnarg
Copy link
Collaborator Author

Few notes for @nbenn:

  • We'll need to handle the server conflicts with the main branch: from what we discussed, I propose to accept both incoming and current to be able to use the old approach for generate_server.
  • Now that we have the workspace, stacks, blocks, ... a good time to rethink the validation process.
  • This is a basic/default workspace implementation. @JohnCoene has his own with the super framework.

@DivadNojnarg DivadNojnarg mentioned this pull request Jan 11, 2024
Copy link
Collaborator

@nbenn nbenn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm. We should tweak the workspace API a bit. If in your scope you have the workspace available as x, it feels wrong to call e.g. get_workspace_stacks() instead of get_workspace_stacks(x). Happy to discuss your thoughts on whether the workspace object should remain implemented as environment or not.


ns <- NS(id)

stacks <- get_workspace_stacks()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more a note-to-self: my workspace API here is not good. If the workspace is passed as x you'd want to be able to call get_workspace_stacks() as get_workspace_stacks(x).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is weird. We can leave it as is if the time constaint is too high with other priorities. Anyway we still have #92 open so we can add a bullet point here.

}, {
# We can't remove the data block if there are downstream consumers...
stacks <- get_workspace_stacks()
to_remove <- which(chr_ply(stacks, \(x) attr(x, "name")) == id)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not wrong. From a design-perspective, it might be worthwhile to consider either passing the index from the parent scope, where it should be more easily available, no? This is also in anticipation of maybe not implementing the workspace as environment.

R/server.R Outdated
moduleServer(
id = id,
function(input, output, session) {
vals <- reactiveValues(stacks = list(), new_blocks = list())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More of a naming issue (probably my understanding here is incomplete), but why the plural? Does new_blocks actually hold on to multiple new blocks at the same time?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that's TRUE. This is a wrong naming because to the best of my knowledge, we only add 1 block at a time. Can you confirm @JohnCoene? That should also apply to the stack server as well:

#' @param new_blocks For dynamically inserted blocks.
#' @export
generate_server.stack <- function(x, id = NULL, new_blocks = NULL, ...) {
...
}

I can change it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is correct.

I cannot run generate_server on the workspace directly. I need to regenerate their UI on the correct tabs and their servers in their correct tabs/modules as well as pass the adequate new_block reactive to each server.

R/ui.R Outdated
radioButtons(
ns("selected_block"),
"Choose a block",
choices = setNames(seq_len(length(list_blocks())), list_blocks()),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have set_names() in utils.R, b/c I thought it was unnecessary to import an entire package for a 2-line function. This effort was thwarted by @christophsax in 3e1b971.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another remark: after checking with @JohnCoene in another PR, I might be wrong using list_blocks() which is not exported. I should use available_blocks() instead.

@DivadNojnarg DivadNojnarg merged commit ff1d095 into main Jan 12, 2024
7 of 8 checks passed
@DivadNojnarg DivadNojnarg deleted the 121-workspace-server branch January 12, 2024 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants