Skip to content

Commit

Permalink
modules returns only string[]
Browse files Browse the repository at this point in the history
  • Loading branch information
alpaca-tc committed Jun 20, 2024
1 parent b3ef612 commit 4671dde
Show file tree
Hide file tree
Showing 17 changed files with 66 additions and 196 deletions.
4 changes: 1 addition & 3 deletions frontend/components/DefinitionSources/DefinitionSources.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,7 @@ const DefinitionSourceTr: FC<DefinitionSourceTrProps> = ({ source, combinedDefin
<div>
{source.modules.map((module, index) => (
<Text key={index} as="div" whiteSpace="nowrap">
<Link to={path.modules.show(source.modules.slice(0, index + 1).map((mod) => mod.moduleName))}>
{module.moduleName}
</Link>
<Link to={path.modules.show(source.modules.slice(0, index + 1))}>{module}</Link>
</Text>
))}
</div>
Expand Down
8 changes: 2 additions & 6 deletions frontend/components/DotMetadataDialog/DotMetadataDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const SourceDotMetadataContent: FC<{ dotMetadata: DotSourceMetadata } & Pick<Pro
<>
<div>
{dotMetadata.modules.map((module) => (
<p key={module.moduleName}>{module.moduleName}</p>
<p key={module}>{module}</p>
))}
</div>
<Button
Expand Down Expand Up @@ -156,11 +156,7 @@ const ModuleDotMetadataContent: FC<{ dotMetadata: DotModuleMetadata }> = ({ dotM
const items: ComponentProps<typeof DefinitionList>['items'] = [
{
term: 'Module Name',
description: (
<Link to={path.modules.show(dotMetadata.modules.map((module) => module.moduleName))}>
{dotMetadata.modules.map((module) => module.moduleName).join(' / ')}
</Link>
),
description: <Link to={path.modules.show(dotMetadata.modules)}>{dotMetadata.modules.join(' / ')}</Link>,
},
]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC, useCallback, useContext, useEffect, useMemo, useState } from 'react'
import React, { FC, useCallback, useEffect, useMemo, useState } from 'react'

import { Button, Cluster, ComboBoxItem, FaXmarkIcon, FormControl, SingleComboBox } from '@/components/ui'
import { Module } from '@/models/module'
Expand All @@ -14,11 +14,11 @@ type Props = {
onUpdate: (modules: Module[]) => void
}

const equalModules = (a: Module[], b: Module[]) => a.every((module, index) => module.moduleName === (b[index]?.moduleName ?? ''))
const equalModules = (a: Module[], b: Module[]) => a.every((module, index) => module === (b[index] ?? ''))

const convertModulesToItem = (modules: Module[]): Item => ({
label: modules.map((module) => module.moduleName).join(' / '),
value: modules.map((module) => module.moduleName).join('/'),
label: modules.join(' / '),
value: modules.join('/'),
data: modules,
})

Expand Down Expand Up @@ -56,7 +56,7 @@ export const SourceModulesComboBox: FC<Props> = ({ sourceName, initialModules, o

const handleAddItem = useCallback(
(label: string) => {
const temporaryModules: Module[] = label.split(DELIMITER_RE).map((moduleName) => ({ moduleName }))
const temporaryModules: Module[] = label.split(DELIMITER_RE)
const newItem = convertModulesToItem(temporaryModules)

setTemporaryItem(newItem)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const UpdateSourceModulesButton: FC<Props> = ({ sourceName, newModules, o
} else {
return (
<Button square={true} variant="primary" onClick={updateSourceModules} size="s">
<Tooltip message={`Save "${newModules.map((mod) => mod.moduleName).join('/')}"`} horizontal="center" vertical="bottom">
<Tooltip message={`Save "${newModules.join('/')}"`} horizontal="center" vertical="bottom">
<FaCopyIcon />
</Tooltip>
</Button>
Expand Down
8 changes: 2 additions & 6 deletions frontend/models/module.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
export type Module = {
moduleName: string
}
export type Module = string

export type SpecificModule = {
modules: Array<{
moduleName: string
}>
modules: Module[]
sources: Array<{
sourceName: string
memo: string
Expand Down
4 changes: 1 addition & 3 deletions frontend/models/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ export const sortSources = (sources: Source[], key: 'sourceName' | 'modules', so
break
}
case 'modules': {
sorted = sorted.sort((a, b) =>
ascString(a.modules.map((module) => module.moduleName).join('-'), b.modules.map((module) => module.moduleName).join('-')),
)
sorted = sorted.sort((a, b) => ascString(a.modules.join('---'), b.modules.join('---')))
}
}

Expand Down
3 changes: 1 addition & 2 deletions frontend/pages/Modules/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ const ModuleRow: FC<{ modules: Module[] }> = ({ modules }) => (
<Cluster>
{modules.map((module, index) => {
const current = modules.slice(0, index + 1)
const moduleNames: string[] = current.map((mod) => mod.moduleName)

return (
<Text key={index}>
{index > 0 && ' / '}
<Link to={path.modules.show(moduleNames)}>{module.moduleName}</Link>
<Link to={path.modules.show(current)}>{module}</Link>
</Text>
)
})}
Expand Down
4 changes: 1 addition & 3 deletions frontend/pages/Sources/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ const Row: FC<RowProps> = ({ source, recentModules, onUpdated, setRecentModules
<div>
{source.modules.map((module, index) => (
<Text key={index} as="div" whiteSpace="nowrap">
<Link to={path.modules.show(source.modules.slice(0, index + 1).map((mod) => mod.moduleName))}>
{module.moduleName}
</Link>
<Link to={path.modules.show(source.modules.slice(0, index + 1))}>{module}</Link>
</Text>
))}
</div>
Expand Down
8 changes: 2 additions & 6 deletions frontend/pages/Sources/Show.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,9 @@ export const Show: React.FC = () => {
) : (
<tbody>
{specificSource.modules.map((module, index) => (
<tr key={module.moduleName}>
<tr key={module}>
<Td>
<Link
to={path.modules.show(specificSource.modules.slice(0, index + 1).map((mod) => mod.moduleName))}
>
{module.moduleName}
</Link>
<Link to={path.modules.show(specificSource.modules.slice(0, index + 1))}>{module}</Link>
</Td>
</tr>
))}
Expand Down
24 changes: 6 additions & 18 deletions frontend/repositories/combinedDefinitionRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ type DotSourceMetadataResponse = {
type: 'source'
memo: string
source_name: string
modules: Array<{
module_name: string
}>
modules: string[]
}

type DotDependencyMetadataResponse = {
Expand All @@ -32,9 +30,7 @@ type DotDependencyMetadataResponse = {
type DotModuleMetadataResponse = {
id: string
type: 'module'
modules: Array<{
module_name: string
}>
modules: string[]
}

type DotMetadataResponse = DotSourceMetadataResponse | DotDependencyMetadataResponse | DotModuleMetadataResponse
Expand All @@ -48,9 +44,7 @@ type CombinedDefinitionReponse = {
source_name: string
resolved_alias: string | null
memo: string
modules: Array<{
module_name: string
}>
modules: string[]
}>
}

Expand All @@ -62,9 +56,7 @@ const parseDotMetadata = (metadata: DotMetadataResponse): DotMetadata => {
type: metadata.type,
sourceName: metadata.source_name,
memo: metadata.memo,
modules: metadata.modules.map((module) => ({
moduleName: module.module_name,
})),
modules: metadata.modules,
}
}
case 'dependency': {
Expand All @@ -85,9 +77,7 @@ const parseDotMetadata = (metadata: DotMetadataResponse): DotMetadata => {
return {
id: metadata.id,
type: metadata.type,
modules: metadata.modules.map((module) => ({
moduleName: module.module_name,
})),
modules: metadata.modules,
}
}
}
Expand All @@ -105,9 +95,7 @@ export const fetchCombinedDefinition = async (requestPath: string): Promise<Comb
sourceName: source.source_name,
resolvedAlias: source.resolved_alias,
memo: source.memo,
modules: source.modules.map((module) => ({
moduleName: module.module_name,
})),
modules: source.modules,
})),
}
}
Expand Down
12 changes: 4 additions & 8 deletions frontend/repositories/moduleRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,20 @@ import { Module, SpecificModule } from '@/models/module'
import { get } from './httpRequest'

type ModulesReponse = {
modules: Array<Array<{ module_name: string }>>
modules: string[][]
}

export const useModules = () => {
const { data, isLoading, mutate } = useSWR<Module[][]>(path.api.modules.index(), async () => {
const response = await get<ModulesReponse>(path.api.modules.index())
return response.modules.map((moduleList) => moduleList.map((module) => ({ moduleName: module.module_name })))
return response.modules
})

return { data, isLoading, mutate }
}

type SpecificModuleResponse = {
modules: Array<{
module_name: string
}>
modules: string[]
related_definitions: Array<{
id: number
title: string
Expand All @@ -37,9 +35,7 @@ export const useModule = (moduleNames: string[]) => {
const response = await get<SpecificModuleResponse>(path.api.modules.show(moduleNames))

return {
modules: response.modules.map((mod) => ({
moduleName: mod.module_name,
})),
modules: response.modules,
sources: response.sources.map((source) => ({
sourceName: source.source_name,
memo: source.memo,
Expand Down
3 changes: 1 addition & 2 deletions frontend/repositories/sourceModulesRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import { post } from './httpRequest'

const updateModules = async (url: string, { arg }: { arg: { modules: Module[] } }) => {
const { modules } = arg
const moduleNames = modules.map((mod) => mod.moduleName)

await post(url, {
modules: moduleNames,
modules,
})
}

Expand Down
12 changes: 4 additions & 8 deletions frontend/repositories/sourceRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ type SourcesReponse = {
source_name: string
resolved_alias: string | null
memo: string
modules: Array<{
module_name: string
}>
modules: string[]
}>
classified_sources_count: number
}
Expand All @@ -25,7 +23,7 @@ export const useSources = () => {
sourceName: source.source_name,
resolvedAlias: source.resolved_alias,
memo: source.memo,
modules: source.modules.map((module) => ({ moduleName: module.module_name })),
modules: source.modules,
})),
classifiedSourcesCount: response.classified_sources_count,
}
Expand All @@ -38,9 +36,7 @@ type SpecificSourceResponse = {
source_name: string
resolved_alias: string | null
memo: string
modules: Array<{
module_name: string
}>
modules: string[]
related_definitions: Array<{
id: number
title: string
Expand All @@ -63,7 +59,7 @@ export const useSource = (sourceName: string) => {
sourceName: response.source_name,
resolvedAlias: response.resolved_alias,
memo: response.memo,
modules: response.modules.map((module) => ({ moduleName: module.module_name })),
modules: response.modules,
relatedDefinitions: response.related_definitions.map((definition) => ({ id: definition.id, title: definition.title })),
reverseDependencies: response.reverse_dependencies.map((dependency) => ({
sourceName: dependency.source_name,
Expand Down
26 changes: 5 additions & 21 deletions lib/diver_down/web/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ def sources
source_name:,
resolved_alias: @metadata.source_alias.resolve_alias(source_name),
memo: source_metadata.memo,
modules: source_metadata.modules.map do |module_name|
{ module_name: }
end,
modules: source_metadata.modules,
}
end,
classified_sources_count:
Expand All @@ -103,13 +101,7 @@ def modules
# rubocop:enable Style/HashEachMethods

json(
modules: module_set.sort.map do
_1.map do |module_name|
{
module_name:,
}
end
end
modules: module_set.sort
)
end

Expand Down Expand Up @@ -140,11 +132,7 @@ def module(module_names)
related_definitions = related_definition_store_ids.map { @store.get(_1) }

json(
modules: module_names.map do
{
module_name: _1,
}
end,
modules: module_names,
sources: source_names.sort.map do |source_name|
{
source_name:,
Expand Down Expand Up @@ -315,9 +303,7 @@ def source(source_name)
source_name:,
resolved_alias: @metadata.source_alias.resolve_alias(source_name),
memo: @metadata.source(source_name).memo,
modules: module_names.map do
{ module_name: _1 }
end,
modules: module_names,
related_definitions: related_definitions.map do |id, definition|
{
id:,
Expand Down Expand Up @@ -451,9 +437,7 @@ def render_combined_definition(ids, definition, titles, compound:, concentrate:,
source_name: _1.source_name,
resolved_alias: @metadata.source_alias.resolve_alias(_1.source_name),
memo: @metadata.source(_1.source_name).memo,
modules: @metadata.source(_1.source_name).modules.map do |module_name|
{ module_name: }
end,
modules: @metadata.source(_1.source_name).modules,
}
end
)
Expand Down
12 changes: 2 additions & 10 deletions lib/diver_down/web/definition_to_dot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ def to_h
private

def source_to_h
modules = metadata.source(data.source_name).modules.map do
{
module_name: _1,
}
end
modules = metadata.source(data.source_name).modules

{
id:,
Expand Down Expand Up @@ -68,11 +64,7 @@ def module_to_h
{
id:,
type: 'module',
modules: data.map do
{
module_name: _1,
}
end,
modules: data,
}
end
end
Expand Down
Loading

0 comments on commit 4671dde

Please sign in to comment.