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' ;
11
6
import { sortBy } from 'lodash' ;
12
- import { useMemo , useState } from 'react' ;
7
+ import { useMemo } from 'react' ;
13
8
14
9
import { PackageInfo } from '../../../../shared/shared-types' ;
15
10
import { text } from '../../../../shared/text' ;
16
11
import { setTemporaryDisplayPackageInfo } from '../../../state/actions/resource-actions/all-views-simple-actions' ;
17
12
import { useAppDispatch , useAppSelector } from '../../../state/hooks' ;
18
- import { getFrequentLicensesNameOrder } from '../../../state/selectors/resource-selectors' ;
13
+ import {
14
+ getFrequentLicensesNameOrder ,
15
+ getFrequentLicensesTexts ,
16
+ } from '../../../state/selectors/resource-selectors' ;
19
17
import { Confirm } from '../../ConfirmationDialog/ConfirmationDialog' ;
20
18
import { TextBox } from '../../TextBox/TextBox' ;
21
19
import { AttributionFormConfig } from '../AttributionForm' ;
22
- import { attributionColumnClasses } from '../AttributionForm.style' ;
23
20
import { PackageAutocomplete } from '../PackageAutocomplete/PackageAutocomplete' ;
24
21
25
22
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
23
licenseText : {
58
24
marginTop : '12px' ,
59
25
} ,
@@ -76,12 +42,12 @@ export function LicenseSubPanel({
76
42
packageInfo,
77
43
showHighlight,
78
44
onEdit,
79
- expanded : expandedOverride ,
45
+ expanded,
80
46
hidden,
81
47
config,
82
48
} : LicenseSubPanelProps ) {
83
49
const dispatch = useAppDispatch ( ) ;
84
- const [ expanded , setExpanded ] = useState ( expandedOverride ) ;
50
+ const frequentLicenseTexts = useAppSelector ( getFrequentLicensesTexts ) ;
85
51
const frequentLicensesNames = useAppSelector ( getFrequentLicensesNameOrder ) ;
86
52
const defaultLicenses = useMemo (
87
53
( ) =>
@@ -98,99 +64,54 @@ export function LicenseSubPanel({
98
64
) ,
99
65
[ frequentLicensesNames ] ,
100
66
) ;
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
- ) ;
67
+
68
+ const defaultLicenseText = packageInfo . licenseText
69
+ ? undefined
70
+ : frequentLicenseTexts [ packageInfo . licenseName || '' ] ;
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
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
+ < TextBox
87
+ readOnly = { ! onEdit }
88
+ placeholder = { defaultLicenseText }
89
+ sx = { classes . licenseText }
90
+ maxRows = { 8 }
91
+ minRows = { 3 }
92
+ color = { config ?. licenseText ?. color }
93
+ focused = { config ?. licenseText ?. focused }
94
+ multiline
125
95
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 >
138
- )
139
- }
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 >
96
+ title = {
97
+ defaultLicenseText
98
+ ? text . attributionColumn . licenseTextDefault
99
+ : text . attributionColumn . licenseText
100
+ }
101
+ text = { packageInfo . licenseText }
102
+ handleChange = { ( { target : { value } } ) =>
103
+ onEdit ?.( ( ) =>
104
+ dispatch (
105
+ setTemporaryDisplayPackageInfo ( {
106
+ ...packageInfo ,
107
+ licenseText : value ,
108
+ wasPreferred : undefined ,
109
+ } ) ,
110
+ ) ,
111
+ )
112
+ }
113
+ endIcon = { config ?. licenseText ?. endIcon }
114
+ />
194
115
</ MuiBox >
195
116
) ;
196
117
}
0 commit comments