Skip to content

Commit

Permalink
fix bug where editing estimate didn't update UI
Browse files Browse the repository at this point in the history
  • Loading branch information
51ngul4r1ty committed Jan 24, 2024
1 parent 8039232 commit d9a9378
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const InternalBacklogItemPlanningItem: React.FC<BacklogItemPlanningItemProps> =
css.backlogItemUserStoryFormRow,
props.suppressTopPadding ? null : css.embeddedBacklogItemUserStoryFormRow
);
const allowEstimateEdit = !props.totalParts || props.totalParts === 1;
return (
<>
<SimpleDivider key={`divider-unsaved-form-${props.instanceId}`} />
Expand All @@ -71,6 +72,7 @@ const InternalBacklogItemPlanningItem: React.FC<BacklogItemPlanningItemProps> =
acceptedAt={props.acceptedAt}
className={classNameToUse}
editing
allowEstimateEdit={allowEstimateEdit}
estimate={props.estimate}
externalId={props.externalId}
finishedAt={props.finishedAt}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export type BacklogItemDetailFormStateProps = BacklogItemInstanceEditableFields
acceptanceCriteria: string;
acceptedAt: Date | null;
estimate: number | null;
allowEstimateEdit?: boolean;
externalId: string;
finishedAt: Date | null;
friendlyId: string;
Expand Down Expand Up @@ -159,7 +160,7 @@ export class BacklogItemDetailForm extends Component<BacklogItemDetailFormProps>
labelText="Estimate"
size={3}
inputValue={estimateValue}
disabled={this.props.saving}
disabled={this.props.saving || !this.props.allowEstimateEdit}
onChange={(value) => {
const valueToUse = value.trim();
const estimate = valueToUse ? parseFloat(valueToUse) : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ export const backlogItemsReducer = (
const changed = updateItemById(draft, backlogItemId, (item) => {
item.editing = false;
item.saving = false;
item.estimate = actionTyped.payload.response.data.item.estimate;
item.storyEstimate = actionTyped.payload.response.data.item.storyEstimate;
item.unallocatedPoints = actionTyped.payload.response.data.item.unallocatedPoints;
});
if (changed) {
rebuildAllItems(draft);
Expand Down
31 changes: 28 additions & 3 deletions packages/web-app/src/server/api/handlers/backlogItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ export const backlogItemPutHandler = async (req: Request, res: Response) => {
try {
transaction = await sequelize.transaction({ isolationLevel: Transaction.ISOLATION_LEVELS.SERIALIZABLE });
const backlogItem = await BacklogItemDataModel.findOne({
where: { id: bodyItemId },
where: { id: queryParamItemId },
transaction
});
if (!backlogItem) {
Expand All @@ -352,11 +352,36 @@ export const backlogItemPutHandler = async (req: Request, res: Response) => {
}
respondWithNotFound(res, `Unable to find backlogitem to update with ID ${req.body.id}`);
} else {
const requestApiBacklogItem = req.body as ApiBacklogItem;
const originalApiBacklogItem = mapDbToApiBacklogItem(backlogItem);
const estimateDelta = (requestApiBacklogItem.estimate || 0) - (originalApiBacklogItem.estimate || 0);
const updateBacklogItemResult = getUpdatedBacklogItemWhenStatusChanges(originalApiBacklogItem, req.body);
const newDataItem = updateBacklogItemResult.changed ? backlogItem : updateBacklogItemResult.backlogItem;
const newDataItem = updateBacklogItemResult.changed ? originalApiBacklogItem : updateBacklogItemResult.backlogItem;
if (estimateDelta !== 0) {
const backlogItemParts: BacklogItemPartDataModel[] = await BacklogItemPartDataModel.findAll({
where: { backlogitemId: queryParamItemId },
transaction
});
const backlogItemPartIds = backlogItemParts.map((backlogItemPart) => backlogItemPart.id);
if (backlogItemPartIds.length === 0) {
throw new Error(`Unable to update backlog item "${queryParamItemId}" estimate, no matching parts found`);
} else if (backlogItemPartIds.length > 1) {
throw new Error(
`Unable to update backlog item "${queryParamItemId}" estimate, ${backlogItemPartIds.length} matching parts found`
);
} else {
const backlogItemPart = backlogItemParts[0];
const newPartDataItem = mapDbToApiBacklogItemPart(backlogItemPart);
newPartDataItem.points = requestApiBacklogItem.estimate;
await backlogItemPart.update(newPartDataItem, { transaction });
}
newDataItem.unallocatedPoints = requestApiBacklogItem.estimate;
}
await backlogItem.update(newDataItem, { transaction });
await handleResponseAndCommit(originalApiBacklogItem, backlogItem, res, transaction);
const responseBacklogItem = mapApiItemToBacklogItem(backlogItem);
responseBacklogItem.storyEstimate = responseBacklogItem.estimate; // just updated the story estimate
responseBacklogItem.unallocatedPoints = responseBacklogItem.estimate; // all are in backlog
await handleResponseAndCommit(originalApiBacklogItem, responseBacklogItem, res, transaction);
}
} catch (err) {
const errLogContext = logger.warn(`handling error "${err}"`, [functionTag], logContext);
Expand Down

0 comments on commit d9a9378

Please sign in to comment.