Skip to content

Commit

Permalink
Merge pull request #2 from srz2/add-support-for-multiple-jira-instances
Browse files Browse the repository at this point in the history
Add support for multiple Jira instances
  • Loading branch information
srz2 committed Feb 25, 2024
2 parents fca5d41 + e41411d commit 5ffb0ce
Show file tree
Hide file tree
Showing 13 changed files with 424 additions and 109 deletions.
58 changes: 58 additions & 0 deletions Modals/JiraInstanceSuggestModal.ts
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();
}
}
64 changes: 64 additions & 0 deletions Modals/JiraIssueInputModal.ts
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();
}
}
16 changes: 16 additions & 0 deletions Models/JiraInstanceUrl.ts
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
}
}
26 changes: 21 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
# Jira Linker

This is a [Obsidian](https://obsidian.md) plugin enables the ability to quickly add either:
This is an [Obsidian](https://obsidian.md) plugin enables the ability to quickly add:
- A web based url for a Jira issue
- A local based uri for a local folder for an issue

Now supports multiple Jira Instances

## Commands Available
1. **Link Jira issue**

This will link to a Jira instance a given Jira Issue

Note: The *Jira Instance URL* must be set
2. **Link Jira issue (default instance)**

This will link to the default Jira instance of a given Jira Issue

2. **Link Jira issue to info**
3. **Link Jira issue to info**

This will link to a local file for a given Jira Issue. If the path does not exist, it will be created

Expand All @@ -20,7 +24,7 @@ Note: You can optionally change the "main" file. It defaults to "_Info"

## Demo

![demo gif](./documentation/demo.gif)
![demo gif](./documentation/assets/demo.gif)

## How to use

Expand All @@ -30,4 +34,16 @@ Note: You can optionally change the "main" file. It defaults to "_Info"
- Optionally configure the default "main" file
- Highlight your Jira Issue in the editor and invoke the **Link Jira issue** or **Link Jira issue to info** command
- Additionally, you can have nothing selected and have a modal ask you for the Jira Issue
- The text will be replaced with the appropriately linked Jira issue
- The text will be replaced with the appropriately linked Jira issue

## Additional Notes

1. You are able to have as many Jira instances as you'd like
2. There is only 1 location for the 'in obsidian" local folder
3. Unless a specific instance is selected in settings, the default Jira instance used will be the first listed item

## Donate

If you like this plugin and find it useful, please consider donating!

<a href="https://www.buymeacoffee.com/kvnFNpYcl" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-green.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>
Binary file added documentation/assets/demo.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed documentation/demo.gif
Binary file not shown.
18 changes: 18 additions & 0 deletions documentation/deprecation-notes/jira_instance_url.md
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.

0 comments on commit 5ffb0ce

Please sign in to comment.