2021-04-06 12:40:40 +00:00
|
|
|
<Route
|
|
|
|
@name={{routeName}}
|
|
|
|
as |route|>
|
ui: Make it hard to not URLEncode DataSource srcs/URIs (#11117)
Our DataSource came in very iteratively, when we first started using it we specifically tried not to use it for things that would require portions of the @src="" attribute to be URL encoded (so things like service names couldn't be used, but dc etc would be fine). We then gradually added an easy way to url encode the @src="" attributes with a uri helper and began to use the DataSource component more and more. This meant that some DataSource usage continued to be used without our uri helper.
Recently we hit #10901 which was a direct result of us not encoding @src values/URIs (I didn't realise this was one of the places that required URL encoding) and not going back over things to finish things off once we had implemented our uri helper, resulting in ~half of the codebase using it and ~half of it not.
Now that almost all of the UI uses our DataSource component, this PR makes it even harder to not use the uri helper, by wrapping the string that it requires in a private URI class/object, that is then expected/asserted within the DataSource component/service. This means that as a result of this PR you cannot pass a plain string to the DataSource component without seeing an error in your JS console, which in turn means you have to use the uri helper, and it's very very hard to not URL encode any dynamic/user provided values, which otherwise could lead to bugs/errors similar to the one mentioned above.
The error that you see when you don't use the uri helper is currently a 'soft' dev time only error, but like our other functionality that produces a soft error when you mistakenly pass an undefined value to a uri, at some point soon we will make these hard failing "do not do this" errors.
Both of these 'soft error' DX features have been used this to great effect to implement our Admin Partition feature and these kind of things will minimize the amount of these types of bugs moving forwards in a preventative rather than curative manner. Hopefully these are the some of the kinds of things that get added to our codebase that prevent a multitude of problems and therefore are often never noticed/appreciated.
Additionally here we moved the remaining non-uri using DataSources to use uri (that were now super easy to find), and also fixed up a place where I noticed (due to the soft errors) where we were sometimes passing undefined values to a uri call.
The work here also led me to find another couple of non-important 'bugs' that I've PRed already separately, one of which is yet to be merged (#11105), hence the currently failing tests here. I'll rebase that once that PR is in and the tests here should then pass 🤞
Lastly, I didn't go the whole hog here to make DataSink also be this strict with its uri usage, there is a tiny bit more work on DataSink as a result of recently work, so I may (or may not) make DataSink equally as strict as part of that work in a separate PR.
2021-09-30 14:54:46 +00:00
|
|
|
<DataLoader @src={{uri '/${partition}/${nspace}/${dc}/sessions/for-node/${node}'
|
2021-09-15 18:50:11 +00:00
|
|
|
(hash
|
|
|
|
partition=route.params.partition
|
|
|
|
nspace=route.params.nspace
|
|
|
|
dc=route.params.dc
|
|
|
|
node=route.params.name
|
|
|
|
)
|
|
|
|
}} as |api|>
|
|
|
|
|
|
|
|
<BlockSlot @name="error">
|
|
|
|
<AppError
|
|
|
|
@error={{api.error}}
|
|
|
|
@login={{route.model.app.login.open}}
|
|
|
|
/>
|
|
|
|
</BlockSlot>
|
|
|
|
|
|
|
|
<BlockSlot @name="loaded">
|
2021-12-01 11:33:33 +00:00
|
|
|
{{#let api.data as |items|}}
|
|
|
|
<div class="tab-section">
|
|
|
|
<DataWriter
|
|
|
|
@sink={{uri '/${partition}/${dc}/${nspace}/session/'
|
|
|
|
(hash
|
|
|
|
partition=route.params.partition
|
|
|
|
nspace=route.params.nspace
|
|
|
|
dc=route.params.dc
|
|
|
|
)
|
|
|
|
}}
|
|
|
|
@type="session"
|
|
|
|
@label="Lock Session"
|
|
|
|
@ondelete={{refresh-route}}
|
|
|
|
as |writer|>
|
|
|
|
|
|
|
|
<BlockSlot @name="removed" as |after|>
|
|
|
|
<Consul::LockSession::Notifications
|
|
|
|
{{notification
|
|
|
|
after=(action after)
|
|
|
|
}}
|
|
|
|
@type="remove"
|
|
|
|
/>
|
2021-04-06 12:40:40 +00:00
|
|
|
</BlockSlot>
|
2021-12-01 11:33:33 +00:00
|
|
|
|
|
|
|
<BlockSlot @name="error" as |after error|>
|
|
|
|
<Consul::LockSession::Notifications
|
|
|
|
{{notification
|
|
|
|
after=(action after)
|
|
|
|
}}
|
|
|
|
@type="remove"
|
|
|
|
@error={{error}}
|
|
|
|
/>
|
2021-04-06 12:40:40 +00:00
|
|
|
</BlockSlot>
|
2021-12-01 11:33:33 +00:00
|
|
|
|
|
|
|
<BlockSlot @name="content">
|
|
|
|
|
|
|
|
<DataCollection
|
|
|
|
@type="session"
|
|
|
|
@items={{items}}
|
|
|
|
as |collection|>
|
|
|
|
|
|
|
|
<collection.Collection>
|
|
|
|
<Consul::LockSession::List
|
|
|
|
@items={{collection.items}}
|
|
|
|
@ondelete={{writer.delete}}
|
|
|
|
/>
|
|
|
|
</collection.Collection>
|
|
|
|
|
|
|
|
<collection.Empty>
|
|
|
|
<EmptyState
|
|
|
|
@login={{route.model.app.login.open}}
|
|
|
|
>
|
2022-04-11 11:49:59 +00:00
|
|
|
<BlockSlot @name="header">
|
|
|
|
<h2>
|
|
|
|
{{t 'routes.dc.nodes.show.sessions.empty.header'
|
|
|
|
items=items.length
|
|
|
|
}}
|
|
|
|
</h2>
|
|
|
|
</BlockSlot>
|
|
|
|
<BlockSlot @name="body">
|
|
|
|
{{t 'routes.dc.nodes.show.sessions.empty.body'
|
2022-10-06 17:01:49 +00:00
|
|
|
canUseACLs=(can "use acls")
|
2022-04-11 11:49:59 +00:00
|
|
|
htmlSafe=true
|
|
|
|
}}
|
|
|
|
</BlockSlot>
|
2021-12-01 11:33:33 +00:00
|
|
|
|
|
|
|
<BlockSlot @name="actions">
|
2023-02-22 21:05:15 +00:00
|
|
|
<li>
|
|
|
|
<Hds::Link::Standalone
|
|
|
|
@text='Documentation on Lock Sessions'
|
2021-12-01 11:33:33 +00:00
|
|
|
@href="{{env 'CONSUL_DOCS_URL'}}/internals/sessions.html"
|
2023-02-22 21:05:15 +00:00
|
|
|
@icon='docs-link'
|
|
|
|
@iconPosition='trailing'
|
|
|
|
@size='small'
|
|
|
|
/>
|
2021-12-01 11:33:33 +00:00
|
|
|
</li>
|
2023-02-22 21:05:15 +00:00
|
|
|
<li>
|
|
|
|
<Hds::Link::Standalone
|
|
|
|
@text='Take the tutorial'
|
|
|
|
@href='{{env 'CONSUL_DOCS_LEARN_URL'}}/tutorials/consul/distributed-semaphore'
|
|
|
|
@icon='learn-link'
|
|
|
|
@iconPosition='trailing'
|
|
|
|
@size='small'
|
|
|
|
/>
|
2021-12-01 11:33:33 +00:00
|
|
|
</li>
|
|
|
|
</BlockSlot>
|
|
|
|
|
|
|
|
</EmptyState>
|
|
|
|
</collection.Empty>
|
|
|
|
|
|
|
|
</DataCollection>
|
|
|
|
|
2021-04-06 12:40:40 +00:00
|
|
|
</BlockSlot>
|
2021-12-01 11:33:33 +00:00
|
|
|
</DataWriter>
|
|
|
|
</div>
|
2021-09-15 18:50:11 +00:00
|
|
|
{{/let}}
|
|
|
|
</BlockSlot>
|
|
|
|
</DataLoader>
|
2021-04-06 12:40:40 +00:00
|
|
|
</Route>
|