Skip to content

Commit

Permalink
unbreak API by fixing route import (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
fzhao99 authored Dec 18, 2024
1 parent 38f37e2 commit f0188cb
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 76 deletions.
70 changes: 70 additions & 0 deletions query-connector/src/app/DataProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"use client";

import classNames from "classnames";
import { createContext, ReactNode, useState } from "react";

export interface DataDisplayInfo {
title: string;
value?: string | React.JSX.Element | React.JSX.Element[];
}

/**
* Functional component for displaying data.
* @param props - Props for the component.
* @param props.item - The display data item(s) to be rendered.
* @param [props.className] - Additional class name for styling purposes.
* @returns - A React element representing the display of data.
*/
export const DataDisplay: React.FC<{
item: DataDisplayInfo;
className?: string;
}> = ({
item,
className,
}: {
item: DataDisplayInfo;
className?: string;
}): React.JSX.Element => {
return (
<div>
<div className="grid-row">
<div className="data-title" id={item.title}>
{item.title}
</div>
<div
className={classNames("grid-col-auto maxw7 text-pre-line", className)}
>
{item.value}
</div>
</div>
<div className={"section__line_gray"} />
</div>
);
};

export interface DataContextValue {
data: unknown; // You can define a specific data type here
setData: (data: unknown) => void;
}

export const DataContext = createContext<DataContextValue | undefined>(
undefined,
);

/**
*
* @param root0 - Children
* @param root0.children - Children
* @returns - The data provider component.
*/
export function DataProvider({ children }: { children: ReactNode }) {
const [data, setData] = useState<unknown | null>(null);

return (
<DataContext.Provider value={{ data, setData }}>
{children}
</DataContext.Provider>
);
}

export default DataProvider;
2 changes: 1 addition & 1 deletion query-connector/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import "../styles/styles.scss";
import Header from "./query/components/header/header";
import Footer from "./query/components/footer/footer";
import { DataProvider } from "./utils";
import { SessionProvider } from "next-auth/react";
import DataProvider from "./DataProvider";

/**
* Establishes the layout for the application.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { Patient } from "fhir/r4";
import { DataDisplayInfo } from "@/app/utils";
import { DataDisplay } from "@/app/utils";
import * as dateFns from "date-fns";
import { evaluate } from "fhirpath";

Expand All @@ -11,6 +9,7 @@ import {
formatIdentifier,
formatDate,
} from "../../../../format-service";
import { DataDisplay, DataDisplayInfo } from "@/app/DataProvider";

/**
* Displays the demographic information of a patient.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { getCustomQueries } from "@/app/database-service";
import { CustomUserQuery } from "@/app/query-building";
import LoadingView from "@/app/query/components/LoadingView";
import { DataContext } from "@/app/utils";
import {
useContext,
useState,
Expand All @@ -17,6 +16,7 @@ import UserQueriesDisplay from "./UserQueriesDisplay";
import { SelectedQueryDetails, SelectedQueryState } from "./utils";
import styles from "./querySelection.module.scss";
import { BuildStep } from "@/app/constants";
import { DataContext } from "@/app/DataProvider";

type QuerySelectionProps = {
selectedQuery: SelectedQueryState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { Button, Icon, Table } from "@trussworks/react-uswds";
import { ModalRef } from "@/app/query/designSystem/modal/Modal";
import styles from "./querySelection.module.scss";
import { CustomUserQuery } from "@/app/query-building";
import { DataContext } from "@/app/utils";

import { BuildStep } from "@/app/constants";
import {
Expand All @@ -22,6 +21,7 @@ import {
SelectedQueryDetails,
} from "./utils";
import LoadingView from "@/app/query/components/LoadingView";
import { DataContext } from "@/app/DataProvider";

interface UserQueriesDisplayProps {
queries: CustomUserQuery[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import "react-toastify/dist/ReactToastify.css";
import { RefObject } from "react";
import { CustomUserQuery } from "@/app/query-building";
import { deleteQueryById } from "@/app/database-service";
import { DataContextValue } from "@/app/utils";
import { showToastConfirmation } from "@/app/query/designSystem/toast/Toast";
import { DataContextValue } from "@/app/DataProvider";

/**
* Handles deleting a user query.
Expand Down
3 changes: 1 addition & 2 deletions query-connector/src/app/tests/unit/utils.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React from "react";
import { render, screen } from "@testing-library/react";
import {
DataDisplay,
DataDisplayInfo,
groupConditionConceptsIntoValueSets,
unnestValueSetsFromQuery,
} from "../../utils";
Expand All @@ -17,6 +15,7 @@ import {
DEFAULT_CHLAMYDIA_QUERY,
EXPECTED_CHLAMYDIA_VALUESET_LENGTH,
} from "./fixtures";
import { DataDisplayInfo, DataDisplay } from "@/app/DataProvider";

describe("DataDisplay Component", () => {
it("should render the title and value", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,74 +1,6 @@
"use client";
import { createContext, ReactNode, useState } from "react";
import React from "react";
import classNames from "classnames";
import { QueryResultRow } from "pg";
import { ValueSet } from "./constants";

export interface DataDisplayInfo {
title: string;
value?: string | React.JSX.Element | React.JSX.Element[];
}

/**
* Functional component for displaying data.
* @param props - Props for the component.
* @param props.item - The display data item(s) to be rendered.
* @param [props.className] - Additional class name for styling purposes.
* @returns - A React element representing the display of data.
*/
export const DataDisplay: React.FC<{
item: DataDisplayInfo;
className?: string;
}> = ({
item,
className,
}: {
item: DataDisplayInfo;
className?: string;
}): React.JSX.Element => {
return (
<div>
<div className="grid-row">
<div className="data-title" id={item.title}>
{item.title}
</div>
<div
className={classNames("grid-col-auto maxw7 text-pre-line", className)}
>
{item.value}
</div>
</div>
<div className={"section__line_gray"} />
</div>
);
};

export interface DataContextValue {
data: unknown; // You can define a specific data type here
setData: (data: unknown) => void;
}

export const DataContext = createContext<DataContextValue | undefined>(
undefined,
);

/**
*
* @param root0 - Children
* @param root0.children - Children
* @returns - The data provider component.
*/
export function DataProvider({ children }: { children: ReactNode }) {
const [data, setData] = useState<unknown | null>(null);

return (
<DataContext.Provider value={{ data, setData }}>
{children}
</DataContext.Provider>
);
}

type QueryTableQueryDataColumn = {
[condition_name: string]: {
[valueSetId: string]: ValueSet;
Expand Down

0 comments on commit f0188cb

Please sign in to comment.