Skip to content

Commit

Permalink
Add property name
Browse files Browse the repository at this point in the history
  • Loading branch information
dv297 committed Oct 21, 2022
1 parent 73d1502 commit ceb8812
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "IssueAuditEntry" ADD COLUMN "propertyName" TEXT;
23 changes: 12 additions & 11 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,18 @@ model ActiveSprint {
}

model IssueAuditEntry {
id String @id @unique @default(cuid())
issue Issue @relation(fields: [issueId], references: [id])
user User @relation(fields: [userId], references: [id])
oldValue String?
newValue String?
updatedAt DateTime @default(now()) @updatedAt
createdAt DateTime @default(now())
type IssueAuditEntryType
wasEdited Boolean? @default(false)
issueId String
userId String
id String @id @unique @default(cuid())
issue Issue @relation(fields: [issueId], references: [id])
user User @relation(fields: [userId], references: [id])
propertyName String?
oldValue String?
newValue String?
updatedAt DateTime @default(now()) @updatedAt
createdAt DateTime @default(now())
type IssueAuditEntryType
wasEdited Boolean? @default(false)
issueId String
userId String
}

enum IssueRelationType {
Expand Down
7 changes: 6 additions & 1 deletion src/components/pages/issue/IssueAuditEntryListingFactory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const HistoryListing = (props: IssueAuditEntryListingProps) => {
const { issueAuditEntry } = props;
const { user } = issueAuditEntry;

console.log(issueAuditEntry.propertyName);
return (
<>
<div className="relative">
Expand All @@ -85,7 +86,11 @@ const HistoryListing = (props: IssueAuditEntryListingProps) => {
</div>
<div className="mt-2 text-sm text-gray-700 dark:text-gray-100">
<p>
Changed value from <i>&quot;{issueAuditEntry.oldValue}&quot;</i> to{' '}
Changed{' '}
{issueAuditEntry.propertyName
? `"${issueAuditEntry.propertyName}"`
: ''}{' '}
value from <i>&quot;{issueAuditEntry.oldValue}&quot;</i> to{' '}
<i>&quot;{issueAuditEntry.newValue}&quot;</i>
</p>
</div>
Expand Down
22 changes: 14 additions & 8 deletions src/repos/IssueAuditEntryRepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,32 @@ interface IssueAuditEntryOptions {
}

interface PropertyChange {
propertyName: string;
oldValue: string;
newValue: string;
}

function getStatusChangeValues(properties: PropertyChange): PropertyChange {
const convertCasing = (s: string) => s.split('_').join(' ');
return {
oldValue: convertCasing(properties.oldValue),
newValue: convertCasing(properties.newValue),
};
}

function getGenericSanitizedPropertyChange(properties: PropertyChange) {
// Property has already been converted to string, so these values may pop up.
const sanitize = (s: string | null | undefined) =>
s === 'null' || s === 'undefined' || !s ? '' : s;

return {
...properties,
oldValue: sanitize(properties.oldValue),
newValue: sanitize(properties.newValue),
};
}

function getStatusChangeValues(properties: PropertyChange): PropertyChange {
const convertCasing = (s: string) => s.split('_').join(' ');
return {
propertyName: 'Issue Status',
oldValue: convertCasing(properties.oldValue),
newValue: convertCasing(properties.newValue),
};
}

async function getSprintChangeValues(
properties: PropertyChange
): Promise<PropertyChange> {
Expand All @@ -64,6 +67,7 @@ async function getSprintChangeValues(
sanitize(properties.newValue),
]);
return {
propertyName: 'Sprint',
oldValue,
newValue,
};
Expand Down Expand Up @@ -91,6 +95,7 @@ async function getAssigneeChangeValues(
sanitize(properties.newValue),
]);
return {
propertyName: 'Assignee',
oldValue,
newValue,
};
Expand Down Expand Up @@ -182,6 +187,7 @@ const IssueAuditEntryRepo = {
newValue: string;
}) {
const propertyChange = await getPropertyChange(propertyName, {
propertyName,
oldValue,
newValue,
});
Expand Down
2 changes: 2 additions & 0 deletions src/schemas/IssueSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export const IssueAuditEntryType = z

export const IssueAuditEntrySchema = z.object({
id: z.string(),
propertyName: z.string().nullish(),
oldValue: z.string().nullable(),
newValue: z.string().nullable(),
updatedAt: dateSchema,
Expand All @@ -109,6 +110,7 @@ export const GetIssueAuditEntriesResponseSchema = z.object({

export const IssueAuditEntryCreateBodySchema = z.object({
type: z.literal('COMMENT').or(z.literal('CHANGE')),
propertyName: z.string().nullish(),
oldValue: z.string().nullable(),
newValue: z.string(),
});

1 comment on commit ceb8812

@vercel
Copy link

@vercel vercel bot commented on ceb8812 Oct 21, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

planner – ./

planner-nine.vercel.app
planner-dv297.vercel.app
planner-git-main-dv297.vercel.app

Please sign in to comment.