diff --git a/.github/workflows/ci_frontend.yml b/.github/workflows/ci_frontend.yml index 3f937f7..df4a2fa 100644 --- a/.github/workflows/ci_frontend.yml +++ b/.github/workflows/ci_frontend.yml @@ -15,12 +15,25 @@ jobs: steps: - uses: actions/checkout@v4 - name: Setup pnpm - uses: pnpm/action-setup@v2 + uses: pnpm/action-setup@v4 - name: Set up frontend uses: actions/setup-node@v4 with: node-version: 20 cache: 'pnpm' + - name: Get pnpm store directory + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV + - uses: actions/cache@v4 + name: Setup pnpm cache + with: + path: ${{ env.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + - name: Install dependencies + run: pnpm install - name: Run lint run: pnpm run lint @@ -29,11 +42,51 @@ jobs: steps: - uses: actions/checkout@v4 - name: Setup pnpm - uses: pnpm/action-setup@v2 + uses: pnpm/action-setup@v4 - name: Set up frontend uses: actions/setup-node@v4 with: node-version: 20 cache: 'pnpm' + - name: Get pnpm store directory + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV + - uses: actions/cache@v4 + name: Setup pnpm cache + with: + path: ${{ env.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + - name: Install dependencies + run: pnpm install - name: Run test run: pnpm run test + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Setup pnpm + uses: pnpm/action-setup@v4 + - name: Set up frontend + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: 'pnpm' + - name: Get pnpm store directory + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV + - uses: actions/cache@v4 + name: Setup pnpm cache + with: + path: ${{ env.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + - name: Install dependencies + run: pnpm install + - name: Run build + run: pnpm run build diff --git a/frontend/repositories/combinedDefinitionRepository.ts b/frontend/repositories/combinedDefinitionRepository.ts index c1b380c..27e6f4f 100644 --- a/frontend/repositories/combinedDefinitionRepository.ts +++ b/frontend/repositories/combinedDefinitionRepository.ts @@ -1,7 +1,7 @@ import useSWR from 'swr' import { path } from '@/constants/path' -import { CombinedDefinition, CombinedDefinitionGraphOptions, DotMetadata } from '@/models/combinedDefinition' +import { CombinedDefinition, CombinedDefinitionOptions, DotMetadata } from '@/models/combinedDefinition' import { bitIdToIds } from '@/utils/bitId' import { stringify } from '@/utils/queryString' @@ -112,7 +112,7 @@ export const fetchCombinedDefinition = async (requestPath: string): Promise { +export const stringifyCombinedDefinitionOptions = (graphOptions: CombinedDefinitionOptions): string => { const params = { compound: graphOptions.compound, concentrate: graphOptions.concentrate, @@ -122,7 +122,7 @@ export const stringifyCombinedDefinitionOptions = (graphOptions: CombinedDefinit return stringify(params) } -export const useCombinedDefinition = (ids: number[], graphOptions: CombinedDefinitionGraphOptions) => { +export const useCombinedDefinition = (ids: number[], graphOptions: CombinedDefinitionOptions) => { const requestPath = `${path.api.definitions.show(ids)}?${stringifyCombinedDefinitionOptions(graphOptions)}` const shouldFetch = ids.length > 0 const { data, isLoading, mutate } = useSWR(shouldFetch ? requestPath : null, fetchCombinedDefinition) diff --git a/frontend/repositories/moduleDefinitionRepository.ts b/frontend/repositories/moduleDefinitionRepository.ts index af55e56..272bdf8 100644 --- a/frontend/repositories/moduleDefinitionRepository.ts +++ b/frontend/repositories/moduleDefinitionRepository.ts @@ -1,9 +1,9 @@ import { path } from '@/constants/path' -import { CombinedDefinitionGraphOptions } from '@/models/combinedDefinition' +import { CombinedDefinitionOptions } from '@/models/combinedDefinition' import { fetchCombinedDefinition, stringifyCombinedDefinitionOptions } from './combinedDefinitionRepository' import useSWR from 'swr' -export const useModuleDefinition = (moduleNames: string[], graphOptions: CombinedDefinitionGraphOptions) => { +export const useModuleDefinition = (moduleNames: string[], graphOptions: CombinedDefinitionOptions) => { const requestPath = `${path.api.moduleDefinitions.show(moduleNames)}?${stringifyCombinedDefinitionOptions(graphOptions)}` const shouldFetch = moduleNames.length > 0 const { data, isLoading, mutate } = useSWR(shouldFetch ? requestPath : null, fetchCombinedDefinition) diff --git a/frontend/utils/queryString/index.ts b/frontend/utils/queryString/index.ts index 22fd7a9..e200549 100644 --- a/frontend/utils/queryString/index.ts +++ b/frontend/utils/queryString/index.ts @@ -61,14 +61,14 @@ const normalizeParams = (params: Record, name: string, v: any, dept let k: string let after: string - let start: string + let start: number if (!name) { // nil name, treat same as empty string (required by tests) k = after = '' } else if (depth === 0) { // Start of parsing, don't treat [] or [ at start of string specially - const start = name.indexOf('[', 1) + start = name.indexOf('[', 1) if (start !== -1) { // Start of parameter nesting, use part before brackets as key k = name.slice(0, start)