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

feat: LEAP-1454: Custom action buttons in LSF #6411

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

hlomzik
Copy link
Collaborator

@hlomzik hlomzik commented Sep 19, 2024

Introducing custom action buttons for LSF to allow additional actions, controlled from outside of editor. Provided buttons will completely replace the internal ones, but there is a way to reuse buttons you need, just add the button with internal name and no extra params.

TODO: Add example

Custom buttons need to behave similarly to internal ones, so we are using flags and additional checks. They will call the same event handleCustomButton(button_name) so external app will handle customButton event with store, button_name, options params.

Also new types for global MST stores are introduced in a draft state with intention to expand them with more props and methods so they can be used in other TypeScript code, which currently uses any for any MST stuff.

PR fulfills these requirements

  • Tests for the changes have been added/updated (for bug fixes/features)
  • Docs have been added/updated (for bug fixes/features)
  • Best efforts were made to ensure docs/code are concise and coherent (checked for spelling/grammatical errors, commented out code, debug logs etc.)
  • Self-reviewed and ran all changes on a local instance (for bug fixes/features)

Change has impacts in these area(s)

  • Product design
  • Backend (Database)
  • Backend (API)
  • Frontend

Describe the reason for change

We need to introduce new buttons in LSE and instead of creating another "hidden" buttons in LSF we create a way to use any button you need.

What alternative approaches were there?

Hardcode new buttons in LSF and display them by one more interface.

What feature flags were used to cover this change?

None. That's addition and will be used only if specific props are passed in.

Does this PR introduce a breaking change?

  • Yes, and covered entirely by feature flag(s)
  • Yes, and covered partially by feature flag(s)
  • No
  • Not sure (briefly explain the situation below)

What level of testing was included in the change?

  • e2e
  • integration
  • unit

Simple declarative store to describe custom buttons.
Plus universal handler to handle any button depending on its type.
Main stores are covered with some popular props and methods:
AppStore, AnnotationStore, Annotation
They will fully substitute all other buttons for now.
Later we'll add some other buttons specified in custom buttons config.
@github-actions github-actions bot added the feat label Sep 19, 2024
Copy link

netlify bot commented Sep 19, 2024

Deploy Preview for heartex-docs canceled.

Name Link
🔨 Latest commit 0e56d10
🔍 Latest deploy log https://app.netlify.com/sites/heartex-docs/deploys/66ed7b9ff1493c0008c06c7e

Copy link

netlify bot commented Sep 19, 2024

Deploy Preview for label-studio-docs-new-theme canceled.

Name Link
🔨 Latest commit 0e56d10
🔍 Latest deploy log https://app.netlify.com/sites/label-studio-docs-new-theme/deploys/66ed7b9f6042c000087b5f74

return (
<Block name="controls">
{buttons.map((button) => (
<CustomControl button={button} onClick={store.handleCustomButton} />
Copy link

Choose a reason for hiding this comment

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

Add a key prop to the CustomControl component within the map function to ensure each element has a unique key.

Suggested change
<CustomControl button={button} onClick={store.handleCustomButton} />
<CustomControl key={button.id} button={button} onClick={store.handleCustomButton} />

This allows to mix custom buttons with internal ones.
- look for Submit is primary as a fallback value, because it has no secondary
- Button now have a `mod` property from Block, should be infered, but that's for later
- Dropdown pointing to a correct component with additional property
- the rest are just added types or direct type casts
@hlomzik hlomzik changed the title feat: LEAP-1454: Flexible reject buttons feat: LEAP-1454: Custom action buttons in LSF Sep 20, 2024
@@ -80,7 +128,8 @@ export const Controls = controlsInjector(
],
);

const RejectButton = useMemo(() => {
// @todo memo?
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Suggested change
// @todo memo?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant