Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add project select to the contributors page gf-504 #516

Merged
merged 25 commits into from
Sep 27, 2024

Conversation

GvoFor
Copy link
Collaborator

@GvoFor GvoFor commented Sep 24, 2024

Features

Added project select above contributors table

Screenshots

image

image

image

image

image

@GvoFor GvoFor added this to the git-fit-release-6 milestone Sep 24, 2024
@GvoFor GvoFor self-assigned this Sep 24, 2024
@GvoFor GvoFor marked this pull request as draft September 24, 2024 14:19
@GvoFor GvoFor removed the conflicts label Sep 25, 2024
@GvoFor GvoFor marked this pull request as ready for review September 25, 2024 15:16
@GvoFor GvoFor requested a review from perekotypole September 25, 2024 15:16
const { onPageChange, onPageSizeChange, page, pageSize } = usePagination({
queryParameterPrefix: "contributor",
totalItemsCount: totalCount,
});

useEffect(() => {
const loadContributors = useCallback(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a10

} from "../../../../libs/types/types.js";
import { type ContributorOrderBy } from "../enums/contributor-order-by.enum.js";

type ContributorGetAllRequestDto = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't these query parameters? Request dto is for request body

type ContributorGetAllQueryParameters =

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You right

Comment on lines 101 to 113
switch (orderBy) {
case ContributorOrderBy.CREATED_AT: {
query.orderBy(ContributorOrderBy.CREATED_AT, SortType.DESCENDING);
break;
}

public async findAllWithoutPagination({
contributorName,
hasHidden = true,
}: {
contributorName?: string;
hasHidden?: boolean;
}): Promise<{ items: ContributorEntity[] }> {
const query = this.contributorModel
.query()
.select("contributors.*")
.select(
raw(
"COALESCE(ARRAY_AGG(DISTINCT jsonb_build_object('id', projects.id, 'name', projects.name)) FILTER (WHERE projects.id IS NOT NULL), '{}') AS projects",
),
)
.leftJoin("git_emails", "contributors.id", "git_emails.contributor_id")
.leftJoin("activity_logs", "git_emails.id", "activity_logs.git_email_id")
.leftJoin("projects", "activity_logs.project_id", "projects.id")
.groupBy("contributors.id")
.withGraphFetched("gitEmails");

if (!hasHidden) {
query.whereNull("contributors.hiddenAt");
case ContributorOrderBy.LAST_ACTIVITY_DATE: {
query.orderBy(
ContributorOrderBy.LAST_ACTIVITY_DATE,
SortType.DESCENDING,
);
break;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we don't need all this logic and we can do it this way:

query.orderBy(orderBy, SortType.DESCENDING);

in case we need another sortType, this should be passed to query parameters. And for query params validation itself we need to have a validation schema which will restrict orderBy only to two options

@@ -0,0 +1,6 @@
const ContributorOrderBy = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const ContributorOrderBy = {
const ContributorOrderByKey = {

@GvoFor GvoFor removed the conflicts label Sep 26, 2024
@GvoFor
Copy link
Collaborator Author

GvoFor commented Sep 26, 2024

I'm sure I miss some buisness logic bugs while resolving conflicts, so I'll try to find them out tomorrow

Copy link
Contributor

@what1s1ove what1s1ove left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm after Lisa's comments

return results.map(({ projects, ...projectGroup }) => {
const [project] = projects;
return results
.filter(({ projects }) => projects.length)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check for cases when user deletes project, which has some project groups. After such a deletion in the DB project groups are remained in project_groups table, but they relation with projects are lost (corresponding record in projects_to_project_groups are deleted). So without this .filter, project in const [project] = projects; expression is undefined which leads to Reading property 'id' of undefined error.

It would be better to remove this filter after we fix mentioned issue.

Copy link
Collaborator

@liza-veis liza-veis Sep 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to remove this. This shouldn't be the case for project groups. We need to create a migration to make the project field required and delete groups by cascade

@GvoFor GvoFor requested a review from liza-veis September 27, 2024 08:20
Comment on lines +2 to +3
CREATED_AT: "created_at",
LAST_ACTIVITY_DATE: "last_activity_date",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So as we agreed, maybe we should use camelCase here? (I think that this might be fixed in ticket regarding quality criteria, but if you'll fix anything else, you might to fix this also).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Vitaliistf can we fix this in your PR please? we need this pr to be merged to fix deployment

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

@liza-veis liza-veis merged commit 3f1f1c5 into main Sep 27, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Backlog
Development

Successfully merging this pull request may close these issues.

6 participants