* fix: enable markdown editor for problems in libraries too This fix is also achieved on master via5991fd3997/ https://github.com/openedx/frontend-app-authoring/pull/2068 but this is a simpler fix, not a direct backport of that refactor. * fix: remove duplicate markdown_edited save request (#2127) Removes the unnecessary duplicate save request of markdown_edited value to the backend. Part of: https://github.com/openedx/frontend-app-authoring/issues/2099 Backports:62589aea50--------- Co-authored-by: Muhammad Anas <88967643+Anas12091101@users.noreply.github.com>
51 lines
1.6 KiB
TypeScript
51 lines
1.6 KiB
TypeScript
import { getConfig } from '@edx/frontend-platform';
|
|
import React from 'react';
|
|
import { useSelector } from 'react-redux';
|
|
import { useQueryClient } from '@tanstack/react-query';
|
|
|
|
import { getWaffleFlags } from '../../data/selectors';
|
|
import EditorPage from '../../editors/EditorPage';
|
|
import { getBlockType } from '../../generic/key-utils';
|
|
import { useLibraryContext } from '../common/context/LibraryContext';
|
|
import { invalidateComponentData } from '../data/apiHooks';
|
|
|
|
export function canEditComponent(usageKey: string): boolean {
|
|
let blockType: string;
|
|
try {
|
|
blockType = getBlockType(usageKey);
|
|
} catch {
|
|
return false;
|
|
}
|
|
|
|
return !getConfig().LIBRARY_UNSUPPORTED_BLOCKS.includes(blockType);
|
|
}
|
|
|
|
export const ComponentEditorModal: React.FC<Record<never, never>> = () => {
|
|
const { componentBeingEdited, closeComponentEditor, libraryId } = useLibraryContext();
|
|
const queryClient = useQueryClient();
|
|
const { useReactMarkdownEditor } = useSelector(getWaffleFlags);
|
|
|
|
if (componentBeingEdited === undefined) {
|
|
return null;
|
|
}
|
|
const blockType = componentBeingEdited.blockType || getBlockType(componentBeingEdited.usageKey);
|
|
|
|
const onClose = (data?:any) => {
|
|
closeComponentEditor(data);
|
|
invalidateComponentData(queryClient, libraryId, componentBeingEdited.usageKey);
|
|
};
|
|
|
|
return (
|
|
<EditorPage
|
|
courseId={libraryId}
|
|
blockType={blockType}
|
|
blockId={componentBeingEdited.usageKey}
|
|
isMarkdownEditorEnabledForCourse={useReactMarkdownEditor}
|
|
studioEndpointUrl={getConfig().STUDIO_BASE_URL}
|
|
lmsEndpointUrl={getConfig().LMS_BASE_URL}
|
|
onClose={onClose}
|
|
returnFunction={() => onClose}
|
|
/>
|
|
);
|
|
};
|