diff --git a/.dockerignore b/.dockerignore index 8567a5b..62669bc 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,7 +2,6 @@ node_modules /.svelte-kit /package -/playwright-report .env .env.* .eslintcache diff --git a/.forgejo/workflows/ci.yaml b/.forgejo/workflows/ci.yaml index c286741..a7d881e 100644 --- a/.forgejo/workflows/ci.yaml +++ b/.forgejo/workflows/ci.yaml @@ -1,10 +1,6 @@ name: Visitenbuch CI on: push: - branches: - - "main" - tags: - - "v*" pull_request: jobs: @@ -24,6 +20,7 @@ jobs: CLIENT_REDIRECT_URIS: http://localhost:4173/auth/callback/keycloak CLIENT_LOGOUT_REDIRECT_URIS: http://localhost:4173/login?noAuto=1 ISSUER_HOST: oidc:3000 + env: DATABASE_URL: "postgresql://postgres:1234@postgres:5432/test?schema=public" TEST_DATABASE_URL: "postgresql://postgres:1234@postgres:5432/test?schema=public" @@ -32,32 +29,28 @@ jobs: steps: - name: ποΈ Checkout repository uses: actions/checkout@v4 - - name: π¦ pnpm install + - name: Test run: | - pnpm install - cp .env.test .env - - name: π§ lint - run: | - pnpm run check - pnpm run lint - - name: π§ͺ Unit test - run: pnpm run test:unit - - name: π§ͺ Integration test - run: | - npx prisma migrate reset --force - pnpm run test:integration - - name: π¨βπ¬ E2E test - id: e2etest - run: | - pnpm run build -l silent - npx playwright install chromium - pnpm run test:e2e - - name: π’ Upload E2E report - if: ${{ failure() && steps.e2etest.conclusion == 'failure' }} - uses: https://code.forgejo.org/forgejo/upload-artifact@v4 - with: - name: playwright-report - path: playwright-report + curl http://oidc:3000/.well-known/openid-configuration || sleep 1000 + # - name: π¦ pnpm install + # run: | + # pnpm install + # cp .env.test .env + # - name: π§ lint + # run: | + # npm run check + # npm run lint + # - name: π§ͺ Unit test + # run: npm run test:unit + # - name: π§ͺ Integration test + # run: | + # npx prisma migrate reset --force + # npm run test:integration + # - name: π¨βπ¬ E2E test + # run: | + # npx playwright install --with-deps + # npm run build + # npm run test:e2e release: runs-on: cimaster-latest @@ -68,12 +61,12 @@ jobs: - name: ποΈ Checkout repository uses: actions/checkout@v4 with: - fetch-depth: 0 # important to fetch tag logs + fetch-depth: 0 - name: π¦ pnpm install run: pnpm install - name: βοΈ Build web application - run: pnpm run build + run: npm run build - name: π Build docker image uses: https://code.thetadev.de/ThetaDev/action-kaniko@v1 with: diff --git a/.gitignore b/.gitignore index 2b7e811..ffc5dfa 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ node_modules /build /.svelte-kit /package -/playwright-report .env .eslintcache vite.config.js.timestamp-* diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6d1751c..24bca84 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,5 +13,4 @@ repos: entry: npx eslint args: - "--max-warnings=0" - - "--cache" files: \.(js|ts|svelte)$ diff --git a/CHANGELOG.md b/CHANGELOG.md index 0540fe4..879e1cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,61 +3,6 @@ All notable changes to this project will be documented in this file. -## [v0.3.5](https://code.thetadev.de/HSA/Visitenbuch/compare/v0.3.4..v0.3.5) - 2024-05-20 - -### π Features - -- Focus filter bar when pressing F - ([ad796dc](https://code.thetadev.de/HSA/Visitenbuch/commit/ad796dcb578b79b566559d1c22c99f0231a03251)) -- Add optional Keycloak endpoint config - ([d746e47](https://code.thetadev.de/HSA/Visitenbuch/commit/d746e4787d70080bbc22b37263bbfa695c1a7d72)) - -### π Bug Fixes - -- Dont create entry executions if entry is only postponed - ([34e54fa](https://code.thetadev.de/HSA/Visitenbuch/commit/34e54fa4afdf17e7258cbc5ccac5a3d094ee161b)) -- HumanDate capitalization - ([f4f03ab](https://code.thetadev.de/HSA/Visitenbuch/commit/f4f03ab4914f850b15acf7bb39da34b1abb587a7)) -- Filterbar does not exclude present filters from URL, text filters dont confirm when defocused - ([9ed5f15](https://code.thetadev.de/HSA/Visitenbuch/commit/9ed5f15b9ef237cc400b069928baeb920b2d3681)) -- [**breaking**] Ensure category, room and station names are unique - ([98c62ac](https://code.thetadev.de/HSA/Visitenbuch/commit/98c62ac4603fa6d7c97e1a439f613379db7a2587)) -- Allow multiple date filters - ([2a4bda7](https://code.thetadev.de/HSA/Visitenbuch/commit/2a4bda70c6cfd85b4a32989a2e19ba718cc7717e)) -- Add dumb-init to docker image - ([47f0a08](https://code.thetadev.de/HSA/Visitenbuch/commit/47f0a08ea3dbd8b1721a11c52b36c42ad56e8e29)) -- Remove test route - ([03f6c58](https://code.thetadev.de/HSA/Visitenbuch/commit/03f6c5848201eff02999c6b9323ec1515d68fd5a)) - -### βοΈ Miscellaneous Tasks - -- Remove unused zod-form-data dependency - ([882ae66](https://code.thetadev.de/HSA/Visitenbuch/commit/882ae66a6a137259388525df2c91b8e1ed924d86)) - - -## [v0.3.4](https://code.thetadev.de/HSA/Visitenbuch/compare/v0.3.3..v0.3.4) - 2024-05-16 - -### π Features - -- Select table entries on doubleclick - ([c6abf63](https://code.thetadev.de/HSA/Visitenbuch/commit/c6abf633f8ae5e9b562dda36f9f7ab4d6adcb4e1)) - -### π Bug Fixes - -- Escape HTML for licenses file - ([f76e7fd](https://code.thetadev.de/HSA/Visitenbuch/commit/f76e7fd97f62d9b41ecbabc3334c2c1876be253d)) -- Use btn-id class for all tables - ([d5e9a94](https://code.thetadev.de/HSA/Visitenbuch/commit/d5e9a9469f0c57939367141985a97d8404fd6fbe)) -- Avoid global state, use context for savedFilters - ([a4eebb9](https://code.thetadev.de/HSA/Visitenbuch/commit/a4eebb944f55da8e87cc899eebada0bd3fd37aa8)) -- Close autocomplete on defocus - ([4a3155c](https://code.thetadev.de/HSA/Visitenbuch/commit/4a3155c33aa354973d4e0ca3ffeab2b7fd442040)) -- Remove process.on hooks (not necessary) - ([cdb3446](https://code.thetadev.de/HSA/Visitenbuch/commit/cdb344609cde80084876faea9f80e7b26b01d0f2)) -- Autocomplete not closing on tab - ([88a5040](https://code.thetadev.de/HSA/Visitenbuch/commit/88a5040f9c4e19ae3efb5ad0894c8dc5b905a92e)) - - -## [v0.3.3](https://code.thetadev.de/HSA/Visitenbuch/compare/v0.3.2..v0.3.3) - 2024-05-14 - -### π Features - -- Add E2E testing - ([8d9b75c](https://code.thetadev.de/HSA/Visitenbuch/commit/8d9b75c5fd634ae547c2690a68957264a6d447e4)) -- Make page printable - ([04d9883](https://code.thetadev.de/HSA/Visitenbuch/commit/04d9883c9655379301e0c41cc55ebdaa90c68821)) - -### π Bug Fixes - -- Update ESLint config and fix lints - ([009729b](https://code.thetadev.de/HSA/Visitenbuch/commit/009729b877e4f050fa0d1159aaa86dd43d534621)) -- FilterList selection hides items from other FilterLists - ([cc1ebaf](https://code.thetadev.de/HSA/Visitenbuch/commit/cc1ebaff1a4573970f04dc44591ee7e9afb9a842)) - -### π§ͺ Testing - -- Use fixtures for E2E tests, fix wrong OIDC URL in CI - ([cbc7d65](https://code.thetadev.de/HSA/Visitenbuch/commit/cbc7d65103695565db64b4770cce71f5d37920b6)) - - ## [v0.3.2](https://code.thetadev.de/HSA/Visitenbuch/compare/v0.3.1..v0.3.2) - 2024-05-13 ### π Bug Fixes diff --git a/Dockerfile b/Dockerfile index f0631df..6adb62d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,8 +7,7 @@ COPY package.json pnpm-lock.yaml run/entrypoint.sh ./ COPY prisma ./prisma # Setup pnpm, install Prisma CLI (for generating client) and install dependencies -RUN apk add dumb-init && \ - npm config set update-notifier false && \ +RUN npm config set update-notifier false && \ corepack enable && \ pnpm i --prod && \ pnpm audit fix && \ diff --git a/README.md b/README.md index cc42fac..1f1a26e 100644 --- a/README.md +++ b/README.md @@ -4,34 +4,21 @@ for the university hospital in Augsburg ## Development -The project template was created using -[`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte). +The project template was created using [`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte). -Once you've created a project and installed dependencies with `npm install` (or -`pnpm install` or `yarn`), start a development server: +Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server: ```bash -pnpm run dev +npm run dev # or start the server and open the app in a new browser tab -pnpm run dev -- --open +npm run dev -- --open ``` -### Test environment - -Copy the `.env.example` file to `.env` to get access to the required configuration -variables. - -The project depends on a PostgreSQL database and an OIDC authentication server. You can -setup both using the `run/db_up.sh` script. This creates a new testing environment using -docker-compose and fills the test database with mock data. - -### Use the Pisma ORM - -If you apply changes to the database scheme, you have to create a new migration to apply -these changes to the database. +### Handle the prisma ORM ```bash +./run/db_up.sh # Start the docker container, create a new database and run migrations + insert test data npx prisma migrate dev --name my_migration --create-only # Create a new migration npx prisma migrate dev # Apply migrations to the database ``` @@ -41,20 +28,12 @@ npx prisma migrate dev # Apply migrations to the database To create a production version of your app: ```bash -pnpm run build +npm run build ``` You can preview the production build with `npm run preview`. -> To deploy your app, you may need to install an -> [adapter](https://kit.svelte.dev/docs/adapters) for your target environment. - -### Test - -```bash -pnpm test # Unit- und Integrationstests -pnpm test:e2e # End2End-Tests -``` +> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment. ### Release @@ -63,10 +42,3 @@ To release a new version, tun the release script with the new version as a param ```bash ./release.sh 1.0.0 ``` - -### Building docker image - -```bash -pnpm run build -docker build -t thetadev256/visitenbuch . -``` diff --git a/package.json b/package.json index 1bde82a..61fcd29 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "visitenbuch", - "version": "0.3.5", + "version": "0.3.2", "private": true, "license": "AGPL-3.0", "scripts": { @@ -28,7 +28,8 @@ "qs": "^6.12.1", "set-cookie-parser": "^2.6.0", "svelte-floating-ui": "^1.5.8", - "zod": "^3.23.8" + "zod": "^3.23.8", + "zod-form-data": "^2.0.2" }, "devDependencies": { "@faker-js/faker": "^8.4.1", diff --git a/playwright.config.js b/playwright.config.js index ed4ee46..afa7d21 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -1,21 +1,13 @@ import { defineConfig } from "@playwright/test"; -// eslint-disable-next-line no-undef -const CI = Boolean(process.env.CI); - export default defineConfig({ webServer: { command: "npm run preview -m test", port: 4173, - reuseExistingServer: !CI, + reuseExistingServer: true, }, testDir: "tests/e2e", + testMatch: /\.[jt]s$/, globalSetup: "tests/helpers/generate-mockdata.ts", outputDir: ".svelte-kit/test-results", - maxFailures: 0, - retries: CI ? 2 : 0, - reporter: CI ? [["line"], ["html"]] : "list", - use: { - trace: "on-first-retry", - }, }); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c90e8bb..8e977f6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -41,6 +41,9 @@ dependencies: zod: specifier: ^3.23.8 version: 3.23.8 + zod-form-data: + specifier: ^2.0.2 + version: 2.0.2(zod@3.23.8) devDependencies: '@faker-js/faker': @@ -5958,6 +5961,14 @@ packages: dev: true optional: true + /zod-form-data@2.0.2(zod@3.23.8): + resolution: {integrity: sha512-sKTi+k0fvkxdakD0V5rq+9WVJA3cuTQUfEmNqvHrTzPLvjfLmkkBLfR0ed3qOi9MScJXTHIDH/jUNnEJ3CBX4g==} + peerDependencies: + zod: '>= 3.11.0' + dependencies: + zod: 3.23.8 + dev: false + /zod-to-json-schema@3.23.0(zod@3.23.8): resolution: {integrity: sha512-az0uJ243PxsRIa2x1WmNE/pnuA05gUq/JB8Lwe1EDCCL/Fz9MgjYQ0fPlyc2Tcv6aF2ZA7WM5TWaRZVEFaAIag==} requiresBuild: true diff --git a/prisma/migrations/20240518143538_unique_cat_room_station/migration.sql b/prisma/migrations/20240518143538_unique_cat_room_station/migration.sql deleted file mode 100644 index 7686fa8..0000000 --- a/prisma/migrations/20240518143538_unique_cat_room_station/migration.sql +++ /dev/null @@ -1,16 +0,0 @@ -/* - Warnings: - - - A unique constraint covering the columns `[name]` on the table `categories` will be added. If there are existing duplicate values, this will fail. - - A unique constraint covering the columns `[name]` on the table `rooms` will be added. If there are existing duplicate values, this will fail. - - A unique constraint covering the columns `[name]` on the table `stations` will be added. If there are existing duplicate values, this will fail. - -*/ --- CreateIndex -CREATE UNIQUE INDEX "categories_name_key" ON "categories"("name"); - --- CreateIndex -CREATE UNIQUE INDEX "rooms_name_key" ON "rooms"("name"); - --- CreateIndex -CREATE UNIQUE INDEX "stations_name_key" ON "stations"("name"); diff --git a/prisma/schema.prisma b/prisma/schema.prisma index bfc2700..633705d 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -50,7 +50,7 @@ model User { // Hospital station model Station { id Int @id @default(autoincrement()) - name String @unique + name String Room Room[] hidden Boolean @default(false) @@ -60,7 +60,7 @@ model Station { // Hospital room model Room { id Int @id @default(autoincrement()) - name String @unique + name String station Station @relation(fields: [station_id], references: [id], onDelete: Restrict) station_id Int Patient Patient[] @@ -90,7 +90,7 @@ model Patient { // Entry category (e.g. Blood test, Exams, ...) model Category { id Int @id @default(autoincrement()) - name String @unique + name String color String? description String? EntryVersion EntryVersion[] diff --git a/run/entrypoint.sh b/run/entrypoint.sh index f7ebe95..c749cb0 100755 --- a/run/entrypoint.sh +++ b/run/entrypoint.sh @@ -1,4 +1,4 @@ -#!/usr/bin/dumb-init /bin/sh +#!/bin/sh set -e # Migrate database before starting server npx prisma migrate deploy diff --git a/src/app.html b/src/app.html index 50038b5..5f0dd88 100644 --- a/src/app.html +++ b/src/app.html @@ -1,5 +1,5 @@ - +
diff --git a/src/hooks.server.ts b/src/hooks.server.ts index 87c81a0..a7fddf5 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -31,3 +31,7 @@ export const handle = sequence( authorization, createTRPCHandle({ router, createContext }), ); + +// Allow server application to exit +process.on("SIGINT", () => process.exit()); // Ctrl+C +process.on("SIGTERM", () => process.exit()); // docker stop diff --git a/src/lib/components/filter/Autocomplete.svelte b/src/lib/components/filter/Autocomplete.svelte index 7a20f6d..f1a7885 100644 --- a/src/lib/components/filter/Autocomplete.svelte +++ b/src/lib/components/filter/Autocomplete.svelte @@ -166,14 +166,6 @@ if (opened) { onClose(kb); } - // select remaining item if autoselect is enabled - if (!selection) { - if (!noAutoselect1 && filteredItems.length === 1) { - selectListItem(filteredItems[0], true); - } else { - setInputValue(""); - } - } opened = false; } @@ -193,38 +185,43 @@ } function onKeyDown(e: KeyboardEvent): void { - switch (e.key) { - case "Tab": - close(); - break; - case "ArrowDown": + let { key } = e; + if (key === "Tab" && e.shiftKey) key = "ShiftTab"; + const fnmap: Record