skip to Main Content
      {chart?.record?.settings?.yAxis?.type === 'number' &&
        chart?.record?.chartType != 'percentage' && (
          <div className="mt-1 remove remove-input-txt-border">
            <Controller
              name="settings.yAxis.aggregation"
              control={control}
              render={({ field }) => 

I want to make an addition to this code snipet here.

Currently it works when:
yAxis type = number
and
chart type != percentage

I want to change it to work when:

yAxis type = number
and
chart type != percentage

or

yAxis type = formula
and
chart type != percentage

No attempts made so far

2

Answers


  1. Your logic can be simplified to this:

    (yAxis type = number or yAxis type = formula) and chart type != percentage

    The simpler way:

          {(chart?.record?.settings?.yAxis?.type === 'number' || chart?.record?.settings?.yAxis?.type === 'formula') &&
            chart?.record?.chartType != 'percentage' && (
              <div className="mt-1 remove remove-input-txt-border">
                <Controller
                  name="settings.yAxis.aggregation"
                  control={control}
                  render={({ field }) => 
    
    

    The cleaner way:

          {['number', 'formula'].includes(chart?.record?.settings?.yAxis?.type) &&
            chart?.record?.chartType != 'percentage' && (
              <div className="mt-1 remove remove-input-txt-border">
                <Controller
                  name="settings.yAxis.aggregation"
                  control={control}
                  render={({ field }) => 
    
    Login or Signup to reply.
  2. No attempts made so far

    How could you even not try first before asking for help, * sighs *

    chart?.record?.settings?.yAxis?.type === 'number' && chart?.record?.chartType != 'percentage'
    

    to

    (
      (chart?.record?.settings?.yAxis?.type === 'number' && chart?.record?.chartType != 'percentage') || 
      (chart?.record?.settings?.yAxis?.type === 'formula ' && chart?.record?.chartType != 'percentage')
    )
    

    Hope you at least try next time

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search