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

Add RichTextBlock support to Block Kit Kotlin DSL builder #1376

Merged
merged 8 commits into from
Sep 20, 2024

Conversation

KENNYSOFT
Copy link
Contributor

This PR adds RichTextBlock support to Block Kit Kotlin DSL builder. With this changes, we can now use DSL like:

withBlocks {
    richText {
        richTextSection {
            text("Check out these different block types with paragraph breaks between them:\n\n")
        }
        richTextPreformatted {
            text("Hello there, I am preformatted block!\n\nI can have multiple paragraph breaks within the block.")
        }
        richTextSection {
            text("\nI am rich text with a paragraph break following preformatted text. \n\nI can have multiple paragraph breaks within the block.\n\n")
        }
        richTextQuote {
            text("I am a basic rich text quote, \n\nI can have multiple paragraph breaks within the block.")
        }
        richTextSection {
            text("\nI am rich text with a paragraph after the quote block\n\n")
        }
        richTextQuote {
            text("I am a basic quote block following rich text")
        }
        richTextSection {
            text("\n")
        }
        richTextPreformatted {
            text("I am more preformatted text following a quote block")
        }
        richTextSection {
            text("\n")
        }
        richTextQuote {
            text("I am a basic quote block following preformatted text")
        }
        richTextSection {
            text("\n")
        }
        richTextList {
            style(ListStyle.BULLET)
            richTextSection {
                text("list item one")
            }
            richTextSection {
                text("list item two")
            }
        }
        richTextSection {
            text("\nI am rich text with a paragraph break after a list")
        }
    }
}

Category (place an x in each of the [ ])

  • bolt (Bolt for Java)
  • bolt-{sub modules} (Bolt for Java - optional modules)
  • slack-api-client (Slack API Clients)
  • slack-api-model (Slack API Data Models)
  • slack-api-*-kotlin-extension (Kotlin Extensions for Slack API Clients)
  • slack-app-backend (The primitive layer of Bolt for Java)

Requirements

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you agree to those rules.

Copy link

Thanks for the contribution! Before we can merge this, we need @KENNYSOFT to sign the Salesforce Inc. Contributor License Agreement.

Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

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

Great work! Overall, your changes look great to me but could you take a bit more time to adjust the following?

  • A few more adjustments to your changes; see my review comments
  • Run ./scripts/run_no_prep_tests.sh to generate corresponding JSON files
  • Sign our CLA; without it, we are unable to accept any external contribution

Thank you!

* @param name The name of the emoji; i.e. "wave" or "wave::skin-tone-2".
* @see <a href="https://api.slack.com/reference/block-kit/blocks#emoji-element-type">Rich text object documentation</a>
*/
fun emoji(name: String)
Copy link
Member

Choose a reason for hiding this comment

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

emoji method should accept two patterns:

  • name: String, skinTone: Int? = null, style: TextStyle? = null
  • unicode: String

overloading with string type may not work; if that's the case, skipping unicode here is okay

Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://api.slack.com/reference/block-kit/blocks#emoji-element-type

image

I've implemented based on the documents, but yes I've seen that RichTextSectionElement.Emoji has those fields and will take a look for them.

Copy link
Contributor Author

@KENNYSOFT KENNYSOFT Sep 19, 2024

Choose a reason for hiding this comment

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

Resolved in 1be897c

By the way, Kotlin allows for overloading but I think it can be confusing. With this interface:

fun emoji(name: String, skinTone: Int? = null, style: LimitedTextStyle? = null)
fun emoji(unicode: String)

The call emoji("aaa") is directed to the second one, and to use the first method then we should use a named parameter like emoji(name = "aaa").

So I've skipped the Unicode version for now, but also suggesting a different DSL like emojiUnicode("U+AC00") with little confidence.

@seratch seratch added enhancement M-T: A feature request for new functionality project:slack-api-model project:slack-api-model lang:kotlin labels Sep 19, 2024
@seratch seratch self-assigned this Sep 19, 2024
@seratch seratch added this to the 1.x milestone Sep 19, 2024
@KENNYSOFT

This comment was marked as resolved.

@seratch seratch closed this Sep 19, 2024
@seratch seratch reopened this Sep 19, 2024
@KENNYSOFT
Copy link
Contributor Author

Thanks!

@seratch
Copy link
Member

seratch commented Sep 19, 2024

As a workaround, I closed and reopend this PR to let the CLA bot check it again. It seems your status is now correctly updated!

Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

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

Looks good to me! Once the CI builds pass, I will merge this PR. Thank you so much for the contribution!

@seratch
Copy link
Member

seratch commented Sep 19, 2024

Oops, let me correct myself about the merge timing, we'll release this patch release before it: https://github.com/slackapi/java-slack-sdk/milestone/108 After that, this enhancement will be included in an upcoming minor release.

Copy link

codecov bot commented Sep 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.49%. Comparing base (e5565e7) to head (8aa01ca).
Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1376      +/-   ##
============================================
+ Coverage     74.24%   74.49%   +0.24%     
- Complexity     4273     4324      +51     
============================================
  Files           461      472      +11     
  Lines         13364    13491     +127     
  Branches       1377     1377              
============================================
+ Hits           9922    10050     +128     
+ Misses         2629     2628       -1     
  Partials        813      813              

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

@seratch seratch merged commit c442278 into slackapi:main Sep 20, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla:signed enhancement M-T: A feature request for new functionality lang:kotlin project:slack-api-model project:slack-api-model
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants