Skip to content

Commit

Permalink
Merge pull request #8565 from opencrvs/ocrvs-8397
Browse files Browse the repository at this point in the history
Ocrvs 8397
  • Loading branch information
makelicious authored Feb 4, 2025
2 parents 77c8404 + 3acd3e2 commit fbb3f86
Show file tree
Hide file tree
Showing 42 changed files with 982 additions and 224 deletions.
2 changes: 0 additions & 2 deletions .eslintrc.events.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ module.exports = {
'@typescript-eslint/no-unnecessary-boolean-literal-compare': 2,
'@typescript-eslint/no-non-null-assertion': 2,
'@typescript-eslint/no-unnecessary-condition': 1,
'@typescript-eslint/no-unsafe-argument': 1,
'@typescript-eslint/no-unsafe-return': 1,
'@typescript-eslint/prefer-includes': 1,
'@typescript-eslint/promise-function-async': 2,
'@typescript-eslint/require-await': 2,
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"test:watch": "vitest",
"lint": "yarn lint:css && yarn lint:ts",
"lint:css": "stylelint 'src/**/*.{ts,tsx}'",
"lint:ts": "eslint --fix './src/**/*.{ts,tsx}' --max-warnings=314",
"lint:ts": "eslint --fix './src/**/*.{ts,tsx}' --max-warnings=293",
"test:compilation": "tsc --noEmit",
"extract:translations": "bash extract-translations.sh",
"generate-gateway-types": "NODE_OPTIONS=--dns-result-order=ipv4first graphql-codegen --config codegen.ts && prettier --write src/utils/gateway.ts",
Expand Down
50 changes: 46 additions & 4 deletions packages/client/src/v2-events/STYLEGUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,51 @@ interface IApplicationConfig {
}
```

# Coding conventions, definition of done
## Naming functions

- When introducing a new `MessageDescriptor` create a new row in `client.csv`
- They should all have `v2.`-prefix
- Use find\* when you might return undefined

good:

```
async function findEventConfigurationById({
token,
eventType
}: {
token: string
eventType: string
}) {
const configurations = await getEventConfigurations(token)
return configurations.find((config) => config.id === eventType)
}
```

- Use get\* when you can guarantee the result

good:

```
async function getEventConfigurationById({
token,
eventType
}: {
token: string
eventType: string
}) {
const configurations = await getEventConfigurations(token)
const configuration = configurations.find((config) => config.id === eventType)
return getOrThrow(configuration), `No configuration found for event type: ${eventType}`)
}
```

## Naming, abbreviation

When naming things with known abbreviations use camel case format despite of it.
When naming things with known abbreviations use camelCase format

good:

Expand Down Expand Up @@ -93,3 +130,8 @@ export function printPDF(template: PDFTemplate, declarationId: string) {
}
}
```

# Coding conventions, definition of done

- When introducing a new `MessageDescriptor` create a new row in `client.csv`
- Each message used under events should have `v2.`-prefix
3 changes: 1 addition & 2 deletions packages/client/src/v2-events/components/forms/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import {
validate,
DateFieldValue,
TextFieldValue,
RadioGroupFieldValue,
FileFieldValue
RadioGroupFieldValue
} from '@opencrvs/commons/client'
import {
CheckboxFieldValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/

import React, { useEffect, useRef } from 'react'
import React, { useEffect } from 'react'
import { defineMessages } from 'react-intl'
import { useNavigate } from 'react-router-dom'
import { v4 as uuid } from 'uuid'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export function LocationSearch({
buttonLabel="Health facility"
locationList={options}
searchHandler={(location: SearchLocation) =>
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
setFieldValue(props.id, location.id)
}
selectedLocation={initialLocation}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ type Mutation =
| typeof api.event.actions.register
| typeof api.event.actions.validate
| typeof api.event.actions.printCertificate
| typeof api.event.actions.correct.request
| typeof api.event.actions.correct.approve
| typeof api.event.actions.correct.reject
| typeof api.event.actions.correction.request
| typeof api.event.actions.correction.approve
| typeof api.event.actions.correction.reject

type Procedure =
| typeof utils.event.actions.declare
| typeof utils.event.actions.notify
| typeof utils.event.actions.register
| typeof utils.event.actions.validate
| typeof utils.event.actions.printCertificate
| typeof utils.event.actions.correct.request
| typeof utils.event.actions.correct.approve
| typeof utils.event.actions.correct.reject
| typeof utils.event.actions.correction.request
| typeof utils.event.actions.correction.approve
| typeof utils.event.actions.correction.reject

/*
* This makes sure that if you are offline and do
Expand Down Expand Up @@ -183,7 +183,7 @@ utils.event.actions.printCertificate.setMutationDefaults(
})
)

utils.event.actions.correct.request.setMutationDefaults(
utils.event.actions.correction.request.setMutationDefaults(
({ canonicalMutationFn }) => ({
retry: true,
retryDelay: 10000,
Expand All @@ -192,7 +192,7 @@ utils.event.actions.correct.request.setMutationDefaults(
})
)

utils.event.actions.correct.approve.setMutationDefaults(
utils.event.actions.correction.approve.setMutationDefaults(
({ canonicalMutationFn }) => ({
retry: true,
retryDelay: 10000,
Expand All @@ -201,7 +201,7 @@ utils.event.actions.correct.approve.setMutationDefaults(
})
)

utils.event.actions.correct.reject.setMutationDefaults(
utils.event.actions.correction.reject.setMutationDefaults(
({ canonicalMutationFn }) => ({
retry: true,
retryDelay: 10000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,16 @@ export function useEvents() {
),
correct: {
request: useEventAction(
utils.event.actions.correct.request,
api.event.actions.correct.request
utils.event.actions.correction.request,
api.event.actions.correction.request
),
approve: useEventAction(
utils.event.actions.correct.approve,
api.event.actions.correct.approve
utils.event.actions.correction.approve,
api.event.actions.correction.approve
),
reject: useEventAction(
utils.event.actions.correct.reject,
api.event.actions.correct.reject
utils.event.actions.correction.reject,
api.event.actions.correction.reject
)
}
}
Expand Down
16 changes: 1 addition & 15 deletions packages/client/src/v2-events/features/workqueues/Workqueue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
EventConfig,
EventIndex,
getAllFields,
getOrThrow,
RootWorkqueueConfig,
workqueues
} from '@opencrvs/commons/client'
Expand Down Expand Up @@ -50,14 +51,6 @@ const messages = defineMessages({
}
})

function getOrThrow<T>(x: T, message: string) {
if (x === undefined || x === null) {
throw new Error(message)
}

return x
}

/**
* Based on packages/client/src/views/OfficeHome/requiresUpdate/RequiresUpdate.tsx and others in the same directory.
* Ideally we could use a single component for a workqueue.
Expand Down Expand Up @@ -264,14 +257,11 @@ function Workqueue({
}

function getDefaultColumns(): Array<Column> {
// @TODO: Markus should update the types
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return workqueueConfig.defaultColumns.map(
(column): Column => ({
label:
column in defaultColumns
? intl.formatMessage(
// eslint-disable-next-line
defaultColumns[column as keyof typeof defaultColumns].label
)
: '',
Expand All @@ -286,20 +276,16 @@ function Workqueue({
// @TODO: separate types for action button vs other columns
function getColumns(): Array<Column> {
if (width > theme.grid.breakpoints.lg) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return workqueueConfig.columns.map((column) => ({
// eslint-disable-next-line
label: intl.formatMessage(column.label),
width: 35,
key: column.id,
sortFunction: onColumnClick,
isSorted: sortedCol === column.id
}))
} else {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return workqueueConfig.columns
.map((column) => ({
// eslint-disable-next-line
label: intl.formatMessage(column.label),
width: 35,
key: column.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import { fetchImageAsBase64 } from '@client/utils/imageUtils'
async function replaceMinioUrlWithBase64(template: Record<string, any>) {
async function recursiveTransform(obj: any) {
if (typeof obj !== 'object' || obj === null) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return obj
}

Expand All @@ -49,7 +48,6 @@ async function replaceMinioUrlWithBase64(template: Record<string, any>) {
}
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return transformedObject
}
return recursiveTransform(template)
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/views/PrintCertificate/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/
import { IFormData, IFormSectionGroup, ISelectOption } from '@client/forms'
import { Event, EventType } from '@client/utils/gateway'
import { EventType } from '@client/utils/gateway'
import { dynamicMessages } from '@client/i18n/messages/views/certificate'
import { getAvailableLanguages } from '@client/i18n/utils'
import { ILanguageState } from '@client/i18n/reducer'
Expand Down
1 change: 1 addition & 0 deletions packages/commons/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export * from './conditionals/validate'
export * from './documents'
export * from './workqueues'
export * from './uuid'
export * from './utils'
export { DEFAULT_ROLES_DEFINITION } from './authentication'

export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
11 changes: 11 additions & 0 deletions packages/commons/src/events/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,14 @@ export function validateWorkqueueConfig(workqueueConfigs: WorkqueueConfig[]) {
)
})
}

export const findActiveActionFields = (
configuration: EventConfig,
action: ActionType
) => {
const actionConfig = configuration.actions.find((a) => a.type === action)
const form = actionConfig?.forms.find((f) => f.active)

/** Let caller decide whether to throw or default to empty array */
return form?.pages.flatMap((p) => p.fields)
}
Loading

0 comments on commit fbb3f86

Please sign in to comment.