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

Question: Is it possible to add ViewState to blockSuggestion events? #1292

Open
RovoMe opened this issue Mar 19, 2024 · 5 comments
Open

Question: Is it possible to add ViewState to blockSuggestion events? #1292

RovoMe opened this issue Mar 19, 2024 · 5 comments
Labels
auto-triage-skip enhancement M-T: A feature request for new functionality server-side-issue

Comments

@RovoMe
Copy link

RovoMe commented Mar 19, 2024

In a modal view we have two ExternalSelectElements that provide suggestion support for user entering customer and project values. We would love to use the input of the first select element, if a selection was performed, as filter for the second one without having to store the entered value in a short-living cache or backing datastore. The API could simply return the value of the selected elements within the ViewState object similar to how blockAcktion(...) or viewSubmission(...) receive it.

The modal basically looks like this:

View view = View.builder()
            .type("modal")
            .callbackId("some_callback_id")
            .title(ViewTitle.builder()
                    .type("plain_text")
                    .text("Some title")
                    .build())
            .submit(ViewSubmit.builder()
                    .type("plain_text")
                    .text("Submit")
                    .build())
            .close(ViewClose.builder()
                    .type("plain_text")
                    .text("Cancel")
                    .build())
            .blocks(List.of(
                    SectionBlock.builder()
                            .blockId("customerFilterBlock")
                            .text(MarkdownTextObject.builder()
                                    .text("Customer")
                                    .build())
                            .accessory(customerFilter())
                            .build(),
                    SectionBlock.builder()
                            .blockId("projectFilterBlock")
                            .text(MarkdownTextObject.builder()
                                    .text("Project")
                                    .build())
                            .accessory(projectFilter())
                            .build()
            ))
            .privateMetadata(metadata)
            .build();

  private ExternalSelectElement customerFilter() {
    final ExternalSelectElement.ExternalSelectElementBuilder builder =
            ExternalSelectElement.builder()
                    .actionId("customerFilter")
                    .placeholder(PlainTextObject.builder()
                            .text("Customer")
                            .build());

    return builder.build();
  }

  private ExternalSelectElement projectFilter() {
    final ExternalSelectElement.ExternalSelectElementBuilder builder =
            ExternalSelectElement.builder()
                    .actionId("projectFilter")
                    .placeholder(PlainTextObject.builder()
                            .text("Project")
                            .build());

    return builder.build();
  }

Suggestions are provided via

app.blockSuggestion("customerFilter", (req, ctx) -> {
  ...
  return ctx.ack(r -> r.options(suggestions.stream()
      .map(Option.builder()
          .text(...)
          .value(...)
          .build()
      )
      .toList());
});

while

app.blockAction("customerFilter", (req, ctx) -> {
  final BlockSuggestionPayload payload = req.getPayload();
  final View view = payload.getView();
  final Map<String, Map<String, ViewState.Value>> values = view.getState().getValues();
  final ViewState.Value customerOption = values.get("customerFilterBlock").get("customerFilter");
  final String customerUuid = customerOption.getSelectedOption().getValue();
  ...
  return ctx.ack();
});

can be used to learn the actual selected value (before the modal is submitted). Trying that within a blockSuggestion(...) fails as here the ViewState is basically empty (ViewState(values={})).

While we could push that value to some backing cache or datastore, i.e. Redis, so we can access it while making a suggestion for the second one by including the selection of the first input field as filter, I wonder if there are ways to actually get the ViewState also within blockSuggestion(...) and not only blockAction(...) and viewSubmission(...) somehow so we could use the value entered/selected in the first input as filter for the second suggestion? This would avoid having to push those values to a short-living cache or backing datastore.

@filmaj filmaj added enhancement M-T: A feature request for new functionality server-side-issue and removed untriaged labels Mar 20, 2024
@filmaj
Copy link
Contributor

filmaj commented Mar 20, 2024

I think this is a reasonable request and I will raise it internally.

Copy link

👋 It looks like this issue has been open for 30 days with no activity. We'll mark this as stale for now, and wait 10 days for an update or for further comment before closing this issue out. If you think this issue needs to be prioritized, please comment to get the thread going again! Maintainers also review issues marked as stale on a regular basis and comment or adjust status if the issue needs to be reprioritized.

@RovoMe
Copy link
Author

RovoMe commented Apr 25, 2024

@filmaj do you have any update on this one? As you mentioned that the requested change is reasonable and the bot is about to close this issue, I fear that this just increases the likelihood for this request being dropped

@filmaj
Copy link
Contributor

filmaj commented Apr 25, 2024

Sorry about the bot, I forgot to add the 'skip' label. I did raise this internally and have no update to provide at this time - sorry! When I hear about any updates I will certainly let you know.

@RovoMe
Copy link
Author

RovoMe commented Apr 25, 2024

Nah, all fine here. Just wanted to make sure the request isn't dropped due to the bot autoclosing it due to inactivity :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-triage-skip enhancement M-T: A feature request for new functionality server-side-issue
Projects
None yet
Development

No branches or pull requests

2 participants