ToolJet/frontend/src/Editor/Components/KanbanBoard/Column.jsx
Arpit b48fd53ec2
[Feature] Kanban board widget (#3049)
* init kanban board widget

* kanban board

* reverts to beautifully

* kanban UI updates and dnd fixes

* bugfix: when dropped outside the col, should return back to it inital position

* updates min-width of the column

* container and widget styles

* style fixes: column container onDrag

* adds button for new group

* fixes new card overflow

* add btn for adding cards

* groups and cards updated

* add property definition

* improves draggable card position while drag is active

* handle delete group/col

* handle col/group title updates

* handles editing card title

* style fixes for input cursor

* cleanup

* card popover with codehinter fields

* minor card fixes

* updates exposed variable

* simplify boardData into cols and cards

* adds width and min-width style definations

* build board from queries

* handle draggable rbd-id

* removes add group card and delete group option

* fixes typos

* show empty state message

* fixes typos

* removes card extra border color

* fixes column typi and cards updates issue

* adds enableAddCard property defination

* adds accent color options

* default style accent color

* accent color fix

* revets popover with hinter

* fixes card drag and drop

* removes hook

* fixes: state synced with property defination updates(col and cards data)

* fixes: on re-arranging the card via dnd, update the card content

* handles if card columnId is updated

* adds card container layer

* clean up

* dark theme

* fixes card onDrop issue

* renamed the exposed variable data --> lists

* adds custom resolvers to the popover

* handle widget crash when non iterables are passed

* updates default card and col value

* fixes dnd issues for dynamic card values

* refactor: cleanup

* handles empty and undefined cardData

* fixes Height of widget is changing when popover thing is displayed.

* fixes: updating card data in widget inspector

* fixes: updating column data in widget inspector

* fixes adding cards for newly created groups/columns

* clean up

* Add kanban event onCardAdded and expose lastAddedCard

* Add onCardRemoved action and expsed lastRemovedCard variable

* Add events and variables for card movement and selection

* Add card edit feature for kanban widget

* Rename lastAddedRemoved to lastRemovedCard in kanban

* Rename lists to columns on kanban board

* Set max height of kanban column to respond to widget height

* Have "Add description" link if there is no description for Kanban cards

* kanban docs

* Change text from "add +" to "Add card" on kanban

* Validate card data before update

* Add tip about card id type on kanban documentation

* Add default min width and width for kanban

Co-authored-by: Sherfin Shamsudeen <sherfin94@gmail.com>
Co-authored-by: Shubhendra <withshubh@gmail.com>
2022-06-14 11:06:36 +05:30

128 lines
3.6 KiB
JavaScript

import React from 'react';
import { Droppable } from 'react-beautiful-dnd';
import { Card } from './Card';
import { BoardContext } from './KanbanBoard';
const Column = ({
state,
group,
keyIndex,
getListStyle,
getItemStyle,
updateCb,
addNewItem,
fireEvent,
setExposedVariable,
updateCardProperty,
boardHeight,
}) => {
const styles = {
overflowX: 'hidden',
overflowY: 'hidden',
maxHeight: boardHeight - 80,
};
const cards = group['cards'];
const updateGroupTitle = (newTitle) => {
const newState = [...state];
newState[keyIndex]['title'] = newTitle;
updateCb(newState);
};
const flipTitleToEditMode = (index) => {
const newState = [...state];
const isEditing = newState[index]['isEditing'];
if (isEditing === true) {
newState[index]['isEditing'] = false;
} else {
newState[index]['isEditing'] = true;
}
updateCb(newState);
};
const { enableAddCard, accentColor, darkMode } = React.useContext(BoardContext);
const hexaCodeToRgb = (hex) => {
const r = parseInt(hex.slice(1, 3), 16);
const g = parseInt(hex.slice(3, 5), 16);
const b = parseInt(hex.slice(5, 7), 16);
return `rgba(${r},${g},${b},0.2)`;
};
const colAccentColor = {
color: accentColor ?? '#4d72fa',
backgroundColor: accentColor ? hexaCodeToRgb(accentColor) : hexaCodeToRgb('#4d72fa'),
};
return (
<Droppable key={keyIndex} droppableId={String(keyIndex)}>
{(dndProps, dndState) => (
<div
className={`card text-dark mb-3 m-2 kanban-column ${darkMode ? 'bg-dark' : 'bg-light'}`}
ref={dndProps.innerRef}
style={getListStyle(dndState.isDraggingOver)}
{...dndProps.droppableProps}
>
<div className="card-header d-flex">
<div className="flex-grow-1 ">
{group['isEditing'] ? (
<input
type="text"
className="form-control"
defaultValue={group['title']}
autoFocus={true}
onBlur={(e) => {
updateGroupTitle(e.target.value);
flipTitleToEditMode(keyIndex);
}}
onKeyDown={(e) => {
if (e.key === 'Enter') {
updateGroupTitle(e.target.value);
flipTitleToEditMode(keyIndex);
}
}}
/>
) : (
<span
style={colAccentColor}
onClick={() => flipTitleToEditMode(keyIndex)}
className="bade-component cursor-text"
>
{group.title}
</span>
)}
</div>
</div>
<div style={{ ...styles }} className="card-body">
{cards?.map((item, index) => (
<Card
key={index}
item={item}
index={index}
state={state}
updateCb={updateCb}
getItemStyle={getItemStyle}
keyIndex={keyIndex}
fireEvent={fireEvent}
setExposedVariable={setExposedVariable}
updateCardProperty={updateCardProperty}
/>
))}
{dndProps.placeholder}
{enableAddCard && (
<button className="btn btn-primary w-100 add-card-btn" onClick={() => addNewItem(state, keyIndex)}>
Add card
</button>
)}
</div>
</div>
)}
</Droppable>
);
};
export default Column;