Skip to content

Commit

Permalink
frontend: Adjusting ProjectCatalog chipsRow to allow a target and aut…
Browse files Browse the repository at this point in the history
…o-set based on location (#2965)
  • Loading branch information
jdslaugh authored Mar 26, 2024
1 parent 6c719a3 commit 4f338ca
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
6 changes: 3 additions & 3 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
"start": "yarn clean && yarn compile:watch & FORCE_COLOR=true yarn workspace @clutch-sh/app start | cat",
"storybook": "rm -rf node_modules/.cache/storybook/ && start-storybook --disable-telemetry -p 6006 -h localhost",
"storybook:build": "NODE_OPTIONS=--max_old_space_size=4096 build-storybook --no-dll -o netlify/storybook-static",
"test": "lerna run test --stream --no-bail --",
"test:coverage": "lerna run test:coverage --stream --no-bail --",
"test:e2e": "lerna run test:e2e",
"test": "lerna run test --stream --no-bail -- --silent",
"test:coverage": "lerna run test:coverage --stream --no-bail -- --silent",
"test:e2e": "lerna run test:e2e --stream --no-bail --",
"test:licenses": "node license-linter.js",
"test:update": "yarn test:coverage -u",
"test:watch": "lerna run test:watch --parallel"
Expand Down
22 changes: 20 additions & 2 deletions frontend/workflows/projectCatalog/src/details/info/chipsRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,46 @@ import React from "react";
import type { CHIP_VARIANTS } from "@clutch-sh/core";
import { Chip, Grid, Link, Tooltip } from "@clutch-sh/core";
import ChevronRightIcon from "@mui/icons-material/ChevronRight";
import type { LinkProps } from "@mui/material";

export interface ProjectInfoChip {
text: string;
title?: string;
icon?: React.ReactElement;
url?: string;
urlTarget?: LinkProps["target"];
variant?: typeof CHIP_VARIANTS[number];
}

const ChipsRow = ({ chips = [] }: { chips: ProjectInfoChip[] }) => (
<>
{chips.map(({ variant = "neutral", text, icon, title, url }) => {
{chips.map(({ variant = "neutral", text, icon, title, url, urlTarget }) => {
const chipText = (
<Grid container direction="row" wrap="nowrap">
{text}
{url && <ChevronRightIcon fontSize="small" style={{ marginRight: "-12px" }} />}
</Grid>
);
const chipElem = <Chip variant={variant} label={chipText} size="small" icon={icon} />;

if (!urlTarget) {
const externalRoute = url && url.startsWith("http");

// eslint-disable-next-line no-param-reassign
urlTarget = externalRoute ? "_blank" : "_self";
}

return (
<Tooltip title={title ?? text} key={`chip-${title}`}>
<Grid item>{url ? <Link href={url}>{chipElem}</Link> : chipElem}</Grid>
<Grid item>
{url ? (
<Link href={url} {...(urlTarget ? { target: urlTarget } : {})}>
{chipElem}
</Link>
) : (
chipElem
)}
</Grid>
</Tooltip>
);
})}
Expand Down

0 comments on commit 4f338ca

Please sign in to comment.