Skip to content

Commit

Permalink
🪟🔧 Reactor Breadcrumbs component to use anchors (airbytehq#18764)
Browse files Browse the repository at this point in the history
* refactor breadcrumbs to use actual links

* PR comments on styles
  • Loading branch information
josephkmh authored and drewrasm committed Nov 2, 2022
1 parent ffa42fa commit 23804cc
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@use "scss/colors";

.container {
font-weight: normal;
cursor: default;
}

.item {
display: inline-block;

a {
text-decoration: none;
}
}

.unlinked {
font-weight: bold;
}
54 changes: 20 additions & 34 deletions airbyte-webapp/src/components/ui/Breadcrumbs/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
@@ -1,49 +1,35 @@
import React from "react";
import styled from "styled-components";

const BreadcrumbsContainer = styled.div`
font-weight: normal;
cursor: default;
`;
import { Link } from "components";

const LastBreadcrumbsItem = styled.span`
font-weight: bold;
`;

const BreadcrumbsItem = styled.div`
display: inline-block;
cursor: pointer;
color: ${({ theme }) => theme.primaryColor};
&:hover {
opacity: 0.8;
}
`;
import styles from "./Breadcrumbs.module.scss";

export interface BreadcrumbsDataItem {
name: string | React.ReactNode;
onClick?: () => void;
label: string;
to?: string;
}

interface BreadcrumbsProps {
data: BreadcrumbsDataItem[];
}

export const Breadcrumbs: React.FC<BreadcrumbsProps> = ({ data }) => {
const lastIndex = data.length - 1;

return (
<BreadcrumbsContainer>
{data.map((item, key) =>
key === lastIndex ? (
<LastBreadcrumbsItem key={`breadcrumbs-item-${key}`}>{item.name}</LastBreadcrumbsItem>
) : (
<span key={`breadcrumbs-item-${key}`}>
<BreadcrumbsItem onClick={item.onClick}>{item.name}</BreadcrumbsItem>
<span> / </span>
</span>
)
)}
</BreadcrumbsContainer>
<div className={styles.container}>
{data.map((item, index) => (
<span key={index}>
{item.to ? (
<Link to={item.to} $clear className={styles.item}>
{item.label}
</Link>
) : (
<span className={styles.unlinked} key={index}>
{item.label}
</span>
)}
{index !== data.length - 1 && <span> / </span>}
</span>
))}
</div>
);
};
15 changes: 5 additions & 10 deletions airbyte-webapp/src/components/ui/Breadcrumbs/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,17 @@ export default {

const Template: ComponentStory<typeof Breadcrumbs> = (args) => <Breadcrumbs {...args} />;

const onClick = () => {
console.log("onClick");
};

const data: BreadcrumbsDataItem[] = [
{
name: "Workspace",
onClick,
label: "Workspace",
to: "/workspace",
},
{
name: "Source",
onClick,
label: "Source",
to: "/workspace/source",
},
{
name: "Settings",
onClick,
label: "Settings",
},
];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Suspense, useMemo } from "react";
import { FormattedMessage } from "react-intl";
import { useIntl } from "react-intl";
import { Route, Routes, useNavigate, useParams } from "react-router-dom";

import { LoadingPage } from "components";
Expand Down Expand Up @@ -29,6 +29,7 @@ const DestinationItemPage: React.FC = () => {
useTrackPage(PageTrackingCodes.DESTINATION_ITEM);
const params = useParams() as { "*": StepsTypes | ""; id: string };
const navigate = useNavigate();
const { formatMessage } = useIntl();
const currentStep = useMemo<string>(() => (params["*"] === "" ? StepsTypes.OVERVIEW : params["*"]), [params]);

const { sources } = useSourceList();
Expand All @@ -41,19 +42,17 @@ const DestinationItemPage: React.FC = () => {

const { connections } = useConnectionList();

const onClickBack = () => navigate("..");

const onSelectStep = (id: string) => {
const path = id === StepsTypes.OVERVIEW ? "." : id.toLowerCase();
navigate(path);
};

const breadcrumbsData = [
{
name: <FormattedMessage id="admin.destinations" />,
onClick: onClickBack,
label: formatMessage({ id: "admin.destinations" }),
to: "..",
},
{ name: destination.name },
{ label: destination.name },
];

const connectionsWithDestination = connections.filter(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Suspense, useMemo } from "react";
import { FormattedMessage } from "react-intl";
import { useIntl } from "react-intl";
import { Route, Routes, useNavigate, useParams } from "react-router-dom";

import { ApiErrorBoundary } from "components/common/ApiErrorBoundary";
Expand Down Expand Up @@ -29,6 +29,7 @@ const SourceItemPage: React.FC = () => {
useTrackPage(PageTrackingCodes.SOURCE_ITEM);
const params = useParams<{ "*": StepsTypes | "" | undefined; id: string }>();
const navigate = useNavigate();
const { formatMessage } = useIntl();
const currentStep = useMemo<StepsTypes | "" | undefined>(
() => (params["*"] === "" ? StepsTypes.OVERVIEW : params["*"]),
[params]
Expand All @@ -45,10 +46,10 @@ const SourceItemPage: React.FC = () => {

const breadcrumbsData = [
{
name: <FormattedMessage id="sidebar.sources" />,
onClick: () => navigate(".."),
label: formatMessage({ id: "sidebar.sources" }),
to: "..",
},
{ name: source.name },
{ label: source.name },
];

const connectionsWithSource = connections.filter((connectionItem) => connectionItem.sourceId === source.sourceId);
Expand Down

0 comments on commit 23804cc

Please sign in to comment.