Skip to content
This repository has been archived by the owner on Oct 26, 2023. It is now read-only.

Migrates to using react-router 6.4 and react-query to manage asynchronous state #22

Merged
merged 36 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
cea588b
feat: adds react-query and orval to the toolkit REFS #21
devraj Oct 29, 2022
ad03bee
docs: initil thoughts on how router, query will work together
devraj Oct 30, 2022
c1b503c
fix: syntax
devraj Oct 30, 2022
860df93
docs: update notes on operation ids
devraj Oct 30, 2022
e4f0ad3
chore: removes autorest and otc clients
devraj Oct 30, 2022
9573028
refactor: drops autorest and otc generators (REFS #21)
devraj Oct 30, 2022
e5e125e
refactor: drops api calls
devraj Oct 31, 2022
9c8ef36
docs: explains the motivation behind react-query
devraj Oct 31, 2022
1f48413
feat: adds playwright based e2e testing
devraj Oct 31, 2022
3be9cb4
refactor: uses react-query and react-router
devraj Oct 31, 2022
c04af14
docs: accompaying docs from 3be9cb4
devraj Oct 31, 2022
b28c553
refactor: openapi json location
devraj Oct 31, 2022
f612c4e
refactor: orval configuration to generate api clients
devraj Oct 31, 2022
3cbe158
feat: orval api client for react-query
devraj Oct 31, 2022
3724948
docs: describes the orval setup
devraj Oct 31, 2022
a4e6842
fix: syntax
devraj Oct 31, 2022
4e4b094
docs: fixes syntax and typos
devraj Oct 31, 2022
006d24f
chore: adds missing developer packages
devraj Oct 31, 2022
1cf5b3d
chore: adds types for helmet
devraj Oct 31, 2022
33ee0f1
chore: adds types for helmet
devraj Oct 31, 2022
c196429
feat: adds commentary
devraj Oct 31, 2022
b7a5ffc
docs: adds notes around helmet
devraj Oct 31, 2022
d0399ab
chore: generate orval based api client
devraj Nov 3, 2022
98be5dd
chore: regen openapi json
devraj Nov 3, 2022
0f6e6f5
docs: adds todo item for storybook
devraj Nov 3, 2022
9a3ba28
refactor: orval now reading from web server
devraj Nov 4, 2022
acbc1a7
refactor: user api based on crud operations
devraj Nov 4, 2022
3fb5f9c
refactor: package names and casing
devraj Nov 4, 2022
e8cf0ec
refactor: adds admin panel for user records
devraj Nov 7, 2022
dd2d56f
chore: update dependencies
devraj Nov 7, 2022
cfd79b3
chore: regenerate api client
devraj Nov 8, 2022
e0075ef
refactor: router configuration
devraj Nov 8, 2022
5175c00
docs: notes on react-query
devraj Nov 8, 2022
88acb5b
refactor: edit users via the cache
devraj Nov 8, 2022
97fa18e
feat: adds route to add a new user
devraj Nov 8, 2022
788cf84
refactor: delete event wire up
devraj Nov 8, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Playwright Tests
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- name: Install dependencies
run: yarn
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
run: yarn playwright test
- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*
/test-results/
/playwright-report/
/playwright/.cache/
266 changes: 204 additions & 62 deletions README.md

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions orval.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
labs: {
output: {
mode: 'tags-split',
target: 'src/api/labs.ts',
schemas: 'src/api/models',
client: 'react-query',
mock: true,
},
input: {
target: 'http://localhost:8000/openapi.json',
},
},
};
32 changes: 18 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,27 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@headlessui/react": "^1.7.3",
"@heroicons/react": "^2.0.12",
"@stripe/react-stripe-js": "^1.14.1",
"@stripe/stripe-js": "^1.42.0",
"@headlessui/react": "^1.7.4",
"@heroicons/react": "^2.0.13",
"@stripe/react-stripe-js": "^1.14.2",
"@stripe/stripe-js": "^1.42.1",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^14.4.2",
"@types/jest": "^29.2.0",
"@types/node": "^18.11.7",
"@types/react": "^18.0.24",
"@types/jest": "^29.2.2",
"@types/node": "^18.11.9",
"@types/react": "^18.0.25",
"@types/react-dom": "^18.0.8",
"axios": "^1.1.3",
"http-proxy-middleware": "^2.0.6",
"i18next": "^22.0.4",
"labsApi": "file:./src/api/ar",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-helmet": "^6.1.0",
"react-hook-form": "^7.38.0",
"react-hook-form": "^7.39.1",
"react-i18next": "^12.0.0",
"react-router-dom": "^6.4.2",
"react-query": "^3.39.2",
"react-router-dom": "^6.4.3",
"react-scripts": "5.0.1",
"typescript": "^4.8.4",
"web-vitals": "^3.0.4"
Expand All @@ -32,9 +33,8 @@
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"fetch-openapi": "curl https://localhost:3000/api/openapi.json -o src/api/openapi.json",
"generate-ar": "autorest --typescript --input-file=src/api/openapi.json --output-folder=src/api/ar",
"generate-otc": "openapi --input http://localhost:8000/openapi.json --output src/api/otc --name LabsApiClient",
"fetch-openapi": "curl https://localhost:3000/api/openapi.json -o openapi.json",
"codegen": "orval",
"sync": "export $(cat .env) && s3cmd --access_key=$ACCESS_KEY --secret_key=$SECRET_KEY --host=$BUCKET_REGION_FQDN --host-bucket=$BUCKET_FQDN sync --no-mime-magic --acl-public --delete-removed --delete-after build/* s3://$BUCKET_NAME/"
},
"eslintConfig": {
Expand All @@ -56,9 +56,13 @@
]
},
"devDependencies": {
"@faker-js/faker": "^7.6.0",
"@playwright/test": "^1.27.1",
"@types/react-helmet": "^6.1.5",
"autoprefixer": "^10.4.13",
"msw": "^0.47.4",
"openapi-typescript-codegen": "^0.23.0",
"postcss": "^8.4.18",
"tailwindcss": "^3.2.1"
"tailwindcss": "^3.2.2"
}
}
107 changes: 107 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import type { PlaywrightTestConfig } from '@playwright/test';
import { devices } from '@playwright/test';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();

/**
* See https://playwright.dev/docs/test-configuration.
*/
const config: PlaywrightTestConfig = {
testDir: './tests',
/* Maximum time one test can run for. */
timeout: 30 * 1000,
expect: {
/**
* Maximum time expect() should wait for the condition to be met.
* For example in `await expect(locator).toHaveText();`
*/
timeout: 5000
},
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
actionTimeout: 0,
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://localhost:3000',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},

/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: {
...devices['Desktop Chrome'],
},
},

{
name: 'firefox',
use: {
...devices['Desktop Firefox'],
},
},

{
name: 'webkit',
use: {
...devices['Desktop Safari'],
},
},

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: {
// ...devices['Pixel 5'],
// },
// },
// {
// name: 'Mobile Safari',
// use: {
// ...devices['iPhone 12'],
// },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: {
// channel: 'msedge',
// },
// },
// {
// name: 'Google Chrome',
// use: {
// channel: 'chrome',
// },
// },
],

/* Folder for test artifacts such as screenshots, videos, traces, etc. */
// outputDir: 'test-results/',

/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// port: 3000,
// },
};

export default config;
32 changes: 8 additions & 24 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,21 @@
import React from 'react';
import { Link as RouterLink } from 'react-router-dom';
import { LabsApiClient } from 'api/otc';
// TODO: see if we can import this as a module
import { LabsApi } from 'api/ar/src';
import AnomalyLogo from 'assets/icon-anomaly.png';

function App() {
import { Helmet } from 'react-helmet';

// OTC client demo
const otcClient = new LabsApiClient();
// Autoreset client demo
const labsApi: LabsApi = new LabsApi();
import AnomalyLogo from 'assets/icon-anomaly.png';

const otcCallMe = async () => {
otcClient.auth.getMeAuthMeGet().then(res => {
console.log(res);
}).catch(err => {
console.log(err);
});
};

const arCallme = async () => {
labsApi.get.meAuthMeGet().then(res => {
console.log(res);
}).catch(err => {
console.log(err);
});
};
function App() {

return (
<div className="flex flex-col justify-center w-screen h-screen p-20 font-bold text-black app">
<Helmet>
<title>Welcome to labs</title>
<meta name="description" content="Welcome to labs" />
</Helmet>
<img
src={AnomalyLogo}
alt="Anomaly Logo"
width={40}
height={40}/>
<h1 className="my-4 text-3xl font-bold">Anomaly Labs</h1>
Expand Down
46 changes: 0 additions & 46 deletions src/api/ar/README.md

This file was deleted.

18 changes: 0 additions & 18 deletions src/api/ar/api-extractor.json

This file was deleted.

Loading