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

Issue/1298 eslint rule no useless fragments #1673

Merged
merged 2 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ module.exports = {
},
],
'react/jsx-no-target-blank': 'error',
'react/jsx-no-useless-fragment': 'error',
'react/jsx-sort-props': [
'error',
{
Expand Down
5 changes: 3 additions & 2 deletions src/core/i18n/Msg.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ReactNode } from 'react';
import { useIntl } from 'react-intl';

import { InterpolatedMessage, PlainMessage, ValueRecord } from './messages';
Expand All @@ -19,7 +20,7 @@ function Msg<Values extends ValueRecord>({
function Msg<Values extends ValueRecord>({
id,
values,
}: MsgProps<Values>): JSX.Element {
}: MsgProps<Values>): ReactNode {
const intl = useIntl();

const descriptor = {
Expand All @@ -31,7 +32,7 @@ function Msg<Values extends ValueRecord>({
? intl.formatMessage(descriptor, values)
: intl.formatMessage(descriptor);

return <>{str}</>;
return str;
}

export default Msg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,69 +31,65 @@ const CheckboxFilterList = ({

const visibleOptions = expand ? options : options.slice(0, maxCollapsed);
return (
<>
<FormGroup sx={{ mb: 2 }}>
<Box alignItems="center" display="flex" justifyContent="space-between">
<Typography color="secondary" variant="body1">
{title}
</Typography>
<AllAndNoneToggle
maxLength={options.length}
onSelectAll={() =>
onFilterChange(options.map((item) => item.value))
<FormGroup sx={{ mb: 2 }}>
<Box alignItems="center" display="flex" justifyContent="space-between">
<Typography color="secondary" variant="body1">
{title}
</Typography>
<AllAndNoneToggle
maxLength={options.length}
onSelectAll={() => onFilterChange(options.map((item) => item.value))}
onSelectNone={() => onFilterChange([])}
selectedFilterLength={selectedValues.length}
/>
</Box>
{visibleOptions.map((item) => {
return (
<FormControlLabel
key={item.value}
control={
<Checkbox
checked={selectedValues.includes(item.value)}
name={item.value}
onChange={() => {
const alreadyExists = selectedValues.includes(item.value);
onFilterChange(
alreadyExists
? selectedValues.filter(
(filterOption) => filterOption !== item.value
)
: [...selectedValues, item.value]
);
}}
/>
}
onSelectNone={() => onFilterChange([])}
selectedFilterLength={selectedValues.length}
label={item.label}
sx={{ pl: 1 }}
/>
</Box>
{visibleOptions.map((item) => {
return (
<FormControlLabel
key={item.value}
control={
<Checkbox
checked={selectedValues.includes(item.value)}
name={item.value}
onChange={() => {
const alreadyExists = selectedValues.includes(item.value);
onFilterChange(
alreadyExists
? selectedValues.filter(
(filterOption) => filterOption !== item.value
)
: [...selectedValues, item.value]
);
}}
/>
}
label={item.label}
sx={{ pl: 1 }}
/>
);
})}
{options.length > maxCollapsed && (
<Button
onClick={() => setExpand(!expand)}
sx={{
display: 'flex',
justifyContent: 'flex-start',
width: 'fit-content',
}}
variant="text"
>
{expand && <Msg id={messageIds.eventFilter.collapse} />}
{!expand && (
<Typography sx={{ textDecoration: 'underline' }} variant="body2">
<Msg
id={messageIds.eventFilter.expand}
values={{ numOfOptions: options.length - maxCollapsed }}
/>
</Typography>
)}
</Button>
)}
</FormGroup>
</>
);
})}
{options.length > maxCollapsed && (
<Button
onClick={() => setExpand(!expand)}
sx={{
display: 'flex',
justifyContent: 'flex-start',
width: 'fit-content',
}}
variant="text"
>
{expand && <Msg id={messageIds.eventFilter.collapse} />}
{!expand && (
<Typography sx={{ textDecoration: 'underline' }} variant="body2">
<Msg
id={messageIds.eventFilter.expand}
values={{ numOfOptions: options.length - maxCollapsed }}
/>
</Typography>
)}
</Button>
)}
</FormGroup>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,16 @@ const EventInputFilter = ({
<TextField
fullWidth
InputProps={{
endAdornment: (
<>
{userInput && (
<IconButton
onClick={() => {
setUserInput('');
onChangeFilterText('');
}}
>
<Clear />
</IconButton>
)}
</>
),
endAdornment: userInput ? (
<IconButton
onClick={() => {
setUserInput('');
onChangeFilterText('');
}}
>
<Clear />
</IconButton>
) : null,
startAdornment: (
<InputAdornment position="start">
<FilterList />
Expand Down
16 changes: 7 additions & 9 deletions src/features/calendar/components/EventCluster/FieldGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,16 @@ const FieldGroup: FC<FieldGroupProps> = ({ fields, height }) => {
(f) => f.presentation === FIELD_PRESENTATION.ICON_ONLY
);
return (
<>
<Box className={classes.fields} height={height}>
<Box className={classes.fieldsWithIconOnly}>
{fieldsWithIconOnly.map((field, index) => (
<Field key={`${field.kind}-${index}`} field={field} />
))}
</Box>
{fieldsWithLabel.map((field, index) => (
<Box className={classes.fields} height={height}>
<Box className={classes.fieldsWithIconOnly}>
{fieldsWithIconOnly.map((field, index) => (
<Field key={`${field.kind}-${index}`} field={field} />
))}
</Box>
</>
{fieldsWithLabel.map((field, index) => (
<Field key={`${field.kind}-${index}`} field={field} />
))}
</Box>
);
};

Expand Down
126 changes: 62 additions & 64 deletions src/features/calendar/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,71 +87,69 @@ const Calendar = () => {
}

return (
<>
<Box display="flex" flexDirection="column" height={'100%'} padding={2}>
<CalendarNavBar
focusDate={focusDate}
onChangeFocusDate={(date) => {
setFocusDate(date);
}}
onChangeTimeScale={(timeScale) => {
setSelectedTimeScale(timeScale);
}}
onStepBackward={() => {
// Steps back to the last day with an event on day view
if (selectedTimeScale === TimeScale.DAY && prevActivityDay) {
setFocusDate(prevActivityDay[0]);
} else {
setFocusDate(
dayjs(focusDate).subtract(1, selectedTimeScale).toDate()
);
}
}}
onStepForward={() => {
// Steps forward to the next day with an event on day view
if (selectedTimeScale === TimeScale.DAY && nextActivityDay) {
setFocusDate(nextActivityDay[0]);
} else {
setFocusDate(dayjs(focusDate).add(1, selectedTimeScale).toDate());
}
}}
orgId={parseInt(orgId as string)}
timeScale={selectedTimeScale}
/>

<Box
display="flex"
flexDirection="column"
flexGrow={1}
marginTop={2}
overflow="auto"
>
<Suspense>
{selectedTimeScale === TimeScale.DAY && (
<CalendarDayView
focusDate={focusDate}
onClickPreviousDay={(date) => setFocusDate(date)}
previousActivityDay={prevActivityDay}
/>
)}
{selectedTimeScale === TimeScale.WEEK && (
<CalendarWeekView
focusDate={focusDate}
onClickDay={(date) => navigateTo(TimeScale.DAY, date)}
/>
)}
{selectedTimeScale === TimeScale.MONTH && (
<CalendarMonthView
focusDate={focusDate}
onClickDay={(date) => navigateTo(TimeScale.DAY, date)}
onClickWeek={(date) => navigateTo(TimeScale.WEEK, date)}
/>
)}
</Suspense>
</Box>
<SelectionBar />
<Box display="flex" flexDirection="column" height={'100%'} padding={2}>
<CalendarNavBar
focusDate={focusDate}
onChangeFocusDate={(date) => {
setFocusDate(date);
}}
onChangeTimeScale={(timeScale) => {
setSelectedTimeScale(timeScale);
}}
onStepBackward={() => {
// Steps back to the last day with an event on day view
if (selectedTimeScale === TimeScale.DAY && prevActivityDay) {
setFocusDate(prevActivityDay[0]);
} else {
setFocusDate(
dayjs(focusDate).subtract(1, selectedTimeScale).toDate()
);
}
}}
onStepForward={() => {
// Steps forward to the next day with an event on day view
if (selectedTimeScale === TimeScale.DAY && nextActivityDay) {
setFocusDate(nextActivityDay[0]);
} else {
setFocusDate(dayjs(focusDate).add(1, selectedTimeScale).toDate());
}
}}
orgId={parseInt(orgId as string)}
timeScale={selectedTimeScale}
/>

<Box
display="flex"
flexDirection="column"
flexGrow={1}
marginTop={2}
overflow="auto"
>
<Suspense>
{selectedTimeScale === TimeScale.DAY && (
<CalendarDayView
focusDate={focusDate}
onClickPreviousDay={(date) => setFocusDate(date)}
previousActivityDay={prevActivityDay}
/>
)}
{selectedTimeScale === TimeScale.WEEK && (
<CalendarWeekView
focusDate={focusDate}
onClickDay={(date) => navigateTo(TimeScale.DAY, date)}
/>
)}
{selectedTimeScale === TimeScale.MONTH && (
<CalendarMonthView
focusDate={focusDate}
onClickDay={(date) => navigateTo(TimeScale.DAY, date)}
onClickWeek={(date) => navigateTo(TimeScale.WEEK, date)}
/>
)}
</Suspense>
</Box>
</>
<SelectionBar />
</Box>
);
};

Expand Down
36 changes: 17 additions & 19 deletions src/features/events/components/AddPersonButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,25 +106,23 @@ const AddPersonButton = ({ orgId, eventId }: AddPersonButtonProps) => {
};

return (
<>
<ZUIPersonSelect
getOptionDisabled={(option) =>
participants.some(
(participant) => participant.id == option.id
)
}
getOptionExtraLabel={(option) => {
return getOptionExtraLabel(option.id);
}}
name="person"
onChange={(person) => {
addParticipant(person.id);
}}
placeholder={messages.addPerson.addPlaceholder()}
selectedPerson={null}
variant="outlined"
/>
</>
<ZUIPersonSelect
getOptionDisabled={(option) =>
participants.some(
(participant) => participant.id == option.id
)
}
getOptionExtraLabel={(option) => {
return getOptionExtraLabel(option.id);
}}
name="person"
onChange={(person) => {
addParticipant(person.id);
}}
placeholder={messages.addPerson.addPlaceholder()}
selectedPerson={null}
variant="outlined"
/>
);
}}
</ZUIFutures>
Expand Down
Loading
Loading