-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
278 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
'use client'; | ||
|
||
import Button from '@/_components/button'; | ||
import IconButton from '@/_components/icon-button'; | ||
import InsightMenu from '@/_components/insight-menu'; | ||
import PlotFigure from '@/_components/plot-figure'; | ||
import { ListEventsData } from '@/_queries/list-events'; | ||
import { ListInsightsData } from '@/_queries/list-insights'; | ||
import { InsightConfigJson } from '@/_types/insight-config-json'; | ||
import { useSortable } from '@dnd-kit/sortable'; | ||
import { ArrowsPointingOutIcon } from '@heroicons/react/24/outline'; | ||
import Bars2Icon from '@heroicons/react/24/outline/Bars2Icon'; | ||
import { Dispatch, SetStateAction } from 'react'; | ||
import { twMerge } from 'tailwind-merge'; | ||
|
||
interface InsightProps { | ||
activeId: string | null; | ||
config: InsightConfigJson; | ||
events: ListEventsData; | ||
insight: NonNullable<ListInsightsData>[0]; | ||
isPublic?: boolean; | ||
isReadOnly: boolean; | ||
searchString: string; | ||
setActiveId?: Dispatch<SetStateAction<string | null>>; | ||
setSyncDate?: Dispatch<SetStateAction<Date | null>>; | ||
shareOrSubjects: 'share' | 'subjects'; | ||
subjectId: string; | ||
syncDate: Date | null; | ||
} | ||
|
||
const Insight = ({ | ||
activeId, | ||
config, | ||
events, | ||
insight, | ||
isPublic, | ||
isReadOnly, | ||
searchString, | ||
setActiveId, | ||
setSyncDate, | ||
shareOrSubjects, | ||
subjectId, | ||
syncDate, | ||
}: InsightProps) => { | ||
const sortableInsight = useSortable({ id: insight.id }); | ||
|
||
return ( | ||
<div | ||
className={twMerge( | ||
'min-h-12 rounded border border-alpha-1 bg-bg-3', | ||
sortableInsight.isDragging && 'relative z-10 drop-shadow-2xl', | ||
)} | ||
ref={sortableInsight.setNodeRef} | ||
style={{ | ||
transform: sortableInsight.transform | ||
? sortableInsight.isDragging | ||
? `translate(${sortableInsight.transform.x}px, ${sortableInsight.transform.y}px) scale(1.03)` | ||
: `translate(${sortableInsight.transform.x}px, ${sortableInsight.transform.y}px)` | ||
: undefined, | ||
transition: sortableInsight.transition, | ||
}} | ||
> | ||
<div className="-mb-4 flex items-stretch"> | ||
{!isReadOnly && ( | ||
<IconButton | ||
className="m-0 h-full cursor-ns-resize touch-none px-4" | ||
icon={<Bars2Icon className="w-5" />} | ||
{...sortableInsight.attributes} | ||
{...sortableInsight.listeners} | ||
/> | ||
)} | ||
<Button | ||
className={twMerge( | ||
'm-0 flex w-full gap-4 pr-4 pt-3 leading-snug', | ||
!isReadOnly && 'px-0', | ||
)} | ||
href={`/${shareOrSubjects}/${subjectId}/insights/${insight.id}${searchString}`} | ||
scroll={false} | ||
variant="link" | ||
> | ||
{insight.name} | ||
<ArrowsPointingOutIcon className="ml-auto w-5 shrink-0" /> | ||
</Button> | ||
{!isReadOnly && ( | ||
<InsightMenu insightId={insight.id} subjectId={subjectId} /> | ||
)} | ||
</div> | ||
<PlotFigure | ||
barInterval={config.barInterval} | ||
barReducer={config.barReducer} | ||
defaultHeight={200} | ||
events={events} | ||
id={insight.id} | ||
includeEventsFrom={config.includeEventsFrom} | ||
includeEventsSince={config.includeEventsSince} | ||
inputId={config.input} | ||
inputOptions={config.inputOptions} | ||
isPublic={isPublic} | ||
lineCurveFunction={config.lineCurveFunction} | ||
marginBottom={config.marginBottom} | ||
marginLeft={config.marginLeft} | ||
marginRight={config.marginRight} | ||
marginTop={config.marginTop} | ||
setActiveId={setActiveId} | ||
setSyncDate={setSyncDate} | ||
showBars={config.showBars} | ||
showDots={config.showDots} | ||
showLine={config.showLine} | ||
showLinearRegression={config.showLinearRegression} | ||
subjectId={subjectId} | ||
syncDate={insight.id === activeId ? null : syncDate} | ||
title={insight.name} | ||
type={config.type} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Insight; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.