Skip to content
Draft
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1596c1f
adding coral-embed component
thinknoack Apr 11, 2025
3ff6867
remove extra interface
thinknoack Apr 11, 2025
44be7fa
update to docker to run coral over Source - adding a button to test i…
thinknoack Apr 14, 2025
945883b
update to docker to run coral over Source - adding a button to test i…
thinknoack Apr 14, 2025
2ba2ea0
log window.Coral
thinknoack Apr 14, 2025
279bb52
remove draftjs issues for globals, update coarl embed to contain toke…
thinknoack Apr 15, 2025
21cf40d
update to coral talk to use jwt
thinknoack Apr 16, 2025
8924840
adding example config
thinknoack Apr 16, 2025
0c96afc
updates after review
thinknoack Apr 17, 2025
85c086e
removing logs and other lint updates
thinknoack Apr 17, 2025
bd8fd75
adding sigin openneuro from coral sigin in button
thinknoack Apr 21, 2025
0fcf16f
adding basic openneuro theme styling for coralembed
thinknoack Apr 22, 2025
fffd683
remove log
thinknoack Apr 22, 2025
5359c5c
remove comment
thinknoack Apr 22, 2025
b034ef0
removing comments
thinknoack Apr 22, 2025
8a9fbb5
update snapshot
thinknoack Apr 22, 2025
a4e3c07
adding modality to dataset default coralembed compoent, update to mod…
thinknoack Apr 22, 2025
2e71f60
adding coral-embed test spec
thinknoack Apr 23, 2025
4c0faf6
remove async from embed.js script tag to ensure its parsed before app
thinknoack Apr 24, 2025
00e12aa
adding nginx proxy
thinknoack Apr 29, 2025
0d94a89
update location in dev nginx
thinknoack May 2, 2025
d0a041e
update proxy_pass port
thinknoack May 2, 2025
bea1398
Merge branch 'master' into coral-embed
thinknoack May 28, 2025
51f1e87
adding actual conflict fix
thinknoack May 28, 2025
fca0504
update proxy to only serve one file
thinknoack May 29, 2025
04c78b2
remove coral proxy from app
thinknoack May 29, 2025
ad1428c
spacing
thinknoack May 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ PERSISTENT_DIR=/data
# macOS Development Setup - Fixes issues with elastic search container - set to ES_JAVA_OPTS=-XX:UseSVE=0 -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true MEM_LIMIT=2g SECOMP="unconfined"
MEM_LIMIT=
ES_JAVA_OPTS=
SECOMP=
SECOMP=

# coral --------------------------------------------------------------------

CORAL_SIGNING_SECRET=""
3 changes: 3 additions & 0 deletions config.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ CRN_SERVER_URL=http://localhost:9876
# Secret authentication value for this instance
JWT_SECRET=

# Coral Talk Secret from SSO Config in Admin Panel
CORAL_JWT_SECRET=

# Google oauth2 configuration - configure to enable Google auth
# https://developers.google.com/identity/sign-in/web/sign-in for instructions
GOOGLE_CLIENT_ID=
Expand Down
14 changes: 14 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,17 @@ services:
ports:
- "9200:9200"
- "9300:9300"

# Coral Project Talk
coral:
image: coralproject/talk:7
restart: always
ports:
- "5001:5000"
depends_on:
- mongo
- redis
environment:
- MONGODB_URI=mongodb://mongo:27017/coral
- REDIS_URI=redis://redis:6379
- SIGNING_SECRET=${CORAL_SIGNING_SECRET}
3 changes: 3 additions & 0 deletions packages/openneuro-app/src/@types/custom.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ interface Blob {

interface Window {
showDirectoryPicker: any
Coral?: {
createStreamEmbed: (config: any) => void
}
}

interface Navigator {
Expand Down
60 changes: 60 additions & 0 deletions packages/openneuro-app/src/assets/coral/coral-embed.css
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);
}
1 change: 0 additions & 1 deletion packages/openneuro-app/src/client.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* Browser client entrypoint
*/
import "./scripts/utils/global-polyfill"
import "./scripts/sentry"
import { ApolloClient, ApolloProvider, InMemoryCache } from "@apollo/client"
import React from "react"
Expand Down
5 changes: 5 additions & 0 deletions packages/openneuro-app/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
href="https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300;0,400;0,700;1,300;1,400;1,700&display=swap"
rel="stylesheet"
/>
<script
src="http://localhost:5001/assets/js/embed.js"
async
defer
></script>
</head>

<body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -747,15 +747,8 @@ OCI-1131441 (R. Poldrack, PI) in any publications.
</div>
</div>
<div
class="dataset-comments"
>
<h2>
Comments
</h2>
<div>
Please sign in to contribute to the discussion.
</div>
</div>
id="coral_thread"
/>
</div>
</div>
<div
Expand Down
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" }),
}))
Copy link
Contributor

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-mock

Copy link
Contributor Author

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 get

FAIL 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


// 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,
}),
)
})
})
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}` }

Check warning on line 20 in packages/openneuro-app/src/scripts/dataset/comments/coral-embed.tsx

View check run for this annotation

Codecov / codecov/patch

packages/openneuro-app/src/scripts/dataset/comments/coral-embed.tsx#L20

Added line #L20 was not covered by tests
: {}

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)
})
},

Check warning on line 48 in packages/openneuro-app/src/scripts/dataset/comments/coral-embed.tsx

View check run for this annotation

Codecov / codecov/patch

packages/openneuro-app/src/scripts/dataset/comments/coral-embed.tsx#L45-L48

Added lines #L45 - L48 were not covered by tests
})
}
}
fetchAndInitializeCoral()
}, [storyID, isAdminUser, setUserModalOpen])

return <div id="coral_thread" ref={coralContainerRef}></div>
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,50 @@
import { ReadMore } from "../../components/read-more/ReadMore"
import { MetaDataBlock } from "../components/MetaDataBlock"
import Files from "../files/files"
import Comments from "../comments/comments"
import EditDescriptionField from "../fragments/edit-description-field"
import { CoralEmbed } from "../comments/coral-embed"

Check warning on line 7 in packages/openneuro-app/src/scripts/dataset/routes/dataset-default.tsx

View check run for this annotation

Codecov / codecov/patch

packages/openneuro-app/src/scripts/dataset/routes/dataset-default.tsx#L7

Added line #L7 was not covered by tests

/**
* Default tab for dataset draft pages
*/
export const DatasetDefault = ({ dataset, hasEdit }) => (
<>
<MetaDataBlock
heading="README"
className="dataset-readme markdown-body"
item={dataset.draft.readme}
renderEditor={() => (
<EditDescriptionField
datasetId={dataset.id}
field="readme"
rows={12}
description={dataset.draft.readme}
editMode={hasEdit}
>
<ReadMore
id="readme"
expandLabel="Read More"
collapseLabel="Collapse"
export const DatasetDefault = ({ dataset, hasEdit }) => {
return (
<>
<MetaDataBlock
heading="README"
className="dataset-readme markdown-body"
item={dataset.draft.readme}
renderEditor={() => (
<EditDescriptionField
datasetId={dataset.id}
field="readme"
rows={12}
description={dataset.draft.readme}
editMode={hasEdit}

Check warning on line 25 in packages/openneuro-app/src/scripts/dataset/routes/dataset-default.tsx

View check run for this annotation

Codecov / codecov/patch

packages/openneuro-app/src/scripts/dataset/routes/dataset-default.tsx#L12-L25

Added lines #L12 - L25 were not covered by tests
>
<Markdown>{dataset.draft.readme || "N/A"}</Markdown>
</ReadMore>
</EditDescriptionField>
)}
/>
<Files
datasetId={dataset.id}
snapshotTag={null}
datasetName={dataset.draft.description.Name}
files={dataset.draft.files}
editMode={hasEdit}
datasetPermissions={dataset.permissions}
summary={dataset.draft?.summary}
/>
<Comments
datasetId={dataset.id}
uploader={dataset.uploader}
comments={dataset.comments}
/>
</>
)
<ReadMore
id="readme"
expandLabel="Read More"
collapseLabel="Collapse"
>
<Markdown>{dataset.draft.readme || "N/A"}</Markdown>
</ReadMore>
</EditDescriptionField>
)}
/>
<Files
datasetId={dataset.id}
snapshotTag={null}
datasetName={dataset.draft.description.Name}
files={dataset.draft.files}
editMode={hasEdit}
datasetPermissions={dataset.permissions}
summary={dataset.draft?.summary}
/>
<CoralEmbed
storyID={dataset.id}
modalities={dataset.draft.summary.modalities}
/>
</>
)
}

Check warning on line 52 in packages/openneuro-app/src/scripts/dataset/routes/dataset-default.tsx

View check run for this annotation

Codecov / codecov/patch

packages/openneuro-app/src/scripts/dataset/routes/dataset-default.tsx#L27-L52

Added lines #L27 - L52 were not covered by tests
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Markdown } from "../../utils/markdown"
import { ReadMore } from "../../components/read-more/ReadMore"
import { MetaDataBlock } from "../components/MetaDataBlock"
import Files from "../files/files"
import Comments from "../comments/comments"
import { CoralEmbed } from "../comments/coral-embed"

/**
* Default tab for snapshot pages
Expand All @@ -30,10 +30,9 @@ export const SnapshotDefault = ({ dataset, snapshot }) => (
datasetPermissions={dataset.permissions}
summary={snapshot?.summary}
/>
<Comments
datasetId={dataset.id}
uploader={dataset.uploader}
comments={dataset.comments}
<CoralEmbed
storyID={dataset.id}
modalities={dataset.draft.summary.modalities}
/>
</>
)
16 changes: 0 additions & 16 deletions packages/openneuro-app/src/scripts/utils/global-polyfill.ts

This file was deleted.

3 changes: 3 additions & 0 deletions packages/openneuro-server/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ const config = {
jwt: {
secret: process.env.JWT_SECRET,
},
coral: {
secret: process.env.CORAL_JWT_SECRET,
},
},
mongo: {
url: process.env.MONGO_URL,
Expand Down
Loading
Loading