mirror of
https://github.com/twentyhq/twenty.git
synced 2024-12-18 09:02:11 +03:00
Enable optimistic rendering for pipeline stages (#1139)
This commit is contained in:
parent
db8a176342
commit
fbac345164
@ -73,10 +73,9 @@ const StyledNumChildren = styled.div`
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
type OwnProps = {
|
type OwnProps = {
|
||||||
color?: string;
|
color: string;
|
||||||
title: string;
|
title: string;
|
||||||
onTitleEdit: (title: string) => void;
|
onTitleEdit: (title: string, color: string) => void;
|
||||||
onColumnColorEdit: (color: string) => void;
|
|
||||||
totalAmount?: number;
|
totalAmount?: number;
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
isFirstColumn: boolean;
|
isFirstColumn: boolean;
|
||||||
@ -87,7 +86,6 @@ export function BoardColumn({
|
|||||||
color,
|
color,
|
||||||
title,
|
title,
|
||||||
onTitleEdit,
|
onTitleEdit,
|
||||||
onColumnColorEdit,
|
|
||||||
totalAmount,
|
totalAmount,
|
||||||
children,
|
children,
|
||||||
isFirstColumn,
|
isFirstColumn,
|
||||||
@ -124,7 +122,6 @@ export function BoardColumn({
|
|||||||
<BoardColumnMenu
|
<BoardColumnMenu
|
||||||
onClose={handleClose}
|
onClose={handleClose}
|
||||||
onTitleEdit={onTitleEdit}
|
onTitleEdit={onTitleEdit}
|
||||||
onColumnColorEdit={onColumnColorEdit}
|
|
||||||
title={title}
|
title={title}
|
||||||
color={color}
|
color={color}
|
||||||
/>
|
/>
|
||||||
|
@ -31,9 +31,8 @@ const StyledEditModeInput = styled.input`
|
|||||||
type OwnProps = {
|
type OwnProps = {
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
title: string;
|
title: string;
|
||||||
onTitleEdit: (title: string) => void;
|
onTitleEdit: (title: string, color: string) => void;
|
||||||
onColumnColorEdit: (color: string) => void;
|
color: string;
|
||||||
color?: string;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const StyledColorSample = styled.div<{ colorName: string }>`
|
const StyledColorSample = styled.div<{ colorName: string }>`
|
||||||
@ -61,15 +60,17 @@ export const COLOR_OPTIONS = [
|
|||||||
export function BoardColumnEditTitleMenu({
|
export function BoardColumnEditTitleMenu({
|
||||||
onClose,
|
onClose,
|
||||||
onTitleEdit,
|
onTitleEdit,
|
||||||
onColumnColorEdit,
|
|
||||||
title,
|
title,
|
||||||
color,
|
color,
|
||||||
}: OwnProps) {
|
}: OwnProps) {
|
||||||
const [internalValue, setInternalValue] = useState(title);
|
const [internalValue, setInternalValue] = useState(title);
|
||||||
const debouncedOnUpdate = debounce(onTitleEdit, 200);
|
const debouncedOnUpdateTitle = debounce(
|
||||||
|
(newTitle) => onTitleEdit(newTitle, color),
|
||||||
|
200,
|
||||||
|
);
|
||||||
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
|
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
|
||||||
setInternalValue(event.target.value);
|
setInternalValue(event.target.value);
|
||||||
debouncedOnUpdate(event.target.value);
|
debouncedOnUpdateTitle(event.target.value);
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<DropdownMenuItemsContainer>
|
<DropdownMenuItemsContainer>
|
||||||
@ -86,7 +87,7 @@ export function BoardColumnEditTitleMenu({
|
|||||||
<DropdownMenuSelectableItem
|
<DropdownMenuSelectableItem
|
||||||
key={colorOption.name}
|
key={colorOption.name}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
onColumnColorEdit(colorOption.id);
|
onTitleEdit(title, colorOption.id);
|
||||||
onClose();
|
onClose();
|
||||||
}}
|
}}
|
||||||
selected={colorOption.id === color}
|
selected={colorOption.id === color}
|
||||||
|
@ -23,15 +23,13 @@ const StyledMenuContainer = styled.div`
|
|||||||
type OwnProps = {
|
type OwnProps = {
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
title: string;
|
title: string;
|
||||||
color?: string;
|
color: string;
|
||||||
onTitleEdit: (title: string) => void;
|
onTitleEdit: (title: string, color: string) => void;
|
||||||
onColumnColorEdit: (color: string) => void;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export function BoardColumnMenu({
|
export function BoardColumnMenu({
|
||||||
onClose,
|
onClose,
|
||||||
onTitleEdit,
|
onTitleEdit,
|
||||||
onColumnColorEdit,
|
|
||||||
title,
|
title,
|
||||||
color,
|
color,
|
||||||
}: OwnProps) {
|
}: OwnProps) {
|
||||||
@ -66,7 +64,6 @@ export function BoardColumnMenu({
|
|||||||
color={color}
|
color={color}
|
||||||
onClose={onClose}
|
onClose={onClose}
|
||||||
onTitleEdit={onTitleEdit}
|
onTitleEdit={onTitleEdit}
|
||||||
onColumnColorEdit={onColumnColorEdit}
|
|
||||||
title={title}
|
title={title}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
@ -40,14 +40,12 @@ export function EntityBoard({
|
|||||||
boardOptions,
|
boardOptions,
|
||||||
updateSorts,
|
updateSorts,
|
||||||
onEditColumnTitle,
|
onEditColumnTitle,
|
||||||
onEditColumnColor,
|
|
||||||
}: {
|
}: {
|
||||||
boardOptions: BoardOptions;
|
boardOptions: BoardOptions;
|
||||||
updateSorts: (
|
updateSorts: (
|
||||||
sorts: Array<SelectedSortType<PipelineProgressOrderByWithRelationInput>>,
|
sorts: Array<SelectedSortType<PipelineProgressOrderByWithRelationInput>>,
|
||||||
) => void;
|
) => void;
|
||||||
onEditColumnTitle: (columnId: string, title: string) => void;
|
onEditColumnTitle: (columnId: string, title: string, color: string) => void;
|
||||||
onEditColumnColor: (columnId: string, color: string) => void;
|
|
||||||
}) {
|
}) {
|
||||||
const [boardColumns] = useRecoilState(boardColumnsState);
|
const [boardColumns] = useRecoilState(boardColumnsState);
|
||||||
|
|
||||||
@ -138,7 +136,6 @@ export function EntityBoard({
|
|||||||
boardOptions={boardOptions}
|
boardOptions={boardOptions}
|
||||||
column={column}
|
column={column}
|
||||||
onEditColumnTitle={onEditColumnTitle}
|
onEditColumnTitle={onEditColumnTitle}
|
||||||
onEditColumnColor={onEditColumnColor}
|
|
||||||
/>
|
/>
|
||||||
</RecoilScope>
|
</RecoilScope>
|
||||||
</BoardColumnIdContext.Provider>
|
</BoardColumnIdContext.Provider>
|
||||||
|
@ -51,12 +51,10 @@ export function EntityBoardColumn({
|
|||||||
column,
|
column,
|
||||||
boardOptions,
|
boardOptions,
|
||||||
onEditColumnTitle,
|
onEditColumnTitle,
|
||||||
onEditColumnColor,
|
|
||||||
}: {
|
}: {
|
||||||
column: BoardColumnDefinition;
|
column: BoardColumnDefinition;
|
||||||
boardOptions: BoardOptions;
|
boardOptions: BoardOptions;
|
||||||
onEditColumnTitle: (columnId: string, title: string) => void;
|
onEditColumnTitle: (columnId: string, title: string, color: string) => void;
|
||||||
onEditColumnColor: (columnId: string, color: string) => void;
|
|
||||||
}) {
|
}) {
|
||||||
const boardColumnId = useContext(BoardColumnIdContext) ?? '';
|
const boardColumnId = useContext(BoardColumnIdContext) ?? '';
|
||||||
|
|
||||||
@ -68,19 +66,14 @@ export function EntityBoardColumn({
|
|||||||
boardCardIdsByColumnIdFamilyState(boardColumnId ?? ''),
|
boardCardIdsByColumnIdFamilyState(boardColumnId ?? ''),
|
||||||
);
|
);
|
||||||
|
|
||||||
function handleEditColumnTitle(value: string) {
|
function handleEditColumnTitle(title: string, color: string) {
|
||||||
onEditColumnTitle(boardColumnId, value);
|
onEditColumnTitle(boardColumnId, title, color);
|
||||||
}
|
|
||||||
|
|
||||||
function handleEditColumnColor(newColor: string) {
|
|
||||||
onEditColumnColor(boardColumnId, newColor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Droppable droppableId={column.id}>
|
<Droppable droppableId={column.id}>
|
||||||
{(droppableProvided) => (
|
{(droppableProvided) => (
|
||||||
<BoardColumn
|
<BoardColumn
|
||||||
onColumnColorEdit={handleEditColumnColor}
|
|
||||||
onTitleEdit={handleEditColumnTitle}
|
onTitleEdit={handleEditColumnTitle}
|
||||||
title={column.title}
|
title={column.title}
|
||||||
color={column.colorCode}
|
color={column.colorCode}
|
||||||
|
@ -2,5 +2,5 @@ export type BoardColumnDefinition = {
|
|||||||
id: string;
|
id: string;
|
||||||
title: string;
|
title: string;
|
||||||
index: number;
|
index: number;
|
||||||
colorCode?: string;
|
colorCode: string;
|
||||||
};
|
};
|
||||||
|
@ -45,23 +45,25 @@ export function Opportunities() {
|
|||||||
|
|
||||||
const [updatePipelineStage] = useUpdatePipelineStageMutation();
|
const [updatePipelineStage] = useUpdatePipelineStageMutation();
|
||||||
|
|
||||||
function handleEditColumnTitle(boardColumnId: string, newTitle: string) {
|
function handleEditColumnTitle(
|
||||||
|
boardColumnId: string,
|
||||||
|
newTitle: string,
|
||||||
|
newColor: string,
|
||||||
|
) {
|
||||||
updatePipelineStage({
|
updatePipelineStage({
|
||||||
variables: {
|
variables: {
|
||||||
id: boardColumnId,
|
id: boardColumnId,
|
||||||
data: { name: newTitle },
|
data: { name: newTitle, color: newColor },
|
||||||
},
|
},
|
||||||
refetchQueries: [getOperationName(GET_PIPELINES) || ''],
|
optimisticResponse: {
|
||||||
});
|
__typename: 'Mutation',
|
||||||
}
|
updateOnePipelineStage: {
|
||||||
|
__typename: 'PipelineStage',
|
||||||
function handleEditColumnColor(boardColumnId: string, newColor: string) {
|
id: boardColumnId,
|
||||||
updatePipelineStage({
|
name: newTitle,
|
||||||
variables: {
|
color: newColor,
|
||||||
id: boardColumnId,
|
},
|
||||||
data: { color: newColor },
|
|
||||||
},
|
},
|
||||||
refetchQueries: [getOperationName(GET_PIPELINES) || ''],
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +93,6 @@ export function Opportunities() {
|
|||||||
<EntityBoard
|
<EntityBoard
|
||||||
boardOptions={opportunitiesBoardOptions}
|
boardOptions={opportunitiesBoardOptions}
|
||||||
updateSorts={updateSorts}
|
updateSorts={updateSorts}
|
||||||
onEditColumnColor={handleEditColumnColor}
|
|
||||||
onEditColumnTitle={handleEditColumnTitle}
|
onEditColumnTitle={handleEditColumnTitle}
|
||||||
/>
|
/>
|
||||||
<EntityBoardActionBar>
|
<EntityBoardActionBar>
|
||||||
|
Loading…
Reference in New Issue
Block a user