-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add facts modal/code viewer & detail drawer tab (#1057)
- Adds initial implementation of the facts modal, analysis detail drawer tab for facts, and code viewer for facts json. Notes: This does not cover the filter/sort logic for facts based on sources. There is no mock data available from the api for this yet, but we will be required to collate the fact sources ourselves on the UI side based on the fact keys returned from the hub. konveyor/tackle2-hub#396 for more info on how the api will look. TODO: #1061 TODO: [How should we type facts with an unknown data type? ](#1062) --------- Signed-off-by: ibolton336 <ibolton@redhat.com>
- Loading branch information
1 parent
500ca24
commit 3cbebe2
Showing
9 changed files
with
214 additions
and
1 deletion.
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
98 changes: 98 additions & 0 deletions
98
client/src/app/pages/applications/components/application-detail-drawer/application-facts.tsx
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,98 @@ | ||
import { | ||
FilterCategory, | ||
FilterToolbar, | ||
FilterType, | ||
} from "@app/shared/components/FilterToolbar"; | ||
import { | ||
Button, | ||
Toolbar, | ||
ToolbarContent, | ||
ToolbarItem, | ||
ToolbarToggleGroup, | ||
} from "@patternfly/react-core"; | ||
import React from "react"; | ||
import FilterIcon from "@patternfly/react-icons/dist/esm/icons/filter-icon"; | ||
import spacing from "@patternfly/react-styles/css/utilities/Spacing/spacing"; | ||
import { useTranslation } from "react-i18next"; | ||
import { useLegacyFilterState } from "@app/shared/hooks/useLegacyFilterState"; | ||
import { Fact } from "@app/api/models"; | ||
import { FactDetailModal } from "./fact-detail-modal/fact-detail-modal"; | ||
|
||
export interface IApplicationRiskProps { | ||
facts: Fact[]; | ||
} | ||
|
||
export const ApplicationFacts: React.FC<IApplicationRiskProps> = ({ | ||
facts, | ||
}) => { | ||
const { t } = useTranslation(); | ||
const sources = new Set<string>(); | ||
|
||
// TODO: work through how to store sources for facts in the ui for sorting | ||
// facts.forEach((fact) => sources.add(fact.source || "")); | ||
|
||
const filterCategories: FilterCategory<Fact, "source">[] = [ | ||
{ | ||
key: "source", | ||
title: t("terms.source"), | ||
type: FilterType.multiselect, | ||
placeholderText: t("terms.source"), | ||
// getItemValue: (fact) => fact.source || "Source default name", | ||
selectOptions: Array.from(sources) | ||
//TODO: Custom sorting for facts may be required | ||
// .sort(compareSources) | ||
.map((source) => source || "Source default name") | ||
.map((source) => ({ key: source, value: source })), | ||
logicOperator: "OR", | ||
}, | ||
]; | ||
|
||
const { | ||
filterValues, | ||
setFilterValues, | ||
filteredItems: filteredFacts, | ||
} = useLegacyFilterState(facts, filterCategories); | ||
|
||
const [selectedFactForDetailModal, setSelectedFactForDetailModal] = | ||
React.useState<Fact | null>(null); | ||
|
||
return ( | ||
<> | ||
<Toolbar | ||
clearAllFilters={() => setFilterValues({})} | ||
clearFiltersButtonText={t("actions.clearAllFilters")} | ||
> | ||
<ToolbarContent className={spacing.p_0}> | ||
<ToolbarItem>Filter by:</ToolbarItem> | ||
<ToolbarToggleGroup toggleIcon={<FilterIcon />} breakpoint="xl"> | ||
<FilterToolbar | ||
filterCategories={filterCategories} | ||
filterValues={filterValues} | ||
setFilterValues={setFilterValues} | ||
showFiltersSideBySide | ||
/> | ||
</ToolbarToggleGroup> | ||
</ToolbarContent> | ||
</Toolbar> | ||
{filteredFacts.map((fact) => { | ||
return ( | ||
<div> | ||
<Button | ||
variant="link" | ||
isInline | ||
onClick={() => setSelectedFactForDetailModal(fact)} | ||
> | ||
{fact.name} | ||
</Button> | ||
</div> | ||
); | ||
})} | ||
{selectedFactForDetailModal ? ( | ||
<FactDetailModal | ||
fact={selectedFactForDetailModal} | ||
onClose={() => setSelectedFactForDetailModal(null)} | ||
/> | ||
) : null} | ||
</> | ||
); | ||
}; |
22 changes: 22 additions & 0 deletions
22
...ications/components/application-detail-drawer/fact-detail-modal/fact-code-snip-viewer.tsx
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,22 @@ | ||
import * as React from "react"; | ||
import { CodeEditor, Language } from "@patternfly/react-code-editor"; | ||
import { Fact } from "@app/api/models"; | ||
import yaml from "js-yaml"; | ||
export interface IFactCodeSnipViewerProps { | ||
fact: Fact; | ||
} | ||
|
||
export const FactCodeSnipViewer: React.FC<IFactCodeSnipViewerProps> = ({ | ||
fact, | ||
}) => { | ||
return ( | ||
<CodeEditor | ||
isReadOnly | ||
isDarkTheme | ||
isLineNumbersVisible | ||
language={Language.json} | ||
height="450px" | ||
code={yaml.dump(fact.data, { skipInvalid: true })} | ||
/> | ||
); | ||
}; |
30 changes: 30 additions & 0 deletions
30
...applications/components/application-detail-drawer/fact-detail-modal/fact-detail-modal.tsx
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,30 @@ | ||
import * as React from "react"; | ||
import { Button, Modal } from "@patternfly/react-core"; | ||
import { FactCodeSnipViewer } from "./fact-code-snip-viewer"; | ||
import { Fact } from "@app/api/models"; | ||
|
||
export interface IFactDetailModalProps { | ||
fact: Fact; | ||
onClose: () => void; | ||
} | ||
|
||
export const FactDetailModal: React.FC<IFactDetailModalProps> = ({ | ||
fact, | ||
onClose, | ||
}) => { | ||
return ( | ||
<Modal | ||
title={fact.name} | ||
variant="large" | ||
isOpen | ||
onClose={onClose} | ||
actions={[ | ||
<Button key="close" variant="primary" onClick={onClose}> | ||
Close | ||
</Button>, | ||
]} | ||
> | ||
<FactCodeSnipViewer fact={fact}></FactCodeSnipViewer> | ||
</Modal> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
...rc/app/pages/applications/components/application-detail-drawer/fact-detail-modal/index.ts
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 "./fact-detail-modal"; |
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,27 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
|
||
import { getFacts } from "@app/api/rest"; | ||
import { AxiosError } from "axios"; | ||
import { Fact } from "@app/api/models"; | ||
|
||
export const FactsQueryKey = "facts"; | ||
|
||
export const useFetchFacts = (applicationID: number | string | undefined) => { | ||
const { data, isLoading, error, refetch } = useQuery( | ||
[FactsQueryKey, applicationID], | ||
{ | ||
queryFn: () => getFacts(applicationID), | ||
enabled: !!applicationID, | ||
onError: (error: AxiosError) => console.log("error, ", error), | ||
select: (facts): Fact[] => | ||
Object.keys(facts).map((fact) => ({ name: fact, data: facts[fact] })), | ||
} | ||
); | ||
|
||
return { | ||
facts: data || [], | ||
isFetching: isLoading, | ||
fetchError: error, | ||
refetch, | ||
}; | ||
}; |