Skip to content

Commit 4aa3861

Browse files
authored
Merge pull request #330 from boostcampwm2023/refactor/backlog-page
refactor: 백로그 페이지 컴포넌트 리팩토링
2 parents acd602f + bb57972 commit 4aa3861

File tree

6 files changed

+128
-61
lines changed

6 files changed

+128
-61
lines changed

frontend/src/components/backlog/StoryBlock.tsx

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import ChevronDown from "../../assets/icons/chevron-down.svg?react";
1515
import TrashCan from "../../assets/icons/trash-can.svg?react";
1616
import { MOUSE_KEY } from "../../constants/event";
1717
import { BacklogStatusType, EpicCategoryDTO } from "../../types/DTO/backlogDTO";
18+
import TextInputColumn from "./common/TextInputColumn";
19+
import NumberInputColumn from "./common/NumberInputColumn";
1820

1921
interface StoryBlockProps {
2022
id: number;
@@ -210,40 +212,24 @@ const StoryBlock = ({
210212
/>
211213
)}
212214
</button>
213-
{titleUpdating ? (
214-
<input
215-
className={`w-full rounded-sm focus:outline-none bg-gray-200 hover:cursor-pointer`}
216-
type="text"
217-
ref={titleInputRef}
218-
defaultValue={title}
219-
onKeyUp={handleTitleEnterKeyup}
220-
/>
221-
) : (
222-
<span
223-
title={title}
224-
className="w-full overflow-hidden hover:cursor-pointer text-ellipsis whitespace-nowrap"
225-
>
226-
{title}
227-
</span>
228-
)}
215+
<TextInputColumn
216+
updating={titleUpdating}
217+
inputRef={titleInputRef}
218+
value={title}
219+
onKeyUp={handleTitleEnterKeyup}
220+
/>
229221
</div>
230222
<div
231223
className="flex items-center gap-1 w-[4rem] mr-[2.76rem] text-right hover:cursor-pointer"
232224
onClick={() => handlePointUpdatingOpen(true)}
233225
ref={pointRef}
234226
>
235-
{pointUpdating ? (
236-
<input
237-
className={`min-w-[1.75rem] no-arrows text-right focus:outline-none rounded-sm bg-gray-200 hover:cursor-pointer`}
238-
type="number"
239-
ref={pointInputRef}
240-
defaultValue={point !== 0 && !point ? 0 : point}
241-
onKeyUp={handlePointEnterKeyup}
242-
/>
243-
) : (
244-
<span className="min-w-[1.75rem] text-right">{point}</span>
245-
)}
246-
227+
<NumberInputColumn
228+
updating={pointUpdating}
229+
inputRef={pointInputRef}
230+
value={point}
231+
onKeyUp={handlePointEnterKeyup}
232+
/>
247233
<span> POINT</span>
248234
</div>
249235
<div className="w-[4rem] mr-[2.76rem] text-right">

frontend/src/components/backlog/TaskBlock.tsx

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { MOUSE_KEY } from "../../constants/event";
1414
import ConfirmModal from "../common/ConfirmModal";
1515
import TrashCan from "../../assets/icons/trash-can.svg?react";
1616
import isIntegerOrOneDecimalPlace from "../../utils/isIntegerOrOneDecimalPlace";
17+
import TextInputColumn from "./common/TextInputColumn";
18+
import NumberInputColumn from "./common/NumberInputColumn";
1719

1820
const TaskBlock = ({
1921
id,
@@ -203,17 +205,12 @@ const TaskBlock = ({
203205
ref={titleRef}
204206
onClick={() => handleTitleUpdating(true)}
205207
>
206-
{titleUpdating ? (
207-
<input
208-
className="w-full min-w-[1rem] focus:outline-none rounded-sm bg-gray-200 hover:cursor-pointer"
209-
ref={titleInputRef}
210-
defaultValue={title}
211-
type="text"
212-
onKeyUp={handleTitleKeyup}
213-
/>
214-
) : (
215-
<span title={title}>{title}</span>
216-
)}
208+
<TextInputColumn
209+
inputRef={titleInputRef}
210+
value={title}
211+
onKeyUp={handleTitleKeyup}
212+
updating={titleUpdating}
213+
/>
217214
</div>
218215
<div
219216
className="w-12 min-h-[1.5rem] hover:cursor-pointer relative"
@@ -235,34 +232,24 @@ const TaskBlock = ({
235232
ref={expectedTimeRef}
236233
onClick={() => handleExpectedTimeUpdating(true)}
237234
>
238-
{expectedTimeUpdating ? (
239-
<input
240-
className="w-full min-w-[1rem] no-arrows text-right focus:outline-none rounded-sm bg-gray-200 hover:cursor-pointer"
241-
ref={expectedTimeInputRef}
242-
defaultValue={expectedTime === null ? "" : expectedTime}
243-
type="number"
244-
onKeyUp={handleExpectedTimeKeyup}
245-
/>
246-
) : (
247-
<p className="max-w-full text-right">{expectedTime}</p>
248-
)}
235+
<NumberInputColumn
236+
updating={expectedTimeUpdating}
237+
inputRef={expectedTimeInputRef}
238+
value={expectedTime}
239+
onKeyUp={handleExpectedTimeKeyup}
240+
/>
249241
</div>
250242
<div
251243
className="w-16 min-h-[1.5rem] hover:cursor-pointer"
252244
ref={actualTimeRef}
253245
onClick={() => handleActualTimeUpdating(true)}
254246
>
255-
{actualTimeUpdating ? (
256-
<input
257-
className="w-full min-w-[1rem] no-arrows text-right focus:outline-none rounded-sm bg-gray-200 hover:cursor-pointer"
258-
ref={actualTimeInputRef}
259-
defaultValue={actualTime === null ? "" : actualTime}
260-
type="number"
261-
onKeyUp={handleActualTimeKeyup}
262-
/>
263-
) : (
264-
<p className="min-w-full text-right">{actualTime}</p>
265-
)}
247+
<NumberInputColumn
248+
updating={actualTimeUpdating}
249+
inputRef={actualTimeInputRef}
250+
value={actualTime}
251+
onKeyUp={handleActualTimeKeyup}
252+
/>
266253
</div>
267254
<div
268255
className="w-[6.25rem] hover:cursor-pointer relative"
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
interface NumberInputColumnProps {
2+
updating: boolean;
3+
inputRef: React.MutableRefObject<HTMLInputElement | null>;
4+
value: number | null;
5+
onKeyUp: (event: React.KeyboardEvent) => void;
6+
}
7+
8+
const NumberInputColumn = ({
9+
updating,
10+
inputRef,
11+
value,
12+
onKeyUp,
13+
}: NumberInputColumnProps) => {
14+
if (updating) {
15+
return (
16+
<input
17+
className="w-full min-w-[1.75rem] no-arrows text-right focus:outline-none rounded-sm bg-gray-200 hover:cursor-pointer"
18+
type="number"
19+
ref={inputRef}
20+
defaultValue={value === null ? "" : value}
21+
onKeyUp={onKeyUp}
22+
/>
23+
);
24+
}
25+
26+
return <span className="w-full text-right truncate">{value}</span>;
27+
};
28+
29+
export default NumberInputColumn;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
interface TextInputColumnProps {
2+
updating: boolean;
3+
inputRef: React.MutableRefObject<HTMLInputElement | null>;
4+
value: string;
5+
onKeyUp: (event: React.KeyboardEvent) => void;
6+
}
7+
8+
const TextInputColumn = ({
9+
updating,
10+
inputRef,
11+
value,
12+
onKeyUp,
13+
}: TextInputColumnProps) => {
14+
if (updating) {
15+
return (
16+
<input
17+
className="w-full min-w-[1rem] focus:outline-none rounded-sm bg-gray-200 hover:cursor-pointer"
18+
type="text"
19+
ref={inputRef}
20+
defaultValue={value}
21+
onKeyUp={onKeyUp}
22+
/>
23+
);
24+
}
25+
26+
return (
27+
<span title={value} className="w-full truncate hover:cursor-pointer">
28+
{value}
29+
</span>
30+
);
31+
};
32+
33+
export default TextInputColumn;

frontend/src/pages/backlog/EpicPage.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,12 +335,35 @@ const EpicPage = () => {
335335
action,
336336
content,
337337
}: BacklogSocketData) => {
338+
if (
339+
domain === "epic" &&
340+
action === "delete" &&
341+
content.id === draggingEpicId
342+
) {
343+
setEpicElementIndex(undefined);
344+
return;
345+
}
346+
338347
if (
339348
domain === "story" &&
340349
action === "delete" &&
341350
content.id === draggingStoryId
342351
) {
343352
setStoryElementIndex({ epicId: undefined, storyIndex: undefined });
353+
354+
return;
355+
}
356+
357+
if (
358+
domain === "task" &&
359+
action === "delete" &&
360+
content.id === draggingTaskId
361+
) {
362+
setTaskElementIndex({
363+
epicId: undefined,
364+
storyId: undefined,
365+
taskIndex: undefined,
366+
});
344367
}
345368
};
346369

frontend/src/pages/backlog/UnfinishedStoryPage.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,15 @@ const UnfinishedStoryPage = () => {
168168
content.id === draggingStoryId
169169
) {
170170
setStoryElementIndex(undefined);
171+
return;
172+
}
173+
174+
if (
175+
domain === "task" &&
176+
action === "delete" &&
177+
content.id === draggingTaskId
178+
) {
179+
setTaskElementIndex({ storyId: undefined, taskIndex: undefined });
171180
}
172181
};
173182

0 commit comments

Comments
 (0)