Skip to content

Commit

Permalink
Merge pull request #28 from AtlasOfLivingAustralia/testing
Browse files Browse the repository at this point in the history
Parity with testing
  • Loading branch information
jack-brinkman authored Dec 13, 2024
2 parents 1d824fd + 7420f19 commit f14757f
Show file tree
Hide file tree
Showing 18 changed files with 78 additions and 72 deletions.
24 changes: 8 additions & 16 deletions .github/workflows/upload-pwa-builds.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: Build BioCollect PWA Artifacts

on:
release:
types: [created]
push:
branches:
- 'feature/**'
- 'main'
- 'testing'

jobs:
build-and-attach:
Expand All @@ -26,34 +26,26 @@ jobs:
- name: Build app for CICD
run: npm run build:cicd

- name: Upload build assets
if: github.event_name == 'release'
run: gh release upload "${{ github.event.release.tag_name }}" ./dist/app-production.zip ./dist/app-staging.zip ./dist/app-testing.zip ./dist/app-development.zip --clobber

- name: Upload production artifact
if: github.event_name == 'push'
uses: actions/upload-artifact@v4
with:
name: app-production
path: dist/app-production.zip
name: app-prod
path: dist/app-prod.zip

- name: Upload staging artifact
if: github.event_name == 'push'
uses: actions/upload-artifact@v4
with:
name: app-staging
path: dist/app-staging.zip

- name: Upload testing artifact
if: github.event_name == 'push'
uses: actions/upload-artifact@v4
with:
name: app-testing
path: dist/app-testing.zip
name: app-test
path: dist/app-test.zip

- name: Upload development artifact
if: github.event_name == 'push'
uses: actions/upload-artifact@v4
with:
name: app-development
path: dist/app-development.zip
name: app-dev
path: dist/app-dev.zip
11 changes: 6 additions & 5 deletions cicd/build.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#!/usr/bin/env bash

tsc && for mode in production staging testing development; do
tsc && for mode in prod staging test dev; do
outDir="./dist/app-$mode"
zipFile="./dist/app-$mode.zip"


# If the mode is production, you may not need to specify the --mode flag
if [ "$mode" = "production" ]; then
if [ "$mode" = "prod" ]; then
vite build --outDir "$outDir"
else
vite build --mode "$mode" --outDir "$outDir"
fi

zip -r "$zipFile" "$outDir"
cd "./dist/app-$mode"
zip -r "../app-$mode.zip" . *
cd ../..
done
6 changes: 3 additions & 3 deletions config/.env.development → config/.env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
# VITE_AUTH_CLIENT_ID=7hrtrc4d6q4v6kkficnu7l43ob
VITE_AUTH_AUTHORITY=https://auth.ala.org.au/cas/oidc/.well-known
VITE_AUTH_CLIENT_ID=biocollect-pwa-prod
VITE_AUTH_REDIRECT_URI=https://biocollect-dev.ala.org.au/pwa-mobile
# VITE_AUTH_REDIRECT_URI=http://localhost:5173/pwa-mobile
VITE_AUTH_REDIRECT_URI=https://biocollect-dev.ala.org.au/mobile-app
# VITE_AUTH_END_SESSION_URI=https://auth-secure.auth.ap-southeast-2.amazoncognito.com/logout
# VITE_AUTH_SCOPE="ala"
# VITE_AUTH_SCOPE="email openid profile ala/attrs ala/roles"
VITE_AUTH_SCOPE="openid profile ala roles"
VITE_AUTH_TOKEN_REFRESH_INTERVAL=300000

# API
Expand Down
2 changes: 1 addition & 1 deletion config/.env.functionaltest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Authentication
VITE_AUTH_AUTHORITY=http://localhost:8018/cas/oidc/.well-known
VITE_AUTH_CLIENT_ID=oidcId
VITE_AUTH_REDIRECT_URI=http://localhost:5173/pwa-mobile
VITE_AUTH_REDIRECT_URI=http://localhost:5173/mobile-app
# VITE_AUTH_END_SESSION_URI=ENTER-HERE
VITE_AUTH_SCOPE="openid profile ala roles"
VITE_AUTH_TOKEN_REFRESH_INTERVAL=300000
Expand Down
4 changes: 2 additions & 2 deletions config/.env.production → config/.env.prod
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Authentication
VITE_AUTH_AUTHORITY=https://auth.ala.org.au/cas/oidc/.well-known
VITE_AUTH_CLIENT_ID=biocollect-pwa-prod
VITE_AUTH_REDIRECT_URI=https://biocollect-dev.ala.org.au/pwa-mobile
VITE_AUTH_REDIRECT_URI=https://biocollect.ala.org.au/mobile-app
# VITE_AUTH_END_SESSION_URI=ENTER-HERE
VITE_AUTH_SCOPE="openid profile ala roles"
VITE_AUTH_TOKEN_REFRESH_INTERVAL=300000

# API
VITE_API_TIMEOUT=0
VITE_API_BIOCOLLECT=https://biocollect-dev.ala.org.au
VITE_API_BIOCOLLECT=https://biocollect.ala.org.au
VITE_API_BIOCOLLECT_HUB=acsa
10 changes: 5 additions & 5 deletions config/.env.staging
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Authentication
VITE_AUTH_AUTHORITY=ENTER-HERE
VITE_AUTH_CLIENT_ID=ENTER-HERE
VITE_AUTH_REDIRECT_URI=ENTER-HERE
VITE_AUTH_END_SESSION_URI=ENTER-HERE
VITE_AUTH_SCOPE=ENTER-HERE
VITE_AUTH_AUTHORITY=https://auth.ala.org.au/cas/oidc/.well-known
VITE_AUTH_CLIENT_ID=biocollect-pwa-prod
VITE_AUTH_REDIRECT_URI=https://biocollect-staging.ala.org.au/mobile-app
# VITE_AUTH_END_SESSION_URI=ENTER-HERE
VITE_AUTH_SCOPE="openid profile ala roles"
VITE_AUTH_TOKEN_REFRESH_INTERVAL=300000

# API
Expand Down
14 changes: 14 additions & 0 deletions config/.env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Authentication
VITE_AUTH_AUTHORITY=https://cognito-idp.ap-southeast-2.amazonaws.com/ap-southeast-2_OOXU9GW39
VITE_AUTH_CLIENT_ID=7hrtrc4d6q4v6kkficnu7l43ob
# VITE_AUTH_AUTHORITY=https://auth-test.ala.org.au/cas/oidc/.well-known
# VITE_AUTH_CLIENT_ID=biocollect-pwa-test
VITE_AUTH_REDIRECT_URI=https://biocollect-test.ala.org.au/mobile-app
VITE_AUTH_END_SESSION_URI=https://auth-secure.auth.ap-southeast-2.amazoncognito.com/logout
VITE_AUTH_SCOPE="email openid profile ala/attrs ala/roles"
VITE_AUTH_TOKEN_REFRESH_INTERVAL=300000

# API
VITE_API_TIMEOUT=10000
VITE_API_BIOCOLLECT=https://biocollect-test.ala.org.au
VITE_API_BIOCOLLECT_HUB=acsa
14 changes: 0 additions & 14 deletions config/.env.testing

This file was deleted.

6 changes: 3 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
<link
rel="apple-touch-icon"
sizes="180x180"
href="/icon/light/apple-touch-icon.png"
href="/icon/dark/apple-touch-icon.png"
/>
<link
rel="icon"
type="image/png"
sizes="32x32"
href="/icon/light/32x32.png"
href="/icon/dark/32x32.png"
/>
<link
rel="icon"
type="image/png"
sizes="16x16"
href="/icon/light/16x16.png"
href="/icon/dark/16x16.png"
/>
<link rel="stylesheet" href="/index.css" />
<meta
Expand Down
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite --host",
"dev": "vite --host --mode dev",
"run:functionaltest": "vite --host --mode functionaltest",
"build:production": "tsc && vite build",
"build:staging": "tsc && vite build --mode staging",
"build:testing": "tsc && vite build --mode testing",
"build:development": "tsc && vite build --mode development",
"build:functionaltest": "tsc && vite build --mode functionaltest",
"build:cicd": "./cicd/build.sh",
"lint": "eslint ./src",
Expand Down
2 changes: 1 addition & 1 deletion src/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default function Routes() {
},
],
{
basename: '/pwa-mobile',
basename: '/mobile-app',
}
)
);
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/api/endpoints/biocollect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const filterActiveSurveys = (surveys: BioCollectSurvey[]) =>
({ startDate, endDate, published }) =>
new Date(startDate).getTime() <= Date.now() &&
(!endDate || new Date(endDate).getTime() >= Date.now()) &&
published
(published !== undefined ? published : true)
) || [];

const formatProjects = (projects: BioCollectProject[]) => {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/api/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const APIProvider = (props: PropsWithChildren<{}>): ReactElement => {
} else {
delete axios.defaults.headers['Authorization'];
}
}, [auth.isAuthenticated]);
}, [auth.isAuthenticated, auth.user, auth]);

return (
<APIContext.Provider
Expand Down
25 changes: 17 additions & 8 deletions src/layout/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
UnstyledButton,
Badge,
Loader,
ThemeIcon,
} from '@mantine/core';
import { Link } from 'react-router-dom';
import { useAuth } from 'react-oidc-context';
Expand All @@ -18,6 +19,8 @@ import {
IconFileUpload,
IconUser,
IconSettings,
IconPlugConnected,
IconPlugConnectedX,
} from '@tabler/icons-react';
import jwtDecode from 'jwt-decode';

Expand Down Expand Up @@ -74,11 +77,17 @@ export default function Header() {
}
/>
</Link>
<Group spacing="xs">
<Badge radius="sm" color={onLine ? 'green' : 'red'}>
{onLine ? 'online' : 'offline'}
</Badge>
</Group>
<ThemeIcon
color={onLine ? 'green' : 'red'}
radius="lg"
variant="light"
>
{onLine ? (
<IconPlugConnected size="1rem" />
) : (
<IconPlugConnectedX size="1rem" />
)}
</ThemeIcon>
</Group>
<Group>
<InstallButton />
Expand All @@ -94,7 +103,7 @@ export default function Header() {
const { user, isAuthenticated } = auth;

if (!isAuthenticated) return <Loader size="sm" />;

// Use the given name from the profile field, otherwise fallback to the JWT
const given_name =
user?.profile.given_name ||
Expand Down Expand Up @@ -152,14 +161,14 @@ export default function Header() {
<Menu.Divider />
<Menu.Item
component="a"
href="https://support.ala.org.au/support/solutions/6000139493"
href="https://support.ala.org.au/support/solutions/articles/6000276298-biocollect-pwa-app/"
target="_blank"
icon={<IconQuestionMark />}
>
Help
</Menu.Item>
<Menu.Item
id='signOut'
id="signOut"
onClick={signOut}
icon={<IconLogout />}
disabled={auth.isLoading || !onLine}
Expand Down
2 changes: 1 addition & 1 deletion src/layout/InstallButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export function InstallButton() {
)
}
>
{install ? 'Install' : 'Installation Instructions'}
{install ? 'Install' : 'Install Instructions'}
</Button>
<Modal
fullScreen={mobile}
Expand Down
16 changes: 12 additions & 4 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,21 @@ import App from './App';
// Use localStorage for user persistence
const userStore = new WebStorageStateStore({ store: localStorage });

const authConfig = {
client_id: import.meta.env.VITE_AUTH_CLIENT_ID,
redirect_uri: import.meta.env.VITE_AUTH_REDIRECT_URI,
authority: import.meta.env.VITE_AUTH_AUTHORITY,
scope: import.meta.env.VITE_AUTH_SCOPE,
}

if (import.meta.env.DEV) {
console.log('Auth Config', authConfig);
}

function Main() {
return (
<AuthProvider
client_id={import.meta.env.VITE_AUTH_CLIENT_ID}
redirect_uri={import.meta.env.VITE_AUTH_REDIRECT_URI}
authority={import.meta.env.VITE_AUTH_AUTHORITY}
scope={import.meta.env.VITE_AUTH_SCOPE}
{...authConfig}
userStore={userStore}
onSigninCallback={(user) => {
const params = new URLSearchParams(window.location.search);
Expand Down
2 changes: 1 addition & 1 deletion src/views/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function Home() {
(getNumber('page', 1, params) - 1) * paramMax,
paramMax,
getString('pSort', 'dateCreatedSort', params),
getBool('isUserPage', false, params),
getBool('isUserPage', true, params),
getString('search', undefined, params),
getBool('offline', !onLine, params)
);
Expand Down
2 changes: 1 addition & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const pwaOptions: Partial<VitePWAOptions> = {

// https://vitejs.dev/config/
export default defineConfig({
base: '/pwa-mobile',
base: '/mobile-app',
plugins: [react(), tsconfigPaths(), visualizer() as any, VitePWA(pwaOptions)],
envDir: './config',
});

0 comments on commit f14757f

Please sign in to comment.