Skip to content

Commit

Permalink
Merge pull request #3932 from serlo/fix/pass-testing-secret-through-w…
Browse files Browse the repository at this point in the history
…eb-component

fix(editor): pass testingSecret through web-component
  • Loading branch information
hejtful committed Jul 3, 2024
2 parents 225d1be + f944440 commit bd27541
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
23 changes: 22 additions & 1 deletion packages/editor-web-component/src/editor-web-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export class EditorWebComponent extends HTMLElement {
private _initialState: InitialState = exampleInitialState
private _currentState: unknown

private _testingSecret: string | null = null

constructor() {
super()

Expand All @@ -50,7 +52,7 @@ export class EditorWebComponent extends HTMLElement {
}

static get observedAttributes() {
return ['initial-state', 'mode']
return ['initial-state', 'mode', 'testing-secret']
}

attributeChangedCallback(name: string, oldValue: string, newValue: string) {
Expand Down Expand Up @@ -111,6 +113,14 @@ export class EditorWebComponent extends HTMLElement {
return this._history
}

get testingSecret(): string | null {
return this._testingSecret
}

set testingSecret(newTestingSecret) {
if (newTestingSecret) this.setAttribute('testing-secret', newTestingSecret)
}

connectedCallback() {
if (!this.reactRoot) {
this.reactRoot = ReactDOM.createRoot(this.container)
Expand All @@ -128,6 +138,7 @@ export class EditorWebComponent extends HTMLElement {

mountReactComponent() {
const initialStateAttr = this.getAttribute('initial-state')
const testingSecretAttr = this.getAttribute('testing-secret')

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const initialState: InitialState = initialStateAttr
Expand Down Expand Up @@ -159,6 +170,16 @@ export class EditorWebComponent extends HTMLElement {
<Suspense fallback={<div>Loading editor...</div>}>
<LazySerloEditor
initialState={this.initialState}
pluginsConfig={
testingSecretAttr
? {
general: {
testingSecret: testingSecretAttr,
enableTextAreaExercise: false,
},
}
: {}
}
// HACK: Temporary solution to make image plugin available in Moodle & Chancenwerk integration with file upload disabled.
_enableImagePlugin
onChange={({ changed, getDocument }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export function createReadFile(secret: string) {
},
}),
})
const data = (await response.json()) as MediaUploadQuery
const { data } = (await response.json()) as { data: MediaUploadQuery }
const reader = new FileReader()

reader.onload = async function (e: ProgressEvent) {
Expand Down

0 comments on commit bd27541

Please sign in to comment.