Skip to content

Commit

Permalink
Update typescript eslint (#953)
Browse files Browse the repository at this point in the history
* REFACTOR: To IF statement

Co-authored-by: Jeremiah Uy <[email protected]>
Co-authored-by: Rebecca Gjerstad <[email protected]>

* UPDATE: eslint

Co-authored-by: Jeremiah Uy <[email protected]>
Co-authored-by: Rebecca Gjerstad <[email protected]>

* FIX: type script errors

Co-authored-by: Jeremiah Uy <[email protected]>

* UPDATE: disabling and enabling of eslint rules

Co-authored-by: andregroseth <[email protected]>
Co-authored-by: beeccy <[email protected]>
Co-authored-by: PaulMartinKokseter <[email protected]>

---------

Co-authored-by: Jeremiah Uy <[email protected]>
Co-authored-by: Rebecca Gjerstad <[email protected]>
Co-authored-by: PaulMartinKokseter <[email protected]>
  • Loading branch information
4 people authored Aug 20, 2024
1 parent 618ebf8 commit 6233c8d
Show file tree
Hide file tree
Showing 19 changed files with 92 additions and 44 deletions.
4 changes: 2 additions & 2 deletions apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@
"@types/react-helmet": "^6.1.7",
"@types/react-router-dom": "^5.3.3",
"@types/yup": "^0.32.0",
"@typescript-eslint/eslint-plugin": "^7.1.1",
"@typescript-eslint/parser": "^7.1.1",
"@typescript-eslint/eslint-plugin": "^8.1.0",
"@typescript-eslint/parser": "^8.1.0",
"autoprefixer": "^10.4.16",
"eslint-config-react-app": "^7.0.1",
"eslint-plugin-jsx-a11y": "^6.8.0",
Expand Down
4 changes: 3 additions & 1 deletion apps/frontend/src/api/EtterlevelseApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ export const useEtterlevelse = (id?: string, behandlingId?: string, kravId?: TKr
)

useEffect(() => {
id && !isCreateNew && getEtterlevelse(id).then(setData)
if (id && !isCreateNew) {
getEtterlevelse(id).then(setData)
}
}, [id])

return [data, setData] as [IEtterlevelse | undefined, (k: IEtterlevelse) => void]
Expand Down
29 changes: 21 additions & 8 deletions apps/frontend/src/api/TeamApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,24 @@ const addTeam = (team: ITeam) => {
}

const pSubscribe = (id: string, done: () => void) => {
!people.has(id) && people.set(id, { f: false, v: id })
psubs.has(id) ? psubs.set(id, [...psubs.get(id)!, done]) : psubs.set(id, [done])
if (!people.has(id)) {
people.set(id, { f: false, v: id })
}
if (psubs.has(id)) {
psubs.set(id, [...psubs.get(id)!, done])
} else {
psubs.set(id, [done])
}
}
const tSubscribe = (id: string, done: () => void) => {
!teams.has(id) &&
if (!teams.has(id)) {
teams.set(id, { f: false, v: { id, name: id, description: '', members: [], tags: [] } })
tsubs.has(id) ? tsubs.set(id, [...tsubs.get(id)!, done]) : tsubs.set(id, [done])
}
if (tsubs.has(id)) {
tsubs.set(id, [...tsubs.get(id)!, done])
} else {
tsubs.set(id, [done])
}
}

export const usePersonName = () => {
Expand Down Expand Up @@ -165,7 +176,7 @@ export const useMyTeams = () => {
const ident = user.getIdent()

useEffect(() => {
ident &&
if (ident) {
myTeams()
.then((teamListe) => {
if (teamListe.length === 0) {
Expand Down Expand Up @@ -194,7 +205,9 @@ export const useMyTeams = () => {
setLoading(false)
console.error("couldn't find teams", error)
})
!ident && setLoading(false)
} else {
setLoading(false)
}
}, [ident, productAreas])

return [data, loading] as [ITeam[], boolean]
Expand All @@ -206,7 +219,7 @@ export const useMyProductAreas = () => {
const ident = user.getIdent()

useEffect(() => {
ident &&
if (ident) {
myProductArea()
.then((r) => {
setData(r)
Expand All @@ -217,7 +230,7 @@ export const useMyProductAreas = () => {
setLoading(false)
console.error('couldn\t find product area', e)
})
!ident && setLoading(false)
} else setLoading(false)
}, [ident])

return [data, loading] as [IProductArea[], boolean]
Expand Down
4 changes: 2 additions & 2 deletions apps/frontend/src/components/Lov.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { EListName, codelist } from '../services/Codelist'
import { env } from '../util/env'

// unsure how to refactor code
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
const reactProcessString = require('react-process-string')
// eslint-enable-next-line @typescript-eslint/no-var-requires
// eslint-enable-next-line @typescript-eslint/no-require-imports
const processString = reactProcessString as (
converters: { regex: RegExp; fn: (key: string, result: string[]) => JSX.Element | string }[]
) => (input?: string) => JSX.Element[]
Expand Down
7 changes: 5 additions & 2 deletions apps/frontend/src/components/admin/audit/AuditPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ export const AuditPage = () => {
setAuditLog(undefined)
setError(undefined)
if (!id) {
!!params.id && navigate('/admin/audit')
return
if (params.id) {
navigate('/admin/audit')
} else {
return
}
}
setLoading(true)
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ export const AuditRecentTable = (props: { show: boolean; tableType?: EObjectType

useEffect(() => {
;(async () => {
props.show && setAudits(await getAudits(page - 1, limit, table))
if (props.show) {
setAudits(await getAudits(page - 1, limit, table))
}
})()
}, [page, limit, props.show, table])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ export const EtterlevelseKravView = (props: IProps) => {

useEffect(() => {
;(async () => {
etterlevelseDokumentasjon?.id &&
kravId.kravNummer &&
if (etterlevelseDokumentasjon?.id && kravId.kravNummer) {
getEtterlevelseMetadataByEtterlevelseDokumentasjonAndKravNummerAndKravVersion(
etterlevelseDokumentasjon?.id,
kravId.kravNummer,
Expand All @@ -143,6 +142,7 @@ export const EtterlevelseKravView = (props: IProps) => {
)
}
})
}
})()

if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,9 @@ export const EtterlevelseDokumentasjonForm = (props: TEditEtterlevelseDokumentas
isClearable={false}
loadOptions={searchBehandlingOptions}
onChange={(value) => {
value && fieldArrayRenderProps.push(value)
if (value) {
fieldArrayRenderProps.push(value)
}
if (value && !values.avdeling && values.behandlinger?.length === 0) {
const behandling = value as IBehandling
const newAvdeling = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ export const GjenbrukEtterlevelseDokumentasjonForm = (props: IProps) => {
isClearable={false}
loadOptions={searchBehandlingOptions}
onChange={(value) => {
value && fieldArrayRenderProps.push(value)
if (value) {
fieldArrayRenderProps.push(value)
}
if (value && !values.avdeling && values.behandlinger?.length === 0) {
const behandling = value as IBehandling
const newAvdeling = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ export const EditKravRelasjoner = () => {
isClearable={false}
loadOptions={useSearchKrav}
onChange={(krav) => {
krav && fieldArrayRenderProps.push(krav)
if (krav) {
fieldArrayRenderProps.push(krav)
}
}}
styles={selectOverrides}
/>
Expand Down
4 changes: 3 additions & 1 deletion apps/frontend/src/components/krav/Edit/KravBegreperEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ export const EditBegreper = () => {
isClearable={false}
loadOptions={useBegrepSearch}
onChange={(begrep) => {
begrep && fieldArrayRenderProps.push(begrep)
if (begrep) {
fieldArrayRenderProps.push(begrep)
}
}}
styles={selectOverrides}
/>
Expand Down
6 changes: 3 additions & 3 deletions apps/frontend/src/components/krav/Etterlevelser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ export const Etterlevelser = ({
},
]
}

etterlevelse.etterlevelseDokumentasjon.teamsData &&
if (etterlevelse.etterlevelseDokumentasjon.teamsData) {
etterlevelse.etterlevelseDokumentasjon.teamsData.forEach((t) => {
if (!t.productAreaId && !t.productAreaName) {
t.productAreaId = 'INGEN_PO'
t.productAreaName = 'Ingen produktområde'
}
})
return etterlevelse
return etterlevelse
}
})

const filteredEtterlevelse = etterlevelser.filter((e) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ export const Tilbakemeldinger = ({

const refs = useRefs<HTMLDivElement>(tilbakemeldinger.map((tilbakemelding) => tilbakemelding.id))
useEffect(() => {
!loading && focusNr && setTimeout(() => refs[focusNr]?.current?.scrollIntoView(), 100)
if (!loading && focusNr) {
setTimeout(() => refs[focusNr]?.current?.scrollIntoView(), 100)
}
}, [loading])

const setFocus = (id: string) => {
Expand Down Expand Up @@ -178,7 +180,9 @@ export const Tilbakemeldinger = ({
setFocusNummer={setFocusNr}
ubesvartOgKraveier={ubesvartOgKraveier}
close={(t) => {
t && replace(t)
if (t) {
replace(t)
}
}}
remove={remove}
replace={replace}
Expand Down Expand Up @@ -243,7 +247,9 @@ export const Tilbakemeldinger = ({
krav={krav}
open={addTilbakemelding}
close={(t) => {
t && add(t)
if (t) {
add(t)
}
setAddTilbakemelding(false)
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ export const SlackChannelSearch = ({ add, close }: TAddVarslingsadresseProps) =>
onChange={(slackKanal) => {
const channel = slackKanal as ISlackChannel
if (channel) add({ type: EAdresseType.SLACK, adresse: channel.id })
close && close()
if (close) {
close()
}
}}
styles={selectOverrides}
/>
Expand All @@ -237,7 +239,9 @@ export const SlackUserSearch = ({ add, close }: TAddVarslingsadresseProps) => {
add({ type: EAdresseType.SLACK_USER, adresse: user.id })
setLoadingSlackId(false)
setError('')
close && close()
if (close) {
close()
}
})
.catch((e) => {
setError('Fant ikke slack for bruker, error: ' + e.toString())
Expand Down Expand Up @@ -306,7 +310,9 @@ export const AddEmail = ({ added, add: doAdd, close }: TAddVarslingsadresseProps
doAdd({ type: EAdresseType.EPOST, adresse: toAdd })
setVal('')
}
close && close()
if (close) {
close()
}
}

const onKey = (e: React.KeyboardEvent) => e.key === 'Enter' && add()
Expand Down
14 changes: 7 additions & 7 deletions apps/frontend/src/pages/EtterlevelsePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ export const EtterlevelsePage = () => {
}

useEffect(() => {
etterlevelse &&
if (etterlevelse) {
ampli.logEvent('sidevisning', {
side: 'Etterlevelse side',
sidetittel: getPageTitle(),
...userRoleEventProp,
})

getKravByKravNumberAndVersion(etterlevelse?.kravNummer, etterlevelse?.kravVersjon).then(
(res) => {
if (res) {
Expand All @@ -49,12 +55,6 @@ export const EtterlevelsePage = () => {
}
}
)
if (etterlevelse) {
ampli.logEvent('sidevisning', {
side: 'Etterlevelse side',
sidetittel: getPageTitle(),
...userRoleEventProp,
})
}
}, [etterlevelse])

Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/src/query/EtterlevelseDokumentasjonQuery.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { gql } from '@apollo/client'

// eslint-disable-next-line @typescript-eslint/ban-types
// eslint-disable-next-line "@typescript-eslint/no-restricted-types"
export const getEtterlevelseDokumentasjonListQuery = gql`
query getEtterlevelseDokumentasjoner(
$pageNumber: NonNegativeInt
Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/src/query/KravQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const useKravCounter = (
})
}

// eslint-disable-next-line @typescript-eslint/ban-types
// eslint-disable-next-line "@typescript-eslint/no-restricted-types"
const getKravtableQuery = gql`
query getKravByFilter(
$relevans: [String!]
Expand Down
12 changes: 9 additions & 3 deletions apps/frontend/src/util/hooks/customHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export function useDebouncedState<T>(
useEffect(() => {
const handler = setTimeout(() => {
setDebouncedValue(value)
passThrough && passThrough(value)
if (passThrough) {
passThrough(value)
}
}, delay)
return () => {
clearTimeout(handler)
Expand Down Expand Up @@ -41,10 +43,14 @@ export function useAwait<T>(promise: Promise<T>, setLoading?: Dispatch<SetStateA

useEffect(() => {
;(async () => {
setLoading && setLoading(true)
if (setLoading) {
setLoading(true)
}
await promise
update()
setLoading && setLoading(false)
if (setLoading) {
setLoading(false)
}
})()
}, [])
}
Expand Down
4 changes: 3 additions & 1 deletion apps/frontend/src/util/network.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ const init = (onErr: (e: any) => void) => {

export const useNetworkStatus = () => {
const [error, setError] = useState<any>()
!done && init(setError)
if (!done) {
init(setError)
}

const clear = () => {
setError(undefined)
Expand Down

0 comments on commit 6233c8d

Please sign in to comment.