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

[Free Response Widget] Add ability to customize placeholder #2297

Open
wants to merge 5 commits into
base: feature/free-response-widget
Choose a base branch
from

Conversation

rgpass
Copy link

@rgpass rgpass commented Mar 12, 2025

Summary:

This PR adds the ability to set the placeholder text in a Free Response Widget component.

Issue: LIT-1668

Test plan:

  • Open Storybook
  • See the placeholder can be changed in the editor
  • See the placeholder can be changed in the renderer
Screenshot 2025-03-12 at 8 47 49 AM Screenshot 2025-03-12 at 8 48 04 AM

NOTE: The screenshots use something I typed in. The default value is "Please provide response here"

@rgpass rgpass self-assigned this Mar 12, 2025
Copy link
Contributor

github-actions bot commented Mar 12, 2025

Size Change: +102 B (+0.01%)

Total Size: 874 kB

Filename Size Change
packages/perseus-core/dist/es/index.js 30.3 kB +25 B (+0.08%)
packages/perseus-editor/dist/es/index.js 277 kB +72 B (+0.03%)
packages/perseus/dist/es/index.js 368 kB +5 B (0%)
ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 39.7 kB
packages/keypad-context/dist/es/index.js 760 B
packages/kmath/dist/es/index.js 11.1 kB
packages/math-input/dist/es/index.js 78.2 kB
packages/math-input/dist/es/strings.js 1.79 kB
packages/perseus-linter/dist/es/index.js 22.8 kB
packages/perseus-score/dist/es/index.js 20.6 kB
packages/perseus/dist/es/strings.js 6.74 kB
packages/pure-markdown/dist/es/index.js 4.14 kB
packages/simple-markdown/dist/es/index.js 13.1 kB

compressed-size-action

@rgpass rgpass requested review from aag, benchristel and handeyeco March 12, 2025 13:30
@rgpass rgpass marked this pull request as ready for review March 12, 2025 13:30
Copy link
Contributor

github-actions bot commented Mar 12, 2025

npm Snapshot: Published

Good news!! We've packaged up the latest commit from this PR (a9cabf2) and published it to npm. You
can install it using the tag PR2297.

Example:

pnpm add @khanacademy/perseus@PR2297

If you are working in Khan Academy's webapp, you can run:

./dev/tools/bump_perseus_version.sh -t PR2297

@rgpass
Copy link
Author

rgpass commented Mar 12, 2025

Do I need to add a changeset if merging into a feature branch?

@handeyeco
Copy link
Contributor

Do I need to add a changeset if merging into a feature branch?

@rgpass The important thing is that there's a changeset when landing into main and that changeset includes all the packages that changed. If a package is changed and it's not included in the changeset, it might not get a new version in npm and thus can't be referenced in package.json.

We don't use feature branches a lot in Perseus, so that's why the changeset check isn't smarter about looking at your base branch. IMO it's fine to land a PR without a changeset as long as you're not landing into main.

You can also do pnpm changeset --empty and it'll make a blank changeset which will quiet the check.

>;

const defaultWidgetOptions: FreeResponseDefaultWidgetOptions = {
placeholder: "Please provide response here",
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is probably the right way to do this. My initial gut concern was that this needed to be marked for translation in Perseus (vs CP), but I don't think that's correct.

  1. "Please provide response here" will be the default in the editor and content creators can write their own string
  2. On publish this string will get sent to CP and their parser will need to know that this is a translatable string
  3. It'll get published and we'll receive the translated string when rendering

That seems fine. If we were storing the placeholder as something like string | null | undefined in the schema and defaulting to "Please provide response here" at render (vs at publish) then we would need that string in perseus/src/strings.ts.

Going this path does allow for less flexibility in the future if we want to change the default string:

  1. If we use a default placeholder when publishing (what this PR is doing), we have to run a backfill to update existing content
  2. If we use a default placeholder when rendering, we can change the string without running a backfill since we could just change the string in perseus/src/string.ts and request a new translation for that one string

Hmm...now that I've typed all this up I'm wondering if this should change. @benchristel what do you think?

Copy link
Member

Choose a reason for hiding this comment

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

I don't know the product context for this feature, so it's hard for me to say what the right choice is. TBH, I don't quite understand why content creators want the ability to customize the placeholder.

In the absence of more information, I would lean toward the current approach of defaulting the placeholder at content-creation time. That way, even if we change the default in the future, learners looking at old content will always see a placeholder that makes sense in context.

Copy link
Author

Choose a reason for hiding this comment

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

That way, even if we change the default in the future, learners looking at old content will always see a placeholder that makes sense in context.

That was our thinking as well.

Given that, are there any changes needed?

Copy link
Member

@benchristel benchristel left a comment

Choose a reason for hiding this comment

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

LGTM!

@benchristel
Copy link
Member

We don't use feature branches a lot in Perseus, so that's why the changeset check isn't smarter about looking at your base branch. IMO it's fine to land a PR without a changeset as long as you're not landing into main.

You can also do pnpm changeset --empty and it'll make a blank changeset which will quiet the check.

I think I'd prefer adding a changeset to each individual PR before landing into the feature branch. That way, each changeset refers to one atomic change, and it's easier to trace the changes through the git history and PRs.

I think that workflow will work well with our tooling. AFAIK the changesets check in CI just wants to see a changeset for each package that differs from the base branch. So we won't have to add extra changesets before landing the feature branch into main.

…ity to customize the placeholder text in a Free Response widget
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