Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui: Toggle for read-only view #16279

Merged
merged 12 commits into from
Mar 20, 2023
Merged

Conversation

ChaiWithJai
Copy link
Contributor

Closes #16269 for creating a Toggle Button to display both the Job Specification and Full Definition.

Functional Changes
This PR adds a toggle button when the JobEditor component is in a read-only state.

Refactoring
This PR refactors the JobEditor component to improve its flexibility and maintainability. The original code tightly coupled the component's state with its rendering logic, which made it difficult to modify and extend. This PR introduces several improvements to make the code more modular and easier to understand.

Changes

  • Uses Ember's component helper to dynamically render the appropriate child component based on the value of the stage property.
  • Reorganizes the code to separate the component state from the rendering logic, which makes the component more modular and easier to test.

@ChaiWithJai ChaiWithJai changed the title ui: Display HCL in the UI ui: Toggle for read-only view Feb 28, 2023
@github-actions
Copy link

github-actions bot commented Feb 28, 2023

Ember Asset Size action

As of 0cefe88

Files that got Bigger 🚨:

File raw gzip
nomad-ui.js +3.49 kB +680 B
nomad-ui.css +386 B +57 B

Files that stayed the same size 🤷‍:

File raw gzip
vendor.js 0 B 0 B
vendor.css 0 B 0 B

@github-actions
Copy link

github-actions bot commented Feb 28, 2023

Ember Test Audit comparison

15982/trunk/main 0cefe88 change
passes 1467 1464 -3
failures 0 4 +4
flaky 0 0 0
duration 11m 20s 220ms 000ms -11m 20s 220ms

Comment on lines 4 to 21
<div class="pull-right" style="display: flex">
<div class="select-mode" data-test-toggle={{@data.view}}>
<button
class="button is-small is-borderless {{if (eq @data.view "job-spec") "is-active"}}"
type="button"
{{on "click" @fns.onToggle}}
>
Job Spec
</button>
<button
class="button is-small is-borderless {{if (eq @data.view "full-definition") "is-active"}}"
type="button"
{{on "click" @fns.onToggle}}
data-test-toggle-full
>
Full Definition
</button>
</div>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be conditionally rendered because old jobs will not have this functionality. This wasn't addressed in the mocks so I will tackle this issue separately.

@ChaiWithJai ChaiWithJai requested a review from philrenaud March 1, 2023 19:57
Copy link
Contributor Author

@ChaiWithJai ChaiWithJai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI it allows users to toggle between full specification and JSON definition is a test that is made to fail until the next PR.

@ChaiWithJai ChaiWithJai marked this pull request as ready for review March 1, 2023 19:58
@philrenaud
Copy link
Contributor

Small note: if you use the GitHub web ui's "Create a branch for...." from an issue, it'll auto-track it. Makes it a little easier to traverse from issue to pr and back.

Copy link
Contributor

@philrenaud philrenaud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few changes and requests for clarification.

Some of the terminology could be changed to be clearer IMO. For example, I'm able to grok that definition means JSON and specification means HCL in this context, but that wasn't immediately clear.

ui/app/templates/components/job-editor/edit.hbs Outdated Show resolved Hide resolved
ui/app/components/job-editor.js Show resolved Hide resolved
ui/app/components/job-editor.js Show resolved Hide resolved
Comment on lines 10 to 15
const definitionWithoutSpecification = { ...definition };
delete definitionWithoutSpecification.Specification;

const specification = await new Blob([
definition?.Specification?.Definition,
]).text();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you help me understand what this is accomplishing? delete prop outside of a serializer has me wondering if this is the optimal place for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fetchRawDefinition specifically is made to skip the Ember Data and thus should not be serialized because we serialize payloads to format them before they enter the Ember Data store.

That leaves me with 2 places to handle this concerns: the Route who makes the fetch request outside of Ember Data or creating a Service and extract our logic there. I opted for minimally changing the API surface and handling the concern where we are loading the data.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, so why are we deleting .Specification here?

What's the format of definition ? Why does Specification need to be removed from it? I'm struggling to understand what this model is trying to accomplish.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're doing what we would do in our Serializer here. We don't require this field. We could keep it, as we're not concerned with it and it won't break anything.

},
},
};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: why not use a factory to accomplish this? They're extensible and most things you have listed here are either already job defaults or else unrelated to the acceptance test below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not in the camp of factory or writing test logic. It becomes painful to maintain and that's personally the part of the test suite I hate the most. If you want it, I'm happy to create it. But it's just more code to maintain.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a few things here:

  1. This data isn't going to be modeled because this is a raw request. We're explicitly using the API response to visualize the response itself in code mirror.
  2. We could overcome this using the afterCreate hook. But we already have 200 lines of logic in that hook and I simply don't want to touch it.

The best solution would be to just move this into a utility file if you wish to separate this fixture from the test code. And I can address that in a follow up PR.

ui/app/styles/components/codemirror.scss Outdated Show resolved Hide resolved
ui/app/components/job-editor.js Show resolved Hide resolved
Co-authored-by: Phil Renaud <[email protected]>
* chore: update mirage scenario:

* ui: conditionally render toggle button (#16497)
Copy link
Contributor Author

@ChaiWithJai ChaiWithJai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed there were test failures associated with the job definition acceptance test module. However, those test failures don't occur for me locally. I will ignore the test failures for now for that reason.

@ChaiWithJai ChaiWithJai merged this pull request into 15982/trunk/main Mar 20, 2023
@ChaiWithJai ChaiWithJai deleted the 15982/trunk/hcl-in-ui branch March 20, 2023 16:25
ChaiWithJai added a commit that referenced this pull request Mar 20, 2023
* ui: model update for specification

* style: add styling for select

* style: add styling for select

* refact: add spec to view

* refact: update component API

* test: refactor for new UI state

* refact: clean conditional

* refact: update component API for prop

* chore: correct naming

* chore:  remove `fn` helper

Co-authored-by: Phil Renaud <[email protected]>

* update `default` Mirage scenario (#16496)

* chore: update mirage scenario:

* ui: conditionally render toggle button (#16497)

* chore: update css variable name (#16498)

---------

Co-authored-by: Phil Renaud <[email protected]>
ChaiWithJai added a commit that referenced this pull request Mar 21, 2023
* ui: model update for specification

* style: add styling for select

* style: add styling for select

* refact: add spec to view

* refact: update component API

* test: refactor for new UI state

* refact: clean conditional

* refact: update component API for prop

* chore: correct naming

* chore:  remove `fn` helper

Co-authored-by: Phil Renaud <[email protected]>

* update `default` Mirage scenario (#16496)

* chore: update mirage scenario:

* ui: conditionally render toggle button (#16497)

* chore: update css variable name (#16498)

---------

Co-authored-by: Phil Renaud <[email protected]>
ChaiWithJai added a commit that referenced this pull request Mar 27, 2023
* ui: model update for specification

* style: add styling for select

* style: add styling for select

* refact: add spec to view

* refact: update component API

* test: refactor for new UI state

* refact: clean conditional

* refact: update component API for prop

* chore: correct naming

* chore:  remove `fn` helper

Co-authored-by: Phil Renaud <[email protected]>

* update `default` Mirage scenario (#16496)

* chore: update mirage scenario:

* ui: conditionally render toggle button (#16497)

* chore: update css variable name (#16498)

---------

Co-authored-by: Phil Renaud <[email protected]>
ChaiWithJai added a commit that referenced this pull request Apr 26, 2023
* ui: model update for specification

* style: add styling for select

* style: add styling for select

* refact: add spec to view

* refact: update component API

* test: refactor for new UI state

* refact: clean conditional

* refact: update component API for prop

* chore: correct naming

* chore:  remove `fn` helper

Co-authored-by: Phil Renaud <[email protected]>

* update `default` Mirage scenario (#16496)

* chore: update mirage scenario:

* ui: conditionally render toggle button (#16497)

* chore: update css variable name (#16498)

---------

Co-authored-by: Phil Renaud <[email protected]>
ChaiWithJai added a commit that referenced this pull request Apr 26, 2023
* ui: model update for specification

* style: add styling for select

* style: add styling for select

* refact: add spec to view

* refact: update component API

* test: refactor for new UI state

* refact: clean conditional

* refact: update component API for prop

* chore: correct naming

* chore:  remove `fn` helper

Co-authored-by: Phil Renaud <[email protected]>

* update `default` Mirage scenario (#16496)

* chore: update mirage scenario:

* ui: conditionally render toggle button (#16497)

* chore: update css variable name (#16498)

---------

Co-authored-by: Phil Renaud <[email protected]>
ChaiWithJai added a commit that referenced this pull request Apr 26, 2023
* ui: model update for specification

* style: add styling for select

* style: add styling for select

* refact: add spec to view

* refact: update component API

* test: refactor for new UI state

* refact: clean conditional

* refact: update component API for prop

* chore: correct naming

* chore:  remove `fn` helper

Co-authored-by: Phil Renaud <[email protected]>

* update `default` Mirage scenario (#16496)

* chore: update mirage scenario:

* ui: conditionally render toggle button (#16497)

* chore: update css variable name (#16498)

---------

Co-authored-by: Phil Renaud <[email protected]>
ChaiWithJai added a commit that referenced this pull request Apr 26, 2023
* ui:  Toggle for `read-only` view (#16279)

* ui: model update for specification

* style: add styling for select

* style: add styling for select

* refact: add spec to view

* refact: update component API

* test: refactor for new UI state

* refact: clean conditional

* refact: update component API for prop

* chore: correct naming

* chore:  remove `fn` helper

Co-authored-by: Phil Renaud <[email protected]>

* update `default` Mirage scenario (#16496)

* chore: update mirage scenario:

* ui: conditionally render toggle button (#16497)

* chore: update css variable name (#16498)

---------

Co-authored-by: Phil Renaud <[email protected]>

* refact: `JobEditor` reactive query parameters (#16710)

* refact: add query parameter

* refact: move toggle action to controller

* ui:  remove toggle behavior in `JobEditor` (#16711)

* refact: rename logic for select

* chore: instantiate qp in route

* refact:  uniform alerts (#16715)

* style: buffer between alert and header

* refact: extract alerts into a component

* chore: update tests for qp

* chore: defensive logic for app controller

* refact:  move `edit` state to controller (#16725)

* refact: move edit state to controller

* refact: handle edit state (#16731)

* refact: handle edit state

* ui:  warning message (#16732)

* ui: warning message

* ui:  enable editing of HCL vars in the UI (#16734)

* enable editing of HCL vars

* refact: default qp logic

* refact: alert condition

* refact: variables as string

* style: revert styling change

---------

Co-authored-by: Phil Renaud <[email protected]>
ChaiWithJai added a commit that referenced this pull request May 9, 2023
…ition` view (#16669)

* ui:  Toggle for `read-only` view (#16279)

* ui: model update for specification

* style: add styling for select

* style: add styling for select

* refact: add spec to view

* refact: update component API

* test: refactor for new UI state

* refact: clean conditional

* refact: update component API for prop

* chore: correct naming

* chore:  remove `fn` helper

Co-authored-by: Phil Renaud <[email protected]>

* update `default` Mirage scenario (#16496)

* chore: update mirage scenario:

* ui: conditionally render toggle button (#16497)

* chore: update css variable name (#16498)

---------

Co-authored-by: Phil Renaud <[email protected]>

* ui:  Display JSON view of variables associated to job specification (#16570)

* chore: move fixture to util

* chore: update tests:

* ui: display variables table

* chore: add mirage fixture (#16572)

* ui: regex for job spec parse (#16668)

* ui: remove variable table (#16670)

* ui:  notify user if specification has variables (#16671)

* ui: regex for job spec parse

* chore: deprecate variable references

* chore: update mirage

* ui: add notification

* test: add test coverage for parse method (#16590)

* refact: `JobEditor` reactive query parameters (#16710)

* refact: add query parameter

* refact: move toggle action to controller

* ui:  remove toggle behavior in `JobEditor` (#16711)

* refact: rename logic for select

* chore: instantiate qp in route

* refact:  uniform alerts (#16715)

* style: buffer between alert and header

* refact: extract alerts into a component

* chore: update tests for qp

* chore: defensive logic for app controller

* refact:  move `edit` state to controller (#16725)

* refact: move edit state to controller

* refact: handle edit state (#16731)

* refact: handle edit state

* ui:  warning message (#16732)

* ui: warning message

* ui:  enable editing of HCL vars in the UI (#16734)

* enable editing of HCL vars

* refact: default qp logic

* refact: alert condition

* refact: Pass `variables` as string (#16849)

* ui:  Toggle for `read-only` view (#16279)

* ui: model update for specification

* style: add styling for select

* style: add styling for select

* refact: add spec to view

* refact: update component API

* test: refactor for new UI state

* refact: clean conditional

* refact: update component API for prop

* chore: correct naming

* chore:  remove `fn` helper

Co-authored-by: Phil Renaud <[email protected]>

* update `default` Mirage scenario (#16496)

* chore: update mirage scenario:

* ui: conditionally render toggle button (#16497)

* chore: update css variable name (#16498)

---------

Co-authored-by: Phil Renaud <[email protected]>

* refact: `JobEditor` reactive query parameters (#16710)

* refact: add query parameter

* refact: move toggle action to controller

* ui:  remove toggle behavior in `JobEditor` (#16711)

* refact: rename logic for select

* chore: instantiate qp in route

* refact:  uniform alerts (#16715)

* style: buffer between alert and header

* refact: extract alerts into a component

* chore: update tests for qp

* chore: defensive logic for app controller

* refact:  move `edit` state to controller (#16725)

* refact: move edit state to controller

* refact: handle edit state (#16731)

* refact: handle edit state

* ui:  warning message (#16732)

* ui: warning message

* ui:  enable editing of HCL vars in the UI (#16734)

* enable editing of HCL vars

* refact: default qp logic

* refact: alert condition

* refact: variables as string

* style: revert styling change

---------

Co-authored-by: Phil Renaud <[email protected]>

* bug: correctly edit variables (#16989)

* ui: visualize variables (#16987)

* ui: fetchRawSpecification

* refact: integrate new model method

* test: fetchRaw unit

* styling: enable height on cm

* chore: update copy

* feat: visual variables

* chore: conditional render info txt

* refact: add mirage endpoint

* refact: update test for new schema

* refact: job submit flow (#17015)

* refact: job update logic

* chore: remove dead code

* bug:  update `job.run` and `job.update` adapter methods (#17055)

* refact:  update adapter

* chore: update api usage

* styling:  UX requests (#17064)

* refact:  update adapter

* chore: update api usage

* styling: disable toggle w text

* styling: stick button

* style: space out alerts

* chore:  autofocus on first editor

* bug: dismiss alert

* chore:  add jsdoc and assertion check

* chore:  update mirage for Vercel (#17054)

* chore: mirage logic for vercel deploy

* chore:  update test for mirage change

* refact:  API refactoring (#17083)

* refact: udpate for req schema

* refact: update for variable flags and literal

* bug: visualize job model not derived state

* chore:  update copy

* chore: fix incorrect copy

* chore: deprecate variables derived state

* chore: update copy

* feat: enable toggle on edit

* chore: prettify

* refact: move conditional

---------

Co-authored-by: Phil Renaud <[email protected]>
@tgross tgross mentioned this pull request Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants