Skip to content

Commit

Permalink
Merge pull request #61 from alpaca-tc/fix-frontend
Browse files Browse the repository at this point in the history
fix: broken frontend
  • Loading branch information
alpaca-tc authored Jun 17, 2024
2 parents c45c057 + 16a3bab commit b698bc5
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 9 deletions.
57 changes: 55 additions & 2 deletions .github/workflows/ci_frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
6 changes: 3 additions & 3 deletions frontend/repositories/combinedDefinitionRepository.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -112,7 +112,7 @@ export const fetchCombinedDefinition = async (requestPath: string): Promise<Comb
}
}

export const stringifyCombinedDefinitionOptions = (graphOptions: CombinedDefinitionGraphOptions): string => {
export const stringifyCombinedDefinitionOptions = (graphOptions: CombinedDefinitionOptions): string => {
const params = {
compound: graphOptions.compound,
concentrate: graphOptions.concentrate,
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions frontend/repositories/moduleDefinitionRepository.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 2 additions & 2 deletions frontend/utils/queryString/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ const normalizeParams = (params: Record<string, any>, 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)
Expand Down

0 comments on commit b698bc5

Please sign in to comment.