From f6f5efef0bd496c133ee533fb570f5d5f322889b Mon Sep 17 00:00:00 2001 From: Axel Bocciarelli Date: Thu, 26 Sep 2024 15:42:27 +0200 Subject: [PATCH] Use `&&` operator to render JSX conditionally where possible --- .../components/Equipment/PlateManipulator.jsx | 55 +++++++++---------- ui/src/components/Equipment/SampleChanger.jsx | 4 +- ui/src/components/Lims/LimsResultSummary.jsx | 2 +- .../SampleQueue/CharacterisationTaskItem.jsx | 23 ++++---- .../SampleQueue/EnergyScanTaskItem.jsx | 4 +- ui/src/components/SampleQueue/TaskItem.jsx | 38 ++++++------- .../SampleQueue/WorkflowTaskItem.jsx | 6 +- ui/src/components/SampleQueue/XRFTaskItem.jsx | 4 +- ui/src/components/Tasks/DataCollection.jsx | 4 +- ui/src/components/Tasks/GenericTaskForm.jsx | 4 +- ui/src/components/Tasks/Workflow.jsx | 4 +- .../GphlWorkflowParametersDialog.jsx | 5 +- ui/src/containers/SampleViewContainer.jsx | 8 +-- 13 files changed, 79 insertions(+), 82 deletions(-) diff --git a/ui/src/components/Equipment/PlateManipulator.jsx b/ui/src/components/Equipment/PlateManipulator.jsx index 18e6c7545..9db1ca16b 100644 --- a/ui/src/components/Equipment/PlateManipulator.jsx +++ b/ui/src/components/Equipment/PlateManipulator.jsx @@ -278,7 +278,7 @@ export default function PlateManipulator(props) { > Move to drop {selectedDrop} - {crystalForSelectedWell?.shelf === selectedDrop ? ( + {crystalForSelectedWell?.shelf === selectedDrop && ( <> - ) : null} + )} - {crystalForSelectedWell?.shelf === selectedDrop - ? crimsImg( - crystalForSelectedWell.image_url, - crystalForSelectedWell.sample, - ) - : null} + {crystalForSelectedWell?.shelf === selectedDrop && + crimsImg( + crystalForSelectedWell.image_url, + crystalForSelectedWell.sample, + )} {plate.name === 'ChipX' ? (
Move to this Well - {crystal !== null - ? ((), - (Crystal Info : ), - ( -
    -
  • Sample : {crystal.sample}
  • -
  • Drop : {crystal.shelf}
  • -
- )) - : null} + {crystal !== null && ( + <> + + Crystal Info : +
    +
  • Sample : {crystal.sample}
  • +
  • Drop : {crystal.shelf}
  • +
+ + )}
); @@ -592,16 +591,16 @@ export default function PlateManipulator(props) { > Move to this Well
- {crystal !== null - ? ((), - (Crystal Info : ), - ( -
    -
  • Sample : {crystal.sample}
  • -
  • Drop : {crystal.shelf}
  • -
- )) - : null} + {crystal !== null && ( + <> + + Crystal Info : +
    +
  • Sample : {crystal.sample}
  • +
  • Drop : {crystal.shelf}
  • +
+ + )} ); diff --git a/ui/src/components/Equipment/SampleChanger.jsx b/ui/src/components/Equipment/SampleChanger.jsx index beac3a8c4..6ee558aec 100644 --- a/ui/src/components/Equipment/SampleChanger.jsx +++ b/ui/src/components/Equipment/SampleChanger.jsx @@ -114,11 +114,11 @@ function SampleChangerTreeItem(props) { Mount - {props.loadedSample === props.label ? ( + {props.loadedSample === props.label && ( Umount this position - ) : null} + )}   diff --git a/ui/src/components/Lims/LimsResultSummary.jsx b/ui/src/components/Lims/LimsResultSummary.jsx index b88c0f539..ccf1c8841 100644 --- a/ui/src/components/Lims/LimsResultSummary.jsx +++ b/ui/src/components/Lims/LimsResultSummary.jsx @@ -76,7 +76,7 @@ export class LimsResultSummary extends React.Component { className="lims-result-summary" style={style} > - {!taskHasLimsData(task) ? this.taskSummary() : null} + {!taskHasLimsData(task) && this.taskSummary()}
{ diff --git a/ui/src/components/SampleQueue/CharacterisationTaskItem.jsx b/ui/src/components/SampleQueue/CharacterisationTaskItem.jsx index 41037c374..306b8a163 100644 --- a/ui/src/components/SampleQueue/CharacterisationTaskItem.jsx +++ b/ui/src/components/SampleQueue/CharacterisationTaskItem.jsx @@ -238,16 +238,16 @@ export default class TaskItem extends Component { {parameters.energy.toFixed(4)} - {parameters.kappa_phi !== null ? ( + {parameters.kappa_phi !== null && ( {parameters.kappa_phi.toFixed(2)} - ) : null} - {parameters.kappa !== null ? ( + )} + {parameters.kappa !== null && ( {parameters.kappa.toFixed(2)} - ) : null} + )} ); } @@ -291,7 +291,6 @@ export default class TaskItem extends Component { ); } - // eslint-disable-next-line sonarjs/cognitive-complexity render() { const { state, data, show } = this.props; const wedges = @@ -342,16 +341,16 @@ export default class TaskItem extends Component { {this.pointIDString(wedges)} {data.label} - {state === TASK_RUNNING ? this.progressBar() : null} + {state === TASK_RUNNING && this.progressBar()} - {state === TASK_UNCOLLECTED ? ( + {state === TASK_UNCOLLECTED && ( - ) : null} + )}
@@ -413,12 +412,12 @@ export default class TaskItem extends Component { T (%) Res. (Å) E (keV) - {wedge.parameters.kappa_phi !== null ? ( + {wedge.parameters.kappa_phi !== null && ( φ ° - ) : null} - {wedge.parameters.kappa !== null ? ( + )} + {wedge.parameters.kappa !== null && ( κ ° - ) : null} + )} {this.wedgeParameters(wedge)} diff --git a/ui/src/components/SampleQueue/EnergyScanTaskItem.jsx b/ui/src/components/SampleQueue/EnergyScanTaskItem.jsx index cc611ee42..0feeed427 100644 --- a/ui/src/components/SampleQueue/EnergyScanTaskItem.jsx +++ b/ui/src/components/SampleQueue/EnergyScanTaskItem.jsx @@ -224,13 +224,13 @@ export default class EnergyScanTaskItem extends Component {
- {state === TASK_UNCOLLECTED ? ( + {state === TASK_UNCOLLECTED && ( - ) : null} + )} diff --git a/ui/src/components/SampleQueue/TaskItem.jsx b/ui/src/components/SampleQueue/TaskItem.jsx index 486d0afe3..a610254a2 100644 --- a/ui/src/components/SampleQueue/TaskItem.jsx +++ b/ui/src/components/SampleQueue/TaskItem.jsx @@ -168,16 +168,16 @@ export default class TaskItem extends Component { const { parameters } = wedge; return ( - {parameters.osc_start !== null ? ( + {parameters.osc_start !== null && ( {parameters.osc_start.toFixed(2)} - ) : null} - {parameters.osc_range !== null ? ( + )} + {parameters.osc_range !== null && ( {parameters.osc_range.toFixed(2)} - ) : null} + )} {parameters.exp_time.toFixed(6)} @@ -193,16 +193,16 @@ export default class TaskItem extends Component { {parameters.energy.toFixed(4)} - {parameters.kappa_phi !== null ? ( + {parameters.kappa_phi !== null && ( {parameters.kappa_phi.toFixed(2)} - ) : null} - {parameters.kappa !== null ? ( + )} + {parameters.kappa !== null && ( {parameters.kappa.toFixed(2)} - ) : null} + )} ); } @@ -300,16 +300,16 @@ export default class TaskItem extends Component { {this.pointIDString(wedges)} {data.label} - {state === TASK_RUNNING ? this.progressBar() : null} + {state === TASK_RUNNING && this.progressBar()} - {state === TASK_UNCOLLECTED ? ( + {state === TASK_UNCOLLECTED && ( - ) : null} + )} @@ -364,23 +364,23 @@ export default class TaskItem extends Component { > - {wedge.parameters.osc_start !== null ? ( + {wedge.parameters.osc_start !== null && ( Start ° - ) : null} - {wedge.parameters.osc_range !== null ? ( + )} + {wedge.parameters.osc_range !== null && ( Osc. ° - ) : null} + )} t (s) # Img T (%) Res. (Å) E (keV) - {wedge.parameters.kappa_phi !== null ? ( + {wedge.parameters.kappa_phi !== null && ( φ ° - ) : null} - {wedge.parameters.kappa !== null ? ( + )} + {wedge.parameters.kappa !== null && ( κ ° - ) : null} + )} {this.wedgeParameters(wedge)} diff --git a/ui/src/components/SampleQueue/WorkflowTaskItem.jsx b/ui/src/components/SampleQueue/WorkflowTaskItem.jsx index 9365dacec..4d18d3192 100644 --- a/ui/src/components/SampleQueue/WorkflowTaskItem.jsx +++ b/ui/src/components/SampleQueue/WorkflowTaskItem.jsx @@ -218,17 +218,17 @@ export default class WorkflowTaskItem extends Component { {this.pointIDString(parameters)} {data.parameters.label} - {state === TASK_RUNNING ? this.progressBar() : null} + {state === TASK_RUNNING && this.progressBar()} - {state === TASK_UNCOLLECTED ? ( + {state === TASK_UNCOLLECTED && ( - ) : null} + )} diff --git a/ui/src/components/SampleQueue/XRFTaskItem.jsx b/ui/src/components/SampleQueue/XRFTaskItem.jsx index 923826f1b..2a3305fc2 100644 --- a/ui/src/components/SampleQueue/XRFTaskItem.jsx +++ b/ui/src/components/SampleQueue/XRFTaskItem.jsx @@ -292,13 +292,13 @@ export default class XRFTaskItem extends Component { - {state === TASK_UNCOLLECTED ? ( + {state === TASK_UNCOLLECTED && ( - ) : null} + )} diff --git a/ui/src/components/Tasks/DataCollection.jsx b/ui/src/components/Tasks/DataCollection.jsx index f9814906a..8432040e3 100644 --- a/ui/src/components/Tasks/DataCollection.jsx +++ b/ui/src/components/Tasks/DataCollection.jsx @@ -265,7 +265,7 @@ class DataCollection extends React.Component { label="Resolution" /> - {this.props.taskResult.energyScan.length > 0 ? ( + {this.props.taskResult.energyScan.length > 0 && ( - ) : null} + )} diff --git a/ui/src/components/Tasks/GenericTaskForm.jsx b/ui/src/components/Tasks/GenericTaskForm.jsx index 397288378..8fca81877 100644 --- a/ui/src/components/Tasks/GenericTaskForm.jsx +++ b/ui/src/components/Tasks/GenericTaskForm.jsx @@ -218,13 +218,13 @@ class GenericTaskForm extends React.Component { } = props; return (
- {id !== 'root' ? ( + {id !== 'root' && ( - ) : null} + )} {description} {children} {errors} diff --git a/ui/src/components/Tasks/Workflow.jsx b/ui/src/components/Tasks/Workflow.jsx index 3ffb10ad2..4ef900ed2 100644 --- a/ui/src/components/Tasks/Workflow.jsx +++ b/ui/src/components/Tasks/Workflow.jsx @@ -78,7 +78,7 @@ function Workflow(props) { /> ) : null} - {strategyNames.length > 0 ? ( + {strategyNames.length > 0 && (
- ) : null} + )} diff --git a/ui/src/containers/GphlWorkflowParametersDialog.jsx b/ui/src/containers/GphlWorkflowParametersDialog.jsx index f876be1df..c2e84e9bc 100644 --- a/ui/src/containers/GphlWorkflowParametersDialog.jsx +++ b/ui/src/containers/GphlWorkflowParametersDialog.jsx @@ -269,9 +269,8 @@ function GphlWorkflowParametersDialog(props) { {schema.properties[fieldKey].type !== - 'boolean' - ? schema.properties[fieldKey].title - : null} + 'boolean' && + schema.properties[fieldKey].title} {schema.properties[fieldKey].type === 'boolean' ? ( diff --git a/ui/src/containers/SampleViewContainer.jsx b/ui/src/containers/SampleViewContainer.jsx index 4d4ea06d2..31c713630 100644 --- a/ui/src/containers/SampleViewContainer.jsx +++ b/ui/src/containers/SampleViewContainer.jsx @@ -148,7 +148,7 @@ class SampleViewContainer extends Component { />
- {this.props.mode === 'SSX-CHIP' ? ( + {this.props.mode === 'SSX-CHIP' && ( - ) : null} - {this.props.sampleChangerContents.name === 'PlateManipulator' ? ( + )} + {this.props.sampleChangerContents.name === 'PlateManipulator' && ( - ) : null} + )}