Skip to content

Commit

Permalink
Render resolved alias
Browse files Browse the repository at this point in the history
  • Loading branch information
alpaca-tc committed Jun 6, 2024
1 parent 70d14b0 commit 820c440
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 3 deletions.
2 changes: 2 additions & 0 deletions frontend/models/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Module } from './module'

export type Source = {
sourceName: string
resolvedAlias: string | null
memo: string
modules: Module[]
}
Expand All @@ -19,6 +20,7 @@ type ReverseDependency = {

export type SpecificSource = {
sourceName: string
resolvedAlias: string | null
memo: string
modules: Module[]
relatedDefinitions: RelatedDefinition[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,14 @@ const DefinitionSourceTr: FC<DefinitionSourceTrProps> = ({ source, combinedDefin
return (
<tr ref={ref}>
<Td>
<Link to={path.sources.show(source.sourceName)}>{source.sourceName}</Link>
<Cluster>
<Link to={path.sources.show(source.sourceName)}>{source.sourceName}</Link>
{source.resolvedAlias ? (
<Tooltip message={`Alias: ${source.resolvedAlias}`} horizontal="center" vertical="bottom">
<FaCircleInfoIcon />
</Tooltip>
) : null}
</Cluster>
</Td>
<Td>
{editingMemo ? (
Expand Down
4 changes: 3 additions & 1 deletion frontend/pages/SourceAliases/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ const SourceAliasRow: FC<SourceAliasRowProps> = ({ sourceAlias, setOpenedDialog
return (
<tr>
<Td>
<Link to={path.sources.show(sourceAlias.aliasName)}>{sourceAlias.aliasName}</Link>
<Stack>
<Link to={path.sources.show(sourceAlias.aliasName)}>{sourceAlias.aliasName}</Link>
</Stack>
</Td>
<Td>
<Stack>
Expand Down
2 changes: 2 additions & 0 deletions frontend/pages/Sources/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const Row: FC<RowProps> = ({ source, recentModules, onUpdated, setRecentModules
<Td>
<Link to={path.sources.show(source.sourceName)}>{source.sourceName}</Link>
</Td>
<Td>{source.resolvedAlias ? <Link to={path.sources.show(source.resolvedAlias)}>{source.resolvedAlias}</Link> : null}</Td>
<Td>
{editingMemo ? (
<SourceMemoInput
Expand Down Expand Up @@ -226,6 +227,7 @@ export const List: FC = () => {
<Th sort={sortState.key === 'sourceName' ? sortState.sort : 'none'} onSort={() => setNextSortType('sourceName')}>
Source name
</Th>
<Th>Source Alias</Th>
<Th>Memo</Th>
<Th sort={sortState.key === 'modules' ? sortState.sort : 'none'} onSort={() => setNextSortType('modules')}>
Modules
Expand Down
11 changes: 11 additions & 0 deletions frontend/pages/Sources/Show.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ export const Show: React.FC = () => {
</Stack>
</Section>

<Section>
<Stack gap={0.5}>
<Heading type="sectionTitle">Source Alias</Heading>
<div style={{ overflow: 'clip' }}>
{specificSource.resolvedAlias ? (
<Link to={path.sources.show(specificSource.resolvedAlias)}>{specificSource.resolvedAlias}</Link>
) : null}
</div>
</Stack>
</Section>

<Section>
<Stack gap={0.5}>
<Heading type="sectionTitle">Modules</Heading>
Expand Down
2 changes: 2 additions & 0 deletions frontend/repositories/combinedDefinitionRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type CombinedDefinitionReponse = {
dot_metadata: DotMetadataResponse[]
sources: Array<{
source_name: string
resolved_alias: string | null
memo: string
modules: Array<{
module_name: string
Expand Down Expand Up @@ -102,6 +103,7 @@ const fetchDefinitionShow = async (requestPath: string): Promise<CombinedDefinit
dotMetadata: response.dot_metadata.map((res) => parseDotMetadata(res)),
sources: response.sources.map((source) => ({
sourceName: source.source_name,
resolvedAlias: source.resolved_alias,
memo: source.memo,
modules: source.modules.map((module) => ({
moduleName: module.module_name,
Expand Down
4 changes: 4 additions & 0 deletions frontend/repositories/sourceRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { get } from './httpRequest'
type SourcesReponse = {
sources: Array<{
source_name: string
resolved_alias: string | null
memo: string
modules: Array<{
module_name: string
Expand All @@ -22,6 +23,7 @@ export const useSources = () => {
return {
sources: response.sources.map((source) => ({
sourceName: source.source_name,
resolvedAlias: source.resolved_alias,
memo: source.memo,
modules: source.modules.map((module) => ({ moduleName: module.module_name })),
})),
Expand All @@ -34,6 +36,7 @@ export const useSources = () => {

type SpecificSourceResponse = {
source_name: string
resolved_alias: string | null
memo: string
modules: Array<{
module_name: string
Expand All @@ -58,6 +61,7 @@ export const useSource = (sourceName: string) => {

return {
sourceName: response.source_name,
resolvedAlias: response.resolved_alias,
memo: response.memo,
modules: response.modules.map((module) => ({ moduleName: module.module_name })),
relatedDefinitions: response.related_definitions.map((definition) => ({ id: definition.id, title: definition.title })),
Expand Down
8 changes: 7 additions & 1 deletion lib/diver_down/web/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,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: }
Expand Down Expand Up @@ -225,7 +226,10 @@ def combine_definitions(bit_id, compound, concentrate, only_module)
end

if definition
definition_to_dot = DiverDown::Web::DefinitionToDot.new(definition, @metadata, compound:, concentrate:, only_module:)
# Resolve source aliases
resolved_definition = @alias_resolver.resolve(definition)

definition_to_dot = DiverDown::Web::DefinitionToDot.new(resolved_definition, @metadata, compound:, concentrate:, only_module:)

json(
titles:,
Expand All @@ -235,6 +239,7 @@ def combine_definitions(bit_id, compound, concentrate, only_module)
sources: definition.sources.map do
{
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: }
Expand Down Expand Up @@ -292,6 +297,7 @@ def source(source_name)

json(
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 }
Expand Down

0 comments on commit 820c440

Please sign in to comment.