Skip to content

Commit 65e6401

Browse files
Addressed bash feedback
1 parent 70b3abc commit 65e6401

File tree

7 files changed

+128
-34
lines changed

7 files changed

+128
-34
lines changed

src/licensing/gui/src/components/App/index.js

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ import {
2222
selectError,
2323
selectAuthEnabled,
2424
selectIsAuthenticated,
25-
selectIsInvalidTokenError
26-
25+
selectIsInvalidTokenError,
26+
selectLicensingIsMhlm,
27+
selectLicensingIsNlm,
28+
selectLicensingIsExistingLicense,
29+
selectLicensingMhlmUsername,
30+
selectLicensingNLMConnectionString
2731
} from "../../selectors";
2832

2933
import {
@@ -53,7 +57,12 @@ function App() {
5357
const authEnabled = useSelector(selectAuthEnabled);
5458
const error = useSelector(selectError)
5559
const isInvalidTokenError = useSelector(selectIsInvalidTokenError)
56-
60+
const isMHLM = useSelector(selectLicensingIsMhlm)
61+
const isNLM = useSelector(selectLicensingIsNlm)
62+
const isExistingLicense = useSelector(selectLicensingIsExistingLicense)
63+
const mhlmUsername = useSelector(selectLicensingMhlmUsername)
64+
const nlmConnectionString = useSelector(selectLicensingNLMConnectionString)
65+
5766
function handleClick(e) {
5867
e.preventDefault();
5968
dispatch(fetchUnsetLicensing())
@@ -63,10 +72,15 @@ function App() {
6372
dialog = (
6473
<Error message="Server unreachable"> </Error>
6574
);
66-
} else if(error && !isInvalidTokenError){
75+
} else if(error && !isInvalidTokenError){
76+
const actionToTake = ['OnlineLicensingError', 'LicensingError', 'EntitlementError'].includes(error.type) ? (
77+
<span onClick={handleClick} style={{ color: 'blue', cursor: 'pointer' }}> Try Licensing again </span>
78+
) : null;
79+
80+
6781
dialog = (
68-
<Error message={error.message}>
69-
<span onClick={handleClick} style={{ color: 'blue', cursor: 'pointer' }}> Try Licensing again </span>
82+
<Error message={error.message}>
83+
{actionToTake}
7084
</Error>
7185
);
7286
}
@@ -136,7 +150,20 @@ function App() {
136150
} else if (hasEntitlements && !isEntitled) {
137151
overlayContent = <EntitlementSelector options={licensingInfo.entitlements} />;
138152
} else {
139-
overlayContent = <div> <h1>You have successfully signed in. Please feel free to close this window</h1> </div>
153+
// Licensing was successful
154+
let textToShow
155+
156+
if(isNLM){
157+
textToShow = <div> <h1>Using Network License Manager at <i>{nlmConnectionString}</i><br/>Close this window and continue in VSCode.</h1> </div>
158+
} else if(isExistingLicense) {
159+
textToShow = <div> <h1> MATLAB is activated<br/>Close this window and continue in VSCode.` </h1> </div>
160+
} else if(isMHLM){
161+
textToShow = <div><h1> You have successfully signed in as <i>{mhlmUsername}</i><br/>Close this window and continue in VSCode.</h1> </div>
162+
}
163+
164+
overlayContent = <div style={{textAlign: 'center'}} >
165+
{textToShow}
166+
</div>
140167
transparent = true;
141168
}
142169

src/licensing/gui/src/components/LicensingGatherer/MHLM.js

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ function initLogin(clientNonce, serverNonce, sourceId) {
6565
loginFrame.postMessage(JSON.stringify(initPayload), "*");
6666
}
6767

68+
const versionRegex = /^[Rr]\d{4}[ab]$/
69+
70+
function validateInput(matlabVersion) {
71+
return versionRegex.test(matlabVersion)
72+
}
73+
6874
// Adding a child prop with null as default for improved testability.
6975
function MHLM({mhlmLicensingInfo = null}) {
7076
const matlabVersionRef = useRef(null);
@@ -77,6 +83,10 @@ function MHLM({mhlmLicensingInfo = null}) {
7783
// useState variable to store response from mhlm after authentication
7884
const [fetchedMhlmLicensingInfo, setFetchedMhlmLicensingInfo] = useState(mhlmLicensingInfo)
7985

86+
const [matlabVersionInput, setMatlabVersionInput] = useState("");
87+
const [changed, setChanged] = useState(false);
88+
const valid = validateInput(matlabVersionInput)
89+
8090
const mhlmLoginHostname = useMemo(
8191
() => {
8292
let subdomain = 'login';
@@ -172,22 +182,37 @@ function MHLM({mhlmLicensingInfo = null}) {
172182
const chooseMatlabVersionDropDown = (
173183
<div id="ChooseMatlabVersion">
174184
<form onSubmit={submitForm}>
175-
<div className='form-group'>
185+
<div className={`form-group has-feedback ${changed ? (valid ? 'has-success' : 'has-error') : ''}`}>
176186
<p>
177187
<b>Note</b>: The MATLAB version could not be determined. Enter the version of MATLAB you are attempting to start.
178188
</p>
179189
<br/>
180190
<label htmlFor="matlabVersion">MATLAB Version:</label>
181-
<input
191+
192+
193+
<div className="input-group">
194+
<input
182195
type="text"
183196
className="form-control"
197+
placeholder={'R20XYb'}
184198
id="matlabVersion"
185-
ref={matlabVersionRef}
186-
/>
199+
aria-invalid={!valid}
200+
ref={matlabVersionRef}
201+
value={matlabVersionInput}
202+
onChange={event => { setChanged(true); setMatlabVersionInput(event.target.value); }}
203+
/>
204+
<span className="input-group-addon" >
205+
{valid ? (
206+
<span className="glyphicon glyphicon-ok form-control-feedback" style={{ paddingLeft: '8px' }}></span>
207+
) : (
208+
<span className="glyphicon glyphicon-remove form-control-feedback" style={{ paddingLeft: '8px' }}></span>
209+
)}
210+
</span>
211+
</div>
187212

188213
<br/><br/>
189214

190-
<input type="submit" id="startMatlabBtn" value="Submit" className="btn btn_color_blue" />
215+
<input disabled={!valid} type="submit" id="startMatlabBtn" value="Submit" className="btn btn_color_blue" />
191216
</div>
192217
</form>
193218
</div>

src/licensing/gui/src/components/LicensingGatherer/NLM.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,25 @@ function NLM() {
6060
<form onSubmit={submitForm}>
6161
<div className={`form-group has-feedback ${changed ? (valid ? 'has-success' : 'has-error') : ''}`}>
6262
<label htmlFor="nlm-connection-string">License Server Address</label>
63-
<input id="nlm-connection-string"
64-
type="text"
65-
required={true}
66-
placeholder={'port@hostname'}
67-
className="form-control"
68-
aria-invalid={!valid}
69-
value={connStr}
70-
onChange={event => { setChanged(true); setConnStr(event.target.value); }}
71-
/>
72-
<span className="glyphicon form-control-feedback glyphicon-remove"></span>
73-
<span className="glyphicon form-control-feedback glyphicon-ok"></span>
63+
<div className="input-group">
64+
<input id="nlm-connection-string"
65+
type="text"
66+
required={true}
67+
placeholder={'port@hostname'}
68+
className="form-control"
69+
aria-invalid={!valid}
70+
value={connStr}
71+
onChange={event => { setChanged(true); setConnStr(event.target.value); }}
72+
/>
73+
74+
<span className="input-group-addon" >
75+
{valid ? (
76+
<span className="glyphicon glyphicon-ok form-control-feedback" style={{ paddingLeft: '8px' }}></span>
77+
) : (
78+
<span className="glyphicon glyphicon-remove form-control-feedback" style={{ paddingLeft: '8px' }}></span>
79+
)}
80+
</span>
81+
</div>
7482
</div>
7583
<input type="submit" id="submit" value="Submit" className="btn btn_color_blue" disabled={!valid} />
7684
</form>

src/licensing/gui/src/selectors/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,30 @@ export const selectLicensingIsMhlm = createSelector(
8787
(licensingInfo, licensingProvided) => licensingProvided && licensingInfo.type === 'mhlm'
8888
);
8989

90+
export const selectLicensingIsNlm = createSelector(
91+
selectLicensingInfo,
92+
selectLicensingProvided,
93+
(licensingInfo, licensingProvided) => licensingProvided && licensingInfo.type === 'nlm'
94+
);
95+
96+
export const selectLicensingIsExistingLicense = createSelector(
97+
selectLicensingInfo,
98+
selectLicensingProvided,
99+
(licensingInfo, licensingProvided) => licensingProvided && licensingInfo.type === 'existing_license'
100+
);
101+
90102
export const selectLicensingMhlmUsername = createSelector(
91103
selectLicensingInfo,
92104
selectLicensingIsMhlm,
93105
(licensingInfo, isMhlm) => isMhlm ? licensingInfo.emailAddress : ''
94106
);
95107

108+
export const selectLicensingNLMConnectionString = createSelector(
109+
selectLicensingInfo,
110+
selectLicensingIsNlm,
111+
(licensingInfo, isNlm) => isNlm ? licensingInfo.connectionString : ''
112+
);
113+
96114
// Selector to check if the license type is mhlm and entitlements property is not empty
97115
export const selectLicensingMhlmHasEntitlements = createSelector(
98116
selectLicensingIsMhlm,

src/licensing/index.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export default class Licensing {
162162
* @private
163163
* @returns {boolean} `true` if the licensing type is MHLM, `false` otherwise.
164164
*/
165-
private isMHLMLicensing (): boolean {
165+
isMHLMLicensing (): boolean {
166166
return isMHLMLicensingDataType(this.data);
167167
}
168168

@@ -171,7 +171,7 @@ export default class Licensing {
171171
* @private
172172
* @returns {boolean} `true` if the licensing type is NLM, `false` otherwise.
173173
*/
174-
private isNLMLicensing (): boolean {
174+
isNLMLicensing (): boolean {
175175
return isNLMLicensingDataType(this.data)
176176
}
177177

@@ -180,7 +180,7 @@ export default class Licensing {
180180
* @private
181181
* @returns {boolean} `true` if the licensing type is an existing license, `false` otherwise.
182182
*/
183-
private isExistingLicensing (): boolean {
183+
isExistingLicensing (): boolean {
184184
return isExistingLicensingDataType(this.data)
185185
}
186186

@@ -189,7 +189,7 @@ export default class Licensing {
189189
* @private
190190
* @returns {boolean} `true` if there is no licensing configured, `false` otherwise.
191191
*/
192-
private isNoLicensing (): boolean {
192+
isNoLicensing (): boolean {
193193
return isNoLicensingDataType(this.data);
194194
}
195195

@@ -214,10 +214,11 @@ export default class Licensing {
214214
*/
215215
async unsetLicensing (): Promise<void> {
216216
this.data = null
217-
if (this.error instanceof LicensingError) {
217+
if (this.error && this.error instanceof LicensingError) {
218218
this.error = null
219-
}
219+
}
220220
await this.deleteCachedConfigFile()
221+
console.log("Successfully unset licensing")
221222
}
222223

223224
/**
@@ -329,11 +330,12 @@ export default class Licensing {
329330
* @param connectionStr - The NLM connection string.
330331
* @private
331332
*/
332-
private setLicensingToNLM (connectionStr: string): void {
333+
private setLicensingToNLM (data: any): void {
334+
const {connectionString} = data;
333335
this.data = {
334336
type: NLMLicenseType,
335-
conn_str: connectionStr
336-
};
337+
conn_str: connectionString
338+
}
337339

338340
Logger.log('Persisting NLM info.')
339341
this.persistConfigData();
@@ -449,7 +451,7 @@ export default class Licensing {
449451
* @private
450452
* @returns {Promise<boolean>} `true` if the licensing information was updated and persisted successfully, `false` otherwise.
451453
*/
452-
private async updateAndPersistLicensing (): Promise<boolean> {
454+
async updateAndPersistLicensing (): Promise<boolean> {
453455
const successfulUpdate = await this.updateEntitlements();
454456
if (successfulUpdate) {
455457
this.persistConfigData();

src/licensing/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export function isMHLMLicensingDataType (data: LicensingData): boolean {
126126
*/
127127
export function isNLMLicensingDataType (data: LicensingData): boolean {
128128
return typeof data === 'object' && data != null &&
129-
Object.keys(data).length === 1 &&
129+
Object.keys(data).length === 2 &&
130130
'conn_str' in data && data.conn_str !== null;
131131
}
132132

src/utils/LicensingUtils.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,18 @@ export async function handleSignInChanged (configuration: Settings): Promise<voi
170170
*/
171171
export function handleInstallPathSettingChanged (configuration: Settings): void {
172172
setInstallPath(configuration.installPath)
173+
const licensing = new Licensing()
174+
175+
// Entitlements are based on the MATLAB version
176+
// As installPath is changed, we need to update the entitlements using the
177+
// new MATLAB version.
178+
if(licensing.isMHLMLicensing()){
179+
licensing.updateAndPersistLicensing().then(isSuccessful => {
180+
if(isSuccessful){
181+
Logger.log("Successfully updated entitlements using the new MATLAB version")
182+
} else {
183+
Logger.log("Failed to update entitlements using the new MATLAB version")
184+
}
185+
})
186+
}
173187
}

0 commit comments

Comments
 (0)