-
Notifications
You must be signed in to change notification settings - Fork 6
[feat] Added workspace class and editor preferences at Repo, Context and Global levels with cascade #30
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
Merged
Merged
[feat] Added workspace class and editor preferences at Repo, Context and Global levels with cascade #30
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
32b4ef8
GitHub oAuth added for simpler auth
Palanikannan1437 2994d55
added preferences at repo, context and global level with cascading be…
Palanikannan1437 5acdfd3
fixed default preferences and added more context in navigation title …
Palanikannan1437 c153fc5
Delete workspace_preferences.tsx
Palanikannan1437 c304cf6
added global preferences as default preferences for non-configured re…
Palanikannan1437 436fa82
removed showOptions from url to directly open in the set ide
Palanikannan1437 657b838
added workspace class icons with revalidation and fixed useLatest edi…
Palanikannan1437 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,41 @@ | ||
import { LocalStorage } from "@raycast/api"; | ||
import { useCachedState } from "@raycast/utils"; | ||
import { useEffect } from "react"; | ||
|
||
import { BranchDetailsFragment, ExtendedRepositoryFieldsFragment } from "../generated/graphql"; | ||
|
||
const VISITED_BRANCH_KEY = "VISITED_BRANCHES"; | ||
const VISITED_BRANCH_LENGTH = 10; | ||
|
||
// History was stored in `LocalStorage` before, after migration it's stored in `Cache` | ||
async function loadVisitedBranches() { | ||
const item = await LocalStorage.getItem<string>(VISITED_BRANCH_KEY); | ||
if (item) { | ||
const parsed = JSON.parse(item).slice(0, VISITED_BRANCH_LENGTH); | ||
return parsed as BranchDetailsFragment[]; | ||
} else { | ||
return []; | ||
} | ||
} | ||
export function useBranchHistory() { | ||
const [history, setHistory] = useCachedState<BranchDetailsFragment[]>("BranchHistory", []); | ||
const [migratedHistory, setMigratedHistory] = useCachedState<boolean>("migratedBranchHistory", false); | ||
|
||
useEffect(() => { | ||
if (!migratedHistory) { | ||
loadVisitedBranches().then((branches) => { | ||
setHistory(branches); | ||
setMigratedHistory(true); | ||
}); | ||
} | ||
}, [migratedHistory]); | ||
|
||
function visitBranch(branch: BranchDetailsFragment, repository: ExtendedRepositoryFieldsFragment) { | ||
const visitedBranch = [branch, ...(history?.filter((item) => item.branchName !== branch.branchName) ?? [])]; | ||
LocalStorage.setItem(VISITED_BRANCH_KEY, JSON.stringify(visitedBranch)); | ||
const nextBranch = visitedBranch.slice(0, VISITED_BRANCH_LENGTH); | ||
setHistory(nextBranch); | ||
} | ||
|
||
return { history, visitBranch }; | ||
} |
This file contains hidden or 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,55 @@ | ||
import { LocalStorage, open, showToast, Toast } from "@raycast/api"; | ||
import { getPreferenceValues } from "@raycast/api"; | ||
|
||
interface Preferences { | ||
preferredEditor: string; | ||
useLatest: boolean; | ||
preferredEditorClass: "g1-standard" | "g1-large"; | ||
} | ||
|
||
export default async function OpenInGitpod(contextUrl: string, type: "Branch" | "Pull Request" | "Issue" | "Repository", repository: string, context?: string) { | ||
let preferences = getPreferenceValues<Preferences>(); | ||
|
||
if (type === "Branch" || type === "Pull Request" || type === "Issue") { | ||
const item = await LocalStorage.getItem<string>(`${repository}%${context}`) | ||
const contextPref = item ? await JSON.parse(item) : null | ||
if (contextPref && contextPref.preferredEditor && contextPref.preferredEditorClass) { | ||
preferences = contextPref | ||
} else { | ||
const repoItem = await LocalStorage.getItem<string>(`${repository}`); | ||
const repoPref = repoItem ? await JSON.parse(repoItem) : null | ||
if (repoPref && repoPref.preferredEditor && repoPref.preferredEditorClass) { | ||
preferences = repoPref | ||
} | ||
} | ||
} else if (type === "Repository") { | ||
const item = await LocalStorage.getItem<string>(`${repository}`); | ||
const repoPref = item ? await JSON.parse(item) : null | ||
if (repoPref && repoPref.preferredEditor && repoPref.preferredEditorClass) { | ||
preferences = repoPref | ||
} | ||
} | ||
|
||
if (type === "Branch") { | ||
//visit branch | ||
} else if (type === "Pull Request") { | ||
//vitit pr | ||
} else if (type === "Issue") { | ||
//visit issue | ||
} | ||
|
||
try { | ||
await showToast({ | ||
title: "Launching your workspace", | ||
style: Toast.Style.Success, | ||
}); | ||
setTimeout(() => { | ||
open(`https://gitpod.io/?useLatest=${preferences.useLatest}&editor=${preferences.preferredEditor}&workspaceClass=${preferences.preferredEditorClass}#${contextUrl}`); | ||
Palanikannan1437 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, 1000); | ||
} catch (error) { | ||
await showToast({ | ||
title: "Error launching workspace", | ||
style: Toast.Style.Failure, | ||
}); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.