Skip to content

Commit 1b7ca3a

Browse files
committed
Merged Conflict
2 parents 671aabf + 48dd9ff commit 1b7ca3a

File tree

116 files changed

+3139
-923
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+3139
-923
lines changed

.env.example

Lines changed: 0 additions & 7 deletions
This file was deleted.

.github/workflows/deploy-beta-testing.yml

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ jobs:
3030
working-directory: packages/design-system
3131
run: npm run build
3232

33-
- name: Create and populate .env file
33+
- name: Build with base path
34+
run: npm run build -- --base=/spa
35+
36+
- name: Override runtime config.js for BETA
3437
env:
3538
DATAVERSE_BACKEND_URL: ${{ secrets.BETA_DATAVERSE_BACKEND_URL }}
3639
OIDC_CLIENT_ID: ${{ secrets.BETA_OIDC_CLIENT_ID }}
@@ -39,18 +42,26 @@ jobs:
3942
OIDC_LOGOUT_ENDPOINT: ${{ secrets.BETA_OIDC_LOGOUT_ENDPOINT }}
4043
OIDC_STORAGE_KEY_PREFIX: ${{ secrets.BETA_OIDC_STORAGE_KEY_PREFIX }}
4144
run: |
42-
touch .env
43-
echo VITE_DATAVERSE_BACKEND_URL="$DATAVERSE_BACKEND_URL" >> .env
44-
echo VITE_OIDC_CLIENT_ID="$OIDC_CLIENT_ID" >> .env
45-
echo VITE_OIDC_AUTHORIZATION_ENDPOINT="$OIDC_AUTHORIZATION_ENDPOINT" >> .env
46-
echo VITE_OIDC_TOKEN_ENDPOINT="$OIDC_TOKEN_ENDPOINT" >> .env
47-
echo VITE_OIDC_LOGOUT_ENDPOINT="$OIDC_LOGOUT_ENDPOINT" >> .env
48-
echo VITE_OIDC_STORAGE_KEY_PREFIX="$OIDC_STORAGE_KEY_PREFIX" >> .env
45+
mkdir -p ./dist
46+
cat > ./dist/config.js <<EOF
47+
window.__APP_CONFIG__ = {
48+
backendUrl: "${DATAVERSE_BACKEND_URL}",
49+
oidc: {
50+
clientId: "${OIDC_CLIENT_ID}",
51+
authorizationEndpoint: "${OIDC_AUTHORIZATION_ENDPOINT}",
52+
tokenEndpoint: "${OIDC_TOKEN_ENDPOINT}",
53+
logoutEndpoint: "${OIDC_LOGOUT_ENDPOINT}",
54+
localStorageKeyPrefix: "${OIDC_STORAGE_KEY_PREFIX}"
55+
},
56+
languages: [
57+
{ code: 'en', name: 'English' },
58+
{ code: 'es', name: 'Español' }
59+
],
60+
defaultLanguage: 'en'
61+
}
62+
EOF
4963
shell: bash
5064

51-
- name: Build with base path
52-
run: npm run build -- --base=/spa
53-
5465
- uses: actions/upload-artifact@v4
5566
with:
5667
name: built-site

.github/workflows/deploy.yml

Lines changed: 62 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ jobs:
4141
working-directory: packages/design-system
4242
run: npm run build
4343

44-
# For BETA environment
45-
- name: Create and populate .env file for BETA
44+
- name: Build with base path
45+
run: npm run build -- --base=/${{ github.event.inputs.basepath }}
46+
47+
- name: Override runtime config.js for BETA
4648
if: ${{ github.event.inputs.environment == 'beta' }}
4749
env:
4850
DATAVERSE_BACKEND_URL: ${{ secrets.BETA_DATAVERSE_BACKEND_URL }}
@@ -52,17 +54,26 @@ jobs:
5254
OIDC_LOGOUT_ENDPOINT: ${{ secrets.BETA_OIDC_LOGOUT_ENDPOINT }}
5355
OIDC_STORAGE_KEY_PREFIX: ${{ secrets.BETA_OIDC_STORAGE_KEY_PREFIX }}
5456
run: |
55-
touch .env
56-
echo VITE_DATAVERSE_BACKEND_URL="$DATAVERSE_BACKEND_URL" >> .env
57-
echo VITE_OIDC_CLIENT_ID="$OIDC_CLIENT_ID" >> .env
58-
echo VITE_OIDC_AUTHORIZATION_ENDPOINT="$OIDC_AUTHORIZATION_ENDPOINT" >> .env
59-
echo VITE_OIDC_TOKEN_ENDPOINT="$OIDC_TOKEN_ENDPOINT" >> .env
60-
echo VITE_OIDC_LOGOUT_ENDPOINT="$OIDC_LOGOUT_ENDPOINT" >> .env
61-
echo VITE_OIDC_STORAGE_KEY_PREFIX="$OIDC_STORAGE_KEY_PREFIX" >> .env
62-
shell: bash
63-
64-
# For QA environment
65-
- name: Create and populate .env file for QA
57+
mkdir -p ./dist
58+
cat > ./dist/config.js <<EOF
59+
window.__APP_CONFIG__ = {
60+
backendUrl: "${DATAVERSE_BACKEND_URL}",
61+
oidc: {
62+
clientId: "${OIDC_CLIENT_ID}",
63+
authorizationEndpoint: "${OIDC_AUTHORIZATION_ENDPOINT}",
64+
tokenEndpoint: "${OIDC_TOKEN_ENDPOINT}",
65+
logoutEndpoint: "${OIDC_LOGOUT_ENDPOINT}",
66+
localStorageKeyPrefix: "${OIDC_STORAGE_KEY_PREFIX}"
67+
},
68+
languages: [
69+
{ code: 'en', name: 'English' },
70+
{ code: 'es', name: 'Español' },
71+
],
72+
defaultLanguage: 'en'
73+
}
74+
EOF
75+
76+
- name: Override runtime config.js for QA
6677
if: ${{ github.event.inputs.environment == 'qa' }}
6778
env:
6879
DATAVERSE_BACKEND_URL: ${{ secrets.QA_DATAVERSE_BACKEND_URL }}
@@ -72,17 +83,26 @@ jobs:
7283
OIDC_LOGOUT_ENDPOINT: ${{ secrets.QA_OIDC_LOGOUT_ENDPOINT }}
7384
OIDC_STORAGE_KEY_PREFIX: ${{ secrets.QA_OIDC_STORAGE_KEY_PREFIX }}
7485
run: |
75-
touch .env
76-
echo VITE_DATAVERSE_BACKEND_URL="$DATAVERSE_BACKEND_URL" >> .env
77-
echo VITE_OIDC_CLIENT_ID="$OIDC_CLIENT_ID" >> .env
78-
echo VITE_OIDC_AUTHORIZATION_ENDPOINT="$OIDC_AUTHORIZATION_ENDPOINT" >> .env
79-
echo VITE_OIDC_TOKEN_ENDPOINT="$OIDC_TOKEN_ENDPOINT" >> .env
80-
echo VITE_OIDC_LOGOUT_ENDPOINT="$OIDC_LOGOUT_ENDPOINT" >> .env
81-
echo VITE_OIDC_STORAGE_KEY_PREFIX="$OIDC_STORAGE_KEY_PREFIX" >> .env
82-
shell: bash
83-
84-
# For DEMO environment
85-
- name: Create and populate .env file for DEMO
86+
mkdir -p ./dist
87+
cat > ./dist/config.js <<EOF
88+
window.__APP_CONFIG__ = {
89+
backendUrl: "${DATAVERSE_BACKEND_URL}",
90+
oidc: {
91+
clientId: "${OIDC_CLIENT_ID}",
92+
authorizationEndpoint: "${OIDC_AUTHORIZATION_ENDPOINT}",
93+
tokenEndpoint: "${OIDC_TOKEN_ENDPOINT}",
94+
logoutEndpoint: "${OIDC_LOGOUT_ENDPOINT}",
95+
localStorageKeyPrefix: "${OIDC_STORAGE_KEY_PREFIX}"
96+
},
97+
languages: [
98+
{ code: 'en', name: 'English' },
99+
{ code: 'es', name: 'Español' },
100+
],
101+
defaultLanguage: 'en'
102+
}
103+
EOF
104+
105+
- name: Override runtime config.js for DEMO
86106
if: ${{ github.event.inputs.environment == 'demo' }}
87107
env:
88108
DATAVERSE_BACKEND_URL: ${{ secrets.DEMO_DATAVERSE_BACKEND_URL }}
@@ -92,17 +112,24 @@ jobs:
92112
OIDC_LOGOUT_ENDPOINT: ${{ secrets.DEMO_OIDC_LOGOUT_ENDPOINT }}
93113
OIDC_STORAGE_KEY_PREFIX: ${{ secrets.DEMO_OIDC_STORAGE_KEY_PREFIX }}
94114
run: |
95-
touch .env
96-
echo VITE_DATAVERSE_BACKEND_URL="$DATAVERSE_BACKEND_URL" >> .env
97-
echo VITE_OIDC_CLIENT_ID="$OIDC_CLIENT_ID" >> .env
98-
echo VITE_OIDC_AUTHORIZATION_ENDPOINT="$OIDC_AUTHORIZATION_ENDPOINT" >> .env
99-
echo VITE_OIDC_TOKEN_ENDPOINT="$OIDC_TOKEN_ENDPOINT" >> .env
100-
echo VITE_OIDC_LOGOUT_ENDPOINT="$OIDC_LOGOUT_ENDPOINT" >> .env
101-
echo VITE_OIDC_STORAGE_KEY_PREFIX="$OIDC_STORAGE_KEY_PREFIX" >> .env
102-
shell: bash
103-
104-
- name: Build with base path
105-
run: npm run build -- --base=/${{ github.event.inputs.basepath }}
115+
mkdir -p ./dist
116+
cat > ./dist/config.js <<EOF
117+
window.__APP_CONFIG__ = {
118+
backendUrl: "${DATAVERSE_BACKEND_URL}",
119+
oidc: {
120+
clientId: "${OIDC_CLIENT_ID}",
121+
authorizationEndpoint: "${OIDC_AUTHORIZATION_ENDPOINT}",
122+
tokenEndpoint: "${OIDC_TOKEN_ENDPOINT}",
123+
logoutEndpoint: "${OIDC_LOGOUT_ENDPOINT}",
124+
localStorageKeyPrefix: "${OIDC_STORAGE_KEY_PREFIX}"
125+
},
126+
languages: [
127+
{ code: 'en', name: 'English' },
128+
{ code: 'es', name: 'Español' },
129+
],
130+
defaultLanguage: 'en'
131+
}
132+
EOF
106133
107134
- uses: actions/upload-artifact@v4
108135
with:

.github/workflows/test.yml

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,6 @@ jobs:
3333
working-directory: packages/design-system
3434
run: npm run build
3535

36-
- name: Create and populate .env file
37-
env:
38-
DATAVERSE_BACKEND_URL: 'http://localhost:8000'
39-
OIDC_CLIENT_ID: 'test'
40-
OIDC_AUTHORIZATION_ENDPOINT: 'http://localhost:8000/realms/test/protocol/openid-connect/auth'
41-
OIDC_TOKEN_ENDPOINT: 'http://localhost:8000/realms/test/protocol/openid-connect/token'
42-
OIDC_LOGOUT_ENDPOINT: 'http://localhost:8000/realms/test/protocol/openid-connect/logout'
43-
OIDC_STORAGE_KEY_PREFIX: 'DV_'
44-
run: |
45-
touch .env
46-
echo VITE_DATAVERSE_BACKEND_URL="$DATAVERSE_BACKEND_URL" >> .env
47-
echo VITE_OIDC_CLIENT_ID="$OIDC_CLIENT_ID" >> .env
48-
echo VITE_OIDC_AUTHORIZATION_ENDPOINT="$OIDC_AUTHORIZATION_ENDPOINT" >> .env
49-
echo VITE_OIDC_TOKEN_ENDPOINT="$OIDC_TOKEN_ENDPOINT" >> .env
50-
echo VITE_OIDC_LOGOUT_ENDPOINT="$OIDC_LOGOUT_ENDPOINT" >> .env
51-
echo VITE_OIDC_STORAGE_KEY_PREFIX="$OIDC_STORAGE_KEY_PREFIX" >> .env
52-
shell: bash
53-
5436
- name: Create containerized development environment .env file
5537
working-directory: dev-env
5638
run: cp .env.example .env
@@ -113,24 +95,6 @@ jobs:
11395
sed -i -e 's/<YOUR_GITHUB_AUTH_TOKEN>/${{ secrets.GITHUB_TOKEN }}/g' .npmrc
11496
sed -i -e 's/<YOUR_NPM_AUTH_TOKEN>/${{ secrets.NPM_AUTH_TOKEN }}/g' .npmrc
11597
116-
- name: Create and populate .env file
117-
env:
118-
DATAVERSE_BACKEND_URL: 'http://localhost:8000'
119-
OIDC_CLIENT_ID: 'test'
120-
OIDC_AUTHORIZATION_ENDPOINT: 'http://localhost:8000/realms/test/protocol/openid-connect/auth'
121-
OIDC_TOKEN_ENDPOINT: 'http://localhost:8000/realms/test/protocol/openid-connect/token'
122-
OIDC_LOGOUT_ENDPOINT: 'http://localhost:8000/realms/test/protocol/openid-connect/logout'
123-
OIDC_STORAGE_KEY_PREFIX: 'DV_'
124-
run: |
125-
touch .env
126-
echo VITE_DATAVERSE_BACKEND_URL="$DATAVERSE_BACKEND_URL" >> .env
127-
echo VITE_OIDC_CLIENT_ID="$OIDC_CLIENT_ID" >> .env
128-
echo VITE_OIDC_AUTHORIZATION_ENDPOINT="$OIDC_AUTHORIZATION_ENDPOINT" >> .env
129-
echo VITE_OIDC_TOKEN_ENDPOINT="$OIDC_TOKEN_ENDPOINT" >> .env
130-
echo VITE_OIDC_LOGOUT_ENDPOINT="$OIDC_LOGOUT_ENDPOINT" >> .env
131-
echo VITE_OIDC_STORAGE_KEY_PREFIX="$OIDC_STORAGE_KEY_PREFIX" >> .env
132-
shell: bash
133-
13498
- name: Install Dependencies
13599
run: npm install
136100

.storybook/preview-head.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<script src="/config.js"></script>
12
<script>
23
window.global = window
34
</script>

.storybook/preview.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'react-loading-skeleton/dist/skeleton.css'
99
import '../src/assets/global.scss'
1010
import '../src/assets/swal-custom.scss'
1111
import '../src/assets/react-toastify-custom.scss'
12+
import { initAppConfig } from '../src/config'
1213

1314
const preview: Preview = {
1415
parameters: {
@@ -22,6 +23,11 @@ const preview: Preview = {
2223
},
2324
decorators: [
2425
(Story) => {
26+
const result = initAppConfig()
27+
if (!result.ok) {
28+
console.error('Storybook runtime config invalid/missing:', result.message)
29+
}
30+
2531
FakerHelper.setFakerSeed()
2632

2733
const routes: RouteObject[] = [

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,23 @@ This changelog follows the principles of [Keep a Changelog](https://keepachangel
1212
- Contact Owner button in File Page.
1313
- Share button in File Page.
1414
- Link Collection and Link Dataset features.
15-
- Edit Terms Integration
15+
- Edit Terms Integration.
16+
- With the addition of the new runtime configuration approach, we now support dynamic configuration for languages. If more than one language is configured, the Language Switcher will be shown in the header to allow users to change the language.
1617

1718
### Changed
1819

20+
- Add pagination support to the Dataset Version Summaries and File Version Summaries use cases by introducing optional pagination object. #885
21+
- Refactored pagination to use consistent `CollectionItemsPaginationInfo` object in getMyDataCollectionItems, instead of individual limit/selectedPage parameters.
1922
- Use of the new `sourceLastUpdateTime` query parameter from update dataset and file metadata endpoints to support optimistic concurrency control during editing operations. See [Edit Dataset Metadata](https://guides.dataverse.org/en/6.8/api/native-api.html#edit-dataset-metadata) and [Updating File Metadata](https://guides.dataverse.org/en/6.8/api/native-api.html#updating-file-metadata) guides for more details.
2023
- Changed the way we were handling DATE type metadata field validation to better match the backend validation and give users better error messages. For example, for an input like “foo AD”, we now show “Production Date is not a valid date. The AD year must be numeric.“. For an input like “99999 AD”, we now show “Production Date is not a valid date. The AD year cant be higher than 9999.“. For an input like “[-9999?], we now show “Production Date is not a valid date. The year in brackets cannot be negative.“, etc.
24+
- The SPA now fetches the runtime configuration from `config.js` on each load, allowing configurations without rebuilding the app. We don't use `.env` variables at build time anymore.
2125

2226
### Fixed
2327

2428
- Add word-break to items text to prevent layout issues when long descriptions without spaces are entered. (#839)
2529
- Show toast notification when API token is copied to clipboard.
30+
- Dataset versions: (1) file changes should be `Access: Restricted` instead of `isResticted: true/false`; (2) logic of View Detail button. (#879)
31+
- File versions: (1) logic of linking to a file version; (2)If file not included, show text information "File not included in this version.". (#879)
2632

2733
### Removed
2834

DEVELOPER_GUIDE.md

Lines changed: 77 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
<li><a href="#1-unit-tests-or-component-tests">Unit Tests or Component tests</a></li>
5555
<li><a href="#2-integration-tests">Integration Tests</a></li>
5656
<li><a href="#3-end-to-end-e2e-tests">End-to-End (e2e) Tests</a></li>
57+
<li><a href="#mocking-runtime-configuration-in-tests">Mocking runtime configuration in tests</a></li>
5758
<li><a href="#patterns-and-conventions">Patterns and Conventions</a></li>
5859
<li><a href="#continuous-integration-ci">Continuous Integration (CI)</a></li>
5960
<li><a href="#test-coverage">Test Coverage</a></li>
@@ -136,12 +137,6 @@ cd packages/design-system && npm run build
136137
137138
**Running &amp; Building the App:**
138139
139-
Set up your environment file.
140-
141-
```bash
142-
cp .env.example .env
143-
```
144-
145140
Run the app in the development mode. Open [http://localhost:5173][dv_app_localhost_build_url] to view it in your browser.
146141
147142
```bash
@@ -826,11 +821,82 @@ describe('Create Dataset', () => {
826821
827822
</details>
828823
829-
> **Note:** Some end-to-end (e2e) tests are failing in local development environments despite passing in GitHub Actions.
830-
> This discrepancy appears to be due to variations in machine resources.
831-
>
832-
> We need to investigate and potentially optimize several aspects of our local setup. Check the issue
833-
> [here](https://github.com/IQSS/dataverse-frontend/issues/371).
824+
### Mocking runtime configuration in tests
825+
826+
The SPA reads its runtime configuration from `window.__APP_CONFIG__` in `src/config.ts` file, which is provided by `public/config.js`.
827+
In Cypress tests we bootstrap a test-safe config and allow you to override any field per test.
828+
829+
#### Component (unit) tests: override with Cypress.env
830+
831+
Component tests automatically get a runtime config via the bootstrap file; you only need to set `env` on a per-test basis to customize values.
832+
833+
Example: overriding languages for a component test
834+
835+
```ts
836+
// tests/component/sections/layout/header/LanguageSwitcher.spec.tsx
837+
it(
838+
'renders language options correctly when more than one language is configured',
839+
{
840+
env: {
841+
languages: [
842+
{ code: 'en', name: 'English' },
843+
{ code: 'es', name: 'Español' },
844+
{ code: 'it', name: 'Italiano' }
845+
]
846+
}
847+
},
848+
() => {
849+
cy.customMount(<LanguageSwitcher />)
850+
cy.get('#language-switcher-dropdown').click()
851+
cy.findByText('English').should('exist')
852+
cy.findByText('Español').should('exist')
853+
cy.findByText('Italiano').should('exist')
854+
}
855+
)
856+
```
857+
858+
#### E2E tests: intercept public/config.js
859+
860+
In e2e tests, the app fetches `public/config.js`. Intercept that request and respond with a body built from your `Cypress.env()` settings using the provided helper.
861+
862+
```ts
863+
// Example e2e spec
864+
import { buildConfigJsBody } from '../tests/support/bootstrapAppConfig'
865+
866+
it(
867+
'test description',
868+
{
869+
env: {
870+
languages: [
871+
{ code: 'en', name: 'English' },
872+
{ code: 'it', name: 'Italiano' }
873+
],
874+
defaultLanguage: 'en'
875+
}
876+
},
877+
() => {
878+
// We intercept config.js request and the body will read from the updated Cypress.env() defined in this test above.
879+
cy.intercept(
880+
{ method: 'GET', url: 'config.js' },
881+
{
882+
statusCode: 200,
883+
headers: { 'content-type': 'application/javascript' },
884+
body: buildConfigJsBody()
885+
}
886+
)
887+
888+
cy.visit('/spa/')
889+
890+
// Assertions that rely on your overridden config
891+
cy.findByText('English').should('exist')
892+
cy.findByText('Italiano').should('exist')
893+
}
894+
)
895+
```
896+
897+
Notes
898+
899+
- If you don't intercept `config.js` in e2e tests, the app will use the real file from `public/config.js` and ignore your `Cypress.env()` overrides.
834900
835901
### Patterns and Conventions
836902

0 commit comments

Comments
 (0)