From baa377ddca7d663e014d9ef4fb32afe41233765a Mon Sep 17 00:00:00 2001 From: John Cowen Date: Fri, 8 Oct 2021 16:29:30 +0100 Subject: [PATCH] ui: Adds initial CRUD for partitions (#11188) * Add `is` and `test` helpers in a similar vein to `can` Adds 2 new helpers in a similar vein to ember-cans can: - `is` allows you to use vocab/phrases such as (is "something model") which calls isSomething() on the models ability. - `test` allows you to use vocab/phrases such as (test "is something model") or (test "can something model")which calls isSomething() / canSomething() on the models ability. Mostly using the is helper and the can helper. It's basically the is/can helper combined. * Adds TextInput component + related modifiers/helpers/machines/services (#11189) Adds a few new components/modifiers/helpers to aid building forms. - state-chart helper, used in lieu of a more generic approach for requiring our statecharts. - A few modifications to our existing disabled modifier. - A new 'validation' modifier, a super small form validation approach built to make use of state charts (optionally). Eventually we should be able to replace our current validation approach (ember-changeset-validations + extra deps) with this. - A new TextInput component, which is the first of our new components specifically to make it easy to build forms with validations. This is still a WIP, I left some comments in pointing out where this one would be progressed, but as we don't need the planned functionality yet, I left it where it was. All of this will be fleshed out more at a later date. Documentation is included for all of ^ * ui: Adds initial CRUD for partitions (#11190) Adds basic CRUD support for partitions. Engineering-wise probably the biggest takeaway here is that we needed to write very little javascript code to add this entire feature, and the little javascript we did need to write was very straightforwards. Everything is pretty much just HTML. Another note to make is that both ember-changeset and ember-data (model layer things) are now completely abstracted away from the view layer of the application. New components: - Consul::Partition::Form - Consul::Partition::List - Consul::Partition::Notifications - Consul::Partition::SearchBar - Consul::Partition::Selector See additional documentation here for more details New Route templates: - index.hbs partition listing/searching/filtering - edit.hbs partition editing and creation Additionally: There is some additional debug work here for better observability and to prevent any errors regarding our href-to usage when a dc is not available in our documentation site. Our softDelete functionality has been DRYed out a little to be used across two repos. isLinkable was removed from our ListCollection component for lists like upstream and service listing, and instead use our new is helper from within the ListCollection, meaning we've added a few more lighterweight templateOnly components. * ui: Exclude all debug-like files from the build (#11211) This PR adds **/*-debug.* to our test/prod excluded files (realised I needed to add test-support.js also so added that here as its more or less the same thing). Conditionally juggling ES6 static imports (specifically debug ones) for this was also getting a little hairy, so I moved it all to use the same approach as our conditional routes. All in all it brings the vendor build back down to ~430kb gzipped. --- .changelog/11188.txt | 3 + .circleci/config.yml | 4 +- ui/package.json | 2 +- ui/packages/consul-acls/package.json | 5 + .../consul-acls/vendor/consul-acls/routes.js | 18 +++ .../consul/partition/form/README.mdx | 24 +++ .../consul/partition/form/index.hbs | 126 ++++++++++++++++ .../consul/partition/list/README.mdx | 32 ++++ .../consul/partition/list/index.hbs | 63 ++++++++ .../consul/partition/list/test-support.js | 18 +++ .../consul/partition/notifications/README.mdx | 46 ++++++ .../consul/partition/notifications/index.hbs | 24 +++ .../consul/partition/search-bar/README.mdx | 30 ++++ .../consul/partition/search-bar/index.hbs | 98 ++++++++++++ .../consul/partition/selector/README.mdx | 40 +++++ .../consul/partition/selector/index.hbs | 53 +++++++ .../app/templates/dc/partitions/edit.hbs | 68 +++++++++ .../app/templates/dc/partitions/index.hbs | 138 +++++++++++++++++ ui/packages/consul-partitions/package.json | 5 + .../vendor/consul-partitions/routes.js | 38 +++++ ui/packages/consul-ui/.docfy-config.js | 6 + ui/packages/consul-ui/app/abilities/base.js | 13 ++ ui/packages/consul-ui/app/abilities/nspace.js | 4 + .../consul-ui/app/abilities/partition.js | 6 +- .../consul-ui/app/abilities/service.js | 4 + .../consul-ui/app/abilities/upstream.js | 9 ++ .../consul-ui/app/adapters/partition.js | 34 +++++ .../components/consul/nspace/list/index.hbs | 2 +- .../components/consul/nspace/list/index.js | 7 - .../components/consul/service/list/index.hbs | 2 +- .../components/consul/service/list/index.js | 9 -- .../components/consul/upstream/list/index.hbs | 2 +- .../components/consul/upstream/list/index.js | 9 -- .../app/components/data-form/index.js | 3 +- .../app/components/data-writer/index.hbs | 1 + .../app/components/hashicorp-consul/index.hbs | 61 +------- .../app/components/list-collection/index.hbs | 10 +- .../app/components/text-input/README.mdx | 46 ++++++ .../app/components/text-input/index.hbs | 48 ++++++ ui/packages/consul-ui/app/forms/partition.js | 7 + ui/packages/consul-ui/app/helpers/is.js | 24 +++ ui/packages/consul-ui/app/helpers/is.mdx | 20 +++ .../consul-ui/app/helpers/state-chart.js | 10 ++ ui/packages/consul-ui/app/helpers/test.js | 14 ++ ui/packages/consul-ui/app/helpers/test.mdx | 16 ++ .../consul-ui/app/initializers/routing.js | 8 - .../app/instance-initializers/container.js | 34 +++++ .../app/locations/fsm-with-optional.js | 32 +++- .../consul-ui/app/machines/validate.xstate.js | 29 ++++ ui/packages/consul-ui/app/models/partition.js | 2 + .../consul-ui/app/modifiers/disabled.js | 15 +- .../consul-ui/app/modifiers/validate.js | 139 ++++++++++++++++++ .../consul-ui/app/modifiers/validate.mdx | 93 ++++++++++++ .../app/routing/application-debug.js | 27 ++++ ui/packages/consul-ui/app/routing/route.js | 16 ++ .../oauth2-code-with-url-provider.js} | 30 ++-- .../app/services/data-sink/protocols/http.js | 1 + ui/packages/consul-ui/app/services/form.js | 2 + .../debug.js => services/i18n-debug.js} | 39 +---- .../i18n.js | 8 +- .../consul-ui/app/services/repository.js | 21 +++ .../app/services/repository/nspace.js | 22 +-- .../app/services/repository/partition.js | 25 +++- .../app/services/state-with-charts.js | 10 ++ ui/packages/consul-ui/app/services/state.js | 10 +- .../app/sort/comparators/partition.js | 3 + ui/packages/consul-ui/app/styles/debug.scss | 21 ++- ui/packages/consul-ui/ember-cli-build.js | 50 ++++++- .../lib/startup/templates/body.html.js | 38 ++++- ui/packages/consul-ui/mock-api/v1/partition/_ | 6 + ui/packages/consul-ui/package.json | 3 + ui/packages/consul-ui/vendor/acls/routes.js | 15 -- .../vendor/consul-ui/services-debug.js | 15 ++ .../consul-ui/vendor/consul-ui/services.js | 21 +++ 74 files changed, 1711 insertions(+), 226 deletions(-) create mode 100644 .changelog/11188.txt create mode 100644 ui/packages/consul-acls/package.json create mode 100644 ui/packages/consul-acls/vendor/consul-acls/routes.js create mode 100644 ui/packages/consul-partitions/app/components/consul/partition/form/README.mdx create mode 100644 ui/packages/consul-partitions/app/components/consul/partition/form/index.hbs create mode 100644 ui/packages/consul-partitions/app/components/consul/partition/list/README.mdx create mode 100644 ui/packages/consul-partitions/app/components/consul/partition/list/index.hbs create mode 100644 ui/packages/consul-partitions/app/components/consul/partition/list/test-support.js create mode 100644 ui/packages/consul-partitions/app/components/consul/partition/notifications/README.mdx create mode 100644 ui/packages/consul-partitions/app/components/consul/partition/notifications/index.hbs create mode 100644 ui/packages/consul-partitions/app/components/consul/partition/search-bar/README.mdx create mode 100644 ui/packages/consul-partitions/app/components/consul/partition/search-bar/index.hbs create mode 100644 ui/packages/consul-partitions/app/components/consul/partition/selector/README.mdx create mode 100644 ui/packages/consul-partitions/app/components/consul/partition/selector/index.hbs create mode 100644 ui/packages/consul-partitions/app/templates/dc/partitions/edit.hbs create mode 100644 ui/packages/consul-partitions/app/templates/dc/partitions/index.hbs create mode 100644 ui/packages/consul-partitions/package.json create mode 100644 ui/packages/consul-partitions/vendor/consul-partitions/routes.js create mode 100644 ui/packages/consul-ui/app/abilities/upstream.js delete mode 100644 ui/packages/consul-ui/app/components/consul/nspace/list/index.js delete mode 100644 ui/packages/consul-ui/app/components/consul/service/list/index.js delete mode 100644 ui/packages/consul-ui/app/components/consul/upstream/list/index.js create mode 100644 ui/packages/consul-ui/app/components/text-input/README.mdx create mode 100644 ui/packages/consul-ui/app/components/text-input/index.hbs create mode 100644 ui/packages/consul-ui/app/forms/partition.js create mode 100644 ui/packages/consul-ui/app/helpers/is.js create mode 100644 ui/packages/consul-ui/app/helpers/is.mdx create mode 100644 ui/packages/consul-ui/app/helpers/state-chart.js create mode 100644 ui/packages/consul-ui/app/helpers/test.js create mode 100644 ui/packages/consul-ui/app/helpers/test.mdx delete mode 100644 ui/packages/consul-ui/app/initializers/routing.js create mode 100644 ui/packages/consul-ui/app/machines/validate.xstate.js create mode 100644 ui/packages/consul-ui/app/modifiers/validate.js create mode 100644 ui/packages/consul-ui/app/modifiers/validate.mdx create mode 100644 ui/packages/consul-ui/app/routing/application-debug.js rename ui/packages/consul-ui/app/{initializers/oidc-provider.js => services/auth-providers/oauth2-code-with-url-provider.js} (63%) rename ui/packages/consul-ui/app/{instance-initializers/debug.js => services/i18n-debug.js} (63%) rename ui/packages/consul-ui/app/{instance-initializers => services}/i18n.js (83%) create mode 100644 ui/packages/consul-ui/app/services/state-with-charts.js create mode 100644 ui/packages/consul-ui/app/sort/comparators/partition.js create mode 100644 ui/packages/consul-ui/mock-api/v1/partition/_ delete mode 100644 ui/packages/consul-ui/vendor/acls/routes.js create mode 100644 ui/packages/consul-ui/vendor/consul-ui/services-debug.js create mode 100644 ui/packages/consul-ui/vendor/consul-ui/services.js diff --git a/.changelog/11188.txt b/.changelog/11188.txt new file mode 100644 index 0000000000..d8d62daa02 --- /dev/null +++ b/.changelog/11188.txt @@ -0,0 +1,3 @@ +```release-note:feature +ui: Added initial support for admin partition CRUD +``` diff --git a/.circleci/config.yml b/.circleci/config.yml index 91e04262cb..b62764a253 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -22,7 +22,7 @@ references: test-results: &TEST_RESULTS_DIR /tmp/test-results cache: - yarn: &YARN_CACHE_KEY consul-ui-v4-{{ checksum "ui/yarn.lock" }} + yarn: &YARN_CACHE_KEY consul-ui-v5-{{ checksum "ui/yarn.lock" }} rubygem: &RUBYGEM_CACHE_KEY static-site-gems-v1-{{ checksum "Gemfile.lock" }} environment: &ENVIRONMENT @@ -602,7 +602,7 @@ jobs: - run: name: install yarn packages - command: cd ui && yarn install + command: cd ui && yarn install && cd packages/consul-ui && yarn install - save_cache: key: *YARN_CACHE_KEY diff --git a/ui/package.json b/ui/package.json index 4c22878ed2..06b57506c0 100644 --- a/ui/package.json +++ b/ui/package.json @@ -11,7 +11,7 @@ "scripts": { "doc:toc": "doctoc README.md", "compliance": "npm-run-all compliance:*", - "compliance:licenses": "license-checker --summary --onlyAllow 'Python-2.0;Apache*;Apache License, Version 2.0;Apache-2.0;Apache 2.0;Artistic-2.0;BSD;BSD-3-Clause;CC-BY-3.0;CC-BY-4.0;CC0-1.0;ISC;MIT;MPL-2.0;Public Domain;Unicode-TOU;Unlicense;WTFPL' --excludePackages 'consul-ui@2.2.0;'" + "compliance:licenses": "license-checker --summary --onlyAllow 'Python-2.0;Apache*;Apache License, Version 2.0;Apache-2.0;Apache 2.0;Artistic-2.0;BSD;BSD-3-Clause;CC-BY-3.0;CC-BY-4.0;CC0-1.0;ISC;MIT;MPL-2.0;Public Domain;Unicode-TOU;Unlicense;WTFPL' --excludePackages 'consul-ui@2.2.0;consul-acls@0.1.0;consul-partitions@0.1.0'" }, "devDependencies": { diff --git a/ui/packages/consul-acls/package.json b/ui/packages/consul-acls/package.json new file mode 100644 index 0000000000..b2a513fb82 --- /dev/null +++ b/ui/packages/consul-acls/package.json @@ -0,0 +1,5 @@ +{ + "name": "consul-acls", + "version": "0.1.0", + "private": true +} diff --git a/ui/packages/consul-acls/vendor/consul-acls/routes.js b/ui/packages/consul-acls/vendor/consul-acls/routes.js new file mode 100644 index 0000000000..cf4dc72d8b --- /dev/null +++ b/ui/packages/consul-acls/vendor/consul-acls/routes.js @@ -0,0 +1,18 @@ +(routes => routes({ + dc: { + acls: { + tokens: { + _options: { + abilities: ['read tokens'], + }, + }, + }, + }, +}))( + (json, data = document.currentScript.dataset) => { + const appNameJS = data.appName.split('-') + .map((item, i) => i ? `${item.substr(0, 1).toUpperCase()}${item.substr(1)}` : item) + .join(''); + data[`${appNameJS}Routes`] = JSON.stringify(json); + } +); diff --git a/ui/packages/consul-partitions/app/components/consul/partition/form/README.mdx b/ui/packages/consul-partitions/app/components/consul/partition/form/README.mdx new file mode 100644 index 0000000000..6f72a5cdef --- /dev/null +++ b/ui/packages/consul-partitions/app/components/consul/partition/form/README.mdx @@ -0,0 +1,24 @@ +# Consul::Partition::Form + +```hbs preview-template + + + + + +``` diff --git a/ui/packages/consul-partitions/app/components/consul/partition/form/index.hbs b/ui/packages/consul-partitions/app/components/consul/partition/form/index.hbs new file mode 100644 index 0000000000..7795f03c1f --- /dev/null +++ b/ui/packages/consul-partitions/app/components/consul/partition/form/index.hbs @@ -0,0 +1,126 @@ +
+ + + + +{{#let + + @item + + (hash + help='Must be a valid DNS hostname. Must contain 1-64 characters (numbers, letters, and hyphens), and must begin with a letter. Once created, this cannot be changed.' + Name=(array + (hash + test='^[a-zA-Z0-9]([a-zA-Z0-9-]{0,62}[a-zA-Z0-9])?$' + error='Name must be a valid DNS hostname.' + ) + ) + ) + + (hash + Description=(array) + ) + +as |item Name Description|}} + +
+ + + +
+ {{#if (is "new partition" item=item)}} + +{{/if}} + +
+ +
+{{#if (and (is "new partition" item=item) (can "create partitions")) }} + +{{else if (can "write partition" item=item)}} + +{{/if}} + + + +{{#if (and (not (is "new partition" item=item)) (can "delete partition" item=item))}} + + + + + + + + +{{/if}} + +
+ +
+
+ +{{/let}} +
+
+
diff --git a/ui/packages/consul-partitions/app/components/consul/partition/list/README.mdx b/ui/packages/consul-partitions/app/components/consul/partition/list/README.mdx new file mode 100644 index 0000000000..326465ee90 --- /dev/null +++ b/ui/packages/consul-partitions/app/components/consul/partition/list/README.mdx @@ -0,0 +1,32 @@ +# Consul::Partition::List + +A presentational component for rendering Consul Partitions + +Please note: + +- For the moment, make sure you have enabled partitions using developer debug + cookies. + +```hbs preview-template + + + +``` + + +### Arguments + +| Argument/Attribute | Type | Default | Description | +| --- | --- | --- | --- | +| `items` | `array` | | An array of Partitions | +| `ondelete` | `function` | | An action to execute when the `Delete` action is clicked | + +### See + +- [Component Source Code](./index.js) +- [Template Source Code](./index.hbs) + +--- diff --git a/ui/packages/consul-partitions/app/components/consul/partition/list/index.hbs b/ui/packages/consul-partitions/app/components/consul/partition/list/index.hbs new file mode 100644 index 0000000000..1dcd6023e4 --- /dev/null +++ b/ui/packages/consul-partitions/app/components/consul/partition/list/index.hbs @@ -0,0 +1,63 @@ + + +{{#if item.DeletedAt}} +

+ Deleting {{item.Name}}... +

+{{else}} + {{item.Name}} +{{/if}} +
+ +{{#if item.Description}} +
+
Description
+
+ {{item.Description}} +
+
+{{/if}} +
+ +{{#if (not item.DeletedAt)}} + + + +{{#if (can "write partition" item=item)}} + Edit +{{else}} + View +{{/if}} + + + {{#if (can "delete partition" item=item)}} + + + Delete + + + + + Confirm delete + + +

+ Are you sure you want to delete this partition? +

+
+ + Delete + +
+
+
+ {{/if}} +
+{{/if}} +
+
diff --git a/ui/packages/consul-partitions/app/components/consul/partition/list/test-support.js b/ui/packages/consul-partitions/app/components/consul/partition/list/test-support.js new file mode 100644 index 0000000000..c6ec1c4521 --- /dev/null +++ b/ui/packages/consul-partitions/app/components/consul/partition/list/test-support.js @@ -0,0 +1,18 @@ +export const selectors = () => ({ + ['.consul-partition-list']: { + row: { + $: '[data-test-list-row]', + partition: 'a', + name: '[data-test-partition]', + description: '[data-test-description]' + } + } +}); +export const pageObject = (collection, clickable, attribute, text, actions) => () => { + return collection('.consul-partition-list [data-test-list-row]', { + partition: clickable('a'), + name: attribute('data-test-partition', '[data-test-partition]'), + description: text('[data-test-description]'), + ...actions(['edit', 'delete']), + }); +}; diff --git a/ui/packages/consul-partitions/app/components/consul/partition/notifications/README.mdx b/ui/packages/consul-partitions/app/components/consul/partition/notifications/README.mdx new file mode 100644 index 0000000000..e84187b9d0 --- /dev/null +++ b/ui/packages/consul-partitions/app/components/consul/partition/notifications/README.mdx @@ -0,0 +1,46 @@ +# Consul::Partition::Notifications + +A Notification component specifically for Partitions (at some point will be replaced with just using `ember-intl`/`t`. + +```hbs preview-template +
+
Provide a widget to change the @type
+ + +
+
+
Provide a widget to change the @status
+ + +
+
+
Show the notification text
+

+ +

+
+ +``` + + + +## See + +- [Template Source Code](./index.hbs) + +--- diff --git a/ui/packages/consul-partitions/app/components/consul/partition/notifications/index.hbs b/ui/packages/consul-partitions/app/components/consul/partition/notifications/index.hbs new file mode 100644 index 0000000000..14eb0c41a7 --- /dev/null +++ b/ui/packages/consul-partitions/app/components/consul/partition/notifications/index.hbs @@ -0,0 +1,24 @@ +{{#if (eq @type 'create')}} + {{#if (eq @status 'success') }} + Your partition has been added. + {{else}} + There was an error adding your partition. + {{/if}} +{{else if (eq @type 'update') }} + {{#if (eq @status 'success') }} + Your partition has been saved. + {{else}} + There was an error saving your partition. + {{/if}} +{{ else if (eq @type 'delete')}} + {{#if (eq @status 'success') }} + Your partition has been marked for deletion. + {{else}} + There was an error deleting your partition. + {{/if}} +{{/if}} +{{#let @error.errors.firstObject as |error|}} + {{#if error.detail }} +
{{concat '(' (if error.status (concat error.status ': ')) error.detail ')'}} + {{/if}} +{{/let}} diff --git a/ui/packages/consul-partitions/app/components/consul/partition/search-bar/README.mdx b/ui/packages/consul-partitions/app/components/consul/partition/search-bar/README.mdx new file mode 100644 index 0000000000..484b1116c8 --- /dev/null +++ b/ui/packages/consul-partitions/app/components/consul/partition/search-bar/README.mdx @@ -0,0 +1,30 @@ +# Consul::Partition::SearchBar + +Searchbar tailored for searching Partitions. Follows our more generic +'*::SearchBar' component interface. + +```hbs preview-template + +``` + +## See + +- [Template Source Code](./index.hbs) + +--- diff --git a/ui/packages/consul-partitions/app/components/consul/partition/search-bar/index.hbs b/ui/packages/consul-partitions/app/components/consul/partition/search-bar/index.hbs new file mode 100644 index 0000000000..1d2999c9b4 --- /dev/null +++ b/ui/packages/consul-partitions/app/components/consul/partition/search-bar/index.hbs @@ -0,0 +1,98 @@ + + <:status as |search|> + +{{#let + + (t (concat "components.consul.nspace.search-bar." search.status.key) + default=(array + (concat "common.search." search.status.key) + (concat "common.consul." search.status.key) + ) + ) + + (t (concat "components.consul.nspace.search-bar." search.status.value) + default=(array + (concat "common.search." search.status.value) + (concat "common.consul." search.status.value) + (concat "common.brand." search.status.value) + ) + ) + +as |key value|}} + +
+
{{key}}
+
{{value}}
+
+
+{{/let}} + + + <:search as |search|> + + + + + {{t "common.search.searchproperty"}} + + + + {{#let components.Optgroup components.Option as |Optgroup Option|}} + {{#each @filter.searchproperty.default as |prop|}} + + {{/each}} + {{/let}} + + + + + <:sort as |search|> + + + + {{#let (from-entries (array + (array "Name:asc" (t "common.sort.alpha.asc")) + (array "Name:desc" (t "common.sort.alpha.desc")) + )) + as |selectable| + }} + {{get selectable @sort.value}} + {{/let}} + + + + {{#let components.Optgroup components.Option as |Optgroup Option|}} + + + + + {{/let}} + + + +
\ No newline at end of file diff --git a/ui/packages/consul-partitions/app/components/consul/partition/selector/README.mdx b/ui/packages/consul-partitions/app/components/consul/partition/selector/README.mdx new file mode 100644 index 0000000000..f802edb1d9 --- /dev/null +++ b/ui/packages/consul-partitions/app/components/consul/partition/selector/README.mdx @@ -0,0 +1,40 @@ +# Consul::Partition::Selector + +A conditional, autoloading, menu component specifically for making it easy to select partitions. + +Please note: + +- Currently at least, you must add this inside of a `