Skip to content
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

🪟🔧 Reactor Breadcrumbs component to use anchors #18764

Merged
merged 4 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@use "scss/colors";

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

.item {
display: inline-block;
cursor: pointer;
color: colors.$blue-400;
text-decoration: none;
josephkmh marked this conversation as resolved.
Show resolved Hide resolved

&--unlinked {
josephkmh marked this conversation as resolved.
Show resolved Hide resolved
font-weight: bold;
}

&:hover {
opacity: 0.8;
}
}
55 changes: 20 additions & 35 deletions airbyte-webapp/src/components/ui/Breadcrumbs/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
@@ -1,49 +1,34 @@
import React from "react";
import styled from "styled-components";
import { Link } from "react-router-dom";

const BreadcrumbsContainer = styled.div`
font-weight: normal;
cursor: default;
`;

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} className={styles.item}>
{item.label}
</Link>
) : (
<span className={styles["item--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