Skip to content

Commit

Permalink
Merge branch 'issues/6503/displayCNSon4k' of https://github.com/i0am0…
Browse files Browse the repository at this point in the history
…arunava/care_fe into issues/6503/displayCNSon4k
  • Loading branch information
i0am0arunava committed Nov 9, 2024
2 parents 93b9cc0 + 087867b commit b867242
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 38 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ cypress/fixtures/token.json
# Care Apps
/apps/*
src/pluginMap.ts
/apps_backup/*
9 changes: 5 additions & 4 deletions cypress/e2e/facility_spec/FacilityLocation.cy.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { v4 as uuidv4 } from "uuid";

import { AssetPage } from "../../pageobject/Asset/AssetCreation";
import { UserCreationPage } from "../../pageobject/Users/UserCreation";
import FacilityPage from "../../pageobject/Facility/FacilityCreation";
import FacilityLocation from "../../pageobject/Facility/FacilityLocation";
import { AssetPagination } from "../../pageobject/Asset/AssetPagination";
import FacilityPage from "../../pageobject/Facility/FacilityCreation";
import FacilityHome from "../../pageobject/Facility/FacilityHome";
import { v4 as uuidv4 } from "uuid";
import FacilityLocation from "../../pageobject/Facility/FacilityLocation";
import { UserCreationPage } from "../../pageobject/Users/UserCreation";

describe("Location Management Section", () => {
const assetPage = new AssetPage();
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/users_spec/UsersProfile.cy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import LoginPage from "../../pageobject/Login/LoginPage";
import UserProfilePage from "../../pageobject/Users/UserProfilePage";
import ManageUserPage from "../../pageobject/Users/ManageUserPage";
import UserProfilePage from "../../pageobject/Users/UserProfilePage";

describe("Manage User Profile", () => {
const loginPage = new LoginPage();
Expand Down
5 changes: 2 additions & 3 deletions cypress/pageobject/Patient/PatientPredefined.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// PatientPredefined.js

import { PatientPage } from "../../pageobject/Patient/PatientCreation";
import FacilityPage from "../../pageobject/Facility/FacilityCreation";
import { PatientPage } from "../../pageobject/Patient/PatientCreation";
import PatientMedicalHistory from "../../pageobject/Patient/PatientMedicalHistory";
import {
generatePhoneNumber,
generateEmergencyPhoneNumber,
generatePhoneNumber,
} from "../utils/constants";

class PatientPredefined {
Expand Down
15 changes: 12 additions & 3 deletions cypress/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@
"compilerOptions": {
"baseUrl": "./",
"target": "es5",
"lib": ["es5", "dom", "es2015", "es2016", "es2017", "es2018", "es2019", "es2020"],
"lib": [
"es5",
"dom",
"es2015",
"es2016",
"es2017",
"es2018",
"es2019",
"es2020"
],
"typeRoots": ["./support"],
"resolveJsonModule": true
},
"include": ["**/*.cy.ts", "support/commands.ts","**/*.ts"],
}
"include": ["**/*.cy.ts", "support/commands.ts", "**/*.ts"]
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"prepare": "husky",
"lint": "eslint ./src",
"lint-fix": "eslint ./src --fix",
"format": "prettier ./src --write",
"format": "prettier ./src ./cypress --write",
"sort-locales": "node ./scripts/sort-locales.js"
},
"dependencies": {
Expand Down Expand Up @@ -166,12 +166,12 @@
"eslint --fix",
"git update-index --again"
],
"src/Locale/*.json": [
"public/locale/*.json": [
"npm run sort-locales"
]
},
"engines": {
"node": ">=22.11.0"
},
"packageManager": "[email protected]"
}
}
6 changes: 3 additions & 3 deletions plugins/treeShakeCareIcons.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Plugin } from "vite";
import * as fs from "fs";
import * as path from "path";
import { globSync } from "glob";
import * as path from "path";
import { Plugin } from "vite";

/**
* Interface defining options for the treeShakeUniconPathsPlugin.
Expand Down Expand Up @@ -48,7 +48,7 @@ export function treeShakeCareIcons(
}
// Finds all used icon names within the project's source files (`.tsx` or `.res` extensions).
function getAllUsedIconNames() {
const files = globSync(path.resolve(rootDir, "src/**/*.{tsx,res}"));
const files = globSync(path.resolve(rootDir, "{apps,src}/**/*.{tsx,res}"));
const usedIconsArray: string[] = [];

files.forEach((file) => {
Expand Down
30 changes: 30 additions & 0 deletions scripts/setup-care-apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,36 @@ const installApp = (app) => {
);
};

const backupDir = path.join(__dirname, "..", "apps_backup");

// Create backup directory if needed
if (!fs.existsSync(backupDir)) {
fs.mkdirSync(backupDir);
}

try {
fs.readdirSync(appsDir, { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
.map((dirent) => dirent.name)
.filter(
(dir) =>
!appsConfig.map((app) => app.package.split("/")[1]).includes(dir),
)
.forEach((unusedApp) => {
const appPath = path.join(appsDir, unusedApp);
const backupPath = path.join(backupDir, `${unusedApp}_${Date.now()}`);
console.log(`Backing up '${unusedApp}' to ${backupPath}`);
fs.cpSync(appPath, backupPath, { recursive: true });
console.log(
`Removing existing app '${unusedApp}' as it is not configured.`,
);
fs.rmSync(appPath, { recursive: true, force: true });
});
} catch (error) {
console.error("Error during cleanup:", error);
process.exit(1);
}

// Clone or pull care apps
appsConfig.forEach((app) => {
const appDir = path.join(appsDir, app.package.split("/")[1]);
Expand Down
2 changes: 1 addition & 1 deletion scripts/sort-locales.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require("fs");

const file = "src/Locale/en.json";
const file = "public/locale/en.json";

const data = JSON.parse(fs.readFileSync(file, "utf8"));

Expand Down
13 changes: 13 additions & 0 deletions src/components/Common/UserAutocompleteFormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
mergeQueryOptions,
} from "@/Utils/utils";

import { Avatar } from "./Avatar";

type BaseProps = FormFieldBaseProps<UserBareMinimum> & {
placeholder?: string;
userType?: UserRole;
Expand Down Expand Up @@ -67,6 +69,16 @@ export default function UserAutocomplete(props: UserSearchProps) {
}
}, [loading, field.required, data?.results, props.noResultsError]);

const getAvatar = (option: UserBareMinimum) => {
return (
<Avatar
className="h-11 w-11 rounded-full"
name={formatName(option)}
imageUrl={option.read_profile_picture_url}
/>
);
};

return (
<FormField field={field}>
<Autocomplete
Expand All @@ -83,6 +95,7 @@ export default function UserAutocomplete(props: UserSearchProps) {
)}
optionLabel={formatName}
optionIcon={userOnlineDot}
optionImage={getAvatar}
optionDescription={(option) =>
`${option.user_type} - ${option.username}`
}
Expand Down
47 changes: 27 additions & 20 deletions src/components/Form/FormFields/Autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ComboboxOption,
ComboboxOptions,
} from "@headlessui/react";
import { useEffect, useState } from "react";
import { ReactNode, useEffect, useState } from "react";
import { useTranslation } from "react-i18next";

import CareIcon from "@/CAREUI/icons/CareIcon";
Expand All @@ -29,6 +29,7 @@ type AutocompleteFormFieldProps<T, V> = FormFieldBaseProps<V> & {
optionValue?: OptionCallback<T, V>;
optionDescription?: OptionCallback<T, string>;
optionIcon?: OptionCallback<T, React.ReactNode>;
optionImage?: OptionCallback<T, ReactNode | undefined>;
optionDisabled?: OptionCallback<T, boolean>;
minQueryLength?: number;
onQuery?: (query: string) => void;
Expand All @@ -55,6 +56,7 @@ const AutocompleteFormField = <T, V>(
placeholder={props.placeholder}
optionLabel={props.optionLabel}
optionIcon={props.optionIcon}
optionImage={props.optionImage}
optionValue={props.optionValue}
optionDescription={props.optionDescription}
optionDisabled={props.optionDisabled}
Expand All @@ -79,6 +81,7 @@ type AutocompleteProps<T, V = T> = {
placeholder?: string;
optionLabel: OptionCallback<T, string>;
optionIcon?: OptionCallback<T, React.ReactNode>;
optionImage?: OptionCallback<T, ReactNode | undefined>;
optionValue?: OptionCallback<T, V>;
optionDescription?: OptionCallback<T, React.ReactNode>;
optionDisabled?: OptionCallback<T, boolean>;
Expand All @@ -89,7 +92,6 @@ type AutocompleteProps<T, V = T> = {
isLoading?: boolean;
allowRawInput?: boolean;
error?: string;
avatar?: boolean;
} & (
| {
required?: false;
Expand Down Expand Up @@ -124,6 +126,7 @@ export const Autocomplete = <T, V>(props: AutocompleteProps<T, V>) => {
description,
search: label.toLowerCase(),
icon: props.optionIcon?.(option),
image: props.optionImage?.(option),
value: props.optionValue ? props.optionValue(option) : option,
disabled: props.optionDisabled?.(option),
};
Expand All @@ -143,6 +146,7 @@ export const Autocomplete = <T, V>(props: AutocompleteProps<T, V>) => {
description: undefined,
search: query.toLowerCase(),
icon: <CareIcon icon="l-plus" />,
image: undefined,
value: query,
disabled: undefined,
},
Expand Down Expand Up @@ -241,25 +245,28 @@ export const Autocomplete = <T, V>(props: AutocompleteProps<T, V>) => {
disabled={option.disabled}
>
{({ focus }) => (
<div className="flex flex-col">
<div className="flex justify-between">
<span>{option.label}</span>
<span>{option.icon}</span>
</div>
{option.description && (
<div
className={classNames(
"text-sm font-normal",
option.disabled
? "text-secondary-700"
: focus
? "text-primary-200"
: "text-secondary-700",
)}
>
{option.description}
<div className="flex flex-row gap-2">
{option?.image}
<div className="flex flex-grow flex-col">
<div className="flex justify-between">
<span>{option.label}</span>
<span>{option.icon}</span>
</div>
)}
{option.description && (
<div
className={classNames(
"text-sm font-normal",
option.disabled
? "text-secondary-700"
: focus
? "text-primary-200"
: "text-secondary-700",
)}
>
{option.description}
</div>
)}
</div>
</div>
)}
</ComboboxOption>
Expand Down

0 comments on commit b867242

Please sign in to comment.