diff --git a/libs/shared/src/packages/fusion-framework/createRender.tsx b/libs/shared/src/packages/fusion-framework/createRender.tsx index 0d094e50c..d5efb17f5 100644 --- a/libs/shared/src/packages/fusion-framework/createRender.tsx +++ b/libs/shared/src/packages/fusion-framework/createRender.tsx @@ -7,7 +7,8 @@ import { createRoot } from 'react-dom/client'; import { ApplicationInsights } from '@microsoft/applicationinsights-web'; import { useState } from 'react'; -import { Button } from '@equinor/eds-core-react'; +import { Button, CircularProgress } from '@equinor/eds-core-react'; +import { QueryClient, QueryClientProvider, useQuery } from '@tanstack/react-query'; /** * Facades the fusion-framework render setup, used in all apps @@ -76,14 +77,18 @@ export function createRender( }; } +const queryClient = new QueryClient(); function createPrLabel(prNumber: string, el: HTMLElement): VoidFunction { const child = document.createElement('div'); - child.id = '123'; + child.id = 'PR_LABEL'; document.body.appendChild(child); const root = createRoot(child); - - root.render(); + root.render( + + + + ); return () => { root.unmount(); @@ -93,7 +98,34 @@ function createPrLabel(prNumber: string, el: HTMLElement): VoidFunction { function PRLabel({ prNumber }: { prNumber: string }) { const [isOpen, setIsOpen] = useState(true); + const { data, isLoading, error } = useQuery( + ['pulls', prNumber], + async () => { + const res = await fetch( + `https://api.github.com/repos/equinor/cc-components/pulls/${prNumber}`, + { headers: { ['Accept']: 'application/vnd.github+json' } } + ); + if (!res.status) { + throw new Error('Failed to load'); + } + return await res.json(); + }, + { suspense: false, useErrorBoundary: false } + ); if (!isOpen) return null; + if (isLoading) { + return ( +
+ Loading... + +
+ ); + } + + if (error || !data) { + return
Failed to load pr {prNumber}
; + } + return (
- - PR: #{prNumber} - - +
+ {data.assignee && ( + + )} + + {data.state === 'open' ? : } + + {data.title} #{prNumber} + + +
); } + +export interface PullRequest { + url: string; + id: number; + node_id: string; + html_url: string; + diff_url: string; + patch_url: string; + issue_url: string; + number: number; + state: string; + locked: boolean; + title: string; + user: User; + body: string; + created_at: string; + updated_at: string; + closed_at: any; + merged_at: any; + merge_commit_sha: string; + assignee: Assignee | null; + assignees: Assignee[]; + requested_reviewers: any[]; + requested_teams: any[]; + labels: Label[]; + milestone: any; + draft: boolean; + commits_url: string; + review_comments_url: string; + review_comment_url: string; + comments_url: string; + statuses_url: string; + head: Head; + base: Base; + _links: Links; + author_association: string; + auto_merge: any; + active_lock_reason: any; + merged: boolean; + mergeable: boolean; + rebaseable: boolean; + mergeable_state: string; + merged_by: any; + comments: number; + review_comments: number; + maintainer_can_modify: boolean; + commits: number; + additions: number; + deletions: number; + changed_files: number; +} + +export interface User { + login: string; + id: number; + node_id: string; + avatar_url: string; + gravatar_id: string; + url: string; + html_url: string; + followers_url: string; + following_url: string; + gists_url: string; + starred_url: string; + subscriptions_url: string; + organizations_url: string; + repos_url: string; + events_url: string; + received_events_url: string; + type: string; + site_admin: boolean; +} + +export interface Assignee { + login: string; + id: number; + node_id: string; + avatar_url: string; + gravatar_id: string; + url: string; + html_url: string; + followers_url: string; + following_url: string; + gists_url: string; + starred_url: string; + subscriptions_url: string; + organizations_url: string; + repos_url: string; + events_url: string; + received_events_url: string; + type: string; + site_admin: boolean; +} + +export interface Label { + id: number; + node_id: string; + url: string; + name: string; + color: string; + default: boolean; + description: string; +} + +export interface Head { + label: string; + ref: string; + sha: string; + user: User; + repo: Repo; +} + +export interface Repo { + id: number; + node_id: string; + name: string; + full_name: string; + private: boolean; + owner: Owner; + html_url: string; + description: string; + fork: boolean; + url: string; + forks_url: string; + keys_url: string; + collaborators_url: string; + teams_url: string; + hooks_url: string; + issue_events_url: string; + events_url: string; + assignees_url: string; + branches_url: string; + tags_url: string; + blobs_url: string; + git_tags_url: string; + git_refs_url: string; + trees_url: string; + statuses_url: string; + languages_url: string; + stargazers_url: string; + contributors_url: string; + subscribers_url: string; + subscription_url: string; + commits_url: string; + git_commits_url: string; + comments_url: string; + issue_comment_url: string; + contents_url: string; + compare_url: string; + merges_url: string; + archive_url: string; + downloads_url: string; + issues_url: string; + pulls_url: string; + milestones_url: string; + notifications_url: string; + labels_url: string; + releases_url: string; + deployments_url: string; + created_at: string; + updated_at: string; + pushed_at: string; + git_url: string; + ssh_url: string; + clone_url: string; + svn_url: string; + homepage: string; + size: number; + stargazers_count: number; + watchers_count: number; + language: string; + has_issues: boolean; + has_projects: boolean; + has_downloads: boolean; + has_wiki: boolean; + has_pages: boolean; + has_discussions: boolean; + forks_count: number; + mirror_url: any; + archived: boolean; + disabled: boolean; + open_issues_count: number; + license: License; + allow_forking: boolean; + is_template: boolean; + web_commit_signoff_required: boolean; + topics: any[]; + visibility: string; + forks: number; + open_issues: number; + watchers: number; + default_branch: string; +} + +export interface Owner { + login: string; + id: number; + node_id: string; + avatar_url: string; + gravatar_id: string; + url: string; + html_url: string; + followers_url: string; + following_url: string; + gists_url: string; + starred_url: string; + subscriptions_url: string; + organizations_url: string; + repos_url: string; + events_url: string; + received_events_url: string; + type: string; + site_admin: boolean; +} + +export interface License { + key: string; + name: string; + spdx_id: string; + url: string; + node_id: string; +} + +export interface Base { + label: string; + ref: string; + sha: string; + user: User; + repo: Repo; +} + +export interface Links { + self: Self; + html: Html; + issue: Issue; + comments: Comments; + review_comments: ReviewComments; + review_comment: ReviewComment; + commits: Commits; + statuses: Statuses; +} + +export interface Self { + href: string; +} + +type Html = Self; +type Issue = Self; +type Comments = Self; +type ReviewComments = Self; +type ReviewComment = Self; +type Commits = Self; +type Statuses = Self; + +const OpenPR = () => ( + + + +); + +const MergedPr = () => ( + +);