fsanyoto commited on
Commit
3c757f7
·
verified ·
1 Parent(s): 09f45d8

Prune files not in the deploy set (stale build context)

Browse files
web/src/apps/AmazonAppStrip.tsx DELETED
@@ -1,109 +0,0 @@
1
- import { useEffect, useRef, useState } from "react";
2
- import { API_V1, CREDENTIALS, UNAUTHORIZED_EVENT, checkTenant, currentTenant, signal } from "../apiContract";
3
- import { fetchWithDeadline } from "../net/deadline";
4
- import { AppMark } from "./templateMarks";
5
- import "../styles/sdlc81/amazon-app-strip.css";
6
-
7
- interface StripApplication { id: string; templateConnector?: string }
8
- type AmazonAppStripProps = { appId: string; application?: StripApplication }
9
- | { appId?: never; application: StripApplication };
10
- interface AmazonApplication {
11
- id: string;
12
- name: string;
13
- templateKind?: string;
14
- templateConnector: "amazon" | "amazon_ads";
15
- }
16
-
17
- function amazonApplications(body: unknown): AmazonApplication[] {
18
- if (!body || typeof body !== "object" || !("applications" in body)
19
- || !Array.isArray(body.applications)) throw new Error("application_list_invalid");
20
- const seen = new Set<string>();
21
- return body.applications.filter((row): row is AmazonApplication => {
22
- if (!row || typeof row !== "object" || typeof row.id !== "string" || !row.id
23
- || typeof row.name !== "string" || !row.name.trim() || seen.has(row.id)
24
- || (row.templateConnector !== "amazon" && row.templateConnector !== "amazon_ads")
25
- || row.capabilities?.read === false) return false;
26
- seen.add(row.id);
27
- return true;
28
- });
29
- }
30
-
31
- /** C9: the grant-filtered nav is the only source of sibling Apps. */
32
- export function AmazonAppStrip({ appId, application }: AmazonAppStripProps) {
33
- const id = appId ?? application.id;
34
- const tenant = currentTenant();
35
- const enabled = !application?.templateConnector
36
- || application.templateConnector === "amazon" || application.templateConnector === "amazon_ads";
37
- const [revision, setRevision] = useState(0);
38
- const scope = JSON.stringify([tenant, id, enabled, revision]);
39
- const wanted = useRef(scope);
40
- wanted.current = scope;
41
- const [result, setResult] = useState<{ scope: string; applications: AmazonApplication[] } | null>(null);
42
- const [focused, setFocused] = useState<{ scope: string; id: string } | null>(null);
43
-
44
- useEffect(() => {
45
- const controller = new AbortController();
46
- const isCurrent = () => !controller.signal.aborted && wanted.current === scope
47
- && currentTenant() === tenant;
48
- const clear = () => {
49
- controller.abort();
50
- setResult(null);
51
- };
52
- const refresh = () => {
53
- clear();
54
- setRevision(value => value + 1);
55
- };
56
- setResult(null);
57
- window.addEventListener(UNAUTHORIZED_EVENT, clear);
58
- window.addEventListener("aios:signed-out", clear);
59
- window.addEventListener("aios:applications-changed", refresh);
60
- if (enabled && id) void fetchWithDeadline(`${API_V1}/nav/applications`, {
61
- method: "GET", credentials: CREDENTIALS, signal: controller.signal, cache: "no-store",
62
- }, async response => {
63
- if (!isCurrent()) throw new Error("application_list_stale");
64
- if (checkTenant(response)) throw new Error("application_list_scope_changed");
65
- if (tenant === null && currentTenant() !== null) {
66
- setRevision(value => value + 1);
67
- throw new Error("application_list_scope_bound");
68
- }
69
- if (response.status === 401) signal(UNAUTHORIZED_EVENT);
70
- if (!response.ok) throw new Error("application_list_failed");
71
- return amazonApplications(await response.json());
72
- }).then(({ body }) => {
73
- if (isCurrent()) setResult({ scope, applications: body });
74
- }).catch(() => {
75
- if (isCurrent()) setResult(null);
76
- });
77
- return () => {
78
- controller.abort();
79
- window.removeEventListener(UNAUTHORIZED_EVENT, clear);
80
- window.removeEventListener("aios:signed-out", clear);
81
- window.removeEventListener("aios:applications-changed", refresh);
82
- };
83
- }, [scope, id, tenant, enabled]);
84
-
85
- const applications = result?.scope === scope ? result.applications : [];
86
- if (applications.length < 2 || !applications.some(app => app.id === id)) return null;
87
- const focusId = focused?.scope === scope && applications.some(app => app.id === focused.id) ? focused.id : id;
88
- return <nav className="amazon-app-strip" role="tablist" aria-label="Amazon Apps" onKeyDown={event => {
89
- if (event.altKey || event.ctrlKey || event.metaKey) return;
90
- const tabs = Array.from(event.currentTarget.querySelectorAll<HTMLAnchorElement>("a[role='tab']"));
91
- const current = tabs.indexOf(event.target as HTMLAnchorElement);
92
- if (current < 0) return;
93
- const next = event.key === "Home" ? 0 : event.key === "End" ? tabs.length - 1
94
- : event.key === "ArrowRight" ? (current + 1) % tabs.length
95
- : event.key === "ArrowLeft" ? (current + tabs.length - 1) % tabs.length : -1;
96
- if (next < 0) return;
97
- event.preventDefault();
98
- tabs[next].focus();
99
- tabs[next].scrollIntoView({ block: "nearest", inline: "nearest" });
100
- }}>
101
- {applications.map(app => <a key={app.id} className="amazon-app-strip-tab" role="tab"
102
- href={`#/app/template/${encodeURIComponent(app.id)}`} aria-selected={app.id === id}
103
- aria-current={app.id === id ? "page" : undefined} tabIndex={app.id === focusId ? 0 : -1}
104
- onFocus={() => setFocused({ scope, id: app.id })}>
105
- <AppMark mark={app.templateKind} connector={app.templateConnector} size={20} />
106
- <span>{app.name}</span>
107
- </a>)}
108
- </nav>;
109
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
web/src/styles/sdlc81/amazon-app-strip.css DELETED
@@ -1,85 +0,0 @@
1
- .amazon-app-strip {
2
- display: flex;
3
- flex: 0 0 auto;
4
- align-items: stretch;
5
- gap: 24px;
6
- min-width: 0;
7
- max-width: 100%;
8
- margin-bottom: 12px;
9
- padding: 4px 4px 0;
10
- overflow-x: auto;
11
- border-bottom: 1px solid var(--lp-line);
12
- scrollbar-width: thin;
13
- scrollbar-color: var(--lp-scroll-thumb) transparent;
14
- }
15
-
16
- .amazon-app-strip-tab {
17
- display: inline-flex;
18
- flex: 0 0 auto;
19
- align-items: center;
20
- gap: 8px;
21
- min-height: 40px;
22
- box-sizing: border-box;
23
- padding: 4px 0 8px;
24
- border-bottom: 2px solid transparent;
25
- border-radius: 0;
26
- color: var(--lp-muted);
27
- font-family: inherit;
28
- font-size: var(--lp-fs-sm);
29
- line-height: var(--lp-lh);
30
- font-weight: 400;
31
- text-decoration: none;
32
- white-space: nowrap;
33
- }
34
-
35
- .amazon-app-strip-tab[aria-selected="true"] {
36
- border-bottom-color: var(--lp-blue-solid);
37
- color: var(--lp-ink);
38
- font-weight: 600;
39
- }
40
-
41
- .amazon-app-strip-tab:focus-visible {
42
- outline: 2px solid var(--lp-blue-deep);
43
- outline-offset: -2px;
44
- border-radius: var(--lp-r-sm);
45
- }
46
-
47
- @media (hover: hover) and (pointer: fine) {
48
- .amazon-app-strip-tab:hover { color: var(--lp-ink); }
49
- }
50
-
51
- /* The grid host gives the strip its own row above the header and toolbar. */
52
- .cg-main:has(> .cg-grid-box > .cg-app-frame-catalog > .amazon-app-strip) {
53
- grid-template-rows: auto auto minmax(0, 1fr) auto;
54
- }
55
- .cg-main > .cg-grid-box > .cg-app-frame-catalog > .amazon-app-strip {
56
- grid-area: 1 / 1 / 2 / -1;
57
- }
58
- .cg-main > .cg-grid-box > .cg-app-frame-catalog:has(> .amazon-app-strip) > .cg-app-frame-header {
59
- grid-area: 2 / 1;
60
- }
61
- .cg-main:has(> .cg-grid-box > .cg-app-frame-catalog > .amazon-app-strip) > .cg-relpin-bar > .cg-toolbar {
62
- grid-area: 2 / 2;
63
- }
64
- .cg-main > .cg-grid-box > .cg-app-frame-catalog:has(> .amazon-app-strip) > :not(.cg-app-frame-header, .amazon-app-strip) {
65
- grid-area: 3 / 1 / 4 / -1;
66
- }
67
- .cg-main:has(> .cg-grid-box > .cg-app-frame-catalog > .amazon-app-strip) > .cg-grid-footer {
68
- grid-area: 4 / 1 / 5 / -1;
69
- }
70
-
71
- @media (max-width: 760px) {
72
- .amazon-app-strip { gap: 16px; }
73
- .cg-main:has(> .cg-grid-box > .cg-app-frame-catalog > .amazon-app-strip) {
74
- grid-template-rows: auto auto auto minmax(0, 1fr) auto;
75
- }
76
- .cg-main:has(> .cg-grid-box > .cg-app-frame-catalog > .amazon-app-strip) > .cg-relpin-bar > .cg-toolbar {
77
- grid-area: 3 / 1;
78
- }
79
- .cg-main > .cg-grid-box > .cg-app-frame-catalog:has(> .amazon-app-strip) > :not(.cg-app-frame-header, .amazon-app-strip) {
80
- grid-area: 4 / 1;
81
- }
82
- .cg-main:has(> .cg-grid-box > .cg-app-frame-catalog > .amazon-app-strip) > .cg-grid-footer {
83
- grid-area: 5 / 1;
84
- }
85
- }