Skip to content

Commit

Permalink
fix: merge errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rpenido committed Oct 8, 2024
1 parent d602803 commit 5c2842a
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 22 deletions.
11 changes: 4 additions & 7 deletions src/library-authoring/LibraryAuthoringPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,18 @@ const TabContent = ({ eventKey, handleTabChange }: TabContentProps) => {
}
};

interface HeaderActionsProps {
canEditLibrary: boolean;
}

const HeaderActions = ({ canEditLibrary }: HeaderActionsProps) => {
const HeaderActions = () => {
const intl = useIntl();
const {
componentPickerMode,
openAddContentSidebar,
openInfoSidebar,
closeLibrarySidebar,
sidebarBodyComponent,
readOnly,
} = useLibraryContext();

if (!canEditLibrary) {
if (!readOnly) {
return null;
}

Expand Down Expand Up @@ -217,7 +214,7 @@ const LibraryAuthoringPage = () => {
)}
subtitle={intl.formatMessage(messages.headingSubtitle)}
headerActions={(
<HeaderActions canEditLibrary={libraryData.canEditLibrary} />
<HeaderActions />
)}
/>
<SearchKeywordsField className="w-50" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { LoadingSpinner } from '../../generic/Loading';
import { CodeEditor, EditorAccessor } from '../../generic/CodeEditor';
import { useLibraryContext } from '../common/context';
import {
useContentLibrary,
useUpdateXBlockOLX,
useXBlockAssets,
useXBlockOLX,
Expand All @@ -27,9 +26,7 @@ interface Props {

export const ComponentAdvancedInfo: React.FC<Props> = ({ usageKey }) => {
const intl = useIntl();
const { libraryId } = useLibraryContext();
const { data: library } = useContentLibrary(libraryId);
const canEditLibrary = library?.canEditLibrary ?? false;
const { readOnly } = useLibraryContext();
const { data: olx, isLoading: isOLXLoading } = useXBlockOLX(usageKey);
const { data: assets, isLoading: areAssetsLoading } = useXBlockAssets(usageKey);
const editorRef = React.useRef<EditorAccessor | undefined>(undefined);
Expand Down Expand Up @@ -83,7 +80,7 @@ export const ComponentAdvancedInfo: React.FC<Props> = ({ usageKey }) => {
<FormattedMessage {...messages.advancedDetailsOLXCancelButton} />
</Button>
</>
) : canEditLibrary ? (
) : !readOnly ? (
<OverlayTrigger
placement="bottom-start"
overlay={(
Expand Down
8 changes: 2 additions & 6 deletions src/library-authoring/component-info/ComponentInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@ import {
} from '@openedx/paragon';

import { useLibraryContext } from '../common/context';
import { getEditUrl } from '../components/utils';
import { ComponentMenu } from '../components';
import { canEditComponent } from '../components/ComponentEditorModal';
import ComponentDetails from './ComponentDetails';
import ComponentManagement from './ComponentManagement';
import ComponentPreview from './ComponentPreview';
import messages from './messages';
import { canEditComponent } from '../components/ComponentEditorModal';
import { useLibraryContext } from '../common/context';
import { useContentLibrary } from '../data/apiHooks';

const ComponentInfo = () => {
const intl = useIntl();
Expand All @@ -30,15 +27,14 @@ const ComponentInfo = () => {
return null;
}

const editUrl = getEditUrl(usageKey);
const canEdit = canEditComponent(usageKey);

return (
<Stack>
{!readOnly && (
<div className="d-flex flex-wrap">
<Button
{...(canEdit ? { onClick: () => openComponentEditor(usageKey) } : { disabled: true })}
{...(canEdit ? { onClick: () => openComponentEditor(usageKey) } : { disabled: true })}
variant="outline-primary"
className="m-1 text-nowrap flex-grow-1"
>
Expand Down
4 changes: 2 additions & 2 deletions src/library-authoring/component-info/ComponentPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ const ComponentPreview = () => {
const intl = useIntl();

const [isModalOpen, openModal, closeModal] = useToggle();
const { data: componentMetadata } = useLibraryBlockMetadata(usageKey);

const { currentComponentUsageKey: usageKey } = useLibraryContext();

// istanbul ignore if: this should never happen
if (!usageKey) {
throw new Error('usageKey is required');
}

const { data: componentMetadata } = useLibraryBlockMetadata(usageKey);

return (
<>
<div className="position-relative m-2">
Expand Down
2 changes: 1 addition & 1 deletion src/library-authoring/components/BaseComponentCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const BaseComponentCard = ({
+ (tags.level2?.length || 0) + (tags.level3?.length || 0);
}, [tags]);

const componentIcon = getItemIcon(type);
const componentIcon = getItemIcon(componentType);
const { componentPickerMode } = useLibraryContext();

return (
Expand Down
13 changes: 12 additions & 1 deletion src/library-authoring/components/ComponentCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import React, { useContext, useState } from 'react';
import { FormattedMessage, useIntl } from '@edx/frontend-platform/i18n';
import {
ActionRow,
Button,
Dropdown,
Icon,
IconButton,
Dropdown,
} from '@openedx/paragon';
import { MoreVert } from '@openedx/paragon/icons';

Expand All @@ -24,6 +25,7 @@ type ComponentCardProps = {
export const ComponentMenu = ({ usageKey }: { usageKey: string }) => {
const intl = useIntl();
const { openComponentEditor } = useLibraryContext();

const canEdit = usageKey && canEditComponent(usageKey);
const { showToast } = useContext(ToastContext);
const [clipboardBroadcastChannel] = useState(() => new BroadcastChannel(STUDIO_CLIPBOARD_CHANNEL));
Expand Down Expand Up @@ -65,6 +67,7 @@ export const ComponentMenu = ({ usageKey }: { usageKey: string }) => {
const ComponentCard = ({ contentHit } : ComponentCardProps) => {
const {
openComponentInfoSidebar,
componentPickerMode,
} = useLibraryContext();

const {
Expand All @@ -88,6 +91,14 @@ const ComponentCard = ({ contentHit } : ComponentCardProps) => {
tags={tags}
actions={(
<ActionRow>
{componentPickerMode && (
<Button
variant="primary"
onClick={() => alert('Hi')}

Check warning on line 97 in src/library-authoring/components/ComponentCard.tsx

View workflow job for this annotation

GitHub Actions / tests (20)

Unexpected alert
>
Hi!
</Button>
)}
<ComponentMenu usageKey={usageKey} />
</ActionRow>
)}
Expand Down

0 comments on commit 5c2842a

Please sign in to comment.