-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from srz2/add-support-for-multiple-jira-instances
Add support for multiple Jira instances
- Loading branch information
Showing
13 changed files
with
424 additions
and
109 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,58 @@ | ||
import {SuggestModal, App} from 'obsidian' | ||
import {IJiraInstanceUrl} from '../Models/JiraInstanceUrl' | ||
|
||
export class JiraInstanceSuggestModal extends SuggestModal<IJiraInstanceUrl> { | ||
items: IJiraInstanceUrl[] | ||
onSubmit: (result: IJiraInstanceUrl) => void; | ||
|
||
/** | ||
* @private | ||
*/ | ||
untitledInstanceCounter = 0; | ||
|
||
constructor(app: App, items: IJiraInstanceUrl[], onSubmit: (result: IJiraInstanceUrl) => void){ | ||
super(app) | ||
this.items = items; | ||
this.onSubmit = onSubmit; | ||
this.inputEl.addEventListener('keydown', () => { | ||
this.untitledInstanceCounter = 0; | ||
}) | ||
} | ||
getSuggestions(query: string): IJiraInstanceUrl[] | Promise<IJiraInstanceUrl[]> { | ||
// Create new items to ensure instance titles are filled | ||
const newItems = this.items.map(x => { | ||
return ( | ||
{ | ||
IsDefault: x.IsDefault, | ||
Url: x.Url, | ||
Title: x.Title === '' ? `Instance ${(this.untitledInstanceCounter++)}` : x.Title | ||
} | ||
) | ||
}) | ||
|
||
// Filter based on input | ||
return newItems.filter(x => | ||
x.Title.toLowerCase().contains(query.toLowerCase()) || | ||
x.Url.toLowerCase().contains(query.toLowerCase()) | ||
); | ||
} | ||
renderSuggestion(value: IJiraInstanceUrl, el: HTMLElement) { | ||
const div = el.createDiv() | ||
div.createEl('h1', { | ||
text: value.Title | ||
}).className = 'jira_instance_title' | ||
|
||
div.createEl('p', { | ||
text: value.Url | ||
}).className = 'jira_instance_url' | ||
} | ||
onChooseSuggestion(item: IJiraInstanceUrl, evt: KeyboardEvent | MouseEvent) { | ||
this.onSubmit(item); | ||
return item; | ||
} | ||
|
||
onClose(): void { | ||
const {contentEl} = this; | ||
contentEl.empty(); | ||
} | ||
} |
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,64 @@ | ||
import { App, Modal, Setting } from "obsidian"; | ||
|
||
export class JiraIssueInputModal extends Modal { | ||
title: string; | ||
description: string; | ||
result: string; | ||
onSubmit: (result: string) => void; | ||
|
||
constructor(app: App, onSubmit: (result: string) => void) { | ||
super(app); | ||
this.title = 'Enter your Jira issue'; | ||
this.description = 'Type in a jira issue number'; | ||
this.onSubmit = onSubmit; | ||
this.containerEl.addEventListener('keydown', (e) =>{ | ||
if (e.key === 'Enter') { | ||
if (this.result !== undefined && this.result !== ''){ | ||
this.close(); | ||
this.onSubmit(this.result); | ||
} | ||
} else if (e.key == 'Escape') { | ||
this.close(); | ||
} | ||
}); | ||
} | ||
|
||
setTitle(newTitle: string): JiraIssueInputModal { | ||
this.title = newTitle; | ||
return this; | ||
} | ||
|
||
setDescription(newDescription: string): JiraIssueInputModal { | ||
this.description = newDescription; | ||
return this; | ||
} | ||
|
||
onOpen() { | ||
const { contentEl } = this; | ||
|
||
contentEl.createEl("h1", { text: this.title }); | ||
contentEl.createEl("p", {text: this.description}) | ||
|
||
new Setting(contentEl) | ||
.setName("Jira Issue") | ||
.addText((text) => | ||
text.onChange((value) => { | ||
this.result = value | ||
})); | ||
|
||
new Setting(contentEl) | ||
.addButton((btn) => | ||
btn | ||
.setButtonText("Link Issue") | ||
.setCta() | ||
.onClick(() => { | ||
this.close(); | ||
this.onSubmit(this.result); | ||
})); | ||
} | ||
|
||
onClose() { | ||
const { contentEl } = this; | ||
contentEl.empty(); | ||
} | ||
} |
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,16 @@ | ||
export interface IJiraInstanceUrl { | ||
Title: string, | ||
IsDefault: boolean, | ||
Url: string | ||
} | ||
export class JiraInstanceUrl implements IJiraInstanceUrl { | ||
Title: string; | ||
IsDefault: boolean; | ||
Url: string; | ||
|
||
constructor(url: string, title?: string){ | ||
this.Title = title ? title : "" | ||
this.Url = url | ||
this.IsDefault = false | ||
} | ||
} |
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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,18 @@ | ||
jira_instance_url | ||
================= | ||
|
||
| Date | Depreciate Version | | ||
| ---- | ------------------ | | ||
| 2/24/24 | 1.1 | | ||
|
||
# Introduction | ||
|
||
This is in regards to the setting variable `jira_instance_url` which represented the Jira instance for a user. Originally written with one Jira instance in mind, this was sutable, but with the upgrade to 1.1, in order to support multiple jira instances easily, it was opted to change the storage object from a single string variable to an array. Additionally it was no longer just a string but an object of `JiraInstanceUrl` which allowed us to have more information if desired. For version 1.1 it included other items such as a label/title for the url and if it was the default url. | ||
|
||
# The Issue | ||
|
||
The main issue is that using a string array is fine, but how do we upgrade users without losing their Jira instance. | ||
|
||
# The Fix | ||
|
||
The solution that I decided upon is a piece of code that would move the `jira_instance_url` variable and put it into the new array with default settings. This would make it simple and seamless for users to upgrade without having to enter in their existing data. |
Oops, something went wrong.