Skip to content

Commit

Permalink
feat: add component sidebar manage tab
Browse files Browse the repository at this point in the history
  • Loading branch information
rpenido committed Sep 12, 2024
1 parent 9bbbf61 commit fac77e7
Show file tree
Hide file tree
Showing 15 changed files with 384 additions and 193 deletions.
3 changes: 2 additions & 1 deletion src/library-authoring/component-info/ComponentInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '@openedx/paragon';

import { ComponentMenu } from '../components';
import ComponentManagement from './ComponentManagement';
import messages from './messages';

interface ComponentInfoProps {
Expand Down Expand Up @@ -37,7 +38,7 @@ const ComponentInfo = ({ usageKey } : ComponentInfoProps) => {
Preview tab placeholder
</Tab>
<Tab eventKey="manage" title={intl.formatMessage(messages.manageTabTitle)}>
Manage tab placeholder
<ComponentManagement usageKey={usageKey} />
</Tab>
<Tab eventKey="details" title={intl.formatMessage(messages.detailsTabTitle)}>
Details tab placeholder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import MockAdapter from 'axios-mock-adapter';
import { IntlProvider } from '@edx/frontend-platform/i18n';
import { AppProvider } from '@edx/frontend-platform/react';
Expand Down
57 changes: 57 additions & 0 deletions src/library-authoring/component-info/ComponentManagement.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { getConfig } from '@edx/frontend-platform';
import { useIntl } from '@edx/frontend-platform/i18n';
import { Collapsible, Icon, Stack } from '@openedx/paragon';
import { Tag } from '@openedx/paragon/icons';

import { useLibraryBlockMetadata } from '../data/apiHooks';
import StatusWidget from '../generic/status-widget';
import messages from './messages';

interface ComponentManagementProps {
usageKey: string;
}
const ComponentManagement = ({ usageKey }: ComponentManagementProps) => {
const intl = useIntl();
const { data: componentMetadata } = useLibraryBlockMetadata(usageKey);

if (!componentMetadata) {
return null;
}

return (

Check warning on line 21 in src/library-authoring/component-info/ComponentManagement.tsx

View check run for this annotation

Codecov / codecov/patch

src/library-authoring/component-info/ComponentManagement.tsx#L21

Added line #L21 was not covered by tests
<Stack gap={3}>
<StatusWidget
{...componentMetadata}
/>
{[true, 'true'].includes(getConfig().ENABLE_TAGGING_TAXONOMY_PAGES)
&& (
<Collapsible

Check warning on line 28 in src/library-authoring/component-info/ComponentManagement.tsx

View check run for this annotation

Codecov / codecov/patch

src/library-authoring/component-info/ComponentManagement.tsx#L28

Added line #L28 was not covered by tests
defaultOpen
title={(
<Stack gap={1} direction="horizontal">
<Icon src={Tag} />
{intl.formatMessage(messages.manageTabTagsTitle)}
</Stack>
)}
className="border-0"
>
Tags placeholder
</Collapsible>
)}
<Collapsible
defaultOpen
title={(
<Stack gap={1} direction="horizontal">
<Icon src={Tag} />
{intl.formatMessage(messages.manageTabCollectionsTitle)}
</Stack>
)}
className="border-0"
>
Collections placeholder
</Collapsible>
</Stack>
);
};

export default ComponentManagement;
10 changes: 10 additions & 0 deletions src/library-authoring/component-info/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ const messages = defineMessages({
defaultMessage: 'Manage',
description: 'Title for manage tab',
},
manageTabTagsTitle: {
id: 'course-authoring.library-authoring.component.manage-tab.tags-title',
defaultMessage: 'Tags',
description: 'Title for the Tags container in the management tab',
},
manageTabCollectionsTitle: {
id: 'course-authoring.library-authoring.component.manage-tab.collections-title',
defaultMessage: 'Collections',
description: 'Title for the Collections container in the management tab',
},
detailsTabTitle: {
id: 'course-authoring.library-authoring.component.details-tab.title',
defaultMessage: 'Details',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import { AppProvider } from '@edx/frontend-platform/react';
import { initializeMockApp } from '@edx/frontend-platform';
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
Expand Down
21 changes: 18 additions & 3 deletions src/library-authoring/data/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ export const getLibraryBlockTypesUrl = (libraryId: string) => `${getApiBaseUrl()
* Get the URL for create content in library.
*/
export const getCreateLibraryBlockUrl = (libraryId: string) => `${getApiBaseUrl()}/api/libraries/v2/${libraryId}/blocks/`;
/**
* Get the URL for library block metadata.
*/
export const getLibraryBlockMetadataUrl = (usageKey: string) => `${getApiBaseUrl()}/api/libraries/v2/blocks/${usageKey}/`;
/**
* Get the URL for content library list API.
*/
export const getContentLibraryV2ListApiUrl = () => `${getApiBaseUrl()}/api/libraries/v2/`;
/**
* Get the URL for commit/revert changes in library.
Expand Down Expand Up @@ -96,7 +103,7 @@ export interface CreateBlockDataRequest {
definitionId: string;
}

export interface CreateBlockDataResponse {
export interface LibraryBlockMetadata {
id: string;
blockType: string;
defKey: string | null;
Expand Down Expand Up @@ -147,7 +154,7 @@ export async function createLibraryBlock({
libraryId,
blockType,
definitionId,
}: CreateBlockDataRequest): Promise<CreateBlockDataResponse> {
}: CreateBlockDataRequest): Promise<LibraryBlockMetadata> {
const client = getAuthenticatedHttpClient();
const { data } = await client.post(
getCreateLibraryBlockUrl(libraryId),
Expand Down Expand Up @@ -210,7 +217,7 @@ export async function revertLibraryChanges(libraryId: string) {
export async function libraryPasteClipboard({
libraryId,
blockId,
}: LibraryPasteClipboardRequest): Promise<CreateBlockDataResponse> {
}: LibraryPasteClipboardRequest): Promise<LibraryBlockMetadata> {
const client = getAuthenticatedHttpClient();
const { data } = await client.post(
getLibraryPasteClipboardUrl(libraryId),
Expand All @@ -221,6 +228,14 @@ export async function libraryPasteClipboard({
return data;
}

/**
* Fetch library block metadata.
*/
export async function getLibraryBlockMetadata(usageKey: string): Promise<LibraryBlockMetadata> {
const { data } = await getAuthenticatedHttpClient().get(getLibraryBlockMetadataUrl(usageKey));
return camelCaseObject(data);

Check warning on line 236 in src/library-authoring/data/api.ts

View check run for this annotation

Codecov / codecov/patch

src/library-authoring/data/api.ts#L236

Added line #L236 was not covered by tests
}

/**
* Fetch xblock fields.
*/
Expand Down
16 changes: 16 additions & 0 deletions src/library-authoring/data/apiHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
revertLibraryChanges,
updateLibraryMetadata,
libraryPasteClipboard,
getLibraryBlockMetadata,
getXBlockFields,
updateXBlockFields,
} from './api';
Expand Down Expand Up @@ -52,6 +53,14 @@ export const libraryAuthoringQueryKeys = {
'content',
'libraryBlockTypes',
],
// FixMe: Move this to another key map
componentMetadata: (usageKey: string) => [
...libraryAuthoringQueryKeys.all,
...libraryAuthoringQueryKeys.contentLibrary('lib'),
'content',
usageKey,
'componentMetadata',
],
xblockFields: (contentLibraryId: string, usageKey: string) => [
...libraryAuthoringQueryKeys.all,
...libraryAuthoringQueryKeys.contentLibrary(contentLibraryId),
Expand Down Expand Up @@ -168,6 +177,13 @@ export const useLibraryPasteClipboard = () => {
});
};

export const useLibraryBlockMetadata = (usageId: string) => (
useQuery({
queryKey: libraryAuthoringQueryKeys.componentMetadata(usageId),
queryFn: () => getLibraryBlockMetadata(usageId),
})
);

export const useXBlockFields = (contentLibrayId: string, usageKey: string) => (
useQuery({
queryKey: libraryAuthoringQueryKeys.xblockFields(contentLibrayId, usageKey),
Expand Down
1 change: 1 addition & 0 deletions src/library-authoring/generic/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "./status-widget/StatusWidget";
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.library-publish-status {
.status-widget {
&.draft-status {
background-color: #FDF3E9;
border-top: 4px solid #F4B57B;
Expand All @@ -9,3 +9,4 @@
border-top: 4px solid $info-400;
}
}

Loading

0 comments on commit fac77e7

Please sign in to comment.