Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
dedenbangkit committed Jan 25, 2024
2 parents 746f29b + 54cda70 commit 2862673
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
3 changes: 1 addition & 2 deletions backend/api/v1/v1_data/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,7 @@ def get_approver(self, instance: PendingDataBatch):
status__in=[
DataApprovalStatus.pending, DataApprovalStatus.rejected
],
level__level__gt=user.user_access.administration.level.level,
).order_by("level__level").first())
).order_by("-level__level").first())
if approval:

data["id"] = approval.user.pk
Expand Down
12 changes: 10 additions & 2 deletions backend/api/v1/v1_data/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,9 +770,12 @@ def list_pending_batch(request, version):
subordinate = serializer.validated_data.get('subordinate')
approved = serializer.validated_data.get('approved')
queryset = ViewPendingDataApproval.objects.filter(user_id=user.id)

rejected = ViewPendingDataApproval.objects.filter(
batch_id__in=queryset.values_list('batch_id', flat=True),
status=DataApprovalStatus.rejected
)
if approved:
queryset = queryset.filter(level_id__gt=F('pending_level'))
queryset = queryset.filter(status=DataApprovalStatus.approved)
else:
if subordinate:
queryset = queryset.filter(
Expand All @@ -782,6 +785,11 @@ def list_pending_batch(request, version):
queryset = queryset.filter(
level_id=F('pending_level'),
batch__approved=False)
if rejected:
# extend query set with rejected batch
queryset = queryset.union(
rejected.values_list('batch_id', flat=True)
)
queryset = queryset.values_list('batch_id', flat=True).order_by('-id')

paginator = PageNumberPagination()
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/pages/approvals/ApprovalDetail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ const ApprovalDetail = ({
setReload,
expandedParentKeys,
setExpandedParentKeys,
readonly = false,
}) => {
const [values, setValues] = useState([]);
const [rawValues, setRawValues] = useState([]);
Expand Down Expand Up @@ -455,7 +454,7 @@ const ApprovalDetail = ({
updateCell={updateCell}
resetCell={resetCell}
disabled={!!dataLoading}
readonly={!approve || readonly}
readonly={!approve}
/>
),
},
Expand Down
23 changes: 15 additions & 8 deletions frontend/src/pages/mobile-assignment/AddAssignment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,12 @@ const AddAssignment = () => {
});
};

const onSelectLevel = async (val) => {
const onSelectLevel = async (val, option) => {
store.update((s) => {
s.administration.length = val;
s.administration = selectedAdm.filter(
(item) => item.level < option.level
);
});
setLevel(val);
};
Expand Down Expand Up @@ -180,21 +183,25 @@ const AddAssignment = () => {
})
);
store.update((s) => {
s.administration = [...parentAdm, ...selectedAdministration]?.map(
(a, ax) => {
const childLevel = levels.filter((l) => l?.level === ax + 1);
s.administration = [...parentAdm, ...selectedAdministration]
?.slice(
[...parentAdm, ...selectedAdministration].findIndex(
(r) => r.id === authUser.administration.id
)
)
.map((a) => {
const childLevel = levels.filter((l) => l?.level === a.level);
return {
...a,
childLevelName: childLevel?.name || null,
};
}
);
});
});
}
if (!id && preload) {
setPreload(false);
}
}, [id, preload, form, editAssignment, levels, selectedAdm]);
}, [id, preload, form, editAssignment, levels, selectedAdm, authUser]);

useEffect(() => {
fetchData();
Expand Down Expand Up @@ -251,7 +258,7 @@ const AddAssignment = () => {
getPopupContainer={(trigger) => trigger.parentNode}
placeholder={text.selectLevel}
onChange={onSelectLevel}
fieldNames={{ value: "id", label: "name" }}
fieldNames={{ value: "id", label: "name", level: "level" }}
options={admLevels}
allowClear
/>
Expand Down

0 comments on commit 2862673

Please sign in to comment.