generated from finos-labs/project-blueprint
-
Notifications
You must be signed in to change notification settings - Fork 88
feat(calm-hub-ui): Deeplinks within CalmHub #1853
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aamanrebello
wants to merge
15
commits into
finos:main
Choose a base branch
from
aamanrebello:deeplink
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+205
β66
Open
Changes from 8 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
a878fb3
feat(calm-hub-ui): Deeplinks within CalmHub
aamanrebello cd29f9f
Merge branch 'main' into deeplink
aamanrebello 8dfb693
Merge branch 'main' into deeplink
aamanrebello 76c0c94
Merge branch 'main' into deeplink
rocketstack-matt 5a805e3
Merge branch 'main' into deeplink
rocketstack-matt 4477e08
Merge branch 'main' into deeplink
aamanrebello 88a7bfb
Merge branch 'main' into deeplink
aamanrebello c8047f6
feat(calm-hub-ui): Better state management
aamanrebello 5d15ca5
Merge branch 'main' into deeplink
aamanrebello b45068e
Merge branch 'main' into deeplink
aamanrebello 0a144d8
Merge branch 'main' into deeplink
markscott-ms 9fb4132
Merge branch 'main' into deeplink
aamanrebello c2f6056
Merge branch 'main' into deeplink
YoofiTT96 32a3c32
Merge branch 'main' into deeplink
aamanrebello 103f97e
Merge branch 'main' into deeplink
rocketstack-matt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import { useEffect, useState } from 'react'; | ||
| import { useCallback, useEffect, useMemo, useState } from 'react'; | ||
| import { IoCompassOutline } from 'react-icons/io5'; | ||
| import { | ||
| fetchNamespaces, | ||
|
|
@@ -14,6 +14,16 @@ import { | |
| } from '../../../service/calm-service.js'; | ||
| import { AdrService } from '../../../service/adr-service/adr-service.js'; | ||
| import { Data, Adr } from '../../../model/calm.js'; | ||
| import { useNavigate, useParams } from 'react-router-dom'; | ||
|
|
||
| type HubParams = { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if this is the best place to define these properties? |
||
| namespace?: string; | ||
| type?: 'Architectures' | 'Patterns' | 'Flows' | 'ADRs'; | ||
| id?: string; | ||
| version?: string; | ||
| }; | ||
|
|
||
| const basePath = '/artifacts'; | ||
|
|
||
| interface TreeNavigationProps { | ||
| onDataLoad: (data: Data) => void; | ||
|
|
@@ -200,7 +210,54 @@ function NamespaceItem({ | |
| ); | ||
| } | ||
|
|
||
| function isNotNullOrEmptyString(value: string | null | undefined): value is string { | ||
| return value !== null && value !== undefined && value !== ''; | ||
| } | ||
|
|
||
| function loadResourceIds(type: string, namespace: string, setArchitectureIDs: (ids: string[]) => void, setPatternIDs: (ids: string[]) => void, setFlowIDs: (ids: string[]) => void, adrService: AdrService, setAdrIDs: (ids: string[]) => void) { | ||
| if (type === 'Architectures') { | ||
| fetchArchitectureIDs(namespace, setArchitectureIDs); | ||
| } else if (type === 'Patterns') { | ||
| fetchPatternIDs(namespace, setPatternIDs); | ||
| } else if (type === 'Flows') { | ||
| fetchFlowIDs(namespace, setFlowIDs); | ||
| } else if (type === 'ADRs') { | ||
| adrService | ||
| .fetchAdrIDs(namespace) | ||
| .then((ids) => setAdrIDs(ids.map((id) => id.toString()))); | ||
| } | ||
| } | ||
|
|
||
| function loadVersions(resourceID: string, type: string, namespace: string, setArchitectureVersions: (versions: string[]) => void, setPatternVersions: (versions: string[]) => void, setFlowVersions: (versions: string[]) => void, adrService: AdrService, setAdrRevisions: (revisions: string[]) => void) { | ||
| if (type === 'Architectures') { | ||
| fetchArchitectureVersions(namespace, resourceID, setArchitectureVersions); | ||
| } else if (type === 'Patterns') { | ||
| fetchPatternVersions(namespace, resourceID, setPatternVersions); | ||
| } else if (type === 'Flows') { | ||
| fetchFlowVersions(namespace, resourceID, setFlowVersions); | ||
| } else if (type === 'ADRs') { | ||
| adrService | ||
| .fetchAdrRevisions(namespace, resourceID) | ||
| .then((revisions) => setAdrRevisions(revisions.map((rev) => rev.toString()))); | ||
| } | ||
| } | ||
|
|
||
| function loadResource(version: string, type: string, namespace: string, resourceID: string, onDataLoad: (data: Data) => void, onAdrLoad: (adr: Adr) => void, adrService: AdrService) { | ||
| if (type === 'Architectures') { | ||
| fetchArchitecture(namespace, resourceID, version, onDataLoad); | ||
| } else if (type === 'Patterns') { | ||
| fetchPattern(namespace, resourceID, version, onDataLoad); | ||
| } else if (type === 'Flows') { | ||
| fetchFlow(namespace, resourceID, version, onDataLoad); | ||
| } else if (type === 'ADRs') { | ||
| adrService.fetchAdr(namespace, resourceID, version).then(onAdrLoad); | ||
| } | ||
| } | ||
|
|
||
| export function TreeNavigation({ onDataLoad, onAdrLoad }: TreeNavigationProps) { | ||
| const navigate = useNavigate(); | ||
| const params = useParams<HubParams>(); | ||
|
|
||
| const [namespaces, setNamespaces] = useState<string[]>([]); | ||
| const [selectedNamespace, setSelectedNamespace] = useState<string>(''); | ||
| const [selectedType, setSelectedType] = useState<string>(''); | ||
|
|
@@ -217,74 +274,54 @@ export function TreeNavigation({ onDataLoad, onAdrLoad }: TreeNavigationProps) { | |
| const [flowVersions, setFlowVersions] = useState<string[]>([]); | ||
| const [adrRevisions, setAdrRevisions] = useState<string[]>([]); | ||
|
|
||
| const adrService = new AdrService(); | ||
| const adrService = useMemo(() => new AdrService(), []); | ||
|
|
||
| useEffect(() => { | ||
| fetchNamespaces(setNamespaces); | ||
| }, []); | ||
|
|
||
| const handleNamespaceClick = (namespace: string) => { | ||
| if (selectedNamespace === namespace) { | ||
| setSelectedNamespace(''); | ||
| } else { | ||
| setSelectedNamespace(namespace); | ||
| } | ||
| setSelectedType(''); | ||
| setSelectedResourceID(''); | ||
| setSelectedVersion(''); | ||
| }; | ||
|
|
||
| const handleTypeClick = (type: string) => { | ||
| if (selectedType === type) { | ||
| setSelectedType(''); | ||
| } else { | ||
| setSelectedType(type); | ||
| if (type === 'Architectures') { | ||
| fetchArchitectureIDs(selectedNamespace, setArchitectureIDs); | ||
| } else if (type === 'Patterns') { | ||
| fetchPatternIDs(selectedNamespace, setPatternIDs); | ||
| } else if (type === 'Flows') { | ||
| fetchFlowIDs(selectedNamespace, setFlowIDs); | ||
| } else if (type === 'ADRs') { | ||
| adrService | ||
| .fetchAdrIDs(selectedNamespace) | ||
| .then((ids) => setAdrIDs(ids.map((id) => id.toString()))); | ||
| // Check if namespace exists | ||
| if (isNotNullOrEmptyString(params.namespace)) { | ||
| //Set selected namespace based on params | ||
| setSelectedNamespace(params.namespace); | ||
| // Check if resource type exists | ||
| if (isNotNullOrEmptyString(params.type)) { | ||
| //Set selected type based on params | ||
| setSelectedType(params.type); | ||
| //Load resource IDs for the selected type and namespace | ||
| loadResourceIds(params.type, params.namespace, setArchitectureIDs, setPatternIDs, setFlowIDs, adrService, setAdrIDs); | ||
| // Check if resource ID exists | ||
| if (isNotNullOrEmptyString(params.id)) { | ||
| //Set selected resource ID based on params | ||
| setSelectedResourceID(params.id); | ||
| //Load versions for the selected resource ID, type, and namespace | ||
| loadVersions(params.id, params.type, params.namespace, setArchitectureVersions, setPatternVersions, setFlowVersions, adrService, setAdrRevisions); | ||
| // Check if version exists | ||
| if (isNotNullOrEmptyString(params.version)) { | ||
| //Set selected version based on params | ||
| setSelectedVersion(params.version); | ||
| //Load the resource data or ADR based on all params | ||
| loadResource(params.version, params.type, params.namespace, params.id, onDataLoad, onAdrLoad, adrService); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| setSelectedResourceID(''); | ||
| setSelectedVersion(''); | ||
| }; | ||
|
|
||
| }, [params, adrService, onDataLoad, onAdrLoad]); | ||
|
|
||
| const handleResourceClick = (resourceID: string, type: string) => { | ||
| setSelectedResourceID(resourceID); | ||
| setSelectedVersion(''); | ||
| const handleNamespaceClick = useCallback((namespace: string) => { | ||
| navigate(`${basePath}/${namespace}`); | ||
| }, [navigate]); | ||
|
|
||
| if (type === 'Architectures') { | ||
| fetchArchitectureVersions(selectedNamespace, resourceID, setArchitectureVersions); | ||
| } else if (type === 'Patterns') { | ||
| fetchPatternVersions(selectedNamespace, resourceID, setPatternVersions); | ||
| } else if (type === 'Flows') { | ||
| fetchFlowVersions(selectedNamespace, resourceID, setFlowVersions); | ||
| } else if (type === 'ADRs') { | ||
| adrService | ||
| .fetchAdrRevisions(selectedNamespace, resourceID) | ||
| .then((revisions) => setAdrRevisions(revisions.map((rev) => rev.toString()))); | ||
| } | ||
| }; | ||
| const handleTypeClick = useCallback((type: string) => { | ||
| navigate(`${basePath}/${selectedNamespace}/${type}`); | ||
| }, [navigate, selectedNamespace]); | ||
|
|
||
| const handleVersionClick = (version: string, type: string) => { | ||
| setSelectedVersion(version); | ||
| const handleResourceClick = useCallback((resourceID: string, type: string) => { | ||
| navigate(`${basePath}/${selectedNamespace}/${type}/${resourceID}`); | ||
| }, [navigate, selectedNamespace]); | ||
|
|
||
| if (type === 'Architectures') { | ||
| fetchArchitecture(selectedNamespace, selectedResourceID, version, onDataLoad); | ||
| } else if (type === 'Patterns') { | ||
| fetchPattern(selectedNamespace, selectedResourceID, version, onDataLoad); | ||
| } else if (type === 'Flows') { | ||
| fetchFlow(selectedNamespace, selectedResourceID, version, onDataLoad); | ||
| } else if (type === 'ADRs') { | ||
| adrService.fetchAdr(selectedNamespace, selectedResourceID, version).then(onAdrLoad); | ||
| } | ||
| }; | ||
| const handleVersionClick = useCallback((version: string, type: string) => { | ||
| navigate(`${basePath}/${selectedNamespace}/${type}/${selectedResourceID}/${version}`); | ||
| }, [navigate, selectedNamespace, selectedResourceID]); | ||
|
|
||
| const getResourceIDs = (type: string): string[] => { | ||
| switch (type) { | ||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.