Skip to content

Commit

Permalink
Create shared resource (#1887)
Browse files Browse the repository at this point in the history
* working

* add shared dir

* moved shared resources folder

* webpack test

* test

* test

* test

* test

* test

* Update docker-compose.yml

* Update buildContainers.yaml

* test

* another test

* remove symlinks if needed

* tests

* tests

* fix lighthouse

* remove symlinks from lighthouse

* update readme

* fix package

* Update Dockerfile

* Update package.json
  • Loading branch information
nickbristow committed Jun 11, 2024
1 parent f844f75 commit d145dd9
Show file tree
Hide file tree
Showing 18 changed files with 18,065 additions and 23 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/buildContainers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Remove symlinks (if needed)
if: ${{ matrix.container-to-build == 'ecr-viewer' }}
working-directory: ./containers/${{matrix.container-to-build}}/src/app/shared
run: rm -rf ./*

- name: Copy shared-resources (if needed)
if: ${{ matrix.container-to-build == 'ecr-viewer' }}
working-directory: ./containers/${{matrix.container-to-build}}
run: cp -r ../../shared-resources/src/ ./src/app/shared/

- name: Target branch in requirements.txt
working-directory: ./containers/${{matrix.container-to-build}}
run: |
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/lighthouse.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ jobs:
with:
node-version: "18"

- name: Remove symlinks
working-directory: ./containers/ecr-viewer/src/app/shared
run: rm -rf ./*

- name: Copy shared-resources (if needed)
working-directory: ./containers/ecr-viewer
run: cp -r ../../shared-resources/src/ ./src/app/shared/

- name: Change to the correct directory
run: cd containers/ecr-viewer

Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@ jobs:
uses: actions/setup-node@v2
with:
node-version: 18 # Adjust the Node.js version as needed
- name: Remove symlinks
working-directory: ./containers/ecr-viewer/src/app/shared
run: rm -rf ./*
- name: Copy shared-resources
working-directory: ./containers/ecr-viewer
run: cp -r ../../shared-resources/src/ ./src/app/shared/
- name: Install dependencies
working-directory: ./containers/ecr-viewer # Navigate to your Node.js app directory
run: npm install
Expand Down Expand Up @@ -240,6 +246,12 @@ jobs:
uses: actions/setup-node@v2
with:
node-version: 18 # Adjust the Node.js version as needed
- name: Remove symlinks
working-directory: ./containers/ecr-viewer/src/app/shared
run: rm -rf ./*
- name: Copy shared-resources
working-directory: ./containers/ecr-viewer
run: cp -r ../../shared-resources/src/ ./src/app/shared/
- name: Install dependencies
working-directory: ./containers/ecr-viewer # Navigate to your Node.js app directory
run: npm install
Expand Down
2 changes: 1 addition & 1 deletion containers/ecr-viewer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ ENV OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://otel-collector:4318/v1/traces

# server.js is created by next build from the standalone output
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
CMD ["node", "server.js"]
CMD ["node", "server.js"]
3 changes: 2 additions & 1 deletion containers/ecr-viewer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"private": true,
"scripts": {
"dev": "next dev",
"local-dev": "npm run setup-local-env && docker compose up db -d && docker-compose logs && export DATABASE_URL=postgres://postgres:pw@localhost:5432/ecr_viewer_db && npm run dev",
"local-dev": "npm run check-shared-resources && npm run setup-local-env && docker compose up db -d && docker-compose logs && export DATABASE_URL=postgres://postgres:pw@localhost:5432/ecr_viewer_db && npm run dev",
"check-shared-resources": "if [ ! -d ../../shared-resources/node_modules ]; then (cd ../../shared-resources && npm install) fi",
"setup-local-env": "./setup-env.sh",
"build": "next build",
"start": "next start",
Expand Down
1 change: 1 addition & 0 deletions containers/ecr-viewer/src/app/shared/src
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import EncounterDetails from "./Encounter";
import ClinicalInfo from "./ClinicalInfo";
import { Bundle } from "fhir/r4";
import React, { ReactNode } from "react";
import { Accordion } from "@trussworks/react-uswds";
import LabInfo from "@/app/view-data/components/LabInfo";
import { formatString } from "@/app/services/formatService";
import { evaluateEcrMetadata } from "../../services/ecrMetadataService";
import { evaluateLabInfoData } from "@/app/services/labsService";
import {
Expand All @@ -19,6 +17,7 @@ import {
evaluateProviderData,
} from "@/app/services/evaluateFhirDataService";
import { evaluateClinicalData } from "./common";
import AccordionContainer from "@/app/shared/src/accordion/AccordionContainer";

type AccordionContainerProps = {
children?: ReactNode;
Expand All @@ -33,7 +32,7 @@ type AccordionContainerProps = {
* @param props.fhirPathMappings - The path mappings used to extract information from the FHIR bundle.
* @returns The JSX element representing the accordion container.
*/
const AccordionContainer: React.FC<AccordionContainerProps> = ({
const AccordionContent: React.FC<AccordionContainerProps> = ({
fhirBundle,
fhirPathMappings,
}) => {
Expand Down Expand Up @@ -142,20 +141,6 @@ const AccordionContainer: React.FC<AccordionContainerProps> = ({
},
];

//Add id, adjust title
accordionItems.forEach((item, index) => {
let formattedTitle = formatString(item["title"]);
item["id"] = `${formattedTitle}_${index + 1}`;
item["title"] = <span id={formattedTitle}>{item["title"]}</span>;
accordionItems[index] = item;
});

return (
<Accordion
className="info-container"
items={accordionItems}
multiselectable={true}
/>
);
return <AccordionContainer accordionItems={accordionItems} />;
};
export default AccordionContainer;
export default AccordionContent;
4 changes: 2 additions & 2 deletions containers/ecr-viewer/src/app/view-data/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"use client";
import AccordionContainer from "@/app/view-data/components/AccordionContainer";
import AccordionContent from "@/app/view-data/components/AccordionContent";
import { useSearchParams } from "next/navigation";
import React, { useEffect, useState } from "react";
import { Bundle } from "fhir/r4";
Expand Down Expand Up @@ -132,7 +132,7 @@ const ECRViewerPage: React.FC = () => {
</Grid>
</Grid>
</GridContainer>
<AccordionContainer
<AccordionContent
fhirPathMappings={mappings}
fhirBundle={fhirBundle}
/>
Expand Down
3 changes: 3 additions & 0 deletions shared-resources/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
./node_modules
.next/
.env.local
35 changes: 35 additions & 0 deletions shared-resources/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Shared Modules for PHDI Containers

This folder contains shared modules that can be used across PHDI Next.js projects. Follow the instructions below to integrate these shared modules into other containers.

## Step 1: Sym link the folder to your container

From the repo you want to sym link to

Example:
```
ln -s ../../../../../shared-resources/src/ ./src/app/shared/
```

## Step 2: Install local requirements for shared-resources
In the shared resources folder run:
```
npm install
```

## Step 3: Update various build commands
Certain github build commands will need to be updated.

In order for docker to work, the files need to be located in the repo they are being used in. See these examples from build container.

```
- name: Remove symlinks (if needed)
if: ${{ matrix.container-to-build == 'ecr-viewer' }}
working-directory: ./containers/${{matrix.container-to-build}}/src/app/shared
run: rm -rf ./*
- name: Copy shared-resources (if needed)
if: ${{ matrix.container-to-build == 'ecr-viewer' }}
working-directory: ./containers/${{matrix.container-to-build}}
run: cp -r ../../shared-resources/src/ ./src/app/shared/
```
15 changes: 15 additions & 0 deletions shared-resources/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const nextJest = require("next/jest");

const createJestConfig = nextJest({
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
dir: "./",
});

// Add any custom config to be passed to Jest
const customJestConfig = {
setupFilesAfterEnv: ["<rootDir>/jest.setup.ts"],
testEnvironment: "jest-environment-jsdom",
};

// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
module.exports = createJestConfig(customJestConfig);
6 changes: 6 additions & 0 deletions shared-resources/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import "@testing-library/jest-dom";
import { toHaveNoViolations } from "jest-axe";
import * as matchers from "jest-extended";

expect.extend(toHaveNoViolations);
expect.extend(matchers);
Loading

0 comments on commit d145dd9

Please sign in to comment.