Skip to content

Commit b40a725

Browse files
committed
upgrade in progress
1 parent 7ed09e6 commit b40a725

File tree

9 files changed

+64
-98
lines changed

9 files changed

+64
-98
lines changed

ui/app/components/namespace-editor.hbs

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,21 @@
1616
</Hds::Form::TextInput::Field>
1717
{{/if}}
1818

19-
<div class="boxed-section">
20-
<div class="boxed-section-head">
21-
Definition
22-
</div>
23-
<div class="boxed-section-body is-full-bleed">
24-
<div
25-
class="namespace-editor-wrapper boxed-section-body is-full-bleed
26-
{{if this.JSONError 'error'}}"
27-
>
28-
{{!-- TODO: Needs to support extraKeys=(hash Cmd-Enter=this.save) --}}
29-
<div
30-
class="namespace-editor"
31-
data-test-namespace-editor
32-
{{hds-code-editor
33-
ariaLabel="Namespace definition"
34-
language="javascript"
35-
value=this.definitionString
36-
onInput=this.updateNamespaceDefinition
37-
}}
38-
/>
39-
{{#if this.JSONError}}
40-
<p class="help is-danger">
41-
{{this.JSONError}}
42-
</p>
43-
{{/if}}
44-
</div>
45-
</div>
46-
</div>
19+
<Hds::CodeEditor
20+
data-test-namespace-editor
21+
@language="json"
22+
@isLintingEnabled={{true}}
23+
@value={{this.definitionString}}
24+
@onInput={{this.updateNamespaceDefinition}}
25+
@onLint={{this.onLint}}
26+
as |CE|
27+
>
28+
<CE.Title>Definition</CE.Title>
29+
</Hds::CodeEditor>
4730

4831
<footer>
4932
{{#if (can "update namespace")}}
50-
<Hds::Button @text="Save Namespace" @color="primary" disabled={{this.JSONError}}
33+
<Hds::Button @text="Save Namespace" @color="primary" disabled={{this.hasLintingErrors}}
5134
{{on "click" this.save}}
5235
data-test-save-namespace
5336
/>

ui/app/components/namespace-editor.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,21 @@ export default class NamespaceEditorComponent extends Component {
2020

2121
@alias('args.namespace') namespace;
2222

23-
@tracked JSONError = null;
2423
@tracked definitionString = this.definitionStringFromNamespace(
2524
this.args.namespace
2625
);
26+
@tracked hasLintingErrors = false;
2727

2828
@action updateNamespaceName({ target: { value } }) {
2929
this.namespace.set('name', value);
3030
}
3131

3232
@action updateNamespaceDefinition(value) {
33-
this.JSONError = null;
3433
this.definitionString = value;
34+
}
3535

36-
try {
37-
JSON.parse(this.definitionString);
38-
} catch (error) {
39-
this.JSONError = 'Invalid JSON';
40-
}
36+
@action onLint(diagnostics) {
37+
this.hasLintingErrors = diagnostics.length > 0;
4138
}
4239

4340
@action async save(e) {

ui/app/components/policy-editor.hbs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,16 @@
1616
</Hds::Form::TextInput::Field>
1717
{{/if}}
1818

19-
<div class="boxed-section">
20-
<div class="boxed-section-head">
21-
Policy Definition
22-
</div>
23-
<div class="boxed-section-body is-full-bleed">
24-
25-
{{!-- TODO: extraKeys=(hash Cmd-Enter=this.save) --}}
26-
<div
27-
class="policy-editor"
28-
data-test-policy-editor
29-
{{hds-code-editor
30-
ariaLabel="Policy definition"
31-
language="ruby"
32-
value=@policy.rules
33-
onInput=this.updatePolicyRules
34-
}}
35-
/>
36-
</div>
37-
</div>
19+
<Hds::CodeEditor
20+
class="policy-editor"
21+
data-test-policy-editor
22+
@language="ruby"
23+
@value={{@policy.rules}}
24+
@onInput={{this.updatePolicyRules}}
25+
as |CE|
26+
>
27+
<CE.Title>Policy Definition</CE.Title>
28+
</Hds::CodeEditor>
3829

3930
<div>
4031
<label>

ui/app/components/sentinel-policy-editor.hbs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,18 @@
1616
</Hds::Form::TextInput::Field>
1717
{{/if}}
1818

19-
<div class="boxed-section">
20-
<div class="boxed-section-head">
19+
<Hds::CodeEditor
20+
class="policy-editor"
21+
data-test-policy-editor
22+
@language="ruby"
23+
@value={{@policy.policy}}
24+
@onInput={{this.updatePolicy}}
25+
as |CE|
26+
>
27+
<CE.Title>
2128
Policy Definition
22-
</div>
23-
<div class="boxed-section-body is-full-bleed">
24-
{{!-- TODO: extraKeys=(hash Cmd-Enter=this.save) --}}
25-
<div
26-
class="policy-editor"
27-
data-test-policy-editor
28-
{{hds-code-editor
29-
ariaLabel="Policy definition"
30-
language="ruby"
31-
value=@policy.policy
32-
onInput=this.updatePolicy
33-
}}
34-
/>
35-
</div>
36-
</div>
29+
</CE.Title>
30+
</Hds::CodeEditor>
3731

3832
<div>
3933
<label>

ui/app/components/variable-form.hbs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,21 +115,20 @@
115115
{{#if (eq this.view "json")}}
116116
<div
117117
class="editor-wrapper boxed-section-body is-full-bleed
118-
{{if this.JSONError 'error'}}"
118+
{{if this.hasJSONErrors 'error'}}"
119119
>
120120
{{!-- TODO: extraKeys=(hash Cmd-Enter=(action "save")) --}}
121121
<div
122122
data-test-json-editor
123123
{{hds-code-editor
124+
ariaLabel="Variable JSON Editor"
125+
language="json"
124126
value=this.JSONItems
127+
isLintingEnabled=true
125128
onInput=this.updateCode
129+
onLint=this.onLint
126130
}}
127131
/>
128-
{{#if this.JSONError}}
129-
<p class="help is-danger">
130-
{{this.JSONError}}
131-
</p>
132-
{{/if}}
133132
</div>
134133
{{else}}
135134
{{#each this.keyValues as |entry iter|}}

ui/app/components/variable-form.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ export default class VariableFormComponent extends Component {
3737
@tracked variableNamespace = null;
3838
@tracked namespaceOptions = null;
3939
@tracked hasConflict = false;
40+
@tracked hasFormatErrors = false;
41+
@tracked lintingErrors = [];
4042

4143
/**
4244
* @typedef {Object} conflictingVariable
@@ -71,6 +73,10 @@ export default class VariableFormComponent extends Component {
7173
}
7274
}
7375

76+
get hasJSONErrors() {
77+
return this.lintingErrors.length > 0 || this.hasFormatErrors;
78+
}
79+
7480
get shouldDisableSave() {
7581
const disallowedPath =
7682
this.path?.startsWith('nomad/') &&
@@ -79,7 +85,7 @@ export default class VariableFormComponent extends Component {
7985
(this.path?.startsWith('nomad/job-templates') &&
8086
trimPath([this.path]) !== 'nomad/job-templates')
8187
);
82-
return !!this.JSONError || !this.path || disallowedPath;
88+
return this.hasJSONErrors || !this.path || disallowedPath;
8389
}
8490

8591
get isJobTemplateVariable() {
@@ -329,6 +335,10 @@ export default class VariableFormComponent extends Component {
329335
return this.args.view === 'json';
330336
}
331337

338+
@action onLint(diagnostics) {
339+
this.lintingErrors = diagnostics;
340+
}
341+
332342
// Prevent duplicate onUpdate events when @view is set to its already-existing value,
333343
// which happens because parent's queryParams and toggle button both resolve independently.
334344
@action onViewChange([view]) {
@@ -381,35 +391,27 @@ export default class VariableFormComponent extends Component {
381391
this.appendRow();
382392
}
383393
}
384-
385-
// Reset any error state, since the errorring json will not persist
386-
set(this, 'JSONError', null);
387394
}
388395

389-
/**
390-
* @type {string}
391-
*/
392-
@tracked JSONError = null;
396+
// TODO: Review this
393397
/**
394398
*
395399
* @param {string} value
396400
*/
397401
@action updateCode(value) {
402+
// "myString" is valid JSON, but it's not a valid Variable.
403+
// Ditto for an array of objects. We expect a single object to be a Variable.
398404
try {
399-
// "myString" is valid JSON, but it's not a valid Variable.
400-
// Ditto for an array of objects. We expect a single object to be a Variable.
401405
const hasFormatErrors =
402406
JSON.parse(value) instanceof Array ||
403407
typeof JSON.parse(value) !== 'object';
404-
if (hasFormatErrors) {
405-
throw new Error('A Variable must be formatted as a single JSON object');
406-
}
407408

408-
set(this, 'JSONError', null);
409-
set(this, 'JSONItems', value);
410-
} catch (error) {
411-
set(this, 'JSONError', error);
409+
this.hasFormatErrors = hasFormatErrors;
410+
} catch (e) {
411+
this.hasFormatErrors = true;
412412
}
413+
414+
set(this, 'JSONItems', value);
413415
}
414416
//#endregion JSON Editing
415417

ui/app/routes/administration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default class AdministrationRoute extends Route.extend(
2424
this.can.cannot('list tokens') ||
2525
this.can.cannot('list namespaces')
2626
) {
27-
this.router.transitionTo('/jobs');
27+
// this.router.transitionTo('/jobs');
2828
}
2929
}
3030

ui/app/routes/administration/policies/new.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export default class AccessControlPoliciesNewRoute extends Route {
9595

9696
beforeModel() {
9797
if (this.can.cannot('write policy')) {
98-
this.router.transitionTo('/administration/policies');
98+
// this.router.transitionTo('/administration/policies');
9999
}
100100
}
101101

ui/app/routes/variables.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default class VariablesRoute extends Route.extend(WithForbiddenState) {
2222

2323
beforeModel() {
2424
if (this.can.cannot('list variables')) {
25-
this.router.transitionTo('/jobs');
25+
// this.router.transitionTo('/jobs');
2626
}
2727
}
2828

0 commit comments

Comments
 (0)