Skip to content

Commit

Permalink
Merge branch 'develop' into configurable-roles
Browse files Browse the repository at this point in the history
  • Loading branch information
Nil20 committed Jan 9, 2025
2 parents 6d3b7ac + d50e2a2 commit 07d655d
Show file tree
Hide file tree
Showing 96 changed files with 1,844 additions and 1,121 deletions.
175 changes: 161 additions & 14 deletions .github/workflows/lint-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@
#
# Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.

name: Lint, run unit tests and security scans
name: Lint and run unit tests

on: [pull_request]
on:
pull_request:
push:
branches:
- develop

jobs:
setup:
name: Setup tests
permissions:
contents: read
pull-requests: write
Expand All @@ -28,6 +33,7 @@ jobs:
# forked repos cannot access secrets.GITHUB_TOKEN which causes this step
# to fail
continue-on-error: true
if: github.event_name == 'pull_request'
with:
message: >
Oops! Looks like you forgot to update the changelog.
Expand All @@ -44,6 +50,7 @@ jobs:
echo "matrix=${PACKAGES}" >> $GITHUB_OUTPUT
test:
name: Test
needs: setup
runs-on: ubuntu-22.04
strategy:
Expand Down Expand Up @@ -136,33 +143,173 @@ jobs:
if: steps.check-scripts.outputs.skip != 'true'
run: CI="" yarn install --frozen-lockfile

# TODO: Move out of the matrix to be built once and shared
- name: Build common package
if: steps.check-scripts.outputs.skip != 'true' && contains(env.DEPENDENCIES, 'packages/commons')
if: matrix.package != 'packages/client' && steps.check-scripts.outputs.skip != 'true' && contains(env.DEPENDENCIES, 'packages/commons')
run: cd packages/commons && yarn build

- name: Build components client and login
if: steps.check-scripts.outputs.skip != 'true' && contains(env.DEPENDENCIES, 'packages/components')
- name: Build components
if: matrix.package != 'packages/client' && steps.check-scripts.outputs.skip != 'true' && contains(env.DEPENDENCIES, 'packages/components')
run: |
cd packages/components && yarn build
# TODO: should run parallel to unit tests as can take as much as unit tests
- name: Run linting
if: steps.check-scripts.outputs.skip != 'true' && steps.check-scripts.outputs.skip-lint != 'true'
if: matrix.package != 'packages/client' && steps.check-scripts.outputs.skip != 'true' && steps.check-scripts.outputs.skip-lint != 'true'
run: cd ${{ matrix.package }} && yarn lint

- name: Run Unit Test
if: steps.check-scripts.outputs.skip != 'true' && steps.check-scripts.outputs.skip-test != 'true'
if: matrix.package != 'packages/client' && steps.check-scripts.outputs.skip != 'true' && steps.check-scripts.outputs.skip-test != 'true'
run: cd ${{ matrix.package }} && yarn test

prepare-client-tests:
name: Prepare client tests
runs-on: ubuntu-22.04
steps:
- name: Checking out git repo
uses: actions/checkout@v4

- name: Use Node.js from .nvmrc
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc

- name: Extract dependencies for client
id: extract-dependencies
run: |
cd ${{ matrix.package }}
if [[ "${{ matrix.package }}" == "packages/client" ]]; then
yarn test --coverage
else
yarn test
fi
DEPENDENCIES=$(node -e "
const { execSync } = require('child_process');
const output = execSync('yarn --silent workspaces info', { encoding: 'utf-8' });
const json = JSON.parse(output.replaceAll('@opencrvs', 'packages'));
const getDependencies = (pkg) =>
json[pkg].workspaceDependencies.concat(
json[pkg].workspaceDependencies.flatMap(getDependencies)
);
console.log(
getDependencies('packages/client').join(' ')
);
")
echo "DEPENDENCIES=${DEPENDENCIES}" >> $GITHUB_ENV
echo "Found dependencies: $DEPENDENCIES"
- name: Remove other package directories
run: |
for dir in packages/*; do
if echo "packages/client $DEPENDENCIES" | grep -q -w "$dir"; then
echo "Skipping $dir"
else
echo "Removing $dir"
rm -rf "$dir"
fi
done
- name: Cache Node.js dependencies
uses: actions/cache@v4
with:
path: |
**/node_modules
~/.cache/yarn/v6
key: node-${{ hashFiles('**/yarn.lock', format('{0}/{1}','packages/client','package.json')) }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: CI="" yarn install --frozen-lockfile

- name: Build common package
run: cd packages/commons && yarn build

- name: Build components
run: |
cd packages/components && yarn build
- name: Upload filesystem as artifact
uses: actions/[email protected]
with:
name: client
include-hidden-files: true
path: |
.
!**/node_modules
lint-client:
name: Lint client
needs: prepare-client-tests
runs-on: ubuntu-22.04

steps:
- name: Download filesystem artifact
uses: actions/[email protected]
with:
name: client
path: .

- name: Use Node.js from .nvmrc
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc

- name: Cache Node.js dependencies
uses: actions/cache@v4
with:
path: |
**/node_modules
~/.cache/yarn/v6
key: node-${{ hashFiles('**/yarn.lock', format('{0}/{1}','packages/client','package.json')) }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: CI="" yarn install --frozen-lockfile

- name: Compile
run: cd packages/client && yarn test:compilation

- name: Run linting
run: cd packages/client && yarn lint

test-client:
name: Test client
needs: prepare-client-tests
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
shards: [1, 2, 3, 4, 5]

steps:
- name: Download filesystem artifact
uses: actions/[email protected]
with:
name: client
path: .

- name: Use Node.js from .nvmrc
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc

- name: Cache Node.js dependencies
uses: actions/cache@v4
with:
path: |
**/node_modules
~/.cache/yarn/v6
key: node-${{ hashFiles('**/yarn.lock', format('{0}/{1}','packages/client','package.json')) }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: CI="" yarn install --frozen-lockfile

- name: Run Unit Test
run: cd packages/client && yarn test -- --shard $(( ${{ strategy.job-index }} + 1 ))/${{ strategy.job-total }}

lint-knip:
name: Lint unused exports with Knip
runs-on: ubuntu-22.04
if: github.event_name == 'pull_request'
steps:
- name: Checkout base branch
uses: actions/checkout@v4
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

### New features

- Misc new feature
- Allow configuring the default search criteria for record search [#6924](https://github.com/opencrvs/opencrvs-core/issues/6924)
- Add checks to validate client and server are always on the same version. This prevents browsers with a cached or outdated client versions from making potentially invalid requests to the backend [#6695](https://github.com/opencrvs/opencrvs-core/issues/6695)
- Two new statuses of record are added: `Validated` and `Correction Requested` for advanced search parameters [#6365](https://github.com/opencrvs/opencrvs-core/issues/6365)
Expand All @@ -26,6 +25,7 @@
- **Template Selection Dropdown**: Updated print workflow to include a dropdown menu for template selection when issuing a certificate.
- Auth now allows exchanging user's token for a new record-specific token [#7728](https://github.com/opencrvs/opencrvs-core/issues/7728)
- A new GraphQL mutation `upsertRegistrationIdentifier` is added to allow updating the patient identifiers of a registration record such as NID [#8034](https://github.com/opencrvs/opencrvs-core/pull/8034)
- Updated GraphQL mutation `confirmRegistration` to allow adding a `comment` for record audit [#8197](https://github.com/opencrvs/opencrvs-core/pull/8197)
- Introduced a new customisable UI component: Banner [#8276](https://github.com/opencrvs/opencrvs-core/issues/8276)

### Improvements
Expand All @@ -40,6 +40,7 @@

### Bug fixes

- Fix task history getting corrupted if a user views a record while it's in external validation [#8278](https://github.com/opencrvs/opencrvs-core/issues/8278)
- Fix health facilities missing from dropdown after correcting a record address [#7528](https://github.com/opencrvs/opencrvs-core/issues/7528)
- "Choose a new password" form now allows the user to submit the form using the "Enter/Return" key [#5502](https://github.com/opencrvs/opencrvs-core/issues/5502)
- Dropdown options now flow to multiple rows in forms [#7653](https://github.com/opencrvs/opencrvs-core/pull/7653)
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ services:
- ES_HOST=elasticsearch:9200
- COUNTRY_CONFIG_URL=http://countryconfig:3040/
- DOCUMENTS_URL=http://documents:9050
- USER_MANAGEMENT_URL=http://localhost:3030/

# User facing services
workflow:
Expand Down
3 changes: 1 addition & 2 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
"build": "NODE_OPTIONS=--max_old_space_size=8000 vite build",
"docker:build": "docker build ../../ -f ../../Dockerfile-register -t ocrvs-client",
"docker:run": "docker run -it --rm -p 5000:80 --name ocrvs-client ocrvs-client",
"test": "yarn test:compilation && NODE_OPTIONS=--max_old_space_size=8000 vitest run",
"test": "NODE_OPTIONS=--max_old_space_size=8000 vitest run --silent --dangerouslyIgnoreUnhandledErrors",
"test:watch": "vitest",
"open:cov": "yarn test && opener coverage/index.html",
"lint": "yarn lint:css && yarn lint:ts",
"lint:css": "stylelint 'src/**/*.{ts,tsx}'",
"lint:ts": "eslint --fix './src/**/*.{ts,tsx}' --max-warnings=353",
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/i18n/messages/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1554,7 +1554,7 @@ const countryMessagesToDefine: Record<
FAR: {
id: 'countries.FAR',
defaultMessage: 'Farajaland',
description: 'Fictional country for OpenCRSV demo'
description: 'Fictional country for OpenCRVS demo'
},
FRO: {
id: 'countries.FRO',
Expand Down
11 changes: 5 additions & 6 deletions packages/client/src/src-sw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import {
import { registerRoute, NavigationRoute } from 'workbox-routing'
import { NetworkFirst, CacheFirst } from 'workbox-strategies'
import { clientsClaim } from 'workbox-core'
import { MINIO_REGEX } from '@opencrvs/commons/client'

// eslint-disable-next-line @typescript-eslint/no-use-before-define
self.__WB_DISABLE_DEV_LOGS = true

declare let self: ServiceWorkerGlobalScope

Expand Down Expand Up @@ -79,12 +83,7 @@ registerRoute(/http(.+)conditionals\.js$/, new NetworkFirst())
registerRoute(/http(.+)config$/, new NetworkFirst())

// This caches the minio urls
registerRoute(
import.meta.env.DEV
? /http(.+)localhost:3535\/ocrvs\/.+/
: /http(.+)minio\.(.+)\/.*ocrvs.*\/.+/,
new CacheFirst()
)
registerRoute(MINIO_REGEX, new CacheFirst())

/*
* Alternate for navigateFallback & navigateFallbackBlacklist
Expand Down
3 changes: 2 additions & 1 deletion packages/client/src/transformer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ export function getChangedValues(
originalDraftData[section.id] ??= {}

if (
!conditionalActions.includes('hide') &&
(!conditionalActions.includes('hide') ||
fieldDef.name === 'detailsExist') &&
!isMetaTypeField(fieldDef) &&
hasFieldChanged(
fieldDef,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
/* eslint-disable */
import { InputField } from '@client/components/form/InputField'
import { DATE, PARAGRAPH, TEXT } from '@client/forms'
import { IAdvancedSearchFormState } from '@client/search/advancedSearch/utils'
import { DateField } from '@opencrvs/components/lib/DateField'
import { Text } from '@opencrvs/components/lib/Text'
import { TextInput } from '@opencrvs/components/lib/TextInput'
Expand All @@ -28,6 +27,7 @@ import {
} from './utils'
import { Errors, getValidationErrorsForForm } from './validation'

import { ActionFormData } from '@opencrvs/commons'
import {
FieldConfig,
FieldValue,
Expand All @@ -49,7 +49,6 @@ import {
useIntl
} from 'react-intl'
import { FileInput } from './inputs/FileInput/FileInput'
import { ActionFormData } from '@opencrvs/commons'

const fadeIn = keyframes`
from { opacity: 0; }
Expand Down Expand Up @@ -223,7 +222,7 @@ interface ExposedProps {
onSetTouched?: (func: ISetTouchedFunction) => void
requiredErrorMessage?: MessageDescriptor
onUploadingStateChanged?: (isUploading: boolean) => void
initialValues?: IAdvancedSearchFormState
initialValues?: ActionFormData
}

type AllProps = ExposedProps & IntlShapeProps & FormikProps<ActionFormData>
Expand Down Expand Up @@ -452,6 +451,7 @@ export const FormFieldGenerator: React.FC<ExposedProps> = (props) => {

return (
<Formik<ActionFormData>
enableReinitialize={true}
initialValues={initialValues}
validate={(values) =>
getValidationErrorsForForm(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const ViewerContainer = styled.div`
`

interface IProps {
previewImage: FileFieldValue
previewImage: Exclude<FileFieldValue, null>
disableDelete?: boolean
title?: string
goBack: () => void
Expand Down
Loading

0 comments on commit 07d655d

Please sign in to comment.