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

[BUG]: Insufficient support for custom ConditionBuilder value labels #6439

Open
2 tasks done
pjborowiecki opened this issue Nov 15, 2024 · 0 comments
Open
2 tasks done

Comments

@pjborowiecki
Copy link

pjborowiecki commented Nov 15, 2024

Package

Carbon for IBM Products

Description

There is currently no sufficient level of control over displayed values of custom components in the ConditionBuilder.

My use case is such that I would like to operate on ISO dateTime values, but display something completely different (e.g. "is past 4 days"), as can be seen in the screenshot below:

Image

The getValue() function (available in source code)) should be extended to allow mor granular control over what is displayed as value (allowing to customise the logic or add a callback function, instead of simply returning the value):

export const getValue = {
  text: (value) => value,
  textarea: (value) => value,
  time: (value) => value,
  number: (value) => value,
  option: (value) => {
    if (value && typeof value !== 'string') {
      const selectedValues = Array.isArray(value) ? value : [value];
      return selectedValues.map((option) => option.label).join(', ');
    }

    return value;
  },
  date: (value) => {
    if (Array.isArray(value) && value.length > 1) {
      const start =
        value?.[0] && !isNaN(new Date(value[0]))
          ? formatDate(new Date(value[0]))
          : '';
      const end =
        value?.[1] && !isNaN(new Date(value[1]))
          ? formatDate(new Date(value[1]))
          : '';
      return `${start} To ${end}`;
    } else if (Array.isArray(value) && !isNaN(new Date(value[0]))) {
      return formatDate(new Date(value[0]));
    } else {
      return value;
    }
  },
  custom: (value) => value,
};

Component(s) impacted

ConditionBuilder

Browser

Chrome, Safari, Firefox, Microsoft Edge

@carbon/ibm-products (previously @carbon/ibm-cloud-cognitive) version

2.50.0

Suggested Severity

Severity 1 = The design is broken in a critical way that blocks users from completing tasks or damages the brand. Affects major functionality, no workaround.

Product/offering

IBM

CodeSandbox or Stackblitz example

https://codesandbox.io

Steps to reproduce the issue (if applicable)

No response

Release date (if applicable)

No response

Code of Conduct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Needs triage 🧐
Development

No branches or pull requests

1 participant