Skip to content

Commit

Permalink
feat(web): support seeing dep detail by jumping to npmjs (#1315)
Browse files Browse the repository at this point in the history
  • Loading branch information
0fatal authored Jun 27, 2023
1 parent 45f8d7e commit 9e57c79
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
6 changes: 3 additions & 3 deletions web/src/components/ConfirmButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { t } from "i18next";

interface ConfirmButtonProps {
onSuccessAction: () => void;
onSuccessAction: React.MouseEventHandler<HTMLButtonElement>;
headerText: string;
bodyText: string | React.ReactElement | any;
confirmButtonText?: string;
Expand All @@ -31,8 +31,8 @@ const ConfirmButton = ({
const { isOpen, onOpen, onClose } = useDisclosure();
const cancelRef = React.useRef<any>();

const onSubmit = () => {
onSuccessAction();
const onSubmit: React.MouseEventHandler<HTMLButtonElement> = (event) => {
onSuccessAction(event);
onClose();
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import { AddIcon, EditIcon, SearchIcon, SmallCloseIcon } from "@chakra-ui/icons";
import { AddIcon, EditIcon, ExternalLinkIcon, SearchIcon, SmallCloseIcon } from "@chakra-ui/icons";
import {
Box,
Button,
Expand Down Expand Up @@ -36,6 +36,7 @@ import {
usePackageSearchQuery,
usePackageVersionsQuery,
} from "../service";
import { openDependenceDetail } from "..";

import useGlobalStore from "@/pages/globalStore";

Expand Down Expand Up @@ -205,7 +206,17 @@ const AddDependenceModal = () => {
}
>
<Box ml={5} width="350px">
<b>{packageItem.package.name}</b>
<div className="flex items-center space-x-1">
<b>{packageItem.package.name}</b>
<ExternalLinkIcon
className="!text-primary-700 hover:scale-110"
onClick={(e) => {
e.stopPropagation();
e.preventDefault();
openDependenceDetail(packageItem.package.name);
}}
/>
</div>
<p className="overflow-hidden text-ellipsis whitespace-nowrap text-base text-second ">
{packageItem.package.description}
</p>
Expand Down
17 changes: 14 additions & 3 deletions web/src/pages/app/functions/mods/DependencePanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import { TPackage, useDelPackageMutation, usePackageQuery } from "./service";
import useCustomSettingStore from "@/pages/customSetting";
import useGlobalStore from "@/pages/globalStore";

export const openDependenceDetail = (depName: string) => {
window.open(`https://www.npmjs.com/package/${encodeURIComponent(depName)}`, "_blank");
};

export default function DependenceList() {
const packageQuery = usePackageQuery();
const globalStore = useGlobalStore((state) => state);
Expand Down Expand Up @@ -77,7 +81,9 @@ export default function DependenceList() {
size="small"
isActive={false}
key={packageItem?.name!}
onClick={() => {}}
onClick={() => {
openDependenceDetail(packageItem.name);
}}
className="group"
>
<FileTypeIcon type={FileType.npm} />
Expand All @@ -93,7 +99,9 @@ export default function DependenceList() {
{!packageItem?.builtin ? (
<span className=" ml-2 hidden w-[10px] group-hover:inline-block">
<ConfirmButton
onSuccessAction={async () => {
onSuccessAction={(e) => {
e.stopPropagation();
e.preventDefault();
delPackageMutation.mutate({ name: packageItem?.name });
}}
headerText={String(t("Delete"))}
Expand Down Expand Up @@ -124,8 +132,11 @@ export default function DependenceList() {
isActive={false}
key={packageItem?.name!}
className="group"
onClick={() => {
openDependenceDetail(packageItem.name);
}}
>
<div className=" text-second">
<div className="text-second">
<span className="inline-block w-40 overflow-hidden overflow-ellipsis whitespace-nowrap">
{packageItem?.name}
</span>
Expand Down

0 comments on commit 9e57c79

Please sign in to comment.