Skip to content

Commit 4e383f5

Browse files
feat(manager): adds 'if-messages' utility that only renders contents if messages exist (#1482)
* does it * Update if_messages.ts * address feedback and fix compilation * Update src/server_manager/web_app/ui_components/if_messages.ts Co-authored-by: Vinicius Fortuna <fortuna@users.noreply.github.com> * annotate converter string --------- Co-authored-by: Vinicius Fortuna <fortuna@users.noreply.github.com>
1 parent f5ac42c commit 4e383f5

File tree

5 files changed

+165
-16
lines changed

5 files changed

+165
-16
lines changed

package-lock.json

+107-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"jasmine": "^3.5.0",
2222
"prettier": "^2.4.1",
2323
"pretty-quick": "^3.1.1",
24-
"typescript": "^4"
24+
"typescript": "^4.9.5"
2525
},
2626
"engines": {
2727
"node": "18.x.x"

src/server_manager/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"google-auth-library": "^8.0.2",
5050
"intl-messageformat": "^7",
5151
"jsonic": "^0.3.1",
52+
"lit": "^3.1.1",
5253
"lit-element": "^2.3.1",
5354
"node-forge": "^1.3.1",
5455
"request": "^2.87.0",

src/server_manager/web_app/ui_components/app-root.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ import './outline-region-picker-step';
4242
import './outline-server-list';
4343
import './outline-tos-view';
4444

45+
import './if_messages';
46+
4547
import {AppLocalizeBehavior} from '@polymer/app-localize-behavior/app-localize-behavior';
4648
import {mixinBehaviors} from '@polymer/polymer/lib/legacy/class';
4749
import {html} from '@polymer/polymer/lib/utils/html-tag';
@@ -397,13 +399,14 @@ export class AppRoot extends polymerElementWithLocalize {
397399
398400
<!-- Links section -->
399401
<paper-listbox>
400-
<a
401-
class="manager-resources-link"
402-
hidden$="[[!showManagerResourcesLink]]"
403-
href="https://www.reddit.com/r/outlinevpn/wiki/index/">
404-
<span>[[localize('manager-resources')]]</span>
405-
<iron-icon icon="open-in-new" />
406-
</a>
402+
<if-messages message-ids="manager-resources" localize="[[localize]]">
403+
<a
404+
class="manager-resources-link"
405+
href="https://www.reddit.com/r/outlinevpn/wiki/index/">
406+
<span>[[localize('manager-resources')]]</span>
407+
<iron-icon icon="open-in-new" />
408+
</a>
409+
</if-messages>
407410
<span on-tap="maybeCloseDrawer"><a href="https://support.getoutline.org/s/article/Data-collection">[[localize('nav-data-collection')]]</a></span>
408411
<span on-tap="submitFeedbackTapped">[[localize('nav-feedback')]]</span>
409412
<span on-tap="maybeCloseDrawer"><a href="https://s3.amazonaws.com/outline-vpn/index.html#/en/support/">[[localize('nav-help')]]</a></span>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
Copyright 2024 The Outline Authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import {nothing, LitElement, html} from 'lit';
18+
import {customElement, property} from 'lit/decorators.js';
19+
20+
@customElement('if-messages')
21+
export class IfMessages extends LitElement {
22+
@property({
23+
type: Array,
24+
attribute: 'message-ids',
25+
converter: (value: string) => value.split(/,\s*/),
26+
})
27+
messageIDs: string[] = [];
28+
@property({type: Function, attribute: 'localize'}) localize: (
29+
msgId: string,
30+
...params: string[]
31+
) => string;
32+
33+
render() {
34+
if (
35+
this.messageIDs.some((id) => {
36+
const result = this.localize(id);
37+
38+
return result === id || result === undefined || result === '';
39+
})
40+
) {
41+
return nothing;
42+
}
43+
44+
return html`<slot></slot>`;
45+
}
46+
}

0 commit comments

Comments
 (0)