-
Notifications
You must be signed in to change notification settings - Fork 142
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
Move Breadcrumbs and reconfigure for V2Routes #1550
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React from "react"; | ||
import styled from "styled-components"; | ||
import useNavigation from "../hooks/navigation"; | ||
import { getPageLabel, getParentNavValue, V2Routes } from "../lib/nav"; | ||
import Flex from "./Flex"; | ||
import Icon, { IconType } from "./Icon"; | ||
import Link from "./Link"; | ||
import Text from "./Text"; | ||
|
||
const CrumbLink = styled(Link)` | ||
${Text} { | ||
font-size: ${(props) => props.theme.fontSizes.large}; | ||
color: ${(props) => props.theme.colors.neutral00}; | ||
} | ||
`; | ||
|
||
export const Breadcrumbs = () => { | ||
const { currentPage } = useNavigation(); | ||
const parentValue = getParentNavValue(currentPage); | ||
|
||
return ( | ||
<Flex align> | ||
{parentValue !== currentPage && ( | ||
<CrumbLink | ||
to={V2Routes[parentValue as V2Routes] || ""} | ||
textProps={{ bold: true }} | ||
> | ||
{getPageLabel(parentValue as V2Routes)} | ||
</CrumbLink> | ||
)} | ||
{parentValue !== currentPage && ( | ||
<Icon type={IconType.NavigateNextIcon} size="large" color="neutral00" /> | ||
)} | ||
<CrumbLink | ||
to={currentPage} | ||
textProps={parentValue === currentPage && { bold: true }} | ||
> | ||
{getPageLabel(currentPage)} | ||
</CrumbLink> | ||
</Flex> | ||
); | ||
}; | ||
|
||
export default styled(Breadcrumbs)``; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React from "react"; | ||
import renderer from "react-test-renderer"; | ||
import { createMockClient, withContext, withTheme } from "../../lib/test-utils"; | ||
import Breadcrumbs from "../Breadcrumbs"; | ||
|
||
describe("snapshots", () => { | ||
it("renders", () => { | ||
const tree = renderer | ||
joshri marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.create( | ||
withTheme( | ||
withContext(<Breadcrumbs />, "/automations", { | ||
jpellizzari marked this conversation as resolved.
Show resolved
Hide resolved
|
||
applicationsClient: createMockClient({}), | ||
}) | ||
) | ||
) | ||
.toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
it("renders child route", () => { | ||
const tree = renderer | ||
.create( | ||
withTheme( | ||
withContext(<Breadcrumbs />, "/kustomization?name=flux", { | ||
applicationsClient: createMockClient({}), | ||
}) | ||
) | ||
) | ||
.toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`snapshots renders 1`] = ` | ||
<div | ||
className="sc-bdvvtL lacWsj" | ||
> | ||
<a | ||
className="sc-hKwDye sc-eCImPb kCA-dBN cQVkzF" | ||
href="/automations" | ||
onClick={[Function]} | ||
> | ||
<span | ||
className="sc-gsDKAQ klFDZy" | ||
color="primary" | ||
size="normal" | ||
> | ||
Applications | ||
</span> | ||
</a> | ||
</div> | ||
`; | ||
|
||
exports[`snapshots renders child route 1`] = ` | ||
<div | ||
className="sc-bdvvtL lacWsj" | ||
> | ||
<a | ||
className="sc-hKwDye sc-eCImPb kCA-dBN cQVkzF" | ||
href="/" | ||
onClick={[Function]} | ||
> | ||
<span | ||
className="sc-gsDKAQ klFDZy" | ||
color="primary" | ||
size="normal" | ||
> | ||
Applications | ||
</span> | ||
</a> | ||
<div | ||
className="sc-bdvvtL lacWsj sc-dkPtRN hTjxvJ" | ||
> | ||
<svg | ||
aria-hidden={true} | ||
className="MuiSvgIcon-root" | ||
focusable="false" | ||
viewBox="0 0 24 24" | ||
> | ||
<path | ||
d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z" | ||
/> | ||
</svg> | ||
</div> | ||
<a | ||
className="sc-hKwDye sc-eCImPb kCA-dBN cQVkzF" | ||
href="/kustomization" | ||
onClick={[Function]} | ||
> | ||
<span | ||
className="sc-gsDKAQ fcdFvu" | ||
color="primary" | ||
size="normal" | ||
> | ||
flux | ||
</span> | ||
</a> | ||
</div> | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import qs from "query-string"; | ||
import { useLocation } from "react-router-dom"; | ||
import { SourceRefSourceKind } from "./api/core/types.pb"; | ||
import { PageRoute } from "./types"; | ||
|
||
|
@@ -41,6 +42,24 @@ export const getParentNavValue = ( | |
} | ||
}; | ||
|
||
export const getPageLabel = (currentPage: string): string => { | ||
const parsed = qs.parse(useLocation().search); | ||
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. 🤔 Not sure how this is working. I was under the impression that you cannot call hooks from plain old JS like this. I thought it had to be within another hook. 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. Me too but it works so I'm not asking questions |
||
switch (currentPage) { | ||
case V2Routes.Automations: | ||
return "Applications"; | ||
case V2Routes.Sources: | ||
return "Sources"; | ||
case V2Routes.FluxRuntime: | ||
return "Flux Runtime"; | ||
case V2Routes.Kustomization: | ||
case V2Routes.HelmRelease: | ||
case V2Routes.GitRepo: | ||
case V2Routes.HelmChart: | ||
case V2Routes.Bucket: | ||
return parsed.name as string; | ||
} | ||
}; | ||
|
||
export const formatURL = (page: string, query: any = {}) => { | ||
return `${page}?${qs.stringify(query)}`; | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer necessary, right?
746b1be
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My branch was out of date :( will fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ALSO - noticed a problem with this - right now DataTable is using the field having a SortType as an indication of whether it's sortable or not - we need a different indication of which columns are sortable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joshri Still not fixed?