2
2
// SPDX-FileCopyrightText: TNG Technology Consulting GmbH <https://www.tngtech.com>
3
3
//
4
4
// SPDX-License-Identifier: Apache-2.0
5
- import ExpandMoreIcon from '@mui/icons-material/ExpandMore' ;
6
- import MuiAccordion from '@mui/material/Accordion' ;
7
- import MuiAccordionDetails from '@mui/material/AccordionDetails' ;
8
- import MuiAccordionSummary from '@mui/material/AccordionSummary' ;
9
5
import MuiBox from '@mui/material/Box' ;
10
- import MuiInputAdornment from '@mui/material/InputAdornment' ;
6
+ import Link from '@mui/material/Link' ;
7
+ import Tooltip from '@mui/material/Tooltip' ;
11
8
import { sortBy } from 'lodash' ;
12
- import { useMemo , useState } from 'react' ;
9
+ import { useEffect , useMemo , useState } from 'react' ;
13
10
14
11
import { PackageInfo } from '../../../../shared/shared-types' ;
15
12
import { text } from '../../../../shared/text' ;
@@ -19,41 +16,9 @@ import { getFrequentLicensesNameOrder } from '../../../state/selectors/resource-
19
16
import { Confirm } from '../../ConfirmationDialog/ConfirmationDialog' ;
20
17
import { TextBox } from '../../TextBox/TextBox' ;
21
18
import { AttributionFormConfig } from '../AttributionForm' ;
22
- import { attributionColumnClasses } from '../AttributionForm.style' ;
23
19
import { PackageAutocomplete } from '../PackageAutocomplete/PackageAutocomplete' ;
24
20
25
21
const classes = {
26
- ...attributionColumnClasses ,
27
- expansionPanel : {
28
- backgroundColor : 'transparent' ,
29
- '&.MuiAccordion-expanded' : {
30
- margin : '0px 0px 6px 0px !important' ,
31
- } ,
32
- } ,
33
- expansionPanelSummary : {
34
- minHeight : '36px' ,
35
- padding : '0px' ,
36
- '& div.MuiAccordionSummary-content' : {
37
- margin : '0px' ,
38
- } ,
39
- '& div.MuiAccordionSummary-expandIcon' : {
40
- padding : '0px' ,
41
- } ,
42
- } ,
43
- expansionPanelDetails : {
44
- padding : '0px' ,
45
- width : 'calc(100% - 36px)' ,
46
- } ,
47
- expansionPanelDetailsDiffView : {
48
- padding : '0px' ,
49
- } ,
50
- expandMoreIcon : {
51
- display : 'flex' ,
52
- alignItems : 'center' ,
53
- justifyContent : 'center' ,
54
- height : '36px' ,
55
- width : '36px' ,
56
- } ,
57
22
licenseText : {
58
23
marginTop : '12px' ,
59
24
} ,
@@ -76,12 +41,12 @@ export function LicenseSubPanel({
76
41
packageInfo,
77
42
showHighlight,
78
43
onEdit,
79
- expanded : expandedOverride ,
44
+ expanded,
80
45
hidden,
81
46
config,
82
47
} : LicenseSubPanelProps ) {
83
48
const dispatch = useAppDispatch ( ) ;
84
- const [ expanded , setExpanded ] = useState ( expandedOverride ) ;
49
+ const [ isLicenseTextShown , setIsLicenseTextShown ] = useState ( false ) ;
85
50
const frequentLicensesNames = useAppSelector ( getFrequentLicensesNameOrder ) ;
86
51
const defaultLicenses = useMemo (
87
52
( ) =>
@@ -98,99 +63,66 @@ export function LicenseSubPanel({
98
63
) ,
99
64
[ frequentLicensesNames ] ,
100
65
) ;
101
- const label = useMemo (
102
- ( ) =>
103
- packageInfo . licenseName &&
104
- frequentLicensesNames
105
- . map ( ( licenseNames ) => [
106
- licenseNames . shortName . toLowerCase ( ) ,
107
- licenseNames . fullName . toLowerCase ( ) ,
108
- ] )
109
- . flat ( )
110
- . includes ( packageInfo . licenseName . toLowerCase ( ) )
111
- ? `Standard license text implied. ${
112
- ! ! onEdit ? 'Insert notice text if necessary.' : ''
113
- } `
114
- : 'License Text (to appear in attribution document)' ,
115
- [ frequentLicensesNames , onEdit , packageInfo . licenseName ] ,
116
- ) ;
66
+ const showLicenseTextInput = expanded || ! ! packageInfo . licenseText ;
67
+
68
+ useEffect ( ( ) => {
69
+ setIsLicenseTextShown ( showLicenseTextInput ) ;
70
+ } , [ showLicenseTextInput ] ) ;
117
71
118
72
return hidden ? null : (
119
- < MuiBox sx = { classes . panel } >
120
- < MuiAccordion
121
- sx = { classes . expansionPanel }
122
- elevation = { 0 }
123
- key = { 'License' }
124
- disableGutters
125
- expanded = { expanded }
126
- square
127
- >
128
- < MuiAccordionSummary
129
- sx = { classes . expansionPanelSummary }
130
- expandIcon = {
131
- expandedOverride ? null : (
132
- < MuiBox
133
- sx = { classes . expandMoreIcon }
134
- onClick = { ( ) => setExpanded ( ( prev ) => ! prev ) }
135
- >
136
- < ExpandMoreIcon aria-label = { 'license text toggle' } />
137
- </ MuiBox >
73
+ < MuiBox >
74
+ < PackageAutocomplete
75
+ attribute = { 'licenseName' }
76
+ title = { text . attributionColumn . licenseName }
77
+ packageInfo = { packageInfo }
78
+ readOnly = { ! onEdit }
79
+ showHighlight = { showHighlight }
80
+ onEdit = { onEdit }
81
+ endAdornment = { config ?. licenseName ?. endIcon }
82
+ defaults = { defaultLicenses }
83
+ color = { config ?. licenseName ?. color }
84
+ focused = { config ?. licenseName ?. focused }
85
+ />
86
+ { isLicenseTextShown ? (
87
+ < TextBox
88
+ readOnly = { ! onEdit }
89
+ sx = { classes . licenseText }
90
+ maxRows = { 10 }
91
+ minRows = { 3 }
92
+ color = { config ?. licenseText ?. color }
93
+ focused = { config ?. licenseText ?. focused }
94
+ multiline
95
+ expanded = { expanded }
96
+ title = { text . attributionColumn . licenseText }
97
+ text = { packageInfo . licenseText }
98
+ handleChange = { ( { target : { value } } ) =>
99
+ onEdit ?.( ( ) =>
100
+ dispatch (
101
+ setTemporaryDisplayPackageInfo ( {
102
+ ...packageInfo ,
103
+ licenseText : value ,
104
+ wasPreferred : undefined ,
105
+ } ) ,
106
+ ) ,
138
107
)
139
108
}
140
- >
141
- < PackageAutocomplete
142
- attribute = { 'licenseName' }
143
- title = { text . attributionColumn . licenseName }
144
- packageInfo = { packageInfo }
145
- readOnly = { ! onEdit }
146
- showHighlight = { showHighlight }
147
- onEdit = { onEdit }
148
- endAdornment = {
149
- config ?. licenseName ?. endIcon ||
150
- ( packageInfo . licenseText ? (
151
- < MuiInputAdornment position = "end" sx = { classes . endAdornment } >
152
- { text . attributionColumn . licenseTextModified }
153
- </ MuiInputAdornment >
154
- ) : undefined )
155
- }
156
- defaults = { defaultLicenses }
157
- color = { config ?. licenseName ?. color }
158
- focused = { config ?. licenseName ?. focused }
159
- />
160
- </ MuiAccordionSummary >
161
- < MuiAccordionDetails
162
- sx = {
163
- expandedOverride
164
- ? classes . expansionPanelDetailsDiffView
165
- : classes . expansionPanelDetails
166
- }
167
- >
168
- < TextBox
169
- readOnly = { ! onEdit }
170
- sx = { classes . licenseText }
171
- maxRows = { 7 }
172
- minRows = { 3 }
173
- color = { config ?. licenseText ?. color }
174
- focused = { config ?. licenseText ?. focused }
175
- multiline
176
- expanded = { expandedOverride }
177
- title = { label }
178
- text = { packageInfo . licenseText }
179
- handleChange = { ( { target : { value } } ) =>
180
- onEdit ?.( ( ) =>
181
- dispatch (
182
- setTemporaryDisplayPackageInfo ( {
183
- ...packageInfo ,
184
- licenseText : value ,
185
- wasPreferred : undefined ,
186
- } ) ,
187
- ) ,
188
- )
189
- }
190
- endIcon = { config ?. licenseText ?. endIcon }
191
- />
192
- </ MuiAccordionDetails >
193
- </ MuiAccordion >
109
+ endIcon = { config ?. licenseText ?. endIcon }
110
+ />
111
+ ) : (
112
+ onEdit && (
113
+ < Tooltip title = { text . attributionColumn . useCustomLicenseTextHint } >
114
+ < Link
115
+ sx = { { padding : '4px' } }
116
+ underline = { 'hover' }
117
+ component = { 'button' }
118
+ variant = { 'caption' }
119
+ onClick = { ( ) => setIsLicenseTextShown ( true ) }
120
+ >
121
+ { text . attributionColumn . useCustomLicenseText }
122
+ </ Link >
123
+ </ Tooltip >
124
+ )
125
+ ) }
194
126
</ MuiBox >
195
127
) ;
196
128
}
0 commit comments