@triptease/tt-navbar 0.0.18 → 0.0.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @triptease/tt-navbar v0.0.20
3
+ */
4
+
5
+ // src/urlMappings.ts
6
+ var urlMappings = {
7
+ "/paidsearch/$CLIENT_KEY/performance": "/channels",
8
+ "/meta/$CLIENT_KEY/performance": "/channels",
9
+ "/retargeting/$CLIENT_KEY/performance": "/channels",
10
+ "/messages/$CLIENT_KEY/messages": "/channels",
11
+ "/$CLIENT_KEY/email": "/channels",
12
+ "/pricematch/$CLIENT_KEY/performance": "/channels",
13
+ "/chat/insights/$CLIENT_KEY": "/channels"
14
+ };
15
+ export {
16
+ urlMappings
17
+ };
18
+ //# sourceMappingURL=urlMappings.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/urlMappings.ts"],
4
+ "sourcesContent": ["type UrlMapping = Record<string, string>;\n\nconst urlMappings: UrlMapping = {\n '/paidsearch/$CLIENT_KEY/performance': '/channels',\n '/meta/$CLIENT_KEY/performance': '/channels',\n '/retargeting/$CLIENT_KEY/performance': '/channels',\n '/messages/$CLIENT_KEY/messages': '/channels',\n '/$CLIENT_KEY/email': '/channels',\n '/pricematch/$CLIENT_KEY/performance': '/channels',\n '/chat/insights/$CLIENT_KEY': '/channels',\n};\n\nexport { urlMappings };\n"],
5
+ "mappings": ";;;;;AAEA,IAAM,cAA0B;AAAA,EAC9B,uCAAuC;AAAA,EACvC,iCAAiC;AAAA,EACjC,wCAAwC;AAAA,EACxC,kCAAkC;AAAA,EAClC,sBAAsB;AAAA,EACtB,uCAAuC;AAAA,EACvC,8BAA8B;AAChC;",
6
+ "names": []
7
+ }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Webcomponent tt-navbar following open-wc recommendations",
4
4
  "license": "MIT",
5
5
  "author": "tt-navbar",
6
- "version": "0.0.18",
6
+ "version": "0.0.20",
7
7
  "type": "module",
8
8
  "main": "dist/src/index.js",
9
9
  "module": "dist/src/index.js",
package/src/TtNavbar.ts CHANGED
@@ -16,6 +16,7 @@ import {
16
16
  } from '@triptease/icons';
17
17
  import { styles } from './styles.js';
18
18
  import { tripteaseLogo } from './triptease-logo.js';
19
+ import { urlMappings } from './urlMappings.js';
19
20
 
20
21
  export class TtNavbar extends LitElement {
21
22
  static styles = styles;
@@ -23,8 +24,11 @@ export class TtNavbar extends LitElement {
23
24
  @property({ type: Function })
24
25
  navigate: ((e: MouseEvent) => void) | undefined;
25
26
 
26
- @property({ type: String, attribute: 'base-url' })
27
- baseUrl?: string;
27
+ @property({ type: String, attribute: 'campaign-manager-url' })
28
+ campaignManagerUrl: string = 'https://app.campaign-manager.triptease.io';
29
+
30
+ @property({ type: String, attribute: 'platform-url' })
31
+ platformUrl?: string;
28
32
 
29
33
  @property({ type: String, attribute: 'client-key' })
30
34
  clientKey?: string;
@@ -68,18 +72,39 @@ export class TtNavbar extends LitElement {
68
72
  let bestMatch: HTMLAnchorElement | undefined;
69
73
  let bestMatchLength = 0;
70
74
 
71
- for (const link of this.allNavLinks) {
72
- link.classList.remove('current-page');
73
- if (link.hasAttribute('aria-current')) {
74
- link.attributes.removeNamedItem('aria-current');
75
+ // Check special cases first, as everything will always match on / and return Dashboard
76
+
77
+ if (this.campaignManagerUrl.includes(window.location.host)) {
78
+ const links = Object.values(this.allNavLinks);
79
+ bestMatch = links.find(link =>
80
+ link.href.includes(this.campaignManagerUrl),
81
+ );
82
+ }
83
+
84
+ if (!bestMatch && this.clientKey) {
85
+ const parsedPath = currentPath.replace(this.clientKey, '$CLIENT_KEY');
86
+ const mappedUrl = urlMappings[parsedPath];
87
+
88
+ if (mappedUrl) {
89
+ const links = Object.values(this.allNavLinks);
90
+ bestMatch = links.find(link => link.href.includes(mappedUrl));
75
91
  }
92
+ }
93
+
94
+ if (!bestMatch) {
95
+ for (const link of this.allNavLinks) {
96
+ link.classList.remove('current-page');
97
+ if (link.hasAttribute('aria-current')) {
98
+ link.attributes.removeNamedItem('aria-current');
99
+ }
76
100
 
77
- const linkPath = new URL(link.href).pathname;
101
+ const linkPath = new URL(link.href).pathname;
78
102
 
79
- if (currentPath.startsWith(linkPath)) {
80
- if (linkPath.length > bestMatchLength) {
81
- bestMatch = link;
82
- bestMatchLength = linkPath.length;
103
+ if (currentPath.startsWith(linkPath)) {
104
+ if (linkPath.length > bestMatchLength) {
105
+ bestMatch = link;
106
+ bestMatchLength = linkPath.length;
107
+ }
83
108
  }
84
109
  }
85
110
  }
@@ -87,6 +112,8 @@ export class TtNavbar extends LitElement {
87
112
  if (bestMatch) {
88
113
  bestMatch.classList.add('current-page');
89
114
  bestMatch.setAttribute('aria-current', 'page');
115
+ } else {
116
+ console.error(`No matching nav link found for path: ${currentPath}`);
90
117
  }
91
118
  };
92
119
 
@@ -122,14 +149,15 @@ export class TtNavbar extends LitElement {
122
149
  if (!this.clientKey) throw new Error('clientKey is required');
123
150
 
124
151
  const formattedPath = path.replace('$CLIENT_KEY', this.clientKey);
125
- if (!this.baseUrl) return formattedPath;
152
+ if (!this.platformUrl) return formattedPath;
126
153
 
127
- return new URL(formattedPath, this.baseUrl).toString();
154
+ return new URL(formattedPath, this.platformUrl).toString();
128
155
  };
129
156
 
130
157
  private onAnchorClick = (e: MouseEvent) => {
131
158
  if (this.navigate) {
132
159
  this.navigate(e);
160
+ this.setActiveState();
133
161
  }
134
162
  };
135
163
 
@@ -156,7 +184,7 @@ export class TtNavbar extends LitElement {
156
184
  @click=${this.onAnchorClick}
157
185
  >${unsafeSVG(home)}<span>Dashboard</span></a
158
186
  >
159
- <a class="nav-item" href="https://app.campaign-manager.triptease.io"
187
+ <a class="nav-item" href=${this.campaignManagerUrl}
160
188
  >${unsafeSVG(campaigns)}<span>Campaigns</span></a
161
189
  >
162
190
  <a
@@ -0,0 +1,13 @@
1
+ type UrlMapping = Record<string, string>;
2
+
3
+ const urlMappings: UrlMapping = {
4
+ '/paidsearch/$CLIENT_KEY/performance': '/channels',
5
+ '/meta/$CLIENT_KEY/performance': '/channels',
6
+ '/retargeting/$CLIENT_KEY/performance': '/channels',
7
+ '/messages/$CLIENT_KEY/messages': '/channels',
8
+ '/$CLIENT_KEY/email': '/channels',
9
+ '/pricematch/$CLIENT_KEY/performance': '/channels',
10
+ '/chat/insights/$CLIENT_KEY': '/channels',
11
+ };
12
+
13
+ export { urlMappings };
@@ -8,7 +8,10 @@ export default {
8
8
 
9
9
  const Template = () => html`
10
10
  <div>
11
- <tt-navbar client-key="zxd47KQGAP">
11
+ <tt-navbar
12
+ client-key="zxd47KQGAP"
13
+ campaign-manager-url="https://app.campaign-manager.triptease.io"
14
+ >
12
15
  <div slot="clientSelector">
13
16
  <p>My Cool Client Selector</p>
14
17
  </div>
@@ -74,17 +74,17 @@ describe('TtNavbar', () => {
74
74
  });
75
75
 
76
76
  it('should render platform URLs against the base URL when it is defined', async () => {
77
- const baseUrl = 'https://app.triptease.io';
77
+ const platformUrl = 'https://app.triptease.io';
78
78
  const navbar = await fixture<TtNavbar>(
79
- `<tt-navbar client-key=${CLIENT_KEY} base-url="${baseUrl}"></tt-navbar>`,
79
+ `<tt-navbar client-key=${CLIENT_KEY} platform-url="${platformUrl}"></tt-navbar>`,
80
80
  );
81
81
  const links = navbar.shadowRoot?.querySelectorAll('a');
82
82
 
83
83
  if (links) {
84
- expect(getLinkByHref(links, `${baseUrl}/`)).to.exist;
84
+ expect(getLinkByHref(links, `${platformUrl}/`)).to.exist;
85
85
  expect(getLinkByHref(links, 'https://app.campaign-manager.triptease.io'))
86
86
  .to.exist; // This shouldn't change
87
- expect(getLinkByHref(links, `${baseUrl}/channels`)).to.exist;
87
+ expect(getLinkByHref(links, `${platformUrl}/channels`)).to.exist;
88
88
  }
89
89
  });
90
90
 
@@ -241,6 +241,9 @@ describe('TtNavbar', () => {
241
241
  [`/parity/${CLIENT_KEY}`, 'Parity'],
242
242
  [`/parity/${CLIENT_KEY}`, 'Parity'],
243
243
  [`/parity/${CLIENT_KEY}/foo`, 'Parity'],
244
+ [`/meta/${CLIENT_KEY}/performance`, 'Channels'],
245
+ [`/chat/insights/${CLIENT_KEY}`, 'Channels'],
246
+ [`/${CLIENT_KEY}/email`, 'Channels'],
244
247
  ];
245
248
 
246
249
  URLs.forEach(([route, text]) => {
@@ -258,4 +261,16 @@ describe('TtNavbar', () => {
258
261
  expect(anchor!.textContent).to.include(text);
259
262
  });
260
263
  });
264
+
265
+ it('should show the current page as campaign manager when on the given campaign manager url', async () => {
266
+ const platformUrl = 'https://app.triptease.io';
267
+ const campaignManagerUrl = 'http://localhost:8000';
268
+
269
+ const navbar = await fixture<TtNavbar>(
270
+ `<tt-navbar client-key=${CLIENT_KEY} platform-url=${platformUrl} campaign-manager-url=${campaignManagerUrl}></tt-navbar>`,
271
+ );
272
+ const anchor = navbar.shadowRoot!.querySelector('a[aria-current="page"]');
273
+ expect(anchor).to.exist;
274
+ expect(anchor!.textContent).to.include('Campaigns');
275
+ });
261
276
  });