Skip to content

Commit

Permalink
feat(manager): adds 'if-messages' utility that only renders contents …
Browse files Browse the repository at this point in the history
…if messages exist (Jigsaw-Code#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>
  • Loading branch information
daniellacosse and fortuna committed Jan 25, 2024
1 parent f5ac42c commit 4e383f5
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 16 deletions.
115 changes: 107 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"jasmine": "^3.5.0",
"prettier": "^2.4.1",
"pretty-quick": "^3.1.1",
"typescript": "^4"
"typescript": "^4.9.5"
},
"engines": {
"node": "18.x.x"
Expand Down
1 change: 1 addition & 0 deletions src/server_manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"google-auth-library": "^8.0.2",
"intl-messageformat": "^7",
"jsonic": "^0.3.1",
"lit": "^3.1.1",
"lit-element": "^2.3.1",
"node-forge": "^1.3.1",
"request": "^2.87.0",
Expand Down
17 changes: 10 additions & 7 deletions src/server_manager/web_app/ui_components/app-root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import './outline-region-picker-step';
import './outline-server-list';
import './outline-tos-view';

import './if_messages';

import {AppLocalizeBehavior} from '@polymer/app-localize-behavior/app-localize-behavior';
import {mixinBehaviors} from '@polymer/polymer/lib/legacy/class';
import {html} from '@polymer/polymer/lib/utils/html-tag';
Expand Down Expand Up @@ -397,13 +399,14 @@ export class AppRoot extends polymerElementWithLocalize {
<!-- Links section -->
<paper-listbox>
<a
class="manager-resources-link"
hidden$="[[!showManagerResourcesLink]]"
href="https://www.reddit.com/r/outlinevpn/wiki/index/">
<span>[[localize('manager-resources')]]</span>
<iron-icon icon="open-in-new" />
</a>
<if-messages message-ids="manager-resources" localize="[[localize]]">
<a
class="manager-resources-link"
href="https://www.reddit.com/r/outlinevpn/wiki/index/">
<span>[[localize('manager-resources')]]</span>
<iron-icon icon="open-in-new" />
</a>
</if-messages>
<span on-tap="maybeCloseDrawer"><a href="https://support.getoutline.org/s/article/Data-collection">[[localize('nav-data-collection')]]</a></span>
<span on-tap="submitFeedbackTapped">[[localize('nav-feedback')]]</span>
<span on-tap="maybeCloseDrawer"><a href="https://s3.amazonaws.com/outline-vpn/index.html#/en/support/">[[localize('nav-help')]]</a></span>
Expand Down
46 changes: 46 additions & 0 deletions src/server_manager/web_app/ui_components/if_messages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Copyright 2024 The Outline Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import {nothing, LitElement, html} from 'lit';
import {customElement, property} from 'lit/decorators.js';

@customElement('if-messages')
export class IfMessages extends LitElement {
@property({
type: Array,
attribute: 'message-ids',
converter: (value: string) => value.split(/,\s*/),
})
messageIDs: string[] = [];
@property({type: Function, attribute: 'localize'}) localize: (
msgId: string,
...params: string[]
) => string;

render() {
if (
this.messageIDs.some((id) => {
const result = this.localize(id);

return result === id || result === undefined || result === '';
})
) {
return nothing;
}

return html`<slot></slot>`;
}
}

0 comments on commit 4e383f5

Please sign in to comment.