Skip to content

Commit

Permalink
refactor: fix more type errors in kanbanItem
Browse files Browse the repository at this point in the history
Fixes: 7401cb8
  • Loading branch information
aloisklink committed Oct 29, 2024
1 parent dffaf9f commit ef30283
Showing 1 changed file with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import { userNodeOverrides, styles2String } from './handDrawnShapeStyles.js';
import rough from 'roughjs';
import type { D3Selection } from '../../../types.js';

const colorFromPriority = (priority: KanbanNode['priority']) => {
const colorFromPriority = (priority: NonNullable<KanbanNode['priority']>) => {
switch (priority) {
case 'Very High':
return 'red';
case 'High':
return 'orange';
case 'Medium':
return null; // no stroke
case 'Low':
return 'blue';
case 'Very Low':
Expand All @@ -20,11 +22,9 @@ const colorFromPriority = (priority: KanbanNode['priority']) => {
};
export const kanbanItem = async <T extends SVGGraphicsElement>(
parent: D3Selection<T>,
node: Node,
kanbanNode: Node | Omit<KanbanNode, 'level'>,
{ config }: ShapeRenderOptions
) => {
const unknownNode = node as unknown;
const kanbanNode = unknownNode as KanbanNode;
const { labelStyles, nodeStyles } = styles2String(kanbanNode);
kanbanNode.labelStyle = labelStyles;

Expand All @@ -42,7 +42,7 @@ export const kanbanItem = async <T extends SVGGraphicsElement>(
let ticketUrl = '';
let link;

if (kanbanNode.ticket && config?.kanban?.ticketBaseUrl) {
if ('ticket' in kanbanNode && kanbanNode.ticket && config?.kanban?.ticketBaseUrl) {
ticketUrl = config?.kanban?.ticketBaseUrl.replace('#TICKET#', kanbanNode.ticket);
link = shapeSvg
.insert<SVGAElement>('svg:a', ':first-child')
Expand All @@ -62,17 +62,21 @@ export const kanbanItem = async <T extends SVGGraphicsElement>(
};
let labelEl, bbox2;
if (link) {
({ label: labelEl, bbox: bbox2 } = await insertLabel(link, kanbanNode.ticket || '', options));
({ label: labelEl, bbox: bbox2 } = await insertLabel(
link,
('ticket' in kanbanNode && kanbanNode.ticket) || '',
options
));
} else {
({ label: labelEl, bbox: bbox2 } = await insertLabel(
shapeSvg,
kanbanNode.ticket || '',
('ticket' in kanbanNode && kanbanNode.ticket) || '',
options
));
}
const { label: labelElAssigned, bbox: bboxAssigned } = await insertLabel(
shapeSvg,
kanbanNode.assigned || '',
('assigned' in kanbanNode && kanbanNode.assigned) || '',
options
);
kanbanNode.width = orgWidth;
Expand Down Expand Up @@ -129,7 +133,9 @@ export const kanbanItem = async <T extends SVGGraphicsElement>(
.attr('y', y)
.attr('width', totalWidth)
.attr('height', totalHeight);
if (kanbanNode.priority) {

const priority = 'priority' in kanbanNode && kanbanNode.priority;
if (priority) {
const line = shapeSvg.append('line', ':first-child');
const lineX = x + 2;

Expand All @@ -142,7 +148,7 @@ export const kanbanItem = async <T extends SVGGraphicsElement>(
.attr('y2', y2)

.attr('stroke-width', '4')
.attr('stroke', colorFromPriority(kanbanNode.priority));
.attr('stroke', colorFromPriority(priority));
}
}

Expand Down

0 comments on commit ef30283

Please sign in to comment.