Skip to content

fix: Correctly determine holdsState in onlyTime mode to prevent result removal #7821

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

xxxinsxxx
Copy link
Contributor

@xxxinsxxx xxxinsxxx commented Jun 24, 2025

🧠 Problem Summary

In only="time" mode, the original logic of the holdsState() method was:

if (self.onlyTime && !isDefined(self.time)) return false;
return isDefined(self.month) || isDefined(self.year);

During the first time selecting a time:

  • self.time is assigned;
  • updateResult() triggers createPerObjectResult(), successfully creating the result.

However, during the second time modifying the time:

  • self.time is assigned;
  • updateResult() triggers self.result.area.setValue(self);
  • It enters setValue(tag);
  • The tag.holdsState is evaluated to determine whether to keep the result;
  • Since !isDefined(self.time) is false, it falls through to return isDefined(self.month) || isDefined(self.year)
  • In only="time" mode, month and year are always undefined, so holdsState returns false
  • As a result, setValue(tag) calls removeResult(result), removing the result, causing the bug where the input disappears after being set.

Changing the value again after that is just repeating this process.This behavior leads to an incorrect state evaluation that breaks expected functionality.

The involved files include: DateTime.jsx, ClassificationBase.js, AreaMixin.js

Description:

In only="time" mode, the previous logic of holdsState() caused a regression where time updates would be discarded unexpectedly. The original condition:

if (self.onlyTime && !isDefined(self.time)) return false;
return isDefined(self.month) || isDefined(self.year);

would fall through to checking month and year, which are always undefined in only="time" mode, leading to an incorrect false return value. This resulted in the result being removed during subsequent time changes.

This change simplifies and corrects the logic:

if (self.onlyTime) return isDefined(self.time);
return isDefined(self.month) || isDefined(self.year);

Now, in only="time" mode, the state is solely determined by whether self.time is defined — aligning with the intended behavior and preventing unintended result removal.


🔍Problem Solved:

before:

before

after:

after


📁 Changed Files

Path: libs/editor/src/tags/control/DateTime.jsx

Code Changes:

 get holdsState() {
-  if (self.onlyTime && !isDefined(self.time)) return false;
-  return isDefined(self.month) || isDefined(self.year);
+  if (self.onlyTime) return isDefined(self.time);
+  return isDefined(self.month) || isDefined(self.year);
 },

✅ Testing Recommendation:

  • Test time input on odd/even updates.
  • Ensure results persist in only="time" mode.
  • Validate behavior in other modes.
  • Verify mixed-mode behavior.

- Modified the holdsState method of the DateTime component
- Optimized the logic of state judgment under the onlyTime property
- Make sure that if there is only a time option, it is correct to determine whether the control has a valid state
Copy link

netlify bot commented Jun 24, 2025

👷 Deploy request for heartex-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit eb21eb9

Copy link

netlify bot commented Jun 24, 2025

👷 Deploy request for label-studio-docs-new-theme pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit eb21eb9

Copy link

netlify bot commented Jun 24, 2025

Deploy Preview for label-studio-storybook ready!

Name Link
🔨 Latest commit eb21eb9
🔍 Latest deploy log https://app.netlify.com/projects/label-studio-storybook/deploys/685a73c37ad5a300087c8c6e
😎 Deploy Preview https://deploy-preview-7821--label-studio-storybook.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link

netlify bot commented Jun 24, 2025

Deploy Preview for label-studio-playground ready!

Name Link
🔨 Latest commit eb21eb9
🔍 Latest deploy log https://app.netlify.com/projects/label-studio-playground/deploys/685a73c321410200080fd20c
😎 Deploy Preview https://deploy-preview-7821--label-studio-playground.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions github-actions bot added the fix label Jun 24, 2025
@xxxinsxxx xxxinsxxx changed the title fix: fix state validation logic in onlyTime mode fix: Correctly determine holdsState in onlyTime mode to prevent result removal Jun 25, 2025
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.

Datetime Tag with only="time" Parameter Fails to Display Selected Value
1 participant