-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from alpaca-tc/module_graph
Experimental feature: Add graph for specific module
- Loading branch information
Showing
30 changed files
with
971 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import React, { useCallback, useMemo, useState } from 'react' | ||
import styled from 'styled-components' | ||
|
||
import { Loading } from '@/components/Loading' | ||
import { Aside, Section, Sidebar, Stack } from '@/components/ui' | ||
import { color } from '@/constants/theme' | ||
|
||
import { RecentModulesContext } from '@/context/RecentModulesContext' | ||
import { Module } from '@/models/module' | ||
import { useGraphOptions } from '@/hooks/useGraphOptions' | ||
import { DefinitionGraph } from '@/components/DefinitionGraph' | ||
import { DefinitionSources } from '@/components/DefinitionSources' | ||
import { useParams } from 'react-router-dom' | ||
import { useModuleDefinition } from '@/repositories/moduleDefinitionRepository' | ||
|
||
export const Show: React.FC = () => { | ||
const pathModules = (useParams()['*'] ?? '').split('/') | ||
|
||
const [graphOptions, setGraphOptions] = useGraphOptions() | ||
const { | ||
data: combinedDefinition, | ||
isLoading: isLoadingCombinedDefinition, | ||
mutate: mutateCombinedDefinition, | ||
} = useModuleDefinition(pathModules, graphOptions) | ||
const [recentModules, setRecentModules] = useState<Module[]>([]) | ||
|
||
return ( | ||
<Wrapper> | ||
<RecentModulesContext.Provider value={{ recentModules, setRecentModules }}> | ||
<StyledSidebar contentsMinWidth="0px" gap={0}> | ||
<StyledSection> | ||
{isLoadingCombinedDefinition ? ( | ||
<CenterStack> | ||
<Loading text="Loading..." alt="Loading" /> | ||
</CenterStack> | ||
) : !combinedDefinition ? ( | ||
<CenterStack> | ||
<p>No data</p> | ||
</CenterStack> | ||
) : ( | ||
<StyledStack> | ||
<DefinitionGraph | ||
combinedDefinition={combinedDefinition} | ||
mutateCombinedDefinition={mutateCombinedDefinition} | ||
graphOptions={graphOptions} | ||
setGraphOptions={setGraphOptions} | ||
/> | ||
<StyledDefinitionSources | ||
combinedDefinition={combinedDefinition} | ||
mutateCombinedDefinition={mutateCombinedDefinition} | ||
/> | ||
</StyledStack> | ||
)} | ||
</StyledSection> | ||
</StyledSidebar> | ||
</RecentModulesContext.Provider> | ||
</Wrapper> | ||
) | ||
} | ||
|
||
const Wrapper = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
height: calc(100% - 1px); /* 100% - padding-top of layout */ | ||
width: 100vw; | ||
` | ||
|
||
const StyledSidebar = styled(Sidebar)` | ||
display: flex; | ||
height: 100%; | ||
` | ||
|
||
const StyledAside = styled(Aside)` | ||
box-sizing: border-box; | ||
border-top: 1px solid ${color.BORDER}; | ||
border-right: 1px solid ${color.BORDER}; | ||
background-color: ${color.WHITE}; | ||
height: inherit; | ||
` | ||
|
||
const StyledSection = styled(Section)` | ||
box-sizing: border-box; | ||
height: inherit; | ||
` | ||
|
||
const CenterStack = styled(Stack)` | ||
display: flex; | ||
flex-direction: row; | ||
height: inherit; | ||
justify-content: center; | ||
` | ||
|
||
const StyledStack = styled(Stack)` | ||
display: flex; | ||
flex-direction: row; | ||
height: inherit; | ||
` | ||
|
||
const StyledDefinitionSources = styled(DefinitionSources)` | ||
flex: 1; | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './Show' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { path } from '@/constants/path' | ||
import { CombinedDefinitionGraphOptions } from '@/models/combinedDefinition' | ||
import { fetchCombinedDefinition, stringifyCombinedDefinitionOptions } from './combinedDefinitionRepository' | ||
import useSWR from 'swr' | ||
|
||
export const useModuleDefinition = (moduleNames: string[], graphOptions: CombinedDefinitionGraphOptions) => { | ||
const requestPath = `${path.api.moduleDefinitions.show(moduleNames)}?${stringifyCombinedDefinitionOptions(graphOptions)}` | ||
const shouldFetch = moduleNames.length > 0 | ||
const { data, isLoading, mutate } = useSWR(shouldFetch ? requestPath : null, fetchCombinedDefinition) | ||
|
||
return { data, isLoading, mutate } | ||
} |
Oops, something went wrong.