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 `