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

Fix partial criteria score #3052

Merged
merged 4 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/ProjectAccessUser/ProjectAccessUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { FC, useCallback, useMemo, useState } from 'react';
import { nullable } from '@taskany/bricks';
import { Fieldset, Switch, SwitchControl } from '@taskany/bricks/harmony';

import { ProjectByIdReturnType } from '../../../trpc/inferredTypes';
import { ProjectByIdReturnTypeV2 } from '../../../trpc/inferredTypes';
import { useProjectResource } from '../../hooks/useProjectResource';
import { ModalEvent, dispatchModalEvent } from '../../utils/dispatchModal';
import { SettingsCard, SettingsCardItem } from '../SettingsContent/SettingsContent';
Expand All @@ -12,7 +12,7 @@ import s from './ProjectAccessUser.module.css';
import { tr } from './ProjectAccessUser.i18n';

interface ProjectAccessUserProps {
project: NonNullable<ProjectByIdReturnType>;
project: NonNullable<ProjectByIdReturnTypeV2>;
}

export const ProjectAccessUser: FC<ProjectAccessUserProps> = ({ project }) => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/ProjectContext/ProjectContext.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createContext } from 'react';

import { ProjectByIdReturnType } from '../../../trpc/inferredTypes';
import { ProjectByIdReturnTypeV2 } from '../../../trpc/inferredTypes';

export const ProjectContext = createContext<{ project: ProjectByIdReturnType }>({
export const ProjectContext = createContext<{ project?: ProjectByIdReturnTypeV2 | null }>({
project: null,
});
2 changes: 1 addition & 1 deletion src/components/ProjectListItem/ProjectListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface ProjectListItemProps {
flowId: string;
title: string;
owner?: ActivityByIdReturnType;
participants?: ActivityByIdReturnType[];
participants: ActivityByIdReturnType[] | null;
starred?: boolean;
watching?: boolean;
averageScore: number | null;
Expand Down
87 changes: 42 additions & 45 deletions src/components/ProjectPage/ProjectPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,48 +32,45 @@ export const ProjectPage = ({ user, ssrTime, params: { id }, defaultPresetFallba
preset,
});

const { data: project } = trpc.project.getById.useQuery(
{
id,
goalsQuery: queryState,
},
{ enabled: Boolean(id) },
);

const { data: projectDeepInfo } = trpc.project.getDeepInfo.useQuery(
{
id,
goalsQuery: queryState,
},
{
keepPreviousData: true,
staleTime: refreshInterval,
enabled: Boolean(id),
},
);

const { data: projectTree } = trpc.v2.project.getProjectChildrenTree.useQuery({
id,
goalsQuery: queryState,
});
const [projectQuery, projectDeepInfoQuery, projectTreeQuery] = trpc.useQueries((ctx) => [
ctx.v2.project.getById({ id }, { enabled: Boolean(id) }),
ctx.v2.project.getProjectGoalsById(
{ id, goalsQuery: queryState },
{
keepPreviousData: true,
staleTime: refreshInterval,
enabled: Boolean(id),
},
),
ctx.v2.project.getProjectChildrenTree(
{
id,
goalsQuery: queryState,
},
{
keepPreviousData: true,
staleTime: refreshInterval,
enabled: Boolean(id),
},
),
]);

const { setPreview, on } = useGoalPreview();

const invalidateFnsCallback = useCallback(() => {
utils.v2.project.getById.invalidate();
utils.v2.project.getProjectGoalsById.invalidate();
}, [utils.v2.project.getProjectGoalsById, utils.v2.project.getById]);

useEffect(() => {
const unsubUpdate = on('on:goal:update', () => {
utils.project.getById.invalidate();
utils.project.getDeepInfo.invalidate();
});
const unsubDelete = on('on:goal:delete', () => {
utils.project.getById.invalidate();
utils.project.getDeepInfo.invalidate();
});
const unsubUpdate = on('on:goal:update', invalidateFnsCallback);
const unsubDelete = on('on:goal:delete', invalidateFnsCallback);

return () => {
unsubUpdate();
unsubDelete();
};
}, [on, utils.project.getDeepInfo, utils.project.getById]);
}, [on, invalidateFnsCallback]);

const handleItemEnter = useCallback(
(goal: NonNullable<GoalByIdReturnType>) => {
Expand All @@ -82,7 +79,7 @@ export const ProjectPage = ({ user, ssrTime, params: { id }, defaultPresetFallba
[setPreview],
);

const ctx = useMemo(() => ({ project: project ?? null }), [project]);
const ctx = useMemo(() => ({ project: projectQuery.data ?? null }), [projectQuery.data]);

return (
<ProjectContext.Provider value={ctx}>
Expand All @@ -92,25 +89,25 @@ export const ProjectPage = ({ user, ssrTime, params: { id }, defaultPresetFallba
scrollerShadow={view === 'kanban' ? 70 : 0}
title={tr
.raw('title', {
project: project?.title,
project: ctx.project?.title,
})
.join('')}
header={
<FiltersPanel
title={project?.title || tr('Projects')}
total={projectDeepInfo?.meta?.count}
counter={projectDeepInfo?.goals?.length}
title={ctx.project?.title || tr('Projects')}
total={ctx.project?._count?.goals ?? 0}
counter={projectDeepInfoQuery.data?.goals?.length}
filterPreset={preset}
enableLayoutToggle
enableHideProjectToggle
>
<FiltersBarItem>
<ProjectPageTabs id={id} editable={project?._isEditable} />
<ProjectPageTabs id={id} editable={ctx.project?._isEditable} />
</FiltersBarItem>
</FiltersPanel>
}
>
{nullable(project?.parent, (p) => (
{nullable(ctx.project?.parent, (p) => (
<Breadcrumbs className={s.Breadcrumbs}>
{p.map((item) => (
<Breadcrumb key={item.id}>
Expand All @@ -122,18 +119,18 @@ export const ProjectPage = ({ user, ssrTime, params: { id }, defaultPresetFallba
</Breadcrumbs>
))}

<ListView onKeyboardClick={handleItemEnter}>
{nullable(project, (p) => (
{nullable(ctx.project, (p) => (
<ListView onKeyboardClick={handleItemEnter}>
<ProjectListItemConnected
key={p.id}
mainProject
visible
project={p}
filterPreset={preset}
subTree={projectTree?.[p.id]}
subTree={projectTreeQuery.data?.[p.id]}
/>
))}
</ListView>
</ListView>
))}

<PresetModals preset={preset} />
</Page>
Expand Down
4 changes: 2 additions & 2 deletions src/components/ProjectParticipants/ProjectParticipants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import { tr } from './ProjectParticipants.i18n';

interface ProjectParticipantsProps {
id: string;
participants: ComponentProps<typeof UserEditableList>['users'];
participants: ComponentProps<typeof UserEditableList>['users'] | null;
}

export const ProjectParticipants: FC<ProjectParticipantsProps> = ({ id, participants }) => {
const filterIds = useMemo(() => participants.map(({ id }) => id), [participants]);
const filterIds = useMemo(() => (participants ?? []).map(({ id }) => id), [participants]);
const { onProjectParticipantAdd, onProjectParticipantRemove } = useProjectResource(id);

const onAdd = useCallback(
Expand Down
10 changes: 9 additions & 1 deletion src/components/ProjectSettingsPage/ProjectSettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const ModalOnEvent = dynamic(() => import('../ModalOnEvent'));

export const ProjectSettingsPage = ({ user, ssrTime, params: { id } }: ExternalPageProps) => {
const router = useRouter();
const project = trpc.project.getById.useQuery({ id });
const project = trpc.v2.project.getById.useQuery({ id, includeChildren: true });

const { updateProject, deleteProject, transferOwnership } = useProjectResource(id);
const { data: childrenIds = [] } = trpc.v2.project.deepChildrenIds.useQuery({ in: [{ id }] });
Expand All @@ -86,6 +86,14 @@ export const ProjectSettingsPage = ({ user, ssrTime, params: { id } }: ExternalP
mode: 'onChange',
reValidateMode: 'onChange',
shouldFocusError: true,
values: {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
id: project.data!.id,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
title: project.data!.title,
description: project.data?.description,
parent: project.data?.parent,
},
defaultValues: {
id: project.data?.id,
title: project.data?.title,
Expand Down
2 changes: 1 addition & 1 deletion src/components/ProjectTeamPage/ProjectTeamPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { tr } from './ProjectTeamPage.i18n';
import s from './ProjectTeamPage.module.css';

export const ProjectTeamPage = ({ user, ssrTime, params: { id } }: ExternalPageProps) => {
const { data: project } = trpc.project.getById.useQuery({ id });
const { data: project } = trpc.v2.project.getById.useQuery({ id });
const { updateProjectTeams } = useProjectResource(id);

const ids = useMemo(() => project?.teams.map(({ externalTeamId }) => externalTeamId) ?? [], [project]);
Expand Down
4 changes: 2 additions & 2 deletions src/components/TeamComboBox/TeamComboBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { IconPlusCircleOutline } from '@taskany/icons';

import { trpc } from '../../utils/trpcClient';
import { useProjectResource } from '../../hooks/useProjectResource';
import { ProjectByIdReturnType, TeamSuggetionsReturnType } from '../../../trpc/inferredTypes';
import { ProjectByIdReturnTypeV2, TeamSuggetionsReturnType } from '../../../trpc/inferredTypes';
import { Dropdown, DropdownPanel, DropdownTrigger } from '../Dropdown/Dropdown';

interface TeamComboBoxProps {
text?: React.ComponentProps<typeof Button>['text'];
placeholder?: string;
disabled?: boolean;
project: NonNullable<ProjectByIdReturnType>;
project: NonNullable<ProjectByIdReturnTypeV2>;
}

export const TeamComboBox: FC<TeamComboBoxProps & React.HTMLAttributes<HTMLDivElement>> = ({
Expand Down
2 changes: 1 addition & 1 deletion src/components/UserEditableList/UserEditableList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { tr } from './UserEditableList.i18n';

export const UserEditableList: FC<{
editable?: boolean;
users: { id: string; user: User | null }[];
users: { id: string; user: User | null }[] | null;
filterIds: string[];
onRemove: (id: string) => void;
onAdd: (id: string) => void;
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useProjectResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export const useProjectResource = (id: string) => {
const removeParticipants = trpc.project.removeParticipants.useMutation();

const invalidate = useCallback(() => {
utils.project.getById.invalidate({ id });
}, [id, utils.project.getById]);
utils.v2.project.getById.invalidate({ id });
}, [id, utils.v2.project.getById]);

const createProject = useCallback(
(cb: Callback<string>) => async (form: ProjectCreate) => {
Expand Down
6 changes: 1 addition & 5 deletions src/pages/projects/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,13 @@ export const getServerSideProps = declareSsrProps(
} = props;

try {
const project = await ssrHelpers.project.getById.fetch({ id, goalsQuery: queryState });
const project = await ssrHelpers.v2.project.getById.fetch({ id });

if (!project) {
throw new TRPCError({ code: 'NOT_FOUND' });
}

await Promise.all([
ssrHelpers.project.getDeepInfo.fetch({
id,
goalsQuery: queryState,
}),
ssrHelpers.v2.project.getProjectChildrenTree.fetch({
id,
goalsQuery: queryState,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/projects/[id]/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { declareSsrProps } from '../../../utils/declareSsrProps';
export const getServerSideProps = declareSsrProps(
async ({ ssrHelpers, params: { id } }) => {
try {
const project = await ssrHelpers.project.getById.fetch({ id });
const project = await ssrHelpers.v2.project.getById.fetch({ id, includeChildren: true });
await ssrHelpers.v2.project.deepChildrenIds.fetch({ in: [{ id }] });

if (!project) {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/projects/[id]/team.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { declareSsrProps } from '../../../utils/declareSsrProps';
export const getServerSideProps = declareSsrProps(
async ({ ssrHelpers, params: { id } }) => {
try {
const project = await ssrHelpers.project.getById.fetch({ id });
const project = await ssrHelpers.v2.project.getById.fetch({ id });

if (!project || !process.env.NEXT_PUBLIC_CREW_URL) {
throw new TRPCError({ code: 'NOT_FOUND' });
Expand Down
2 changes: 1 addition & 1 deletion src/schema/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const projectUpdateSchema = z.object({
title: z.string(),
}),
)
.optional(),
.nullish(),
accessUsers: z
.array(
z.object({
Expand Down
6 changes: 3 additions & 3 deletions src/utils/recalculateCriteriaScore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const baseCalcCriteriaWeight = <
criteriaList: T[],
): number => {
let achivedWithWeight = 0;
let comletedWithoutWeight = 0;
let completedWithoutWeight = 0;
let anyWithoutWeight = 0;
let allWeight = 0;

Expand All @@ -47,7 +47,7 @@ export const baseCalcCriteriaWeight = <
achivedWithWeight += weight;

if (!weight) {
comletedWithoutWeight += 1;
completedWithoutWeight += 1;
}
}
}
Expand All @@ -67,7 +67,7 @@ export const baseCalcCriteriaWeight = <
}

return Math.min(
achivedWithWeight + Math.ceil(quantityByWeightlessCriteria * comletedWithoutWeight),
achivedWithWeight + Math.ceil(quantityByWeightlessCriteria * completedWithoutWeight),
maxPossibleCriteriaWeight,
);
};
Expand Down
1 change: 1 addition & 0 deletions trpc/inferredTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type StateType = State['type'];

export type DashboardProjectV2 = RouterOutputs['v2']['project']['getUserDashboardProjects']['groups'][number];
export type DashboardGoalV2 = NonNullable<DashboardProjectV2['goals']>[number];
export type ProjectByIdReturnTypeV2 = RouterOutputs['v2']['project']['getById'];

export type GoalActivityHistory = RouterOutputs['goal']['getGoalActivityFeed'];
export type GoalComments = RouterOutputs['goal']['getGoalCommentsFeed'];
Expand Down
11 changes: 11 additions & 0 deletions trpc/queries/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,14 @@ export const getUserActivity = () => {
.select([sql`"User"`.as('user'), sql`"Ghost"`.as('ghost')])
.$castTo<Activity>();
};

export const getAccessUsersByProjectId = ({ projectId }: { projectId: string }) => {
return db
.selectFrom('_projectAccess')
.innerJoinLateral(
() => getUserActivity().as('activity'),
(join) => join.onRef('activity.id', '=', '_projectAccess.A'),
)
.selectAll('activity')
.where('_projectAccess.B', '=', projectId);
};
2 changes: 1 addition & 1 deletion trpc/queries/goalV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const getGoalsQuery = (params: GetGoalsQueryParams) =>
({ selectFrom }) =>
selectFrom('GoalAchieveCriteria')
.distinctOn('GoalAchieveCriteria.id')
.leftJoin('Goal as criteriaGoal', 'GoalAchieveCriteria.criteriaGoalId', 'Goal.id')
.leftJoin('Goal as criteriaGoal', 'GoalAchieveCriteria.criteriaGoalId', 'criteriaGoal.id')
.selectAll('GoalAchieveCriteria')
.select([sql`"criteriaGoal"`.as('criteriaGoal')])
.where('GoalAchieveCriteria.deleted', 'is not', true)
Expand Down
Loading
Loading