1- // @ts -check
2- import React , { useState , useMemo } from 'react' ;
1+ import { useState , useMemo } from 'react' ;
32import {
43 Card , Stack , Button , Collapsible , Icon ,
54} from '@openedx/paragon' ;
@@ -10,10 +9,19 @@ import { ContentTagsDrawerSheet } from '..';
109
1110import messages from '../messages' ;
1211import { useContentTaxonomyTagsData } from '../data/apiHooks' ;
12+ import type { ContentTaxonomyTagData , Tag } from '../data/types' ;
1313import { LoadingSpinner } from '../../generic/Loading' ;
1414import TagsTree from '../TagsTree' ;
1515
16- const TagsSidebarBody = ( ) => {
16+ interface TagsSidebarBodyProps {
17+ readOnly : boolean
18+ }
19+
20+ type TagTree = {
21+ [ key : string ] : { children : TagTree , canChangeObjecttag : boolean , canDeleteObjecttag : boolean }
22+ } ;
23+
24+ const TagsSidebarBody = ( { readOnly } : TagsSidebarBodyProps ) => {
1725 const intl = useIntl ( ) ;
1826 const [ showManageTags , setShowManageTags ] = useState ( false ) ;
1927 const contentId = useParams ( ) . blockId ;
@@ -24,8 +32,8 @@ const TagsSidebarBody = () => {
2432 isSuccess : isContentTaxonomyTagsLoaded ,
2533 } = useContentTaxonomyTagsData ( contentId || '' ) ;
2634
27- const buildTagsTree = ( contentTags ) => {
28- const resultTree = { } ;
35+ const buildTagsTree = ( contentTags : Tag [ ] ) => {
36+ const resultTree : TagTree = { } ;
2937 contentTags . forEach ( item => {
3038 let currentLevel = resultTree ;
3139
@@ -46,7 +54,7 @@ const TagsSidebarBody = () => {
4654 } ;
4755
4856 const tree = useMemo ( ( ) => {
49- const result = [ ] ;
57+ const result : ( Omit < ContentTaxonomyTagData , 'tags' > & { tags : TagTree } ) [ ] = [ ] ;
5058 if ( isContentTaxonomyTagsLoaded && contentTaxonomyTagsData ) {
5159 contentTaxonomyTagsData . taxonomies . forEach ( ( taxonomy ) => {
5260 result . push ( {
@@ -88,7 +96,13 @@ const TagsSidebarBody = () => {
8896 </ div >
8997 ) }
9098
91- < Button className = "mt-3 ml-2" variant = "outline-primary" size = "sm" onClick = { ( ) => setShowManageTags ( true ) } >
99+ < Button
100+ className = "mt-3 ml-2"
101+ variant = "outline-primary"
102+ size = "sm"
103+ onClick = { ( ) => setShowManageTags ( true ) }
104+ disabled = { readOnly }
105+ >
92106 { intl . formatMessage ( messages . manageTagsButton ) }
93107 </ Button >
94108 </ Stack >
@@ -102,6 +116,4 @@ const TagsSidebarBody = () => {
102116 ) ;
103117} ;
104118
105- TagsSidebarBody . propTypes = { } ;
106-
107119export default TagsSidebarBody ;
0 commit comments