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

feat:Add svg download custom date #246

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion apps/web/i18n
Submodule i18n updated 3 files
+1 −1 en/analyze.json
+1 −1 en/home.json
+1 −1 zh/home.json
5 changes: 4 additions & 1 deletion apps/web/src/common/components/BaseCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ const BaseCard: React.FC<BaseCardProps> = ({

return (
<div className={classnames(cls)} ref={cardRef} id={id}>
<h3 className="group mb-2 text-lg font-semibold" ref={titleRef}>
<h3
className="group mb-2 text-lg font-semibold text-[#000000]"
ref={titleRef}
>
{title}
<a href={`#${id}`}>
<span className="group-hover:text-primary invisible ml-2 cursor-pointer group-hover:visible">
Expand Down
21 changes: 9 additions & 12 deletions apps/web/src/modules/analyze/components/DownCardLoadImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const DownLoadImage = (props: DownLoadImageProps) => {
return () => {
clearTimeout(timer);
};
}, [cardRef]);
}, [cardRef, onCompleteLoad, size]);

useEffect(() => {
const downLoadImg = async () => {
Expand Down Expand Up @@ -113,7 +113,7 @@ const DownLoadImage = (props: DownLoadImageProps) => {
downLoadImg().catch((e) => {
console.log('error:', e);
});
}, [loadingDownLoadImg]);
}, [loadingDownLoadImg, fileFormat, onComplete]);

if (fileFormat === 'SVG') {
return (
Expand All @@ -126,7 +126,7 @@ const DownLoadImage = (props: DownLoadImageProps) => {
{/* eslint-disable-next-line @next/next/no-img-element */}
<img src={dataURL} className="w-full" alt="" />
{dataURL && (
<div className="mb-2 ml-4 origin-left scale-50 text-xs text-[#585858]">
<div className="mb-2 ml-4 origin-left scale-75 text-xs text-[#b4adbe]">
Powered by oss-compass.org
</div>
)}
Expand Down Expand Up @@ -226,14 +226,9 @@ const DownLoadImage = (props: DownLoadImageProps) => {

if (level === Level.REPO) {
labelNode = (
<a
className="ml-2 mr-1 whitespace-nowrap text-2xl font-semibold text-black hover:underline"
href={label}
target="_blank"
rel={'noreferrer'}
>
<span className="ml-2 text-2xl font-semibold text-black">
{name}
</a>
</span>
);
}
return (
Expand All @@ -244,8 +239,10 @@ const DownLoadImage = (props: DownLoadImageProps) => {
/>
{labelNode}
{level === Level.COMMUNITY && (
<div className="ml-2 inline-block rounded-[10px] bg-[#FFF9F2] px-2 py-0.5 text-xs text-[#D98523]">
{t('home:community')}
<div className="ml-2 inline-block h-5 rounded-[10px] bg-[#FFF9F2] px-2 align-bottom text-xs text-[#D98523]">
<span className="relative -top-1">
{t('home:community')}
</span>
</div>
)}
{index < compareItems.length - 1 ? (
Expand Down
28 changes: 21 additions & 7 deletions apps/web/src/modules/analyze/components/DownloadAndShare.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import * as RadioGroup from '@radix-ui/react-radio-group';
import DownCardLoadImage from './DownCardLoadImage';
import { AiOutlineLoading } from 'react-icons/ai';
import useCompareItems from '@modules/analyze/hooks/useCompareItems';
// import useQueryDateRange from '@modules/analyze/hooks/useQueryDateRange';
// import { format } from 'date-fns';
import useQueryDateRange from '@modules/analyze/hooks/useQueryDateRange';
import { rangeTags } from '../constant';
import { format } from 'date-fns';

const queryMap = {
metricCodequality: 'collab_dev_index',
Expand All @@ -27,11 +28,18 @@ const queryMap = {
metricGroupActivity: 'organizations_activity',
};

const toUnderline = (str) => {
const toUnderline = (str: string) => {
return str.replace(/([A-Z])/g, '_$1').toLowerCase();
};

const getSvgUrl = (slug, id, yAxisScale, onePointSys, yKey) => {
const useGetSvgUrl = (
slug: string,
id: string,
yAxisScale: boolean,
onePointSys: boolean,
yKey: string
) => {
const { range, timeStart, timeEnd } = useQueryDateRange();
let url = `/chart/${slug}.svg`;
let metrc = '';
let field = '';
Expand All @@ -54,9 +62,15 @@ const getSvgUrl = (slug, id, yAxisScale, onePointSys, yKey) => {
) {
url += `&chart=bar`;
}
if (rangeTags.includes(range)) {
url += `&range=${range}`;
} else {
const begin_date = format(timeStart!, 'yyyy-MM-dd');
const end_date = format(timeEnd!, 'yyyy-MM-dd');
url += `&begin_date=${begin_date}&end_date=${end_date}`;
}
return url;
};

const DownloadAndShare = (props: {
cardRef: RefObject<HTMLElement>;
downloadImageSize?: 'middle' | 'full';
Expand All @@ -70,7 +84,7 @@ const DownloadAndShare = (props: {
const slug = router.query.slugs as string;
const { compareItems } = useCompareItems();
const len = compareItems.length;
const svgUrl = getSvgUrl(
const svgUrl = useGetSvgUrl(
slug,
cardRef.current.id,
yAxisScale,
Expand Down Expand Up @@ -278,7 +292,7 @@ const TabPanel = ({ badgeSrc, id }: { badgeSrc: string; id: string }) => {
value="Link"
/>
</Tabs>
<div className="mt-4 flex h-[60px] items-center justify-between rounded border bg-[#fafafa] px-3">
<div className="mt-4 flex h-[70px] items-center justify-between rounded border bg-[#fafafa] px-3">
<div className="break-all text-xs">{source}</div>
<Tooltip
title={
Expand Down