[WEB-2316] chore: Kanban group virtualization (#5565)
* kanban group virtualization * minor name change
This commit is contained in:
parent
aec4162c22
commit
5e83da9ca1
5 changed files with 157 additions and 51 deletions
|
|
@ -11,6 +11,7 @@ type Props = {
|
||||||
classNames?: string;
|
classNames?: string;
|
||||||
placeholderChildren?: ReactNode;
|
placeholderChildren?: ReactNode;
|
||||||
defaultValue?: boolean;
|
defaultValue?: boolean;
|
||||||
|
useIdletime?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const RenderIfVisible: React.FC<Props> = (props) => {
|
const RenderIfVisible: React.FC<Props> = (props) => {
|
||||||
|
|
@ -21,9 +22,10 @@ const RenderIfVisible: React.FC<Props> = (props) => {
|
||||||
horizontalOffset = 0,
|
horizontalOffset = 0,
|
||||||
as = "div",
|
as = "div",
|
||||||
children,
|
children,
|
||||||
defaultValue = false,
|
|
||||||
classNames = "",
|
classNames = "",
|
||||||
placeholderChildren = null, //placeholder children
|
placeholderChildren = null, //placeholder children
|
||||||
|
defaultValue = false,
|
||||||
|
useIdletime = false,
|
||||||
} = props;
|
} = props;
|
||||||
const [shouldVisible, setShouldVisible] = useState<boolean>(defaultValue);
|
const [shouldVisible, setShouldVisible] = useState<boolean>(defaultValue);
|
||||||
const placeholderHeight = useRef<string>(defaultHeight);
|
const placeholderHeight = useRef<string>(defaultHeight);
|
||||||
|
|
@ -37,14 +39,13 @@ const RenderIfVisible: React.FC<Props> = (props) => {
|
||||||
const observer = new IntersectionObserver(
|
const observer = new IntersectionObserver(
|
||||||
(entries) => {
|
(entries) => {
|
||||||
//DO no remove comments for future
|
//DO no remove comments for future
|
||||||
// if (typeof window !== undefined && window.requestIdleCallback) {
|
if (typeof window !== undefined && window.requestIdleCallback && useIdletime) {
|
||||||
// window.requestIdleCallback(() => setShouldVisible(entries[0].isIntersecting), {
|
window.requestIdleCallback(() => setShouldVisible(entries[entries.length - 1].isIntersecting), {
|
||||||
// timeout: 300,
|
timeout: 300,
|
||||||
// });
|
});
|
||||||
// } else {
|
} else {
|
||||||
// setShouldVisible(entries[0].isIntersecting);
|
setShouldVisible(entries[entries.length - 1].isIntersecting);
|
||||||
// }
|
}
|
||||||
setShouldVisible(entries[entries.length - 1].isIntersecting);
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
root: root?.current,
|
root: root?.current,
|
||||||
|
|
@ -69,8 +70,10 @@ const RenderIfVisible: React.FC<Props> = (props) => {
|
||||||
}, [isVisible, intersectionRef]);
|
}, [isVisible, intersectionRef]);
|
||||||
|
|
||||||
const child = isVisible ? <>{children}</> : placeholderChildren;
|
const child = isVisible ? <>{children}</> : placeholderChildren;
|
||||||
const style = isVisible ? {} : { height: placeholderHeight.current, width: "100%" };
|
const style: { width?: string; height?: string } = isVisible
|
||||||
const className = isVisible ? classNames : cn(classNames, "bg-custom-background-80");
|
? {}
|
||||||
|
: { height: placeholderHeight.current, width: "100%" };
|
||||||
|
const className = isVisible || placeholderChildren ? classNames : cn(classNames, "bg-custom-background-80");
|
||||||
|
|
||||||
return React.createElement(as, { ref: intersectionRef, style, className }, child);
|
return React.createElement(as, { ref: intersectionRef, style, className }, child);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -13,14 +13,17 @@ import {
|
||||||
TIssueOrderByOptions,
|
TIssueOrderByOptions,
|
||||||
} from "@plane/types";
|
} from "@plane/types";
|
||||||
// constants
|
// constants
|
||||||
// hooks
|
|
||||||
import { ContentWrapper } from "@plane/ui";
|
import { ContentWrapper } from "@plane/ui";
|
||||||
|
// components
|
||||||
|
import RenderIfVisible from "@/components/core/render-if-visible-HOC";
|
||||||
|
import { KanbanColumnLoader } from "@/components/ui";
|
||||||
|
// hooks
|
||||||
import { useCycle, useKanbanView, useLabel, useMember, useModule, useProject, useProjectState } from "@/hooks/store";
|
import { useCycle, useKanbanView, useLabel, useMember, useModule, useProject, useProjectState } from "@/hooks/store";
|
||||||
import { useIssueStoreType } from "@/hooks/use-issue-layout-store";
|
import { useIssueStoreType } from "@/hooks/use-issue-layout-store";
|
||||||
// types
|
// types
|
||||||
// parent components
|
// parent components
|
||||||
import { TRenderQuickActions } from "../list/list-view-types";
|
import { TRenderQuickActions } from "../list/list-view-types";
|
||||||
import { getGroupByColumns, isWorkspaceLevel, GroupDropLocation } from "../utils";
|
import { getGroupByColumns, isWorkspaceLevel, GroupDropLocation, getApproximateCardHeight } from "../utils";
|
||||||
// components
|
// components
|
||||||
import { HeaderGroupByCard } from "./headers/group-by-card";
|
import { HeaderGroupByCard } from "./headers/group-by-card";
|
||||||
import { KanbanGroup } from "./kanban-group";
|
import { KanbanGroup } from "./kanban-group";
|
||||||
|
|
@ -53,6 +56,7 @@ export interface IKanBan {
|
||||||
scrollableContainerRef?: MutableRefObject<HTMLDivElement | null>;
|
scrollableContainerRef?: MutableRefObject<HTMLDivElement | null>;
|
||||||
handleOnDrop: (source: GroupDropLocation, destination: GroupDropLocation) => Promise<void>;
|
handleOnDrop: (source: GroupDropLocation, destination: GroupDropLocation) => Promise<void>;
|
||||||
showEmptyGroup?: boolean;
|
showEmptyGroup?: boolean;
|
||||||
|
subGroupIndex?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const KanBan: React.FC<IKanBan> = observer((props) => {
|
export const KanBan: React.FC<IKanBan> = observer((props) => {
|
||||||
|
|
@ -80,6 +84,7 @@ export const KanBan: React.FC<IKanBan> = observer((props) => {
|
||||||
orderBy,
|
orderBy,
|
||||||
isDropDisabled,
|
isDropDisabled,
|
||||||
dropErrorMessage,
|
dropErrorMessage,
|
||||||
|
subGroupIndex = 0,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const storeType = useIssueStoreType();
|
const storeType = useIssueStoreType();
|
||||||
|
|
@ -133,15 +138,24 @@ export const KanBan: React.FC<IKanBan> = observer((props) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const isGroupByCreatedBy = group_by === "created_by";
|
const isGroupByCreatedBy = group_by === "created_by";
|
||||||
|
const approximateCardHeight = getApproximateCardHeight(displayProperties);
|
||||||
|
const isSubGroup = !!sub_group_id && sub_group_id !== "null";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ContentWrapper className={`flex-row relative gap-4 py-4`}>
|
<ContentWrapper className={`flex-row relative gap-4 py-4`}>
|
||||||
{list &&
|
{list &&
|
||||||
list.length > 0 &&
|
list.length > 0 &&
|
||||||
list.map((subList: IGroupByColumn) => {
|
list.map((subList: IGroupByColumn, groupIndex) => {
|
||||||
const groupByVisibilityToggle = visibilityGroupBy(subList);
|
const groupByVisibilityToggle = visibilityGroupBy(subList);
|
||||||
|
|
||||||
if (groupByVisibilityToggle.showGroup === false) return <></>;
|
if (groupByVisibilityToggle.showGroup === false) return <></>;
|
||||||
|
|
||||||
|
const issueIds = isSubGroup
|
||||||
|
? ((groupedIssueIds as TSubGroupedIssues)?.[subList.id]?.[sub_group_id] ?? [])
|
||||||
|
: ((groupedIssueIds as TGroupedIssues)?.[subList.id] ?? []);
|
||||||
|
const issueLength = issueIds?.length as number;
|
||||||
|
const groupHeight = issueLength * approximateCardHeight;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={subList.id}
|
key={subList.id}
|
||||||
|
|
@ -168,28 +182,45 @@ export const KanBan: React.FC<IKanBan> = observer((props) => {
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{groupByVisibilityToggle.showIssues && (
|
{groupByVisibilityToggle.showIssues && (
|
||||||
<KanbanGroup
|
<RenderIfVisible
|
||||||
groupId={subList.id}
|
verticalOffset={0}
|
||||||
issuesMap={issuesMap}
|
horizontalOffset={100}
|
||||||
groupedIssueIds={groupedIssueIds}
|
root={scrollableContainerRef}
|
||||||
displayProperties={displayProperties}
|
classNames="relative h-full"
|
||||||
sub_group_by={sub_group_by}
|
defaultHeight={`${groupHeight}px`}
|
||||||
group_by={group_by}
|
placeholderChildren={
|
||||||
orderBy={orderBy}
|
<KanbanColumnLoader
|
||||||
sub_group_id={sub_group_id}
|
ignoreHeader
|
||||||
isDragDisabled={isDragDisabled}
|
cardHeight={approximateCardHeight}
|
||||||
isDropDisabled={!!subList.isDropDisabled || !!isDropDisabled}
|
cardsInColumn={issueLength !== undefined && issueLength < 3 ? issueLength : 3}
|
||||||
dropErrorMessage={subList.dropErrorMessage ?? dropErrorMessage}
|
/>
|
||||||
updateIssue={updateIssue}
|
}
|
||||||
quickActions={quickActions}
|
defaultValue={groupIndex < 5 && subGroupIndex < 2}
|
||||||
enableQuickIssueCreate={enableQuickIssueCreate}
|
useIdletime
|
||||||
quickAddCallback={quickAddCallback}
|
>
|
||||||
disableIssueCreation={disableIssueCreation}
|
<KanbanGroup
|
||||||
canEditProperties={canEditProperties}
|
groupId={subList.id}
|
||||||
scrollableContainerRef={scrollableContainerRef}
|
issuesMap={issuesMap}
|
||||||
loadMoreIssues={loadMoreIssues}
|
groupedIssueIds={groupedIssueIds}
|
||||||
handleOnDrop={handleOnDrop}
|
displayProperties={displayProperties}
|
||||||
/>
|
sub_group_by={sub_group_by}
|
||||||
|
group_by={group_by}
|
||||||
|
orderBy={orderBy}
|
||||||
|
sub_group_id={sub_group_id}
|
||||||
|
isDragDisabled={isDragDisabled}
|
||||||
|
isDropDisabled={!!subList.isDropDisabled || !!isDropDisabled}
|
||||||
|
dropErrorMessage={subList.dropErrorMessage ?? dropErrorMessage}
|
||||||
|
updateIssue={updateIssue}
|
||||||
|
quickActions={quickActions}
|
||||||
|
enableQuickIssueCreate={enableQuickIssueCreate}
|
||||||
|
quickAddCallback={quickAddCallback}
|
||||||
|
disableIssueCreation={disableIssueCreation}
|
||||||
|
canEditProperties={canEditProperties}
|
||||||
|
scrollableContainerRef={scrollableContainerRef}
|
||||||
|
loadMoreIssues={loadMoreIssues}
|
||||||
|
handleOnDrop={handleOnDrop}
|
||||||
|
/>
|
||||||
|
</RenderIfVisible>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -155,7 +155,7 @@ const SubGroupSwimlane: React.FC<ISubGroupSwimlane> = observer((props) => {
|
||||||
<div className="relative h-max min-h-full w-full">
|
<div className="relative h-max min-h-full w-full">
|
||||||
{list &&
|
{list &&
|
||||||
list.length > 0 &&
|
list.length > 0 &&
|
||||||
list.map((_list: IGroupByColumn) => {
|
list.map((_list: IGroupByColumn, subGroupIndex) => {
|
||||||
const issueCount = getGroupIssueCount(undefined, _list.id, true) ?? 0;
|
const issueCount = getGroupIssueCount(undefined, _list.id, true) ?? 0;
|
||||||
const subGroupByVisibilityToggle = visibilitySubGroupBy(_list, issueCount);
|
const subGroupByVisibilityToggle = visibilitySubGroupBy(_list, issueCount);
|
||||||
if (subGroupByVisibilityToggle.showGroup === false) return <></>;
|
if (subGroupByVisibilityToggle.showGroup === false) return <></>;
|
||||||
|
|
@ -184,6 +184,7 @@ const SubGroupSwimlane: React.FC<ISubGroupSwimlane> = observer((props) => {
|
||||||
sub_group_by={sub_group_by}
|
sub_group_by={sub_group_by}
|
||||||
group_by={group_by}
|
group_by={group_by}
|
||||||
sub_group_id={_list.id}
|
sub_group_id={_list.id}
|
||||||
|
subGroupIndex={subGroupIndex}
|
||||||
updateIssue={updateIssue}
|
updateIssue={updateIssue}
|
||||||
quickActions={quickActions}
|
quickActions={quickActions}
|
||||||
kanbanFilters={kanbanFilters}
|
kanbanFilters={kanbanFilters}
|
||||||
|
|
|
||||||
|
|
@ -619,3 +619,54 @@ export const isIssueNew = (issue: TIssue) => {
|
||||||
const diff = currentDate.getTime() - createdDate.getTime();
|
const diff = currentDate.getTime() - createdDate.getTime();
|
||||||
return diff < 30000;
|
return diff < 30000;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns approximate height of Kanban card based on display properties
|
||||||
|
* @param displayProperties
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export function getApproximateCardHeight(displayProperties: IIssueDisplayProperties | undefined) {
|
||||||
|
if (!displayProperties) return 100;
|
||||||
|
|
||||||
|
// default card height
|
||||||
|
let cardHeight = 46;
|
||||||
|
|
||||||
|
const clonedProperties = clone(displayProperties);
|
||||||
|
|
||||||
|
// key adds the height for key
|
||||||
|
if (clonedProperties.key) {
|
||||||
|
cardHeight += 24;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ignore smaller dimension properties
|
||||||
|
const ignoredProperties: (keyof IIssueDisplayProperties)[] = [
|
||||||
|
"key",
|
||||||
|
"sub_issue_count",
|
||||||
|
"link",
|
||||||
|
"attachment_count",
|
||||||
|
"created_on",
|
||||||
|
"updated_on",
|
||||||
|
];
|
||||||
|
|
||||||
|
ignoredProperties.forEach((key: keyof IIssueDisplayProperties) => {
|
||||||
|
delete clonedProperties[key];
|
||||||
|
});
|
||||||
|
|
||||||
|
let propertyCount = 0;
|
||||||
|
|
||||||
|
// count the remaining properties
|
||||||
|
(Object.keys(clonedProperties) as (keyof IIssueDisplayProperties)[]).forEach((key: keyof IIssueDisplayProperties) => {
|
||||||
|
if (clonedProperties[key]) {
|
||||||
|
propertyCount++;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// based on property count, approximate the height of each card
|
||||||
|
if (propertyCount > 3) {
|
||||||
|
cardHeight += 60;
|
||||||
|
} else if (propertyCount > 0) {
|
||||||
|
cardHeight += 32;
|
||||||
|
}
|
||||||
|
|
||||||
|
return cardHeight;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,46 @@
|
||||||
import { forwardRef } from "react";
|
import { forwardRef } from "react";
|
||||||
import { ContentWrapper } from "@plane/ui";
|
import { ContentWrapper } from "@plane/ui";
|
||||||
|
|
||||||
export const KanbanIssueBlockLoader = forwardRef<HTMLSpanElement>((props, ref) => (
|
export const KanbanIssueBlockLoader = forwardRef<HTMLSpanElement, { cardHeight?: number }>(
|
||||||
<span ref={ref} className="block h-28 animate-pulse bg-custom-background-80 rounded" />
|
({ cardHeight = 100 }, ref) => (
|
||||||
));
|
<span
|
||||||
|
ref={ref}
|
||||||
|
className={`block animate-pulse bg-custom-background-80 rounded`}
|
||||||
|
style={{ height: `${cardHeight}px` }}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
export const KanbanColumnLoader = ({
|
||||||
|
cardsInColumn = 3,
|
||||||
|
ignoreHeader = false,
|
||||||
|
cardHeight = 100,
|
||||||
|
}: {
|
||||||
|
cardsInColumn?: number;
|
||||||
|
ignoreHeader?: boolean;
|
||||||
|
cardHeight?: number;
|
||||||
|
}) => (
|
||||||
|
<div className="flex flex-col gap-3">
|
||||||
|
{!ignoreHeader && (
|
||||||
|
<div className="flex items-center justify-between h-9 w-80">
|
||||||
|
<div className="flex item-center gap-3">
|
||||||
|
<span className="h-6 w-6 bg-custom-background-80 rounded animate-pulse" />
|
||||||
|
<span className="h-6 w-24 bg-custom-background-80 rounded animate-pulse" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{Array.from({ length: cardsInColumn }, (_, cardIndex) => (
|
||||||
|
<KanbanIssueBlockLoader key={cardIndex} cardHeight={cardHeight} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
KanbanIssueBlockLoader.displayName = "KanbanIssueBlockLoader";
|
KanbanIssueBlockLoader.displayName = "KanbanIssueBlockLoader";
|
||||||
|
|
||||||
export const KanbanLayoutLoader = ({ cardsInEachColumn = [2, 3, 2, 4, 3] }: { cardsInEachColumn?: number[] }) => (
|
export const KanbanLayoutLoader = ({ cardsInEachColumn = [2, 3, 2, 4, 3] }: { cardsInEachColumn?: number[] }) => (
|
||||||
<ContentWrapper className="flex-row gap-5 py-1.5 overflow-x-auto">
|
<ContentWrapper className="flex-row gap-5 py-1.5 overflow-x-auto">
|
||||||
{cardsInEachColumn.map((cardsInColumn, columnIndex) => (
|
{cardsInEachColumn.map((cardsInColumn, columnIndex) => (
|
||||||
<div key={columnIndex} className="flex flex-col gap-3">
|
<KanbanColumnLoader key={columnIndex} cardsInColumn={cardsInColumn} />
|
||||||
<div className="flex items-center justify-between h-9 w-80">
|
|
||||||
<div className="flex item-center gap-3">
|
|
||||||
<span className="h-6 w-6 bg-custom-background-80 rounded animate-pulse" />
|
|
||||||
<span className="h-6 w-24 bg-custom-background-80 rounded animate-pulse" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{Array.from({ length: cardsInColumn }, (_, cardIndex) => (
|
|
||||||
<KanbanIssueBlockLoader key={cardIndex} />
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
))}
|
))}
|
||||||
</ContentWrapper>
|
</ContentWrapper>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue