Skip to content

Commit

Permalink
TASK: Resolve linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebobo committed Jan 23, 2023
1 parent cd2ecff commit 339adcc
Show file tree
Hide file tree
Showing 11 changed files with 352 additions and 332 deletions.
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"printWidth": 120,
"semi": true,
"singleQuote": true,
"tabWidth": 4
}
5 changes: 4 additions & 1 deletion .stylelintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "stylelint-config-recommended-scss"
"extends": "stylelint-config-recommended-scss",
"rules": {
"no-descending-specificity": null
}
}
8 changes: 4 additions & 4 deletions Resources/Private/JavaScript/components/Filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default function Filters({
id="redirects-search"
type="text"
placeholder={translate('filter.search.placeholder', 'Search for a redirect')}
onChange={e => handleUpdateSearch(e.target.value)}
onChange={(e) => handleUpdateSearch(e.target.value)}
/>
</div>

Expand All @@ -62,7 +62,7 @@ export default function Filters({
<select
id="redirects-filter-status-code"
defaultValue={filterStatusCode.toString()}
onChange={e => handleUpdateFilterStatusCode(parseInt(e.target.value, 10))}
onChange={(e) => handleUpdateFilterStatusCode(parseInt(e.target.value, 10))}
>
<option value="-1">All</option>
{redirectCountByStatusCode.map((numberOfRedirects, statusCode) => {
Expand All @@ -82,10 +82,10 @@ export default function Filters({
<select
id="redirects-filter-type"
defaultValue={filterType}
onChange={e => handleUpdateFilterType(e.target.value)}
onChange={(e) => handleUpdateFilterType(e.target.value)}
>
<option value="">All</option>
{Object.keys(redirectCountByType).map(type => {
{Object.keys(redirectCountByType).map((type) => {
return (
<option key={type} value={type}>
{translate('filter.type.' + type, type)}
Expand Down
34 changes: 14 additions & 20 deletions Resources/Private/JavaScript/components/RedirectForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type RedirectFormState = {
comment: string;
isSendingData: boolean;
activeHelpMessage: string;
}
};

const initialState: RedirectFormState = {
host: '',
Expand Down Expand Up @@ -78,14 +78,8 @@ export class RedirectForm extends PureComponent<RedirectFormProps, RedirectFormS
private handleSubmit = (event: React.FormEvent<HTMLFormElement>): void => {
event.preventDefault();

const {
redirect,
notificationHelper,
actions,
handleNewRedirect,
handleUpdatedRedirect,
translate,
} = this.props;
const { redirect, notificationHelper, actions, handleNewRedirect, handleUpdatedRedirect, translate } =
this.props;

const { csrfToken, defaultStatusCode } = this.context;

Expand All @@ -101,7 +95,7 @@ export class RedirectForm extends PureComponent<RedirectFormProps, RedirectFormS
const parsedTargetUrl: URL = UrlUtil.parseURL(targetUriPath, location.origin);
if (parsedSourceUrl.pathname === parsedTargetUrl.pathname) {
notificationHelper.warning(
translate('error.sameSourceAndTarget', 'The source and target paths cannot be the same'),
translate('error.sameSourceAndTarget', 'The source and target paths cannot be the same')
);
return;
}
Expand Down Expand Up @@ -130,7 +124,7 @@ export class RedirectForm extends PureComponent<RedirectFormProps, RedirectFormS
this.setState({ isSendingData: true });

this.postRedirect(redirect ? actions.update : actions.create, data)
.then(data => {
.then((data) => {
const { messages, changedRedirects } = data;

// Depending on whether an existing redirect was edited handle the list of changes but keep the original
Expand Down Expand Up @@ -175,8 +169,8 @@ export class RedirectForm extends PureComponent<RedirectFormProps, RedirectFormS
},
body: body && JSON.stringify(body),
})
.then(res => res.json())
.then(async data => {
.then((res) => res.json())
.then(async (data) => {
if (data.success) {
return data;
}
Expand Down Expand Up @@ -239,7 +233,7 @@ export class RedirectForm extends PureComponent<RedirectFormProps, RedirectFormS
placeholderText={placeholder}
selected={dateTime}
timeCaption={translate('datepicker.time', 'Time')}
onChange={value => this.handleDatePickerChange(property, value)}
onChange={(value) => this.handleDatePickerChange(property, value)}
/>
);
};
Expand All @@ -256,8 +250,8 @@ export class RedirectForm extends PureComponent<RedirectFormProps, RedirectFormS
<ul>
${changedRedirects
.map(
redirect =>
`<li>${redirect.host || ''}/${redirect.sourceUriPath}&rarr;${redirect.targetUriPath}</li>`,
(redirect) =>
`<li>${redirect.host || ''}/${redirect.sourceUriPath}&rarr;${redirect.targetUriPath}</li>`
)
.join('')}
</ul>`;
Expand Down Expand Up @@ -291,7 +285,7 @@ export class RedirectForm extends PureComponent<RedirectFormProps, RedirectFormS
} = this.state;

return (
<form onSubmit={e => this.handleSubmit(e)} className="add-redirect-form">
<form onSubmit={(e) => this.handleSubmit(e)} className="add-redirect-form">
<div className="row">
<div className="neos-control-group">
<label className="neos-control-label" htmlFor={idPrefix + 'host'}>
Expand Down Expand Up @@ -364,7 +358,7 @@ export class RedirectForm extends PureComponent<RedirectFormProps, RedirectFormS
value={statusCode}
onChange={this.handleInputChange}
>
{Object.keys(statusCodes).map(code => (
{Object.keys(statusCodes).map((code) => (
<option
value={code}
key={code}
Expand Down Expand Up @@ -408,15 +402,15 @@ export class RedirectForm extends PureComponent<RedirectFormProps, RedirectFormS
{this.renderDatePicker(
'startDateTime',
startDateTime,
translate('startDateTime.placeholder', 'Enter start date'),
translate('startDateTime.placeholder', 'Enter start date')
)}
</div>
<div className="neos-control-group neos-control-group--half">
<label className="neos-control-label">{translate('endDateTime', 'End date')}</label>
{this.renderDatePicker(
'endDateTime',
endDateTime,
translate('endDateTime.placeholder', 'Enter end date'),
translate('endDateTime.placeholder', 'Enter end date')
)}
</div>
<div className="neos-control-group">
Expand Down
36 changes: 15 additions & 21 deletions Resources/Private/JavaScript/components/RedirectList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,8 @@ export class RedirectList extends React.Component<RedirectListProps, RedirectLis
* The result is stored in the state, so it doesn't need to be recomputed for pagination or sorting.
*/
private handleUpdateSearch = (searchValue: string): void => {
const {
redirects,
filterStatusCode,
filterType,
redirectCountByStatusCode,
redirectCountByType,
currentPage,
} = this.state;
const { redirects, filterStatusCode, filterType, redirectCountByStatusCode, redirectCountByType, currentPage } =
this.state;
let filteredRedirects: Redirect[] = redirects;

const cleanSearchValue = searchValue.trim().toLowerCase();
Expand All @@ -103,7 +97,7 @@ export class RedirectList extends React.Component<RedirectListProps, RedirectLis

// Filter by search value
if (cleanSearchValue || validStatusCodeSelection || validFilterTypeSelection) {
filteredRedirects = filteredRedirects.filter(redirect => {
filteredRedirects = filteredRedirects.filter((redirect) => {
return (
(validStatusCodeSelection <= 0 || redirect.statusCode === validStatusCodeSelection) &&
(!validFilterTypeSelection || redirect.type === validFilterTypeSelection) &&
Expand Down Expand Up @@ -134,9 +128,9 @@ export class RedirectList extends React.Component<RedirectListProps, RedirectLis
redirectCountByStatusCode: RedirectList.calculateRedirectCountByStatusCode(redirects),
redirectCountByType: RedirectList.calculateRedirectCountByType(redirects),
},
() => this.handleUpdateSearch(this.state.searchValue),
() => this.handleUpdateSearch(this.state.searchValue)
);
}
};

/**
* Counts each type of status code over all given redirects and returns them
Expand Down Expand Up @@ -253,7 +247,7 @@ export class RedirectList extends React.Component<RedirectListProps, RedirectLis
!confirm(
this.props.translate('list.action.confirmDelete', 'Delete the redirect "{0}"?', [
(redirect.host || '') + '/' + redirect.sourceUriPath,
]),
])
)
) {
return;
Expand All @@ -275,24 +269,24 @@ export class RedirectList extends React.Component<RedirectListProps, RedirectLis
},
body: JSON.stringify(data),
})
.then(response => response.json())
.then(data => {
.then((response) => response.json())
.then((data) => {
const { success, messages } = data;
if (success) {
const { redirects } = this.state;
const filteredRedirects = redirects.filter(storedRedirect => redirect !== storedRedirect);
const filteredRedirects = redirects.filter((storedRedirect) => redirect !== storedRedirect);
this.setState(
{
redirects: filteredRedirects,
},
this.refresh,
this.refresh
);
}
messages.forEach(({ title, message, severity }) => {
notificationHelper[severity.toLowerCase()](title || message, message);
});
})
.catch(error => {
.catch((error) => {
notificationHelper.error(error);
});
};
Expand Down Expand Up @@ -333,8 +327,8 @@ export class RedirectList extends React.Component<RedirectListProps, RedirectLis
let { redirects } = this.state;

redirects.forEach((redirect, index, list) => {
const changedRedirectIndex = changedRedirects.findIndex(changedRedirect =>
Helpers.isSameRedirectAs(changedRedirect, redirect),
const changedRedirectIndex = changedRedirects.findIndex((changedRedirect) =>
Helpers.isSameRedirectAs(changedRedirect, redirect)
);
if (changedRedirectIndex >= 0) {
list[index] = changedRedirects[changedRedirectIndex];
Expand All @@ -350,7 +344,7 @@ export class RedirectList extends React.Component<RedirectListProps, RedirectLis
redirects,
editedRedirect: null,
},
this.refresh,
this.refresh
);
};

Expand All @@ -359,7 +353,7 @@ export class RedirectList extends React.Component<RedirectListProps, RedirectLis
*/
private handleUpdatedRedirect = (changedRedirects: Redirect[], oldRedirect: Redirect): void => {
let { redirects } = this.state;
redirects = redirects.filter(redirect => redirect !== oldRedirect);
redirects = redirects.filter((redirect) => redirect !== oldRedirect);
this.setState({ redirects }, () => this.handleNewRedirect(changedRedirects));
};

Expand Down
4 changes: 2 additions & 2 deletions Resources/Private/JavaScript/components/RedirectListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export class RedirectListItem extends React.PureComponent<RedirectListItemProps>
<button
type="button"
className="neos-button"
onClick={e => handleEditAction(e, redirect)}
onClick={(e) => handleEditAction(e, redirect)}
title={translate('list.action.edit', 'Edit')}
data-edit-redirect-id={identifier}
>
Expand All @@ -167,7 +167,7 @@ export class RedirectListItem extends React.PureComponent<RedirectListItemProps>
<button
type="submit"
className="neos-button neos-button-danger"
onClick={e => handleDeleteAction(e, redirect)}
onClick={(e) => handleDeleteAction(e, redirect)}
title={translate('list.action.delete', 'Delete')}
>
<Icon icon="trash-alt" />
Expand Down
Loading

0 comments on commit 339adcc

Please sign in to comment.