Skip to content

Commit

Permalink
Merge remote-tracking branch 'fgp/develop' into issues/9308/unnecessa…
Browse files Browse the repository at this point in the history
…ryAPIcallsAndRerenders
  • Loading branch information
i0am0arunava committed Dec 5, 2024
2 parents 4cc9892 + a24b9ca commit 5971304
Show file tree
Hide file tree
Showing 266 changed files with 10,446 additions and 10,318 deletions.
42 changes: 27 additions & 15 deletions .cursorrules
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
Care is a React Typescript Project, built with Vite and styled with TailwindCSS.
You are an expert in TypeScript, React, Shadcn UI, Tailwind.

Care uses a Plugin Architecture. Apps are installed in /apps.
Key Principles

Care uses a custom useQuery hook to fetch data from the API. APIs are defined in the api.tsx file
- Write concise, technical TypeScript code with accurate examples.
- Use functional and declarative programming patterns; avoid classes.
- Prefer iteration and modularization over code duplication.
- Use descriptive variable names with auxiliary verbs (e.g., isLoading, hasError).

Here's an example of how to use the useQuery hook to fetch data from the API:
Naming Conventions

```
useQuery from "@/common/hooks/useQuery";
const { data, loading, error } = useQuery(routes.getFacilityUsers, {
facility_id: "1",
});
- Use lowercase with dashes for directories (e.g., components/auth-wizard).
- Favor named exports for components.

request from "@/common/utils/request";
const { res } = await request(routes.partialUpdateAsset, {
pathParams: { external_id: assetId },
body: data,
});
```
TypeScript Usage

- Use TypeScript for all code; prefer interfaces over types.
- Avoid enums; use maps instead.
- Use functional components with TypeScript interfaces.

Syntax and Formatting

- Use the "function" keyword for pure functions.
- Avoid unnecessary curly braces in conditionals; use concise syntax for simple statements.
- Use declarative JSX.

UI and Styling

- Use Shadcn UI, Radix, and Tailwind for components and styling.
- Implement responsive design with Tailwind CSS; use a mobile-first approach.

General Guidelines

- Care uses a custom useQuery hook to fetch data from the API. (Docs @ /Utils/request/useQuery)
- APIs are defined in the api.tsx file.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// README at: https://github.com/devcontainers/templates/tree/main/src/javascript-node
{
"name": "care_fe",
"image": "mcr.microsoft.com/devcontainers/javascript-node:1-18-bullseye",
"image": "mcr.microsoft.com/devcontainers/javascript-node:1-22-bookworm",
"features": {
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {
"moby": true,
Expand Down
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ ESLINT_NO_DEV_ERRORS=true
CARE_CDN_URL="https://egov-s3-facility-10bedicu.s3.amazonaws.com https://egov-s3-patient-data-10bedicu.s3.amazonaws.com http://localhost:4566"
REACT_ALLOWED_LOCALES="en,hi,ta,ml,mr,kn"

REACT_ENABLED_APPS=""
REACT_ENABLED_APPS=""
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
2 changes: 1 addition & 1 deletion .github/workflows/auto-testing-label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
}
if (isChangesRequired) {
await github.issues.createComment({
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/cypress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ jobs:
containers: [1, 2, 3, 4]
env:
REACT_CARE_API_URL: http://localhost:9000
REACT_ENABLED_APPS: "ohcnetwork/care_hcx_fe@main,ohcnetwork/care_abdm_fe@main"
REACT_ENABLE_HCX: true
REACT_ENABLE_ABDM: true
steps:
- name: Checkout 📥
uses: actions/checkout@v3
Expand Down Expand Up @@ -114,7 +117,6 @@ jobs:
group: "UI-Chrome"
env:
CYPRESS_SPLIT_TESTS: "true"
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_OPTIONS: --max_old_space_size=4096
COMMIT_INFO_MESSAGE: ${{github.event.pull_request.title}}
Expand All @@ -131,7 +133,7 @@ jobs:

- name: Upload cypress videos 📹
uses: actions/upload-artifact@v3
if: steps.pr_origin.outputs.is_forked == 'true'
if: ${{ failure() && steps.pr_origin.outputs.is_forked == 'true' }}
with:
name: cypress-videos
path: cypress/videos
path: cypress/videos
88 changes: 88 additions & 0 deletions .github/workflows/notify-non-core-qn.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Notify Core Team on Non-Core Questions

on:
issue_comment:
types: [created]

permissions:
issues: write
pull-requests: write

jobs:
notify_core_team:
runs-on: ubuntu-latest
env:
ALLOWED_USERNAMES: ${{ vars.ALLOWED_USERNAMES || '' }}
QUESTION_KEYWORDS: ${{ vars.QUESTION_KEYWORDS || '' }}
QUESTION_LABELS: ${{ vars.QUESTION_LABELS || '' }}
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK || '' }}

steps:
- name: Check and Notify
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const isOrgMember = (commenter, allowedUsers) =>
allowedUsers.split(',').map(u => u.trim()).includes(commenter);
const containsQuestionKeywords = (text, keywords) =>
keywords.split(',').map(k => k.trim()).some(keyword =>
text.toLowerCase().includes(keyword.toLowerCase())
);
const addLabelsToIssue = async (github, context, labelsString) => {
const labels = labelsString.split(',').map(label => label.trim()).filter(Boolean);
if (labels.length > 0) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.issue.number,
labels: labels
});
}
};
const sendSlackNotification = async (webhook, commentUrl) => {
const payload = { commentUrl };
const response = await fetch(webhook, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
if (!response.ok) {
throw new Error(`Slack notification failed with status: ${response.status}`);
}
};
const isBot = async (github, commenter) => {
try {
const { data: user } = await github.rest.users.getByUsername({ username: commenter });
return user.type === 'Bot';
} catch {
return false;
}
};
const commenter = context.payload.comment.user.login;
const allowedUsers = process.env.ALLOWED_USERNAMES;
const keywords = process.env.QUESTION_KEYWORDS;
const labels = process.env.QUESTION_LABELS;
const webhook = process.env.SLACK_WEBHOOK;
if (await isBot(github, commenter)) return;
if (allowedUsers && !isOrgMember(commenter, allowedUsers)) {
const commentBody = context.payload.comment.body.trim();
const filteredCommentBody = commentBody.split('\n').filter(line => !line.startsWith('>')).join('\n');
if (keywords && containsQuestionKeywords(filteredCommentBody, keywords)) {
if (labels) {
await addLabelsToIssue(github, context, labels);
}
if (webhook) {
const commentUrl = context.payload.comment.html_url;
await sendSlackNotification(webhook, commentUrl);
}
}
}
26 changes: 10 additions & 16 deletions .github/workflows/thank-you.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,20 @@ jobs:
uses: actions/[email protected]
with:
script: |
const thankyouNote = 'Your efforts have helped advance digital healthcare and TeleICU systems. :rocket: Thank you for taking the time out to make CARE better. We hope you continue to innovate and contribute; your impact is immense! :raised_hands:'
const thankyouNote = 'Your efforts have helped advance digital healthcare and TeleICU systems. :rocket: Thank you for taking the time out to make CARE better. We hope you continue to innovate and contribute; your impact is immense! :raised_hands:';
const options = {
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
}
};
const result = await github.rest.issues.get({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
})
const { assignees, user } = result.data
const { data : { assignees, user } } = await github.rest.issues.get(options);
const assignees_tagged = assignees.map((user) => '@' + user.login).join(' ')
const owner_tagged = '@' + user.login
const taggedUsers = [...new Set(
assignees.map(u => "@"+u.login).concat("@"+user.login)
)].join(" ")
if (assignees.length == 0) {
await github.rest.issues.createComment({ ...options, body: `${owner_tagged} ${thankyouNote}` })
} else {
await github.rest.issues.createComment({ ...options, body: `${assignees_tagged} ${owner_tagged} ${thankyouNote}` })
}
await github.rest.issues.createComment({
...options,
body: `${taggedUsers} ${thankyouNote}`
});
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/*
36 changes: 0 additions & 36 deletions .husky/_/husky.sh

This file was deleted.

3 changes: 0 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v20
v22
1 change: 0 additions & 1 deletion .nvmrc

This file was deleted.

5 changes: 1 addition & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
#build-stage
FROM --platform=$BUILDPLATFORM node:20-buster-slim as build-stage
FROM --platform=$BUILDPLATFORM node:22-bookworm-slim as build-stage

WORKDIR /app

ENV NODE_OPTIONS="--max-old-space-size=4096"

RUN apt-get update && apt-get install -y git

RUN if [ "$(uname -m)" = "aarch64" ] || [ "$(uname -m)" = "arm64" ]; then apt-get install -y python3-dev make g++; fi


COPY package.json package-lock.json ./

RUN npm install
Expand Down
5 changes: 3 additions & 2 deletions crowdin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
files:
- source: /src/Locale/en/*.json
translation: /src/Locale/%two_letters_code%/%original_file_name%
- source: /public/locale/{{lang}}.json
translation: /public/locale/%two_letters_code%/%original_file_name%
bundles:
- 2

5 changes: 4 additions & 1 deletion cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { defineConfig } from "cypress";
import cypressSplit from "cypress-split";
import * as dotenv from "dotenv";
import fs from "fs";

dotenv.config();

export default defineConfig({
projectId: "wf7d2m",
defaultCommandTimeout: 10000,
Expand Down Expand Up @@ -32,7 +35,7 @@ export default defineConfig({
requestTimeout: 15000,
},
env: {
API_URL: process.env.REACT_CARE_API_URL ?? "http://localhost:9000",
API_URL: process.env.REACT_CARE_API_URL,
ENABLE_HCX: process.env.REACT_ENABLE_HCX ?? false,
},
});
Loading

0 comments on commit 5971304

Please sign in to comment.