Skip to content

Commit

Permalink
chore: estimates and issue parent id fixes (#3188)
Browse files Browse the repository at this point in the history
* chore: validations and bug fixes

* chore: estimate point character limit validation

---------

Co-authored-by: LAKHAN BAHETI <[email protected]>
  • Loading branch information
NarayanBavisetti and 1akhanBaheti authored Dec 27, 2023
1 parent 05eb728 commit 78428fb
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 9 deletions.
10 changes: 10 additions & 0 deletions apiserver/plane/app/serializers/estimate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from plane.db.models import Estimate, EstimatePoint
from plane.app.serializers import WorkspaceLiteSerializer, ProjectLiteSerializer

from rest_framework import serializers

class EstimateSerializer(BaseSerializer):
workspace_detail = WorkspaceLiteSerializer(read_only=True, source="workspace")
Expand All @@ -19,6 +20,15 @@ class Meta:


class EstimatePointSerializer(BaseSerializer):

def validate(self, data):
if not data:
raise serializers.ValidationError("Estimate points are required")
value = data.get("value")
if value and len(value) > 20:
raise serializers.ValidationError("Value can't be more than 20 characters")
return data

class Meta:
model = EstimatePoint
fields = "__all__"
Expand Down
8 changes: 4 additions & 4 deletions apiserver/plane/app/views/estimate.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ def create(self, request, slug, project_id):
)

estimate_points = request.data.get("estimate_points", [])

if not len(estimate_points) or len(estimate_points) > 8:

serializer = EstimatePointSerializer(data=request.data.get("estimate_points"), many=True)
if not serializer.is_valid():
return Response(
{"error": "Estimate points are required"},
status=status.HTTP_400_BAD_REQUEST,
serializer.errors, status=status.HTTP_400_BAD_REQUEST
)

estimate_serializer = EstimateSerializer(data=request.data.get("estimate"))
Expand Down
3 changes: 2 additions & 1 deletion apiserver/plane/app/views/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def filter_issues(self, query, slug, project_id, workspace_search):
q = Q()
for field in fields:
if field == "sequence_id":
sequences = re.findall(r"\d+\.\d+|\d+", query)
# Match whole integers only (exclude decimal numbers)
sequences = re.findall(r"\b\d+\b", query)
for sequence_id in sequences:
q |= Q(**{"sequence_id": sequence_id})
else:
Expand Down
4 changes: 2 additions & 2 deletions apiserver/plane/bgtasks/issue_activites_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ def track_parent(
epoch,
):
if current_instance.get("parent") != requested_data.get("parent"):
old_parent = Issue.objects.filter(pk=current_instance.get("parent")).first()
new_parent = Issue.objects.filter(pk=requested_data.get("parent")).first()
old_parent = Issue.objects.filter(pk=current_instance.get("parent")).first() if current_instance.get("parent") is not None else None
new_parent = Issue.objects.filter(pk=requested_data.get("parent")).first() if requested_data.get("parent") is not None else None

issue_activities.append(
IssueActivity(
Expand Down
26 changes: 24 additions & 2 deletions web/components/estimates/create-update-estimate-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,22 @@ export const CreateUpdateEstimateModal: React.FC<Props> = observer((props) => {
return;
}

if (
formData.value1.length > 20 ||
formData.value2.length > 20 ||
formData.value3.length > 20 ||
formData.value4.length > 20 ||
formData.value5.length > 20 ||
formData.value6.length > 20
) {
setToastAlert({
type: "error",
title: "Error!",
message: "Estimate point cannot have more than 20 characters.",
});
return;
}

if (
checkDuplicates([
formData.value1,
Expand Down Expand Up @@ -269,6 +285,12 @@ export const CreateUpdateEstimateModal: React.FC<Props> = observer((props) => {
<Controller
control={control}
name={`value${i + 1}` as keyof FormValues}
rules={{
maxLength: {
value: 20,
message: "Estimate point must at most be of 20 characters",
},
}}
render={({ field: { value, onChange, ref } }) => (
<Input
ref={ref}
Expand Down Expand Up @@ -299,8 +321,8 @@ export const CreateUpdateEstimateModal: React.FC<Props> = observer((props) => {
? "Updating Estimate..."
: "Update Estimate"
: isSubmitting
? "Creating Estimate..."
: "Create Estimate"}
? "Creating Estimate..."
: "Create Estimate"}
</Button>
</div>
</form>
Expand Down

0 comments on commit 78428fb

Please sign in to comment.