-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: create issue/sub-issue from comments
- Loading branch information
1 parent
11d7dea
commit cacc549
Showing
14 changed files
with
242 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './tegon-issue-extension'; |
50 changes: 50 additions & 0 deletions
50
apps/webapp/src/common/editor/tegon-issue-extension/tegon-issue-component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { NodeViewWrapper } from '@tiptap/react'; | ||
import { getWorkflowColor } from 'common/status-color'; | ||
import { getWorkflowIcon } from 'common/workflow-icons'; | ||
import { useTeamWorkflows } from 'hooks/workflows'; | ||
import Link from 'next/link'; | ||
import { useParams } from 'next/navigation'; | ||
import React from 'react'; | ||
import { useContextStore } from 'store/global-context-provider'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export const TegonIssueComponent = (props: any) => { | ||
const { workspaceSlug } = useParams<{ workspaceSlug: string }>(); | ||
const { issuesStore, teamsStore } = useContextStore(); | ||
|
||
const url = props.node.attrs.url; | ||
const identifier = url.split('/')[url.split('/').length - 1]; | ||
const teamIdentifier = identifier.split('-')[0]; | ||
|
||
const team = teamsStore.getTeamWithIdentifier(identifier.split('-')[0]); | ||
const workflows = useTeamWorkflows(teamIdentifier); | ||
|
||
const issue = team | ||
? issuesStore.getIssueByNumber(identifier, team.id) | ||
: undefined; | ||
|
||
if (!issue) { | ||
return ( | ||
<NodeViewWrapper className="react-component-with-content"> | ||
<div className="content">{url}</div> | ||
</NodeViewWrapper> | ||
); | ||
} | ||
|
||
const workflow = workflows.find((workflow) => workflow.id === issue.stateId); | ||
|
||
const CategoryIcon = getWorkflowIcon(workflow); | ||
return ( | ||
<NodeViewWrapper className="react-component-with-content"> | ||
<div className="content"> | ||
<Link | ||
className="flex gap-1 bg-grayAlpha-100 p-1 px-2 w-fit rounded items-center" | ||
href={`/${workspaceSlug}/issue/${team.identifier}-${issue.number}`} | ||
> | ||
<CategoryIcon size={20} color={getWorkflowColor(workflow).color} /> | ||
{issue.title} | ||
</Link> | ||
</div> | ||
</NodeViewWrapper> | ||
); | ||
}; |
34 changes: 34 additions & 0 deletions
34
apps/webapp/src/common/editor/tegon-issue-extension/tegon-issue-extension.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { mergeAttributes, Node } from '@tiptap/core'; | ||
import { ReactNodeViewRenderer } from '@tiptap/react'; | ||
|
||
import { TegonIssueComponent } from './tegon-issue-component'; | ||
|
||
export const tegonIssueExtension = Node.create({ | ||
name: 'tegonIssueExtension', | ||
group: 'block', | ||
atom: true, | ||
|
||
addAttributes() { | ||
return { | ||
url: { | ||
default: undefined, | ||
}, | ||
}; | ||
}, | ||
|
||
parseHTML() { | ||
return [ | ||
{ | ||
tag: 'tegon-issue-extension', | ||
}, | ||
]; | ||
}, | ||
|
||
renderHTML({ HTMLAttributes }) { | ||
return ['tegon-issue-extension', mergeAttributes(HTMLAttributes)]; | ||
}, | ||
|
||
addNodeView() { | ||
return ReactNodeViewRenderer(TegonIssueComponent); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import type { EditorT } from '@tegonhq/ui/components/editor/index'; | ||
import { useContextStore } from 'store/global-context-provider'; | ||
|
||
// Updates the height of a <textarea> when the value changes. | ||
export const useEditorPasteHandler = () => { | ||
const { issuesStore, teamsStore } = useContextStore(); | ||
|
||
const handlePaste = (editor: EditorT, event: ClipboardEvent) => { | ||
const pastedText = event.clipboardData.getData('text/plain'); | ||
const regex = /https?:\/\/app\.tegon\.ai\/\w+\/issue\/([A-Z]+)-(\d+)/; | ||
const isTegonIssue = regex.test(pastedText); | ||
const parts = regex.exec(pastedText); | ||
if (isTegonIssue && parts) { | ||
const teamIdentifier = parts[1]; // 'ENG' in this case | ||
const issueId = parts[2]; // '11' in this case | ||
const team = teamsStore.getTeamWithIdentifier(teamIdentifier); | ||
const issue = team | ||
? issuesStore.getIssueByNumber(`${teamIdentifier}-${issueId}`, team.id) | ||
: undefined; | ||
|
||
if (issue) { | ||
editor | ||
.chain() | ||
.insertContentAt(editor.view.state.selection.from, [ | ||
{ | ||
type: 'tegonIssueExtension', | ||
attrs: { | ||
url: pastedText, | ||
}, | ||
}, | ||
{ | ||
type: 'paragraph', | ||
content: [ | ||
{ | ||
type: 'text', | ||
text: '\n', | ||
}, | ||
], | ||
}, | ||
]) | ||
.exitCode() | ||
.focus() | ||
.run(); | ||
|
||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
}; | ||
|
||
return { handlePaste }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.