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

read rules for each personalized dashboard project #3108

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions cypress/e2e/dashboard.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ describe('Dashboard', () => {
});

beforeEach(() => {
cy.interceptWhatsNew();
cy.signInViaEmail();
cy.wait('@whatsnew.check');
});

it('filters are active by default', () => {
Expand Down Expand Up @@ -72,7 +74,9 @@ describe('User dashboard', () => {
});

beforeEach(() => {
cy.interceptWhatsNew();
cy.signInViaEmail(testUser);
cy.wait('@whatsnew.check');
});

describe('User have own project', () => {
Expand Down Expand Up @@ -142,6 +146,7 @@ describe('User dashboard', () => {
});

it('User cannot see self goal which assigned in not own project if filter contains next quarter', () => {
cy.hideEmptyProjectOnGoalLists();
cy.get(appliedFiltersPanelEstimate.query).click();
cy.get(estimateQuarterTrigger.query).children().find(':button:contains(@next)').click();
cy.get(appliedFiltersPanelEstimate.query).focus().realPress('{esc}');
Expand Down
2 changes: 2 additions & 0 deletions cypress/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Goal } from '@prisma/client';

Check warning on line 1 in cypress/index.d.ts

View workflow job for this annotation

GitHub Actions / build

'@prisma/client' import is restricted from being used. Use the trpc procedures inferred types instead

import { CommentEditSchema } from '../src/schema/comment';
import { GoalCommentCreateSchema, GoalCommon, GoalUpdate } from '../src/schema/goal';
Expand Down Expand Up @@ -53,6 +53,8 @@
interface Chainable {
logout(): Chainable<void>;
signInViaEmail(fields?: SignInFields): Chainable<void>;
interceptWhatsNew(): Chainable<void>;
hideEmptyProjectOnGoalLists(): Chainable<void>;
createProject(fields: ProjectCreate): Chainable<ProjectCreateReturnType>;
createGoal(projectTitle: string, fields: GoalCommon): Chainable<GoalCreateReturnType>;
updateGoal(shortId: string, filelds: GoalUpdate): Chainable<GoalUpdateReturnType>;
Expand Down
25 changes: 25 additions & 0 deletions cypress/support/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ import {
userSettingsLogoutButton,
commentFormDescription,
pageContent,
sortPanelDropdownTrigger,
sortPanel,
sortPanelEmptyProjectsCheckbox,
} from '../../src/utils/domObjects';
import { keyPredictor } from '../../src/utils/keyPredictor';
import { SignInFields } from '..';
Expand All @@ -54,6 +57,18 @@ Cypress.Commands.addAll({
cy.reload(true);
},

interceptWhatsNew: () => {
cy.intercept('api/trpc/whatsnew.check*', (req) =>
req.on('response', (res) => {
if (res.body.result?.data != null && 'version' in res.body.result.data) {
res.body.result.data = null;
}

res.send();
}),
).as('whatsnew.check');
},

signInViaEmail: (fields?: SignInFields) => {
cy.intercept('/api/auth/session', (req) => {
req.on('after:response', (res) => {
Expand Down Expand Up @@ -268,6 +283,16 @@ Cypress.Commands.addAll({

return cy.wrap(values);
},
hideEmptyProjectOnGoalLists: () => {
cy.get(sortPanelDropdownTrigger.query).should('exist').click();
cy.get(sortPanel.query).should('exist').and('be.visible');

cy.get(sortPanel.query)
.get(sortPanelEmptyProjectsCheckbox.query)
.should('be.checked')
.click()
.should('not.be.checked');
},
});

/**
Expand Down
112 changes: 65 additions & 47 deletions trpc/queries/goalV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,15 @@ export const getGoalsQuery = (params: GetGoalsQueryParams) =>
qb.selectFrom('_goalParticipants').select('A').whereRef('B', '=', 'Goal.id'),
),
)
.leftJoin('Tag as tag', (join) =>
join.onRef('tag.id', 'in', ({ selectFrom }) =>
selectFrom('_GoalToTag').select('B').whereRef('A', '=', 'Goal.id'),
),
.leftJoinLateral(
({ selectFrom }) =>
selectFrom('Tag')
.selectAll('Tag')
.whereRef('Tag.id', 'in', ({ selectFrom }) =>
selectFrom('_GoalToTag').select('B').whereRef('A', '=', 'Goal.id'),
)
.as('tag'),
(join) => join.onTrue(),
)
.leftJoinLateral(
({ selectFrom }) =>
Expand All @@ -105,10 +110,15 @@ export const getGoalsQuery = (params: GetGoalsQueryParams) =>
.as('criteria'),
(join) => join.onTrue(),
)
.leftJoin('Project as partnershipProject', (join) =>
join.onRef('partnershipProject.id', 'in', ({ selectFrom }) =>
selectFrom('_partnershipProjects').select('B').whereRef('A', '=', 'Goal.id'),
),
.leftJoinLateral(
({ selectFrom }) =>
selectFrom('Project')
.selectAll('Project')
.whereRef('Project.id', 'in', ({ selectFrom }) =>
selectFrom('_partnershipProjects').select('B').whereRef('A', '=', 'Goal.id'),
)
.as('partnershipProjects'),
(join) => join.onTrue(),
)
.select(({ case: caseFn, exists, selectFrom, val, fn }) => [
sql<boolean>`("Goal"."ownerId" = ${val(params.activityId)})`.as('_isOwner'),
Expand Down Expand Up @@ -173,42 +183,57 @@ export const getGoalsQuery = (params: GetGoalsQueryParams) =>
.end()
.as('participants'),
caseFn()
.when(fn.count('partnershipProject.id'), '>', 0)
.then(fn.agg('array_agg', [sql`"partnershipProject"`]).distinct())
.when(fn.count('partnershipProjects.id'), '>', 0)
.then(fn.agg('array_agg', [sql`"partnershipProjects"`]).distinct())
.else(null)
.end()
.as('partnershipProjects'),
])
.where(({ or, eb, and }) => {
const baseOr = or([
eb('Goal.projectId', '=', params.projectId),
eb('Goal.id', 'in', ({ selectFrom }) =>
selectFrom('_partnershipProjects').where('B', '=', params.projectId).select('A'),
),
]);

if (params.isOnlySubsGoals) {
return and([
baseOr,
eb('Goal.id', 'in', ({ selectFrom }) =>
selectFrom('_goalStargizers')
.select('B as id')
.where('A', '=', params.activityId)
.union(
selectFrom('_goalWatchers')
.select('B as id')
.where('A', '=', params.activityId),
)
.union(
selectFrom('_partnershipProjects')
.where('B', '=', params.projectId)
.select('A as id'),
),
.where('Goal.archived', 'is not', true)
.where('Goal.projectId', '=', params.projectId)
.where(({ and, or, eb, val, cast, selectFrom }) =>
or([
and([
eb(cast(val(!!params.isOnlySubsGoals), 'boolean'), 'is', false),
eb(
'Goal.id',
'in',
selectFrom('_partnershipProjects').select('A').where('B', '=', params.projectId),
),
]);
}
return baseOr;
})
]),
and([
eb(cast(val(!!params.isOnlySubsGoals), 'boolean'), 'is', true),
or([
eb('Goal.ownerId', '=', params.activityId),
eb('Goal.activityId', '=', params.activityId),
eb('Goal.id', 'in', ({ selectFrom }) =>
selectFrom('_goalParticipants')
.select('B')
.where('A', '=', params.activityId)
.union(
selectFrom('_goalWatchers').select('B').where('A', '=', params.activityId),
)
.union(
selectFrom('_goalStargizers')
.select('B')
.where('A', '=', params.activityId),
)
.union(
selectFrom('_partnershipProjects')
.select('A as B')
.where(
'B',
'in',
selectFrom('Project')
.select('Project.id')
.where('Project.activityId', '=', params.activityId),
),
),
),
]),
]),
]),
)
.where(({ or, and, eb, selectFrom, cast, val }) => {
const { goalsQuery } = params;
const estimate: Array<Date> = [];
Expand All @@ -232,13 +257,7 @@ export const getGoalsQuery = (params: GetGoalsQueryParams) =>

const filters: Record<keyof NonNullable<typeof goalsQuery>, null | ReturnType<typeof eb>> = {
project: null,
partnershipProject: goalsQuery?.partnershipProject?.length
? eb('Goal.id', 'in', ({ selectFrom }) =>
selectFrom('_partnershipProjects')
.where('B', 'in', goalsQuery.partnershipProject || [])
.select('A'),
)
: null,
partnershipProject: null,
owner: eb('Goal.ownerId', 'in', goalsQuery?.owner || []),
issuer: eb('Goal.activityId', 'in', goalsQuery?.issuer || []),
participant: eb('participant.id', 'in', goalsQuery?.participant || []),
Expand Down Expand Up @@ -301,7 +320,6 @@ export const getGoalsQuery = (params: GetGoalsQueryParams) =>

return and(filterToApply);
})
.where('Goal.archived', 'is not', true)
.groupBy(['Goal.id']),
)
.selectFrom('proj_goals')
Expand Down
Loading
Loading