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

fix: unset should unset readOnly date field from custom input component #8192

Merged
merged 4 commits into from
Jan 7, 2025

Conversation

EoinFalconer
Copy link
Contributor

@EoinFalconer EoinFalconer commented Jan 6, 2025

Description

At the moment if you create a custom input component for a datetime field or a date field, and perform unset in the custom input component when the field is readOnly the value will not update on the field.

This occurs because this looks like it stores a local value, and when the field is read only, the input renders a plain text field which never triggers handleDatePickerInputChange.

In this PR, I have removed the plain text field and used the propagated readOnly flag to instead achieve this in the DateTimeInput component

What to review

We think this is ok? I'm not sure of the reasons for using the Text component instead but this feels better to allow the DateTimeInput to be able to be read only, for usage in other scenarios too?

Testing

Didn't add any tests for this, let me know if I should.

Notes for release

unset() inside custom datetime input components will now shown the that the value has been unset in the Studio UI.

@EoinFalconer EoinFalconer requested a review from a team as a code owner January 6, 2025 12:11
@EoinFalconer EoinFalconer requested review from ricokahler and removed request for a team January 6, 2025 12:11
Copy link

vercel bot commented Jan 6, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
page-building-studio 🛑 Canceled (Inspect) Jan 6, 2025 1:37pm
performance-studio ✅ Ready (Inspect) Visit Preview Jan 6, 2025 1:37pm
test-next-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 6, 2025 1:37pm
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 6, 2025 1:37pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Visit Preview Jan 6, 2025 1:37pm

@EoinFalconer EoinFalconer marked this pull request as draft January 6, 2025 12:12
@EoinFalconer EoinFalconer changed the title fix: unset should unset readOnly date field fix: unset should unset readOnly date field from custom input component Jan 6, 2025
@EoinFalconer EoinFalconer marked this pull request as ready for review January 6, 2025 12:45
Copy link
Contributor

github-actions bot commented Jan 6, 2025

No changes to documentation

Copy link
Contributor

github-actions bot commented Jan 6, 2025

Component Testing Report Updated Jan 6, 2025 12:52 PM (UTC)

✅ All Tests Passed -- expand for details
File Status Duration Passed Skipped Failed
comments/CommentInput.spec.tsx ✅ Passed (Inspect) 1m 5s 15 0 0
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 12s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ✅ Passed (Inspect) 37s 6 0 0
formBuilder/inputs/PortableText/copyPaste/CopyPaste.spec.tsx ✅ Passed (Inspect) 50s 11 7 0
formBuilder/inputs/PortableText/copyPaste/CopyPasteFields.spec.tsx ✅ Passed (Inspect) 0s 0 12 0
formBuilder/inputs/PortableText/Decorators.spec.tsx ✅ Passed (Inspect) 25s 6 0 0
formBuilder/inputs/PortableText/DisableFocusAndUnset.spec.tsx ✅ Passed (Inspect) 14s 3 0 0
formBuilder/inputs/PortableText/DragAndDrop.spec.tsx ✅ Passed (Inspect) 26s 6 0 0
formBuilder/inputs/PortableText/FocusTracking.spec.tsx ✅ Passed (Inspect) 1m 6s 15 0 0
formBuilder/inputs/PortableText/Input.spec.tsx ✅ Passed (Inspect) 1m 28s 21 0 0
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ✅ Passed (Inspect) 1m 40s 18 0 0
formBuilder/inputs/PortableText/PresenceCursors.spec.tsx ✅ Passed (Inspect) 13s 3 9 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 26s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ✅ Passed (Inspect) 1m 43s 21 0 0
formBuilder/tree-editing/TreeEditing.spec.tsx ✅ Passed (Inspect) 0s 0 3 0
formBuilder/tree-editing/TreeEditingNestedObjects.spec.tsx ✅ Passed (Inspect) 0s 0 3 0

Copy link
Contributor

github-actions bot commented Jan 6, 2025

⚡️ Editor Performance Report

Updated Mon, 06 Jan 2025 12:55:53 GMT

Benchmark reference
latency of sanity@latest
experiment
latency of this branch
Δ (%)
latency difference
article (title) 18.9 efps (53ms) 22.7 efps (44ms) -9ms (-17.0%)
article (body) 44.8 efps (22ms) 42.9 efps (23ms) +1ms (+4.5%)
article (string inside object) 20.8 efps (48ms) 23.8 efps (42ms) -6ms (-12.5%)
article (string inside array) 19.6 efps (51ms) 20.8 efps (48ms) -3ms (-5.9%)
recipe (name) 45.5 efps (22ms) 52.6 efps (19ms) -3ms (-13.6%)
recipe (description) 48.8 efps (21ms) 62.5 efps (16ms) -5ms (-22.0%)
recipe (instructions) 99.9+ efps (7ms) 99.9+ efps (8ms) +1ms (-/-%)
synthetic (title) 18.7 efps (54ms) 19.2 efps (52ms) -2ms (-2.8%)
synthetic (string inside object) 19.6 efps (51ms) 20.0 efps (50ms) -1ms (-2.0%)

efps — editor "frames per second". The number of updates assumed to be possible within a second.

Derived from input latency. efps = 1000 / input_latency

Detailed information

🏠 Reference result

The performance result of sanity@latest

Benchmark latency p75 p90 p99 blocking time test duration
article (title) 53ms 80ms 99ms 620ms 1129ms 12.9s
article (body) 22ms 27ms 39ms 180ms 316ms 6.7s
article (string inside object) 48ms 50ms 56ms 203ms 177ms 7.6s
article (string inside array) 51ms 54ms 58ms 239ms 303ms 8.0s
recipe (name) 22ms 26ms 37ms 59ms 0ms 7.9s
recipe (description) 21ms 23ms 25ms 47ms 0ms 4.9s
recipe (instructions) 7ms 10ms 11ms 19ms 0ms 3.4s
synthetic (title) 54ms 65ms 77ms 292ms 884ms 13.5s
synthetic (string inside object) 51ms 55ms 71ms 491ms 898ms 8.2s

🧪 Experiment result

The performance result of this branch

Benchmark latency p75 p90 p99 blocking time test duration
article (title) 44ms 77ms 89ms 510ms 943ms 11.4s
article (body) 23ms 28ms 48ms 201ms 259ms 6.8s
article (string inside object) 42ms 46ms 49ms 170ms 148ms 7.2s
article (string inside array) 48ms 53ms 62ms 357ms 460ms 8.0s
recipe (name) 19ms 21ms 24ms 44ms 0ms 7.3s
recipe (description) 16ms 18ms 21ms 34ms 0ms 4.4s
recipe (instructions) 8ms 10ms 11ms 16ms 0ms 3.4s
synthetic (title) 52ms 55ms 61ms 81ms 142ms 15.3s
synthetic (string inside object) 50ms 53ms 72ms 477ms 823ms 8.6s

📚 Glossary

column definitions

  • benchmark — the name of the test, e.g. "article", followed by the label of the field being measured, e.g. "(title)".
  • latency — the time between when a key was pressed and when it was rendered. derived from a set of samples. the median (p50) is shown to show the most common latency.
  • p75 — the 75th percentile of the input latency in the test run. 75% of the sampled inputs in this benchmark were processed faster than this value. this provides insight into the upper range of typical performance.
  • p90 — the 90th percentile of the input latency in the test run. 90% of the sampled inputs were faster than this. this metric helps identify slower interactions that occurred less frequently during the benchmark.
  • p99 — the 99th percentile of the input latency in the test run. only 1% of sampled inputs were slower than this. this represents the worst-case scenarios encountered during the benchmark, useful for identifying potential performance outliers.
  • blocking time — the total time during which the main thread was blocked, preventing user input and UI updates. this metric helps identify performance bottlenecks that may cause the interface to feel unresponsive.
  • test duration — how long the test run took to complete.

Copy link
Contributor

@snorrees snorrees left a comment

Choose a reason for hiding this comment

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

This works well from my PoV!

Tested with the following input component, on the same document in two different windows to check multiplayer as well.

      components: {
        input: function T(props: DateInputProps) {
          const [ro, setRo] = useState(false)
          return (
            <Stack space={2}>
              {props.renderDefault({...props, readOnly: ro})}
              <Button
                text={`Make ${ro ? 'writable' : 'readOnly'}`}
                onClick={() => setRo((r) => !r)}
              />
              <Button text={`Unset field`} onClick={() => props.onChange(unset())} />
              <Button
                text={`Set field`}
                onClick={() => props.onChange(set(new Date().toISOString().split('T')[0]))}
              />
            </Stack>
          )
        },
      }

The input now updates in readonly mode.
Also tested datetime (without the split on the set button)

(TIL: we dont store the date input if it is not valid, so typing garbage in the filed does not sync)

@EoinFalconer EoinFalconer added this pull request to the merge queue Jan 7, 2025
Merged via the queue into next with commit e4f7164 Jan 7, 2025
56 of 57 checks passed
@EoinFalconer EoinFalconer deleted the fix/SAPP-1931 branch January 7, 2025 14:55
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.

2 participants