Skip to content

Commit

Permalink
Merge pull request #69 from alpaca-tc/visualize-wrong-dependency
Browse files Browse the repository at this point in the history
[part1] Visualize wrong dependency
  • Loading branch information
alpaca-tc authored Jul 3, 2024
2 parents 0ea1b6e + c36cc01 commit dbadf84
Show file tree
Hide file tree
Showing 15 changed files with 640 additions and 228 deletions.
3 changes: 3 additions & 0 deletions frontend/components/ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export {
Base,
Button,
CheckBox,
Chip,
Cluster,
DefinitionList,
EmptyTableBody,
Expand All @@ -30,6 +31,8 @@ export {
Sidebar,
SingleComboBox,
Stack,
TabBar,
TabItem,
Table,
TableReel,
Td,
Expand Down
25 changes: 25 additions & 0 deletions frontend/hooks/useSearchParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { parse, stringify } from '@/utils/queryString'
import { useEffect, useState } from 'react'
import { useSearchParams } from 'react-router-dom'

type DeserializeSearchParams<T> = { [urlParam in keyof T]: (v: T[urlParam] | null) => T[urlParam] }

const getInitialState = <T extends Record<string, unknown>>(
searchParams: Record<string, unknown>,
deserializeSearchParams: DeserializeSearchParams<T>,
): T => {
return Object.entries(deserializeSearchParams).reduce((acc, [key, deserialize]) => {
return { ...acc, [key]: deserialize(searchParams[key]) }
}, {} as T)
}

export const useSearchParamsState = <T extends Record<string, unknown>>(deserializeSearchParams: DeserializeSearchParams<T>) => {
const [searchParams, setSearchParams] = useSearchParams()
const [state, setState] = useState<T>(() => getInitialState(parse(searchParams.toString()), deserializeSearchParams))

useEffect(() => {
setSearchParams(new URLSearchParams(stringify(state)))
}, [state, setSearchParams])

return [state, setState] as const
}
35 changes: 15 additions & 20 deletions frontend/models/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,23 @@ import { MethodId } from './methodId'

export type Module = string

export type SpecificModuleDependency = {
sourceName: string
module: Module | null
methodIds: MethodId[]
}

export type SpecificModuleSource = {
sourceName: string
module: Module | null
memo: string
dependencies: SpecificModuleDependency[]
}

export type SpecificModule = {
module: Module
moduleDependencies: Module[]
moduleReverseDependencies: Module[]
sources: Array<{
sourceName: string
module: Module
memo: string
dependencies: Array<{
sourceName: string
module: Module | null
methodIds: MethodId[]
}>
}>
sourceReverseDependencies: Array<{
sourceName: string
module: Module | null
memo: string
dependencies: Array<{
sourceName: string
module: Module
methodIds: MethodId[]
}>
}>
sources: SpecificModuleSource[]
sourceReverseDependencies: SpecificModuleSource[]
}
7 changes: 1 addition & 6 deletions frontend/models/source.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ascString } from '@/utils/sort'
import { MethodId } from './methodId'
import { Module } from './module'

Expand Down Expand Up @@ -40,12 +41,6 @@ export const sortSources = (sources: Source[], key: 'sourceName' | 'module', sor

let sorted = [...sources]

const ascString = (a: string, b: string) => {
if (a > b) return 1
if (a < b) return -1
return 0
}

switch (key) {
case 'sourceName': {
sorted = sorted.sort((a, b) => ascString(a.sourceName, b.sourceName))
Expand Down
Loading

0 comments on commit dbadf84

Please sign in to comment.