Skip to content

Commit

Permalink
Update eslint-config-beslogic to 3.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel-Therrien-Beslogic committed Nov 15, 2024
1 parent 61bd1a2 commit fd9cecb
Show file tree
Hide file tree
Showing 19 changed files with 528 additions and 187 deletions.
567 changes: 422 additions & 145 deletions canopeum_frontend/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion canopeum_frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@types/react-transition-group": "^4.4.10",
"@vitejs/plugin-react": "^4.2.1",
"dprint": "^0.47.2",
"eslint-config-beslogic": "^3.0.2",
"eslint-config-beslogic": "^3.1.1",
"eslint-plugin-jsx-a11y": "^6.8.0",
"eslint-plugin-react": "^7.34.1",
"eslint-plugin-react-hooks": "^4.6.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const AnalyticsSiteHeader = ({ siteSummary }: Props) => {
linear-gradient(
rgba(0, 0, 0, 0.6),
rgba(0, 0, 0, 0.6)
), url(${getImageNameByWMOCategories(siteSummary.weather.description)})
), url(${getImageNameByWMOCategories(siteSummary.weather.description) ?? ''})
`,
}}
>
Expand Down
2 changes: 1 addition & 1 deletion canopeum_frontend/src/components/analytics/ImageUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const ImageUpload = ({ id, onChange, imageUrl }: Props) => {
onDrop={dropHandler}
style={{
border: 'var(--bs-border-width) dashed var(--bs-primary)',
backgroundImage: `url(${imageUrl})`,
backgroundImage: `url(${imageUrl ?? ''})`,
backgroundSize: 'contain',
backgroundRepeat: 'no-repeat',
backgroundPosition: 'center',
Expand Down
2 changes: 2 additions & 0 deletions canopeum_frontend/src/components/assets/SiteTypePin.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { JSX } from 'react'

import CanopeumPin from '@assets/icons/pins/canopeum-pin.svg'
import CorporateLotPin from '@assets/icons/pins/corporate-lot-pin.svg'
import EducationalFacilityPin from '@assets/icons/pins/educational-facility-pin.svg'
Expand Down
4 changes: 2 additions & 2 deletions canopeum_frontend/src/components/context/LanguageContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const LanguageContext = createContext<ILanguageContext>({
})
LanguageContext.displayName = 'LanguageContext'

const { timeZone } = Intl.DateTimeFormat().resolvedOptions()
const { timeZone } = new Intl.DateTimeFormat().resolvedOptions()

const LanguageContextProvider: FunctionComponent<{ readonly children?: ReactNode }> = memo(
props => {
Expand All @@ -36,7 +36,7 @@ const LanguageContextProvider: FunctionComponent<{ readonly children?: ReactNode
...options,
}

return Intl.DateTimeFormat(i18n.language, fullOptions).format(date)
return new Intl.DateTimeFormat(i18n.language, fullOptions).format(date)
}, [i18n])

const translateValue = useCallback((translable: Translatable) => translable[i18n.language], [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const ConfirmationDialog = ({ actions, children, onClose, open, title }: Props)
let buttonClasses = 'btn'
let buttonText = ''
let proceed = false
// eslint-disable-next-line default-case -- Turned off in next eslint-config-beslogic update

switch (action) {
case 'delete': {
buttonClasses += ' btn-outline-danger'
Expand Down
1 change: 1 addition & 0 deletions canopeum_frontend/src/components/settings/AdminCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const AdminCard = ({ admin }: Props) => (
{admin.sites.map(site => (
<div className='d-flex align-items-center text-primary' key={site.id}>
{
//
/* See TODO
<span className='material-symbols-outlined'>
{getSiteTypeIconKey(site.siteType.id)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ const AdminInvitationDialog = ({ open, handleClose }: Props) => {
<label htmlFor='email-input'>{translate('auth.email-label')}</label>
<input
aria-describedby='email'
className={`form-control ${emailError && 'is-invalid'} `}
className={`form-control ${
emailError
? 'is-invalid'
: ''
} `}
id='email-input'
onBlur={() => validateEmail()}
onChange={event => setEmail(event.target.value)}
Expand Down
23 changes: 17 additions & 6 deletions canopeum_frontend/src/components/settings/EditProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,13 @@ const EditProfile = () => {
</label>

<input
//
/* eslint-disable-next-line sonarjs/no-duplicate-string --
Could be fixed by creating a global Input component */
className={`form-control ${currentPasswordError && 'is-invalid'} `}
className={`form-control ${
currentPasswordError
/* eslint-disable-next-line sonarjs/no-duplicate-string --
Could be fixed by creating a global Input component */
? 'is-invalid'
: ''
} `}
id='password-input'
onBlur={() => validateCurrentPassword()}
onChange={event => setCurrentPassword(event.target.value)}
Expand All @@ -307,7 +310,11 @@ const EditProfile = () => {
</label>

<input
className={`form-control ${newPasswordError && 'is-invalid'} `}
className={`form-control ${
newPasswordError
? 'is-invalid'
: ''
} `}
id='password-input'
onBlur={() => validateNewPassword()}
onChange={event => setNewPassword(event.target.value)}
Expand All @@ -330,7 +337,11 @@ const EditProfile = () => {
{translate('settings.edit-profile.new-password-confirmation')}
</label>
<input
className={`form-control ${newPasswordConfirmationError && 'is-invalid'}`}
className={`form-control ${
newPasswordConfirmationError
? 'is-invalid'
: ''
}`}
id='confirmation-password-input'
onBlur={() => validateNewPasswordConfirmation()}
onChange={event => setNewPasswordConfirmation(event.target.value)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,11 @@ const PostCommentsDialog = ({ open, postId, siteId, handleClose }: Props) => {
<div>
<div className='position-relative'>
<textarea
className={`form-control ${commentBodyError && 'is-invalid'}`}
className={`form-control ${
commentBodyError
? 'is-invalid'
: ''
}`}
id='new-comment-body-input'
onBlur={() => validateCommentBody()}
onChange={handleCommentBodyChange}
Expand Down
5 changes: 3 additions & 2 deletions canopeum_frontend/src/components/social/SiteSocialHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import type { PageViewMode } from '@models/PageViewMode.type'
import { getSiteTypeIconKey } from '@models/SiteType'
import { PatchedUpdateSitePublicStatus, type SiteSocial, User } from '@services/api'
import { getApiBaseUrl } from '@services/apiSettings'
import type { ExcludeFunctions } from '@utils/types'

type Props = {
readonly viewMode: PageViewMode,
readonly site: SiteSocial,
readonly site: ExcludeFunctions<SiteSocial>,
}

const SiteSocialHeader = ({ site, viewMode }: Props) => {
Expand Down Expand Up @@ -79,7 +80,7 @@ const SiteSocialHeader = ({ site, viewMode }: Props) => {
<div
className='site-social-image'
style={{
backgroundImage: `url('${getApiBaseUrl() + site.image.asset}')`,
backgroundImage: `url('${getApiBaseUrl()}${site.image.asset}')`,
}}
/>

Expand Down
12 changes: 10 additions & 2 deletions canopeum_frontend/src/pages/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ const Login = () => {
<label htmlFor='email-input'>{translate('auth.email-label')}</label>
<input
aria-describedby='email'
className={`form-control ${emailError && 'is-invalid'} `}
className={`form-control ${
emailError
? 'is-invalid'
: ''
} `}
id='email-input'
onBlur={() => validateEmail()}
onChange={event => setEmail(event.target.value)}
Expand All @@ -105,7 +109,11 @@ const Login = () => {
<div className='w-100'>
<label htmlFor='password-input'>{translate('auth.password-label')}</label>
<input
className={`form-control ${passwordError && 'is-invalid'} `}
className={`form-control ${
passwordError
? 'is-invalid'
: ''
} `}
id='password-input'
onBlur={() => validatePassword()}
onChange={event => setPassword(event.target.value)}
Expand Down
33 changes: 20 additions & 13 deletions canopeum_frontend/src/pages/MapPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,23 @@ const MapPage = () => {
<GeolocateControl position='top-right' />
<NavigationControl position='top-right' showCompass showZoom visualizePitch />
<ScaleControl position='bottom-left' unit='metric' />
{sites.map(site => (
<Marker
anchor='bottom'
key={`${site.id}-${site.coordinates.latitude}-${site.coordinates.longitude}`}
latitude={Number(site.coordinates.latitude)}
longitude={Number(site.coordinates.longitude)}
onClick={event => onMarkerClick(event, site)}
style={{ cursor: 'pointer' }}
>
<SiteTypePin siteTypeId={site.siteType.id as SiteTypeID} />
</Marker>
))}
{sites.map(site => {
const latitude = Number(site.coordinates.latitude)
const longitude = Number(site.coordinates.longitude)

return (
<Marker
anchor='bottom'
key={`${site.id}-${latitude}-${longitude}`}
latitude={latitude}
longitude={longitude}
onClick={event => onMarkerClick(event, site)}
style={{ cursor: 'pointer' }}
>
<SiteTypePin siteTypeId={site.siteType.id as SiteTypeID} />
</Marker>
)
})}
</ReactMap>
</div>

Expand All @@ -103,7 +108,9 @@ const MapPage = () => {
{sites.map(site => (
<div
className={`card ${
selectedSiteId === site.id && 'border border-secondary border-5'
selectedSiteId === site.id
? 'border border-secondary border-5'
: ''
}`}
key={site.id}
>
Expand Down
27 changes: 22 additions & 5 deletions canopeum_frontend/src/pages/Register.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,13 @@ const Register = () => {
<label htmlFor='username-input'>{translate('auth.username-label')}</label>
<input
aria-describedby='emailHelp'
// eslint-disable-next-line sonarjs/no-duplicate-string -- Create an Input Component?
className={`form-control ${usernameError && 'is-invalid'} `}
className={`form-control ${
usernameError
/* eslint-disable-next-line sonarjs/no-duplicate-string
-- Create an Input Component? */
? 'is-invalid'
: ''
} `}
id='username-input'
onBlur={() => validateUsername()}
onChange={event => setUsername(event.target.value)}
Expand All @@ -199,7 +204,11 @@ const Register = () => {
<label htmlFor='email-input'>{translate('auth.email-label')}</label>
<input
aria-describedby='email'
className={`form-control ${emailError && 'is-invalid'} `}
className={`form-control ${
emailError
? 'is-invalid'
: ''
} `}
disabled={!!userInvitation}
id='email-input'
onBlur={() => validateEmail()}
Expand All @@ -222,7 +231,11 @@ const Register = () => {
<div className='w-100'>
<label htmlFor='password-input'>{translate('auth.password-label')}</label>
<input
className={`form-control ${passwordError && 'is-invalid'} `}
className={`form-control ${
passwordError
? 'is-invalid'
: ''
} `}
id='password-input'
onBlur={() => validatePassword()}
onChange={event => setPassword(event.target.value)}
Expand All @@ -245,7 +258,11 @@ const Register = () => {
{translate('auth.password-confirmation-label')}
</label>
<input
className={`form-control ${passwordConfirmationError && 'is-invalid'}`}
className={`form-control ${
passwordConfirmationError
? 'is-invalid'
: ''
}`}
id='confirmation-password-input'
onBlur={() => validatePasswordConfirmation()}
onChange={event => setPasswordConfirmation(event.target.value)}
Expand Down
7 changes: 4 additions & 3 deletions canopeum_frontend/src/pages/SiteSocialPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type { PageViewMode } from '@models/PageViewMode.type'
import { type IWidget, PatchedWidget, type Post, type SiteSocial, Widget } from '@services/api'
import { ensureError } from '@services/errors'
import usePostsStore from '@store/postsStore'
import type { ExcludeFunctions } from '@utils/types'

const SiteSocialPage = () => {
const { t } = useTranslation()
Expand All @@ -38,7 +39,7 @@ const SiteSocialPage = () => {

const [isLoadingSite, setIsLoadingSite] = useState(true)
const [error, setError] = useState<Error | undefined>()
const [site, setSite] = useState<SiteSocial>()
const [site, setSite] = useState<ExcludeFunctions<SiteSocial>>()
const [sitePosts, setSitePosts] = useState<Post[]>([])
const [isWidgetModalOpen, setIsWidgetModalOpen] = useState<[boolean, Widget | undefined]>([
false,
Expand Down Expand Up @@ -148,12 +149,12 @@ const SiteSocialPage = () => {
<div className='d-flex flex-column gap-4'>
<AnnouncementCard
announcement={site.announcement}
onEdit={announcement => setSite(() => ({ ...site, announcement } as SiteSocial))}
onEdit={announcement => setSite(() => ({ ...site, announcement }))}
viewMode={viewMode}
/>
<ContactCard
contact={site.contact}
onEdit={contact => setSite(() => ({ ...site, contact } as SiteSocial))}
onEdit={contact => setSite(() => ({ ...site, contact }))}
viewMode={viewMode}
/>
{site.widget.map(widget => (
Expand Down
4 changes: 2 additions & 2 deletions canopeum_frontend/src/services/apiSettings.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const apiBaseUrl: string | undefined = import.meta.env.VITE_API_URL
const apiBaseUrl = import.meta.env.VITE_API_URL as string | undefined

export type ApiSettings = {
apiBaseUrl: string,
}

export const getApiBaseUrl = () => apiBaseUrl
export const getApiBaseUrl = () => apiBaseUrl ?? ''
3 changes: 2 additions & 1 deletion canopeum_frontend/src/utils/arrayUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export const mapSum = <
values.reduce(
(previous, current) =>
previous + (
/* total-functions/no-unsafe-type-assertion --
//
/* @typescript-eslint/no-unsafe-type-assertion --
The retriction using KeysWithValsOfType ensures the value obtained from the key is of known
type. We don't want the the objects to be restricted to *only* those value types */
(current[key] as number | null | undefined) ?? 0
Expand Down
7 changes: 7 additions & 0 deletions canopeum_frontend/src/utils/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// TODO: This should be added to beslogic libraries

Check warning on line 1 in canopeum_frontend/src/utils/types.ts

View workflow job for this annotation

GitHub Actions / Lint-Autofixes

Unexpected 'TODO' comment: 'TODO: This should be added to beslogic...'

/**
* Useful To create an interface type from a class, where you can spread the object
*/
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type -- We do mean any Function
export type ExcludeFunctions<T> = { [K in keyof T as (T[K] extends Function ? never : K)]: T[K] }

0 comments on commit fd9cecb

Please sign in to comment.