-
Notifications
You must be signed in to change notification settings - Fork 44
[WIP] Coral embed #3427
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
Draft
thinknoack
wants to merge
27
commits into
master
Choose a base branch
from
coral-embed
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
[WIP] Coral embed #3427
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
1596c1f
adding coral-embed component
thinknoack 3ff6867
remove extra interface
thinknoack 44be7fa
update to docker to run coral over Source - adding a button to test i…
thinknoack 945883b
update to docker to run coral over Source - adding a button to test i…
thinknoack 2ba2ea0
log window.Coral
thinknoack 279bb52
remove draftjs issues for globals, update coarl embed to contain toke…
thinknoack 21cf40d
update to coral talk to use jwt
thinknoack 8924840
adding example config
thinknoack 0c96afc
updates after review
thinknoack 85c086e
removing logs and other lint updates
thinknoack bd8fd75
adding sigin openneuro from coral sigin in button
thinknoack 0fcf16f
adding basic openneuro theme styling for coralembed
thinknoack fffd683
remove log
thinknoack 5359c5c
remove comment
thinknoack b034ef0
removing comments
thinknoack 8a9fbb5
update snapshot
thinknoack a4e3c07
adding modality to dataset default coralembed compoent, update to mod…
thinknoack 2e71f60
adding coral-embed test spec
thinknoack 4c0faf6
remove async from embed.js script tag to ensure its parsed before app
thinknoack 00e12aa
adding nginx proxy
thinknoack 0d94a89
update location in dev nginx
thinknoack d0a041e
update proxy_pass port
thinknoack bea1398
Merge branch 'master' into coral-embed
thinknoack 51f1e87
adding actual conflict fix
thinknoack fca0504
update proxy to only serve one file
thinknoack 04c78b2
remove coral proxy from app
thinknoack ad1428c
spacing
thinknoack 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| #coral { | ||
| --palette-primary-200: #b5cbd3; | ||
| --palette-primary-400: #377ed2; | ||
| --palette-primary-500: #1c4550; | ||
| --palette-primary-700: #163a45; | ||
| --palette-primary-800: #102f38; | ||
| --palette-primary-900: #0b252c; | ||
|
|
||
| --palette-error-600: #cc322f; | ||
| --palette-error-700: #b32c29; | ||
| --palette-error-800: #992523; | ||
| --palette-error-900: #7f1f1d; | ||
|
|
||
| --palette-success-600: #28b463; | ||
| --palette-success-700: #239b56; | ||
| --palette-success-800: #1d8348; | ||
| --palette-success-900: #186a3b; | ||
|
|
||
| /* FONTS */ | ||
| --font-family-primary: 'Open Sans', sans-serif; | ||
| --font-family-secondary: 'Nunito', sans-serif; | ||
|
|
||
| --font-weight-primary-bold: 700; | ||
| --font-weight-primary-semi-bold: 600; | ||
| --font-weight-primary-regular: 500; | ||
|
|
||
| --font-weight-secondary-bold: 700; | ||
| --font-weight-secondary-regular: 500; | ||
|
|
||
| /* SHADOWS */ | ||
| --shadow-popover: 1px 0px 4px rgba(0, 0, 0, 0.25); | ||
| } | ||
|
|
||
|
|
||
| #coral .coral.coral-viewerBox{ | ||
| display: none; | ||
| } | ||
|
|
||
| #coral{ | ||
| --palette-primary-500: #1c4550; | ||
| } | ||
|
|
||
| #coral.meg{ | ||
| --palette-primary-500:rgba(156, 57, 0, 1); | ||
| } | ||
|
|
||
| #coral.eeg{ | ||
| --palette-primary-500:rgba(134, 31, 55, 1); | ||
| } | ||
|
|
||
| #coral.pet{ | ||
| --palette-primary-500:rgba(0, 105, 192, 1); | ||
| } | ||
|
|
||
| #coral.ieeg{ | ||
| --palette-primary-500:rgba(18, 109, 62, 1); | ||
| } | ||
| #coral.mri{ | ||
| --palette-primary-500:rgba(79, 51, 130, 1); | ||
| } |
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
44 changes: 44 additions & 0 deletions
44
packages/openneuro-app/src/scripts/dataset/comments/__tests__/coral-embed.spec.jsx
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,44 @@ | ||
| import React from "react" | ||
| import { render, waitFor } from "@testing-library/react" | ||
| import { CoralEmbed } from "../coral-embed" | ||
| import { UserModalOpenCtx } from "../../../utils/user-login-modal-ctx" | ||
| import { vi } from "vitest" | ||
|
|
||
| vi.mock("../../../utils/user-login-modal-ctx", () => ({ | ||
| UserModalOpenCtx: React.createContext({ setUserModalOpen: vi.fn() }), | ||
| })) | ||
|
|
||
| global.fetch = vi.fn().mockResolvedValue(Promise.resolve({ | ||
| json: vi.fn().mockResolvedValue({ token: "mock-sso-token" }), | ||
| })) | ||
|
|
||
| // Mock the global Coral object | ||
| const mockCoralCreateStreamEmbed = vi.fn() | ||
| global.window.Coral = { | ||
| createStreamEmbed: mockCoralCreateStreamEmbed, | ||
| } | ||
|
|
||
| describe("CoralEmbed - Simple Embed.js Check (Vitest)", () => { | ||
| const mockStoryID = "simple-test-story" | ||
| const mockModalities = ["test"] | ||
|
|
||
| it("should check if window.Coral exists and initializeCoralEmbed is called", async () => { | ||
| render( | ||
| <UserModalOpenCtx.Provider value={{ setUserModalOpen: vi.fn() }}> | ||
| <CoralEmbed storyID={mockStoryID} modalities={mockModalities} /> | ||
| </UserModalOpenCtx.Provider>, | ||
| ) | ||
|
|
||
| // fetch and Coral initialization | ||
| await waitFor(() => { | ||
| expect(global.window.Coral).toBeDefined() | ||
| expect(mockCoralCreateStreamEmbed).toHaveBeenCalledTimes(1) | ||
| }) | ||
|
|
||
| expect(mockCoralCreateStreamEmbed).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| storyID: mockStoryID, | ||
| }), | ||
| ) | ||
| }) | ||
| }) | ||
56 changes: 56 additions & 0 deletions
56
packages/openneuro-app/src/scripts/dataset/comments/coral-embed.tsx
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,56 @@ | ||
| import React, { useContext, useEffect, useRef } from "react" | ||
| import * as Sentry from "@sentry/react" | ||
| import { isAdmin } from "../../authentication/admin-user" | ||
| import { UserModalOpenCtx } from "../../utils/user-login-modal-ctx" | ||
|
|
||
| export const CoralEmbed: React.FC<{ storyID: string; modalities: string[] }> = ( | ||
| { storyID, modalities }, | ||
| ) => { | ||
| const coralContainerRef = useRef<HTMLDivElement>(null) | ||
| const isAdminUser = isAdmin() | ||
| const { setUserModalOpen } = useContext(UserModalOpenCtx) | ||
|
|
||
| useEffect(() => { | ||
| const fetchAndInitializeCoral = async () => { | ||
| const accessToken = document.cookie | ||
| .split("; ") | ||
| .find((cookie) => cookie.startsWith("accessToken=")) | ||
| ?.split("=")[1] | ||
| const headers = accessToken | ||
| ? { Authorization: `Bearer ${accessToken}` } | ||
| : {} | ||
thinknoack marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| try { | ||
| const response = await fetch("/api/auth/coral-sso", { headers }) | ||
| const data = await response.json() | ||
| initializeCoralEmbed(data.token) | ||
| } catch (error) { | ||
| Sentry.captureException(error) | ||
| initializeCoralEmbed(undefined) | ||
| } | ||
| } | ||
|
|
||
| const initializeCoralEmbed = (token: string | undefined) => { | ||
| if (coralContainerRef.current && window.Coral) { | ||
| window.Coral.createStreamEmbed({ | ||
| id: coralContainerRef.current.id, | ||
| autoRender: true, | ||
| rootURL: "http://localhost:5001", | ||
| storyID: storyID, | ||
| storyURL: window.location.href, | ||
| accessToken: token, | ||
| role: isAdminUser ? "ADMIN" : "COMMENTER", | ||
| containerClassName: modalities, | ||
| events: function (events) { | ||
| events.on("loginPrompt", function () { | ||
| setUserModalOpen(true) | ||
| }) | ||
| }, | ||
| }) | ||
| } | ||
| } | ||
| fetchAndInitializeCoral() | ||
| }, [storyID, isAdminUser, setUserModalOpen]) | ||
|
|
||
| return <div id="coral_thread" ref={coralContainerRef}></div> | ||
| } | ||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably use the fetch mocking library.
vitest-fetch-mockThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am having an issue with vitest-fetch-mock. Is this some sort of version related vite issue?
just adding
import createFetchMock from 'vitest-fetch-mock';to my test file I getFAIL packages/openneuro-app/src/scripts/dataset/comments/__tests__/coral-embed.spec.jsx > CoralEmbed - Simple Embed.js Check (Vitest) > should check if window.Coral exists and initializeCoralEmbed is called TypeError: Cannot set property testPath of #<Object> which has only a getter