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 priority sorting: now sorts alphabetically #1306

Merged
merged 3 commits into from
Jul 18, 2023
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
11 changes: 11 additions & 0 deletions prisma/migrations/20230714171654_/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
Warnings:

- Made the column `priority` on table `Goal` required. This step will fail if there are existing NULL values in that column.

*/
-- DropIndex
DROP INDEX "Flow_title_key";

-- AlterTable
ALTER TABLE "Goal" ALTER COLUMN "priority" SET NOT NULL;
24 changes: 24 additions & 0 deletions prisma/migrations/20230714181336_/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
Warnings:

- A unique constraint covering the columns `[title]` on the table `Flow` will be added. If there are existing duplicate values, this will fail.
- Added the required column `priorityId` to the `Goal` table without a default value. This is not possible if the table is not empty.

*/
-- AlterTable
ALTER TABLE "Goal" ADD COLUMN "priorityId" INTEGER NOT NULL;

-- CreateTable
CREATE TABLE "Priority" (
"id" SERIAL NOT NULL,
"title" TEXT NOT NULL,
"value" INTEGER NOT NULL,

CONSTRAINT "Priority_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "Flow_title_key" ON "Flow"("title");

-- AddForeignKey
ALTER TABLE "Goal" ADD CONSTRAINT "Goal_priorityId_fkey" FOREIGN KEY ("priorityId") REFERENCES "Priority"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
9 changes: 9 additions & 0 deletions prisma/migrations/20230717183439_/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- DropForeignKey
ALTER TABLE "Goal" DROP CONSTRAINT "Goal_priorityId_fkey";

-- AlterTable
ALTER TABLE "Goal" ALTER COLUMN "priority" DROP NOT NULL,
ALTER COLUMN "priorityId" DROP NOT NULL;

-- AddForeignKey
ALTER TABLE "Goal" ADD CONSTRAINT "Goal_priorityId_fkey" FOREIGN KEY ("priorityId") REFERENCES "Priority"("id") ON DELETE SET NULL ON UPDATE CASCADE;
9 changes: 9 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,13 @@ model EstimateToGoal {
@@index([estimateId])
}

model Priority {
id Int @id @default(autoincrement())
title String
value Int
Goal Goal[]
}

model Goal {
id String @id @default(cuid())
scopeId Int @default(1)
Expand All @@ -195,6 +202,8 @@ model Goal {
private Boolean?
archived Boolean? @default(false)
priority String?
priorityExact Priority? @relation(fields: [priorityId], references: [id])
priorityId Int?
estimate EstimateToGoal[]
project Project? @relation("projectGoals", fields: [projectId], references: [id])
projectId String?
Expand Down
39 changes: 33 additions & 6 deletions prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,29 @@ import { keyPredictor } from '../src/utils/keyPredictor';

const adminEmail = process.env.ADMIN_EMAIL || 'tony@taskany.org';
const adminPassword = process.env.ADMIN_PASSWORD || 'taskany';
const priorities = ['Highest', 'High', 'Medium', 'Low'];
const prioritiesExact = [
{
id: 4,
title: 'Highest',
value: 4,
},
{
id: 3,
title: 'High',
value: 3,
},
{
id: 2,
title: 'Medium',
value: 2,
},
{
id: 1,
title: 'Low',
value: 1,
},
];

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const sample = (arr: any[]) => arr[Math.floor(Math.random() * arr.length)];

Expand Down Expand Up @@ -169,6 +191,8 @@ seed('Default projects', async () => {

await init;

await Promise.all(prioritiesExact.map((priority) => prisma.priority.create({ data: priority })));

const allProjects = await Promise.all(
[
['Frontend', sample(allUsers).activityId],
Expand Down Expand Up @@ -209,16 +233,19 @@ seed('Default projects', async () => {
[faker.lorem.words(2), faker.lorem.sentence(5), sample(allUsers).activityId],
[faker.lorem.words(2), faker.lorem.sentence(5), sample(allUsers).activityId],
// eslint-disable-next-line no-loop-func
].map(([title, description, activityId]: string[], index) =>
prisma.goal.create({
].map(([title, description, activityId]: string[], index) => {
const priority = sample(prioritiesExact);

return prisma.goal.create({
data: {
scopeId: index + 1,
title,
description,
projectId: project.id,
activityId,
ownerId: activityId,
priority: sample(priorities),
priority: priority.title,
priorityId: priority.id,
participants: {
connect:
Math.random() > 0.5
Expand Down Expand Up @@ -273,8 +300,8 @@ seed('Default projects', async () => {
blocks: true,
relatedTo: true,
},
}),
),
});
}),
);
for (const goal of allGoals) {
// eslint-disable-next-line no-await-in-loop
Expand Down
2 changes: 1 addition & 1 deletion trpc/queries/goals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export const goalsFilter = (

if (data.sort?.priority) {
orderBy.push({
priority: data.sort.priority,
priorityId: data.sort.priority,
});
}

Expand Down
Loading