@canonical/summon-application 0.47.0 → 0.49.0-experimental.0
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.
- package/README.md +35 -4
- package/dist/esm/application/react/index.js +28 -1
- package/dist/esm/application/react/index.js.map +1 -1
- package/dist/esm/application/react/templates/README.md.ejs +5 -0
- package/dist/esm/application/react/templates/src/domains/catalog/ProductCard.tsx.ejs +2 -2
- package/dist/esm/application/react/templates/src/domains/dashboard/InstancesPage.tsx.ejs +1 -1
- package/dist/esm/application/react/templates/src/domains/dashboard/OverviewPage.tsx.ejs +6 -6
- package/dist/esm/application/react/templates/src/i18n/ar.ts.ejs +1 -0
- package/dist/esm/application/react/templates/src/i18n/config.ts +2 -2
- package/dist/esm/application/react/templates/src/i18n/en.ts.ejs +1 -0
- package/dist/esm/application/react/templates/src/i18n/fr.ts.ejs +1 -0
- package/dist/esm/application/react/templates/src/i18n/negotiation.test.ts +5 -5
- package/dist/esm/application/react/templates/src/lib/LocaleSelector/LocaleSelector.test.tsx +10 -0
- package/dist/esm/application/react/templates/src/lib/LocaleSelector/LocaleSelector.tsx.ejs +35 -21
- package/dist/esm/application/react/templates/src/lib/ThemeSelector/ServerThemeContext.ts +13 -0
- package/dist/esm/application/react/templates/src/lib/ThemeSelector/ThemeSelector.ssr.test.tsx.ejs +45 -0
- package/dist/esm/application/react/templates/src/lib/ThemeSelector/ThemeSelector.test.tsx.ejs +67 -0
- package/dist/esm/application/react/templates/src/lib/ThemeSelector/ThemeSelector.tsx.ejs +60 -26
- package/dist/esm/application/react/templates/src/lib/ThemeSelector/index.ts.ejs +4 -0
- package/dist/esm/application/react/templates/src/lib/TopBar/TopBar.test.tsx.ejs +7 -10
- package/dist/esm/application/react/templates/src/lib/TopBar/styles.css +8 -3
- package/dist/esm/application/react/templates/src/server/entry.tsx.ejs +23 -14
- package/dist/esm/application/react/templates/src/server/handlePreferenceForm.test.ts.ejs +63 -0
- package/dist/esm/application/react/templates/src/server/handlePreferenceForm.ts.ejs +158 -0
- package/dist/esm/application/react/templates/src/server/preferenceFormMiddleware.ts +42 -0
- package/dist/esm/application/react/templates/src/server/preview.bun.ts +5 -0
- package/dist/esm/application/react/templates/src/server/preview.express.ts +4 -0
- package/dist/esm/application/react/templates/src/server/resolveReturnTo.ts +18 -0
- package/dist/esm/application/react/templates/src/server/server.bun.ts.ejs +5 -0
- package/dist/esm/application/react/templates/src/server/server.express.ts.ejs +4 -0
- package/dist/esm/application/react/templates/test/e2e/servers.e2e.ts.ejs +56 -0
- package/dist/esm/application/react/templates/vitest.config.ts +4 -0
- package/dist/esm/application/svelte/index.js +337 -0
- package/dist/esm/application/svelte/index.js.map +1 -0
- package/dist/esm/application/svelte/templates/.storybook/main.ts +3 -0
- package/dist/esm/application/svelte/templates/.storybook/preview.ts.ejs +21 -0
- package/dist/esm/application/svelte/templates/README.md.ejs +168 -0
- package/dist/esm/application/svelte/templates/biome.json.ejs +12 -0
- package/dist/esm/application/svelte/templates/gitignore.ejs +7 -0
- package/dist/esm/application/svelte/templates/package.json.ejs +76 -0
- package/dist/esm/application/svelte/templates/scripts/copy-icons.js +10 -0
- package/dist/esm/application/svelte/templates/src/app.d.ts.ejs +14 -0
- package/dist/esm/application/svelte/templates/src/app.html.ejs +19 -0
- package/dist/esm/application/svelte/templates/src/domains/account/AccountPage.svelte.ejs +18 -0
- package/dist/esm/application/svelte/templates/src/domains/account/LoginPage.svelte.ejs +32 -0
- package/dist/esm/application/svelte/templates/src/domains/account/getAuthRedirect.test.ts +18 -0
- package/dist/esm/application/svelte/templates/src/domains/account/getAuthRedirect.ts +18 -0
- package/dist/esm/application/svelte/templates/src/domains/account/guardAccount.ts +15 -0
- package/dist/esm/application/svelte/templates/src/domains/catalog/CatalogPage.svelte.ejs +35 -0
- package/dist/esm/application/svelte/templates/src/domains/catalog/ProductCard.svelte.ejs +51 -0
- package/dist/esm/application/svelte/templates/src/domains/catalog/ProductList.stories.svelte.ejs +110 -0
- package/dist/esm/application/svelte/templates/src/domains/catalog/ProductList.svelte.ejs +41 -0
- package/dist/esm/application/svelte/templates/src/domains/catalog/constants.ts +2 -0
- package/dist/esm/application/svelte/templates/src/domains/catalog/data.test.ts +19 -0
- package/dist/esm/application/svelte/templates/src/domains/catalog/data.ts +75 -0
- package/dist/esm/application/svelte/templates/src/domains/catalog/loadCatalog.ts +7 -0
- package/dist/esm/application/svelte/templates/src/domains/catalog/types.ts +25 -0
- package/dist/esm/application/svelte/templates/src/domains/contact/ContactPage.svelte.ejs +86 -0
- package/dist/esm/application/svelte/templates/src/domains/contact/types.ts.ejs +19 -0
- package/dist/esm/application/svelte/templates/src/domains/contact/validateContact.test.ts.ejs +31 -0
- package/dist/esm/application/svelte/templates/src/domains/contact/validateContact.ts.ejs +28 -0
- package/dist/esm/application/svelte/templates/src/domains/dashboard/DashboardBreadcrumbs.svelte.ejs +29 -0
- package/dist/esm/application/svelte/templates/src/domains/dashboard/DashboardLayout.svelte.ejs +35 -0
- package/dist/esm/application/svelte/templates/src/domains/dashboard/InstancesPage.svelte.ejs +245 -0
- package/dist/esm/application/svelte/templates/src/domains/dashboard/OverviewPage.svelte.ejs +180 -0
- package/dist/esm/application/svelte/templates/src/domains/dashboard/SettingsPage.svelte.ejs +103 -0
- package/dist/esm/application/svelte/templates/src/domains/dashboard/constants.ts.ejs +253 -0
- package/dist/esm/application/svelte/templates/src/domains/dashboard/createDashboardNavigation.ts.ejs +103 -0
- package/dist/esm/application/svelte/templates/src/domains/dashboard/createInstance.test.ts +22 -0
- package/dist/esm/application/svelte/templates/src/domains/dashboard/createInstance.ts +28 -0
- package/dist/esm/application/svelte/templates/src/domains/dashboard/projectBreadcrumbs.test.ts +78 -0
- package/dist/esm/application/svelte/templates/src/domains/dashboard/projectBreadcrumbs.ts +47 -0
- package/dist/esm/application/svelte/templates/src/domains/dashboard/selectRelativeTime.test.ts +19 -0
- package/dist/esm/application/svelte/templates/src/domains/dashboard/selectRelativeTime.ts +24 -0
- package/dist/esm/application/svelte/templates/src/domains/dashboard/styles.css +98 -0
- package/dist/esm/application/svelte/templates/src/domains/dashboard/types.ts.ejs +61 -0
- package/dist/esm/application/svelte/templates/src/domains/marketing/GuidePage.svelte.ejs +29 -0
- package/dist/esm/application/svelte/templates/src/domains/marketing/HomePage.svelte.ejs +47 -0
- package/dist/esm/application/svelte/templates/src/domains/marketing/isGuideSlug.ts +8 -0
- package/dist/esm/application/svelte/templates/src/formatDocumentTitle.ts.ejs +9 -0
- package/dist/esm/application/svelte/templates/src/hooks.server.ts.ejs +51 -0
- package/dist/esm/application/svelte/templates/src/i18n/ar.ts.ejs +174 -0
- package/dist/esm/application/svelte/templates/src/i18n/catalogs.ts +14 -0
- package/dist/esm/application/svelte/templates/src/i18n/config.ts +19 -0
- package/dist/esm/application/svelte/templates/src/i18n/en.ts.ejs +173 -0
- package/dist/esm/application/svelte/templates/src/i18n/fr.ts.ejs +171 -0
- package/dist/esm/application/svelte/templates/src/i18n/index.ts +45 -0
- package/dist/esm/application/svelte/templates/src/i18n/negotiation.test.ts +92 -0
- package/dist/esm/application/svelte/templates/src/layouts/ErrorPage.svelte.ejs +40 -0
- package/dist/esm/application/svelte/templates/src/layouts/PublicLayout.svelte +18 -0
- package/dist/esm/application/svelte/templates/src/layouts/RootLayout.svelte.ejs +43 -0
- package/dist/esm/application/svelte/templates/src/layouts/TopBarLayout.svelte +28 -0
- package/dist/esm/application/svelte/templates/src/lib/ApplicationShell/ApplicationShell.stories.svelte +87 -0
- package/dist/esm/application/svelte/templates/src/lib/ApplicationShell/ApplicationShell.svelte.ejs +60 -0
- package/dist/esm/application/svelte/templates/src/lib/ApplicationShell/index.ts +2 -0
- package/dist/esm/application/svelte/templates/src/lib/ApplicationShell/styles.css +43 -0
- package/dist/esm/application/svelte/templates/src/lib/ApplicationShell/types.ts +23 -0
- package/dist/esm/application/svelte/templates/src/lib/CanonicalLogo/CanonicalLogo.svelte.ejs +27 -0
- package/dist/esm/application/svelte/templates/src/lib/CanonicalLogo/index.ts +2 -0
- package/dist/esm/application/svelte/templates/src/lib/CanonicalLogo/styles.css +31 -0
- package/dist/esm/application/svelte/templates/src/lib/CanonicalLogo/types.ts +15 -0
- package/dist/esm/application/svelte/templates/src/lib/CodeMessage/CodeMessage.svelte +18 -0
- package/dist/esm/application/svelte/templates/src/lib/CodeMessage/index.ts +2 -0
- package/dist/esm/application/svelte/templates/src/lib/CodeMessage/types.ts +14 -0
- package/dist/esm/application/svelte/templates/src/lib/ExampleComponent/ExampleComponent.stories.svelte +15 -0
- package/dist/esm/application/svelte/templates/src/lib/ExampleComponent/ExampleComponent.svelte +17 -0
- package/dist/esm/application/svelte/templates/src/lib/ExampleComponent/index.ts +2 -0
- package/dist/esm/application/svelte/templates/src/lib/ExampleComponent/styles.css +17 -0
- package/dist/esm/application/svelte/templates/src/lib/ExampleComponent/types.ts +10 -0
- package/dist/esm/application/svelte/templates/src/lib/Icon/Icon.svelte +16 -0
- package/dist/esm/application/svelte/templates/src/lib/Icon/index.ts +2 -0
- package/dist/esm/application/svelte/templates/src/lib/Icon/types.ts +10 -0
- package/dist/esm/application/svelte/templates/src/lib/LazyComponent/LazyComponent.stories.svelte +19 -0
- package/dist/esm/application/svelte/templates/src/lib/LazyComponent/LazyComponent.svelte.ejs +29 -0
- package/dist/esm/application/svelte/templates/src/lib/LazyComponent/createDelayedData.ts.ejs +24 -0
- package/dist/esm/application/svelte/templates/src/lib/LazyComponent/index.ts +2 -0
- package/dist/esm/application/svelte/templates/src/lib/LazyComponent/types.ts.ejs +19 -0
- package/dist/esm/application/svelte/templates/src/lib/LocaleSelector/LocaleSelector.svelte.ejs +50 -0
- package/dist/esm/application/svelte/templates/src/lib/LocaleSelector/index.ts +2 -0
- package/dist/esm/application/svelte/templates/src/lib/LocaleSelector/types.ts +7 -0
- package/dist/esm/application/svelte/templates/src/lib/Navigation/Navigation.svelte.ejs +42 -0
- package/dist/esm/application/svelte/templates/src/lib/Navigation/index.ts +2 -0
- package/dist/esm/application/svelte/templates/src/lib/Navigation/types.ts +14 -0
- package/dist/esm/application/svelte/templates/src/lib/ThemeSelector/ThemeSelector.svelte.ejs +38 -0
- package/dist/esm/application/svelte/templates/src/lib/ThemeSelector/constants.ts +8 -0
- package/dist/esm/application/svelte/templates/src/lib/ThemeSelector/index.ts +5 -0
- package/dist/esm/application/svelte/templates/src/lib/ThemeSelector/readTheme.test.ts +13 -0
- package/dist/esm/application/svelte/templates/src/lib/ThemeSelector/readTheme.ts +15 -0
- package/dist/esm/application/svelte/templates/src/lib/ThemeSelector/setTheme.ts +27 -0
- package/dist/esm/application/svelte/templates/src/lib/ThemeSelector/types.ts +18 -0
- package/dist/esm/application/svelte/templates/src/lib/TopBar/TopBar.stories.svelte.ejs +24 -0
- package/dist/esm/application/svelte/templates/src/lib/TopBar/TopBar.svelte.ejs +32 -0
- package/dist/esm/application/svelte/templates/src/lib/TopBar/index.ts +2 -0
- package/dist/esm/application/svelte/templates/src/lib/TopBar/styles.css +54 -0
- package/dist/esm/application/svelte/templates/src/lib/TopBar/types.ts +15 -0
- package/dist/esm/application/svelte/templates/src/lib/index.ts.ejs +16 -0
- package/dist/esm/application/svelte/templates/src/params/guide.ts +5 -0
- package/dist/esm/application/svelte/templates/src/resolveReturnTo.test.ts +27 -0
- package/dist/esm/application/svelte/templates/src/resolveReturnTo.ts +13 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/(public)/+layout.svelte +8 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/(public)/+page.server.ts +6 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/(public)/+page.svelte +8 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/(public)/+page.ts +6 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/(public)/account/+page.svelte +5 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/(public)/account/+page.ts +4 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/(public)/catalog/+page.svelte +8 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/(public)/catalog/+page.ts +4 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/(public)/contact/+page.server.ts +25 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/(public)/contact/+page.svelte.ejs +30 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/(public)/guides/[slug=guide]/+page.svelte +6 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/(public)/login/+page.svelte +6 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/+layout.svelte +9 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/dashboard/+layout.svelte +9 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/dashboard/+page.svelte +5 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/dashboard/instances/+page.server.ts.ejs +28 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/dashboard/instances/+page.svelte.ejs +19 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/dashboard/settings/+page.server.ts +9 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/dashboard/settings/+page.svelte +5 -0
- package/dist/esm/application/svelte/templates/src/routes/+error.svelte +6 -0
- package/dist/esm/application/svelte/templates/src/routes/+layout.server.ts.ejs +8 -0
- package/dist/esm/application/svelte/templates/src/routes/+layout.svelte.ejs +21 -0
- package/dist/esm/application/svelte/templates/src/routes/+layout.ts.ejs +30 -0
- package/dist/esm/application/svelte/templates/src/routes/home/+page.ts +4 -0
- package/dist/esm/application/svelte/templates/src/routes/home/+server.ts +3 -0
- package/dist/esm/application/svelte/templates/src/routes/icons/[icon]/+server.ts +37 -0
- package/dist/esm/application/svelte/templates/src/routes/language/+server.ts +30 -0
- package/dist/esm/application/svelte/templates/src/routes/preferences/+server.ts +32 -0
- package/dist/esm/application/svelte/templates/src/routes/sitemap.xml/+server.ts.ejs +47 -0
- package/dist/esm/application/svelte/templates/src/storybook/I18nDecorator.svelte +28 -0
- package/dist/esm/application/svelte/templates/src/storybook/decorators.ts +12 -0
- package/dist/esm/application/svelte/templates/src/styles/app.css +38 -0
- package/dist/esm/application/svelte/templates/src/styles/index.css.ejs +25 -0
- package/dist/esm/application/svelte/templates/src/styles/standins/Card.css +198 -0
- package/dist/esm/application/svelte/templates/src/styles/standins/Icon.css +32 -0
- package/dist/esm/application/svelte/templates/src/styles/standins/InlineCode.css +30 -0
- package/dist/esm/application/svelte/templates/src/styles/standins/SidePanel.css +462 -0
- package/dist/esm/application/svelte/templates/src/styles/standins/Tile.css +108 -0
- package/dist/esm/application/svelte/templates/src/styles/standins/Timeline.css +171 -0
- package/dist/esm/application/svelte/templates/src/styles/standins.css.ejs +17 -0
- package/dist/esm/application/svelte/templates/svelte.config.js.ejs +17 -0
- package/dist/esm/application/svelte/templates/test/app.test.js.ejs +758 -0
- package/dist/esm/application/svelte/templates/test/spa.test.js.ejs +224 -0
- package/dist/esm/application/svelte/templates/tsconfig.json +15 -0
- package/dist/esm/application/svelte/templates/vite.config.ts +4 -0
- package/dist/esm/application/svelte/templates/vitest.config.ts +10 -0
- package/dist/esm/application/svelte/textHelpers.js +20 -0
- package/dist/esm/application/svelte/textHelpers.js.map +1 -0
- package/dist/esm/domain/index.js +39 -5
- package/dist/esm/domain/index.js.map +1 -1
- package/dist/esm/domain/templates/Page.svelte.ejs +2 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/page/index.js +44 -7
- package/dist/esm/page/index.js.map +1 -1
- package/dist/esm/page/templates/Page.svelte.ejs +2 -0
- package/dist/esm/shared/versions.js +10 -8
- package/dist/esm/shared/versions.js.map +1 -1
- package/dist/esm/wrapper/index.js +38 -5
- package/dist/esm/wrapper/index.js.map +1 -1
- package/dist/esm/wrapper/templates/Layout.svelte.ejs +5 -0
- package/dist/types/application/react/index.d.ts.map +1 -1
- package/dist/types/application/svelte/index.d.ts +12 -0
- package/dist/types/application/svelte/index.d.ts.map +1 -0
- package/dist/types/application/svelte/textHelpers.d.ts +21 -0
- package/dist/types/application/svelte/textHelpers.d.ts.map +1 -0
- package/dist/types/domain/index.d.ts +2 -1
- package/dist/types/domain/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/page/index.d.ts +1 -0
- package/dist/types/page/index.d.ts.map +1 -1
- package/dist/types/shared/versions.d.ts +11 -9
- package/dist/types/shared/versions.d.ts.map +1 -1
- package/dist/types/wrapper/index.d.ts +2 -1
- package/dist/types/wrapper/index.d.ts.map +1 -1
- package/package.json +8 -8
- package/dist/esm/application/react/templates/src/lib/ThemeSelector/index.ts +0 -1
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { Button } from "@canonical/svelte-ds-global";
|
|
3
|
+
import {
|
|
4
|
+
createFormState,
|
|
5
|
+
Field,
|
|
6
|
+
Form,
|
|
7
|
+
} from "@canonical/svelte-ds-global-form";
|
|
8
|
+
import type { Attachment } from "svelte/attachments";
|
|
9
|
+
import formatDocumentTitle from "../../formatDocumentTitle.js";
|
|
10
|
+
<% if (intl) { -%>
|
|
11
|
+
import { createAppTranslator, getLocaleSource } from "../../i18n/index.js";
|
|
12
|
+
<% } -%>
|
|
13
|
+
import type { ContactErrors, ContactValues } from "./types.js";
|
|
14
|
+
import { validateContact } from "./validateContact.js";
|
|
15
|
+
|
|
16
|
+
let {
|
|
17
|
+
form,
|
|
18
|
+
post,
|
|
19
|
+
onSubmit,
|
|
20
|
+
}: {
|
|
21
|
+
/** The action's answer to the last post: the values and their errors. */
|
|
22
|
+
form?: { values?: ContactValues; errors?: ContactErrors } | null;
|
|
23
|
+
/** Posts a valid form to the page's action in place, such as `enhance`. */
|
|
24
|
+
post?: Attachment<HTMLFormElement>;
|
|
25
|
+
/** Handles a valid submit instead of posting, where there is no action. */
|
|
26
|
+
onSubmit?: (values: ContactValues) => void;
|
|
27
|
+
} = $props();
|
|
28
|
+
<% if (intl) { -%>
|
|
29
|
+
|
|
30
|
+
const locale = getLocaleSource();
|
|
31
|
+
const t = $derived(createAppTranslator($locale));
|
|
32
|
+
<% } -%>
|
|
33
|
+
const subjects = $derived([
|
|
34
|
+
{ value: "general", label: <%- str("contact.subjectGeneral", "General enquiry") %> },
|
|
35
|
+
{ value: "support", label: <%- str("contact.subjectSupport", "Support") %> },
|
|
36
|
+
{ value: "feedback", label: <%- str("contact.subjectFeedback", "Feedback") %> },
|
|
37
|
+
]);
|
|
38
|
+
|
|
39
|
+
// Each answer of the action seeds a fresh owner, so the server's values and
|
|
40
|
+
// errors show with JavaScript or without it. The owner validates with the
|
|
41
|
+
// action's own rules before the form posts.
|
|
42
|
+
const owner = $derived(
|
|
43
|
+
createFormState<ContactValues>({
|
|
44
|
+
defaultValues: form?.values ?? {
|
|
45
|
+
name: "",
|
|
46
|
+
email: "",
|
|
47
|
+
subject: "general",
|
|
48
|
+
message: "",
|
|
49
|
+
},
|
|
50
|
+
errors: form?.errors,
|
|
51
|
+
validate: validateContact,
|
|
52
|
+
onSubmit,
|
|
53
|
+
}),
|
|
54
|
+
);
|
|
55
|
+
<% if (intl) { -%>
|
|
56
|
+
|
|
57
|
+
/** Translates a field's error, which holds a catalog key. */
|
|
58
|
+
const translateError = (name: keyof ContactValues) => {
|
|
59
|
+
const key = (owner.errors as ContactErrors)[name];
|
|
60
|
+
return key ? t(key) : undefined;
|
|
61
|
+
};
|
|
62
|
+
<% } -%>
|
|
63
|
+
</script>
|
|
64
|
+
|
|
65
|
+
<svelte:head><title>{formatDocumentTitle(<%- str("contact.title", "Contact") %>)}</title></svelte:head>
|
|
66
|
+
|
|
67
|
+
<section aria-labelledby="contact-title">
|
|
68
|
+
<h1 id="contact-title"><%- msg("contact.heading", "Contact") %></h1>
|
|
69
|
+
<Form method="post" {owner} {@attach post}>
|
|
70
|
+
<Field inputType="text" label=<%- attr("contact.name", "Full name") %> name="name" />
|
|
71
|
+
<Field error=<%- intl ? '{translateError("email")}' : "{owner.errors.email}" %> inputType="text" label=<%- attr("contact.email", "Email address") %> name="email" />
|
|
72
|
+
<Field inputType="select" label=<%- attr("contact.subject", "Subject") %> name="subject" options={subjects} />
|
|
73
|
+
<Field description=<%- attr("contact.messageHint", "Maximum 500 characters") %> inputType="textarea" label=<%- attr("contact.message", "Message") %> name="message" />
|
|
74
|
+
<Button type="submit"><%- msg("contact.send", "Send message") %></Button>
|
|
75
|
+
</Form>
|
|
76
|
+
</section>
|
|
77
|
+
|
|
78
|
+
<!-- @component
|
|
79
|
+
The contact form. Its owner validates the email before the form posts, with
|
|
80
|
+
the rules the page's action uses, and is seeded from the action's answer, so
|
|
81
|
+
the action's values and errors show with JavaScript or without it. With `post`
|
|
82
|
+
(SvelteKit's `enhance`), a valid form posts to the action in place; with
|
|
83
|
+
`onSubmit`, a valid submit is handled instead of posted, as in the client-only
|
|
84
|
+
build, which has no action. Without JavaScript the form posts natively and the
|
|
85
|
+
action validates the same way.
|
|
86
|
+
-->
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<% if (intl) { -%>
|
|
2
|
+
import type { MessageKey } from "../../i18n/index.js";
|
|
3
|
+
|
|
4
|
+
<% } -%>
|
|
5
|
+
/** The contact form's fields, as posted. */
|
|
6
|
+
export type ContactValues = {
|
|
7
|
+
readonly name: string;
|
|
8
|
+
readonly email: string;
|
|
9
|
+
readonly subject: string;
|
|
10
|
+
readonly message: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
<% if (intl) { -%>
|
|
14
|
+
/** The catalog key of each invalid field's message. */
|
|
15
|
+
export type ContactErrors = Partial<Record<keyof ContactValues, MessageKey>>;
|
|
16
|
+
<% } else { -%>
|
|
17
|
+
/** Each invalid field's message. */
|
|
18
|
+
export type ContactErrors = Partial<Record<keyof ContactValues, string>>;
|
|
19
|
+
<% } -%>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { readContact, validateContact } from "./validateContact.js";
|
|
3
|
+
|
|
4
|
+
const formData = (entries: Record<string, string>) => {
|
|
5
|
+
const data = new FormData();
|
|
6
|
+
for (const [name, value] of Object.entries(entries)) data.set(name, value);
|
|
7
|
+
return data;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
describe("validateContact", () => {
|
|
11
|
+
it("requires the email", () => {
|
|
12
|
+
expect(validateContact(readContact(formData({ email: " " })))).toEqual({
|
|
13
|
+
email: <%- intl ? '"contact.emailRequired"' : '"Email is required"' %>,
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("accepts a form with an email", () => {
|
|
18
|
+
expect(
|
|
19
|
+
validateContact(readContact(formData({ email: "ada@example.com" }))),
|
|
20
|
+
).toEqual({});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("reads every field, empty when absent", () => {
|
|
24
|
+
expect(readContact(formData({ name: "Ada" }))).toEqual({
|
|
25
|
+
name: "Ada",
|
|
26
|
+
email: "",
|
|
27
|
+
subject: "",
|
|
28
|
+
message: "",
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ContactErrors, ContactValues } from "./types.js";
|
|
2
|
+
|
|
3
|
+
/** Reads the contact fields from a submitted form. */
|
|
4
|
+
export function readContact(formData: FormData): ContactValues {
|
|
5
|
+
const text = (name: keyof ContactValues) => {
|
|
6
|
+
const value = formData.get(name);
|
|
7
|
+
return typeof value === "string" ? value : "";
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
return {
|
|
11
|
+
name: text("name"),
|
|
12
|
+
email: text("email"),
|
|
13
|
+
subject: text("subject"),
|
|
14
|
+
message: text("message"),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
<% if (intl) { -%>
|
|
20
|
+
* Returns the catalog key of each invalid field: the email is required, as
|
|
21
|
+
<% } else { -%>
|
|
22
|
+
* Returns the message of each invalid field: the email is required, as
|
|
23
|
+
<% } -%>
|
|
24
|
+
* the only rule the form has.
|
|
25
|
+
*/
|
|
26
|
+
export function validateContact(values: ContactValues): ContactErrors {
|
|
27
|
+
return values.email.trim() ? {} : { email: <%- intl ? '"contact.emailRequired"' : '"Email is required"' %> };
|
|
28
|
+
}
|
package/dist/esm/application/svelte/templates/src/domains/dashboard/DashboardBreadcrumbs.svelte.ejs
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { Breadcrumbs } from "@canonical/svelte-ds-global";
|
|
3
|
+
import { page } from "$app/state";
|
|
4
|
+
<% if (intl) { -%>
|
|
5
|
+
import { createAppTranslator, getLocaleSource } from "../../i18n/index.js";
|
|
6
|
+
<% } -%>
|
|
7
|
+
import { LEGAL_URL, PROJECT_NAME } from "./constants.js";
|
|
8
|
+
import createDashboardNavigation from "./createDashboardNavigation.js";
|
|
9
|
+
import projectBreadcrumbs from "./projectBreadcrumbs.js";
|
|
10
|
+
|
|
11
|
+
<% if (intl) { -%>
|
|
12
|
+
const locale = getLocaleSource();
|
|
13
|
+
const t = $derived(createAppTranslator($locale));
|
|
14
|
+
const { root } = $derived(
|
|
15
|
+
createDashboardNavigation({ legalUrl: LEGAL_URL, t }),
|
|
16
|
+
);
|
|
17
|
+
<% } else { -%>
|
|
18
|
+
const { root } = $derived(createDashboardNavigation({ legalUrl: LEGAL_URL }));
|
|
19
|
+
<% } -%>
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<Breadcrumbs aria-label=<%- attr("dashboard.breadcrumbs", "Breadcrumb") %> items={[{ label: PROJECT_NAME, url: "/dashboard" }, ...projectBreadcrumbs(root, page.url.pathname)]} />
|
|
23
|
+
|
|
24
|
+
<!-- @component
|
|
25
|
+
The breadcrumb trail of the current dashboard page: the project, then the
|
|
26
|
+
page's path in the side navigation's tree. The trail is projected from the
|
|
27
|
+
same navigation items the side navigation renders, so a page never states its
|
|
28
|
+
own position and the two cannot disagree.
|
|
29
|
+
-->
|
package/dist/esm/application/svelte/templates/src/domains/dashboard/DashboardLayout.svelte.ejs
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
<% if (intl) { -%>
|
|
4
|
+
import { createAppTranslator, getLocaleSource } from "../../i18n/index.js";
|
|
5
|
+
<% } -%>
|
|
6
|
+
import { ApplicationShell } from "../../lib/index.js";
|
|
7
|
+
import { LEGAL_URL } from "./constants.js";
|
|
8
|
+
import createDashboardNavigation from "./createDashboardNavigation.js";
|
|
9
|
+
|
|
10
|
+
let {
|
|
11
|
+
currentUrl,
|
|
12
|
+
children,
|
|
13
|
+
}: {
|
|
14
|
+
/** The current page's pathname. */
|
|
15
|
+
currentUrl: string;
|
|
16
|
+
/** The dashboard page. */
|
|
17
|
+
children?: Snippet;
|
|
18
|
+
} = $props();
|
|
19
|
+
<% if (intl) { -%>
|
|
20
|
+
|
|
21
|
+
const locale = getLocaleSource();
|
|
22
|
+
const t = $derived(createAppTranslator($locale));
|
|
23
|
+
<% } -%>
|
|
24
|
+
const navigation = $derived(
|
|
25
|
+
createDashboardNavigation({ legalUrl: LEGAL_URL<%= intl ? ", t" : "" %> }),
|
|
26
|
+
);
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<ApplicationShell {currentUrl} footerRoot={navigation.footerRoot} label=<%- attr("dashboard.nav.label", "Dashboard") %> root={navigation.root}>{@render children?.()}</ApplicationShell>
|
|
30
|
+
|
|
31
|
+
<!-- @component
|
|
32
|
+
The frame of every dashboard page: the application shell, with the
|
|
33
|
+
dashboard's side navigation. The dashboard's route layout renders it beneath
|
|
34
|
+
the top bar.
|
|
35
|
+
-->
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { ContentLayout, ViewLayout } from "@canonical/svelte-ds-app";
|
|
3
|
+
import { Badge, Button } from "@canonical/svelte-ds-global";
|
|
4
|
+
<% if (forms) { -%>
|
|
5
|
+
import { Field, Form } from "@canonical/svelte-ds-global-form";
|
|
6
|
+
<% } -%>
|
|
7
|
+
import formatDocumentTitle from "../../formatDocumentTitle.js";
|
|
8
|
+
<% if (intl) { -%>
|
|
9
|
+
import {
|
|
10
|
+
createAppFormatters,
|
|
11
|
+
createAppTranslator,
|
|
12
|
+
getLocaleSource,
|
|
13
|
+
} from "../../i18n/index.js";
|
|
14
|
+
<% } -%>
|
|
15
|
+
<% if (forms) { -%>
|
|
16
|
+
import { Icon } from "../../lib/index.js";
|
|
17
|
+
<% } -%>
|
|
18
|
+
<% if (forms) { -%>
|
|
19
|
+
import {
|
|
20
|
+
CREATE_DEFAULTS,
|
|
21
|
+
INSTANCES,
|
|
22
|
+
RELEASE_OPTIONS,
|
|
23
|
+
<%= intl ? "STATUS_KEYS" : "STATUS_LABELS" %>,
|
|
24
|
+
} from "./constants.js";
|
|
25
|
+
import createInstance from "./createInstance.js";
|
|
26
|
+
<% } else { -%>
|
|
27
|
+
import { INSTANCES, <%= intl ? "STATUS_KEYS" : "STATUS_LABELS" %> } from "./constants.js";
|
|
28
|
+
<% } -%>
|
|
29
|
+
import DashboardBreadcrumbs from "./DashboardBreadcrumbs.svelte";
|
|
30
|
+
import type { Instance } from "./types.js";
|
|
31
|
+
import "./styles.css";
|
|
32
|
+
|
|
33
|
+
<% if (forms) { -%>
|
|
34
|
+
let {
|
|
35
|
+
created,
|
|
36
|
+
selected,
|
|
37
|
+
isCreating = false,
|
|
38
|
+
nameError,
|
|
39
|
+
}: {
|
|
40
|
+
/** An instance the create action added, when the form posted without JavaScript. */
|
|
41
|
+
created?: Instance;
|
|
42
|
+
/** The instance chosen through the `selected` query, without JavaScript. */
|
|
43
|
+
selected?: string;
|
|
44
|
+
/** Renders the create panel open, as `?create=1` asks without JavaScript. */
|
|
45
|
+
isCreating?: boolean;
|
|
46
|
+
/** The create action's error <%= intl ? "key" : "message" %> for the name, when it posted without one. */
|
|
47
|
+
nameError?: <%- intl ? '"dashboard.instances.nameRequired"' : "string" %>;
|
|
48
|
+
} = $props();
|
|
49
|
+
|
|
50
|
+
const panelId = $props.id();
|
|
51
|
+
const createFormId = "create-instance";
|
|
52
|
+
const openFormId = "open-create-instance";
|
|
53
|
+
<% } else { -%>
|
|
54
|
+
let {
|
|
55
|
+
selected,
|
|
56
|
+
}: {
|
|
57
|
+
/** The instance chosen through the `selected` query, without JavaScript. */
|
|
58
|
+
selected?: string;
|
|
59
|
+
} = $props();
|
|
60
|
+
|
|
61
|
+
<% } -%>
|
|
62
|
+
const selectFormId = "select-instance";
|
|
63
|
+
<% if (intl) { -%>
|
|
64
|
+
|
|
65
|
+
const locale = getLocaleSource();
|
|
66
|
+
const t = $derived(createAppTranslator($locale));
|
|
67
|
+
const formatters = $derived(createAppFormatters($locale));
|
|
68
|
+
<% } else { -%>
|
|
69
|
+
// The app has one language, so the formatter is fixed to it.
|
|
70
|
+
const number = new Intl.NumberFormat("en");
|
|
71
|
+
<% } -%>
|
|
72
|
+
<% if (forms) { -%>
|
|
73
|
+
// The props seed the client state: after hydration the page owns the list.
|
|
74
|
+
// svelte-ignore state_referenced_locally
|
|
75
|
+
let instances = $state<readonly Instance[]>(
|
|
76
|
+
created ? [...INSTANCES, created] : INSTANCES,
|
|
77
|
+
);
|
|
78
|
+
// svelte-ignore state_referenced_locally
|
|
79
|
+
let selectedName = $state<string | null>(created?.name ?? selected ?? null);
|
|
80
|
+
// svelte-ignore state_referenced_locally
|
|
81
|
+
let nameErrorKey = $state(nameError);
|
|
82
|
+
<% } else { -%>
|
|
83
|
+
const instances: readonly Instance[] = INSTANCES;
|
|
84
|
+
// The prop seeds the client state: after hydration the page owns the choice.
|
|
85
|
+
// svelte-ignore state_referenced_locally
|
|
86
|
+
let selectedName = $state<string | null>(selected ?? null);
|
|
87
|
+
<% } -%>
|
|
88
|
+
const selectedInstance = $derived(
|
|
89
|
+
instances.find((instance) => instance.name === selectedName),
|
|
90
|
+
);
|
|
91
|
+
<% if (forms) { -%>
|
|
92
|
+
let panelRef = $state<HTMLDialogElement>();
|
|
93
|
+
let openerElement: HTMLElement | null = null;
|
|
94
|
+
|
|
95
|
+
function openPanel(event: MouseEvent) {
|
|
96
|
+
event.preventDefault();
|
|
97
|
+
if (!panelRef || panelRef.open) return;
|
|
98
|
+
openerElement = event.currentTarget as HTMLElement;
|
|
99
|
+
panelRef.show();
|
|
100
|
+
panelRef.focus();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function closePanel(event?: Event) {
|
|
104
|
+
event?.preventDefault();
|
|
105
|
+
panelRef?.close();
|
|
106
|
+
openerElement?.focus();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function handlePanelKeydown(event: KeyboardEvent) {
|
|
110
|
+
if (event.key === "Escape") closePanel(event);
|
|
111
|
+
}
|
|
112
|
+
<% } -%>
|
|
113
|
+
|
|
114
|
+
function selectInstance(event: MouseEvent, name: string) {
|
|
115
|
+
event.preventDefault();
|
|
116
|
+
selectedName = name;
|
|
117
|
+
}
|
|
118
|
+
<% if (forms) { -%>
|
|
119
|
+
|
|
120
|
+
function handleCreate(event: SubmitEvent) {
|
|
121
|
+
event.preventDefault();
|
|
122
|
+
const form = event.currentTarget as HTMLFormElement;
|
|
123
|
+
const instance = createInstance(Object.fromEntries(new FormData(form)));
|
|
124
|
+
|
|
125
|
+
if (!instance) {
|
|
126
|
+
nameErrorKey = <%- intl ? '"dashboard.instances.nameRequired"' : '"Instance name is required"' %>;
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
nameErrorKey = undefined;
|
|
131
|
+
instances = [...instances, instance];
|
|
132
|
+
selectedName = instance.name;
|
|
133
|
+
closePanel();
|
|
134
|
+
}
|
|
135
|
+
<% } -%>
|
|
136
|
+
</script>
|
|
137
|
+
|
|
138
|
+
<svelte:head><title>{formatDocumentTitle(<%- str("dashboard.instances.title", "Instances") %>)}</title></svelte:head>
|
|
139
|
+
|
|
140
|
+
<% if (forms) { -%>
|
|
141
|
+
{#snippet plusIcon()}<Icon name="plus" />{/snippet}
|
|
142
|
+
{#snippet closeIcon()}<Icon name="close" />{/snippet}
|
|
143
|
+
|
|
144
|
+
<!-- Without JavaScript, Create instance asks for the page with the panel
|
|
145
|
+
open, and each Details button for the page with that instance chosen;
|
|
146
|
+
with JavaScript their click handlers do both in place. -->
|
|
147
|
+
<form action="" hidden id={openFormId}><input name="create" type="hidden" value="1" /></form>
|
|
148
|
+
<% } else { -%>
|
|
149
|
+
<!-- Without JavaScript, each Details button asks for the page with that
|
|
150
|
+
instance chosen; with JavaScript its click handler does it in place. -->
|
|
151
|
+
<% } -%>
|
|
152
|
+
<form action="" hidden id={selectFormId}></form>
|
|
153
|
+
|
|
154
|
+
<ViewLayout class="dashboard-view">
|
|
155
|
+
<ContentLayout>
|
|
156
|
+
<header class="titlebar">
|
|
157
|
+
<div>
|
|
158
|
+
<DashboardBreadcrumbs />
|
|
159
|
+
<h1><%- msg("dashboard.instances.heading", "Instances") %> <Badge value={instances.length} /></h1>
|
|
160
|
+
</div>
|
|
161
|
+
<% if (forms) { -%>
|
|
162
|
+
<div class="actions">
|
|
163
|
+
<Button aria-controls={panelId} form={openFormId} icon={plusIcon} importance="primary" onclick={openPanel} type="submit"><%- msg("dashboard.instances.create", "Create instance") %></Button>
|
|
164
|
+
</div>
|
|
165
|
+
<% } -%>
|
|
166
|
+
</header>
|
|
167
|
+
|
|
168
|
+
<section aria-label=<%- attr("dashboard.instances.heading", "Instances") %> class="section">
|
|
169
|
+
<ul class="tiles">
|
|
170
|
+
{#each instances as instance (instance.name)}
|
|
171
|
+
<li>
|
|
172
|
+
<div class="ds tile surface">
|
|
173
|
+
<div class="ds tile-header">{instance.name}</div>
|
|
174
|
+
<div class="ds tile-content">
|
|
175
|
+
<% if (intl) { -%>
|
|
176
|
+
<p class="muted">{t("dashboard.instances.summary", { status: t(STATUS_KEYS[instance.status]), release: instance.release })}</p>
|
|
177
|
+
<Button aria-label={t("dashboard.instances.show", { name: instance.name })} aria-pressed={instance.name === selectedName} form={selectFormId} importance="tertiary" name="selected" onclick={(event) => selectInstance(event, instance.name)} type="submit" value={instance.name}>{t("dashboard.instances.details")}</Button>
|
|
178
|
+
<% } else { -%>
|
|
179
|
+
<p class="muted">{STATUS_LABELS[instance.status]} · {instance.release}</p>
|
|
180
|
+
<Button aria-label={`Show details of ${instance.name}`} aria-pressed={instance.name === selectedName} form={selectFormId} importance="tertiary" name="selected" onclick={(event) => selectInstance(event, instance.name)} type="submit" value={instance.name}>Details</Button>
|
|
181
|
+
<% } -%>
|
|
182
|
+
</div>
|
|
183
|
+
</div>
|
|
184
|
+
</li>
|
|
185
|
+
{/each}
|
|
186
|
+
</ul>
|
|
187
|
+
</section>
|
|
188
|
+
</ContentLayout>
|
|
189
|
+
<% if (forms) { -%>
|
|
190
|
+
|
|
191
|
+
<!-- A stand-in for React's SidePanel: a non-modal dialog docked to the
|
|
192
|
+
inline-end edge, with the same markup classes. -->
|
|
193
|
+
<dialog aria-labelledby={`${panelId}-title`} bind:this={panelRef} class="ds side-panel" id={panelId} onkeydown={handlePanelKeydown} open={isCreating || undefined} tabindex="-1">
|
|
194
|
+
<div class="ds side-panel-header">
|
|
195
|
+
<span class="title p" id={`${panelId}-title`}><%- msg("dashboard.instances.create", "Create instance") %></span>
|
|
196
|
+
<Button aria-label=<%- attr("dashboard.instances.closePanel", "Close panel") %> class="close" command="close" commandfor={panelId} icon={closeIcon} importance="tertiary" onclick={closePanel} type="button" />
|
|
197
|
+
</div>
|
|
198
|
+
<!-- svelte-ignore a11y_no_noninteractive_tabindex: the pane scrolls, so it is a tab stop, as in React's SidePanel -->
|
|
199
|
+
<div class="ds side-panel-content" tabindex="0">
|
|
200
|
+
<Form action="?/create" id={createFormId} method="post" onsubmit={handleCreate}>
|
|
201
|
+
<Field error=<%- intl ? "{nameErrorKey ? t(nameErrorKey) : undefined}" : "{nameErrorKey}" %> inputType="text" label=<%- attr("dashboard.instances.name", "Instance name") %> name="instance_name" value={CREATE_DEFAULTS.instance_name} />
|
|
202
|
+
<Field inputType="select" label=<%- attr("dashboard.instances.release", "Ubuntu release") %> name="release" options={RELEASE_OPTIONS} value={CREATE_DEFAULTS.release} />
|
|
203
|
+
<Field controlLabel=<%- attr("dashboard.instances.pro", "Enable Ubuntu Pro") %> description=<%- attr("dashboard.instances.proDescription", "Security and compliance coverage for your instances, including extended support for the packages you care about.") %> inputType="checkbox" isOptional name="enable_pro" value={CREATE_DEFAULTS.enable_pro} />
|
|
204
|
+
<Field description=<%- attr("dashboard.instances.cloudInitDescription", "Configuration to run on first boot: packages to install, users to create, commands to run.") %> inputType="textarea" isOptional label=<%- attr("dashboard.instances.cloudInit", "Cloud-init user data") %> name="cloud_init" value={CREATE_DEFAULTS.cloud_init} />
|
|
205
|
+
</Form>
|
|
206
|
+
</div>
|
|
207
|
+
<div class="ds side-panel-footer">
|
|
208
|
+
<Button command="close" commandfor={panelId} onclick={closePanel} type="button"><%- msg("dashboard.cancel", "Cancel") %></Button>
|
|
209
|
+
<Button anticipation="constructive" form={createFormId} importance="primary" type="submit"><%- msg("dashboard.instances.create", "Create instance") %></Button>
|
|
210
|
+
</div>
|
|
211
|
+
</dialog>
|
|
212
|
+
<% } -%>
|
|
213
|
+
|
|
214
|
+
{#snippet aside()}
|
|
215
|
+
<section aria-labelledby="details-title" class="panel">
|
|
216
|
+
<h2 id="details-title">{selectedInstance ? selectedInstance.name : <%- str("dashboard.instances.details", "Details") %>}</h2>
|
|
217
|
+
{#if selectedInstance}
|
|
218
|
+
<dl class="details">
|
|
219
|
+
<dt><%- msg("dashboard.instances.status", "Status") %></dt>
|
|
220
|
+
<dd><%- intl ? "{t(STATUS_KEYS[selectedInstance.status])}" : "{STATUS_LABELS[selectedInstance.status]}" %></dd>
|
|
221
|
+
<dt><%- msg("dashboard.instances.release", "Ubuntu release") %></dt>
|
|
222
|
+
<dd>{selectedInstance.release}</dd>
|
|
223
|
+
<dt><%- msg("dashboard.instances.address", "IPv4 address") %></dt>
|
|
224
|
+
<dd>{selectedInstance.ipv4 || "—"}</dd>
|
|
225
|
+
<dt><%- msg("dashboard.instances.memory", "Memory") %></dt>
|
|
226
|
+
<% if (intl) { -%>
|
|
227
|
+
<dd>{t("dashboard.instances.memoryValue", { value: formatters.formatNumber(selectedInstance.memoryGib) })}</dd>
|
|
228
|
+
<% } else { -%>
|
|
229
|
+
<dd>{number.format(selectedInstance.memoryGib)} GiB</dd>
|
|
230
|
+
<% } -%>
|
|
231
|
+
</dl>
|
|
232
|
+
{:else}
|
|
233
|
+
<p class="muted"><%- msg("dashboard.instances.selectHint", "Select an instance to see its details.") %></p>
|
|
234
|
+
{/if}
|
|
235
|
+
</section>
|
|
236
|
+
{/snippet}
|
|
237
|
+
</ViewLayout>
|
|
238
|
+
|
|
239
|
+
<!-- @component
|
|
240
|
+
The instances page: a tile per instance with its count beside the heading, a
|
|
241
|
+
details aside for the chosen one, and a side panel that creates instances in
|
|
242
|
+
the page's state. Without JavaScript the panel
|
|
243
|
+
opens through `?create=1`, the create form posts to the page's action, and a
|
|
244
|
+
Details button chooses through `?selected=`.
|
|
245
|
+
-->
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { ContentLayout, ViewLayout } from "@canonical/svelte-ds-app";
|
|
3
|
+
import { Button } from "@canonical/svelte-ds-global";
|
|
4
|
+
import formatDocumentTitle from "../../formatDocumentTitle.js";
|
|
5
|
+
<% if (intl) { -%>
|
|
6
|
+
import {
|
|
7
|
+
createAppFormatters,
|
|
8
|
+
createAppTranslator,
|
|
9
|
+
getLocaleSource,
|
|
10
|
+
} from "../../i18n/index.js";
|
|
11
|
+
<% } -%>
|
|
12
|
+
import { Icon } from "../../lib/index.js";
|
|
13
|
+
import {
|
|
14
|
+
ACTIVITY,
|
|
15
|
+
<%= intl ? "CHANNEL_KEYS" : "CHANNEL_LABELS" %>,
|
|
16
|
+
OVERVIEW_FIGURES,
|
|
17
|
+
RELEASES,
|
|
18
|
+
TERABYTES,
|
|
19
|
+
} from "./constants.js";
|
|
20
|
+
import DashboardBreadcrumbs from "./DashboardBreadcrumbs.svelte";
|
|
21
|
+
import selectRelativeTime from "./selectRelativeTime.js";
|
|
22
|
+
import "./styles.css";
|
|
23
|
+
|
|
24
|
+
/** The form the create buttons submit: a GET to the instances page. */
|
|
25
|
+
const instancesFormId = "open-instances";
|
|
26
|
+
<% if (intl) { -%>
|
|
27
|
+
|
|
28
|
+
const locale = getLocaleSource();
|
|
29
|
+
const t = $derived(createAppTranslator($locale));
|
|
30
|
+
const formatters = $derived(createAppFormatters($locale));
|
|
31
|
+
<% } else { -%>
|
|
32
|
+
// The app has one language, so the formatters are fixed to it.
|
|
33
|
+
const formatters = {
|
|
34
|
+
formatNumber: (value: number, options?: Intl.NumberFormatOptions) =>
|
|
35
|
+
new Intl.NumberFormat("en", options).format(value),
|
|
36
|
+
formatRelativeTime: (
|
|
37
|
+
value: number,
|
|
38
|
+
unit: Intl.RelativeTimeFormatUnit,
|
|
39
|
+
options?: Intl.RelativeTimeFormatOptions,
|
|
40
|
+
) => new Intl.RelativeTimeFormat("en", options).format(value, unit),
|
|
41
|
+
};
|
|
42
|
+
<% } -%>
|
|
43
|
+
|
|
44
|
+
function formatRelative(minutesAgo: number): string {
|
|
45
|
+
const { value, unit } = selectRelativeTime(minutesAgo);
|
|
46
|
+
return formatters.formatRelativeTime(value, unit, { numeric: "auto" });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const tiles = $derived([
|
|
50
|
+
{
|
|
51
|
+
label: <%- str("dashboard.overview.running", "Running") %>,
|
|
52
|
+
figure: formatters.formatNumber(OVERVIEW_FIGURES.running),
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
label: <%- str("dashboard.overview.stopped", "Stopped") %>,
|
|
56
|
+
figure: formatters.formatNumber(OVERVIEW_FIGURES.stopped),
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
label: <%- str("dashboard.overview.storage", "Storage") %>,
|
|
60
|
+
figure: formatters.formatNumber(
|
|
61
|
+
OVERVIEW_FIGURES.storageUsedTb,
|
|
62
|
+
TERABYTES,
|
|
63
|
+
),
|
|
64
|
+
<% if (intl) { -%>
|
|
65
|
+
detail: t("dashboard.overview.storageOf", {
|
|
66
|
+
total: formatters.formatNumber(
|
|
67
|
+
OVERVIEW_FIGURES.storageTotalTb,
|
|
68
|
+
TERABYTES,
|
|
69
|
+
),
|
|
70
|
+
}),
|
|
71
|
+
<% } else { -%>
|
|
72
|
+
detail: `of ${formatters.formatNumber(OVERVIEW_FIGURES.storageTotalTb, TERABYTES)} used`,
|
|
73
|
+
<% } -%>
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
label: <%- str("dashboard.overview.alerts", "Alerts") %>,
|
|
77
|
+
figure: formatters.formatNumber(OVERVIEW_FIGURES.alerts),
|
|
78
|
+
},
|
|
79
|
+
]);
|
|
80
|
+
</script>
|
|
81
|
+
|
|
82
|
+
<svelte:head><title>{formatDocumentTitle(<%- str("dashboard.overview.title", "Dashboard") %>)}</title></svelte:head>
|
|
83
|
+
|
|
84
|
+
{#snippet plusIcon()}<Icon name="plus" />{/snippet}
|
|
85
|
+
|
|
86
|
+
<!-- The create buttons navigate to the instances page. They submit this GET
|
|
87
|
+
form, which SvelteKit turns into a client-side navigation, so they also
|
|
88
|
+
work without JavaScript. -->
|
|
89
|
+
<form action="/dashboard/instances" hidden id={instancesFormId}></form>
|
|
90
|
+
|
|
91
|
+
<ViewLayout class="dashboard-view">
|
|
92
|
+
<ContentLayout>
|
|
93
|
+
<header class="titlebar">
|
|
94
|
+
<div>
|
|
95
|
+
<DashboardBreadcrumbs />
|
|
96
|
+
<h1><%- msg("dashboard.overview.heading", "Overview") %></h1>
|
|
97
|
+
</div>
|
|
98
|
+
<div class="actions">
|
|
99
|
+
<Button form={instancesFormId} icon={plusIcon} importance="primary" type="submit"><%- msg("dashboard.instances.create", "Create instance") %></Button>
|
|
100
|
+
</div>
|
|
101
|
+
</header>
|
|
102
|
+
|
|
103
|
+
<section aria-labelledby="status-title" class="section">
|
|
104
|
+
<h2 id="status-title"><%- msg("dashboard.overview.status", "Status") %></h2>
|
|
105
|
+
<ul class="tiles">
|
|
106
|
+
{#each tiles as tile (tile.label)}
|
|
107
|
+
<li>
|
|
108
|
+
<div class="ds tile surface">
|
|
109
|
+
<div class="ds tile-header">{tile.label}</div>
|
|
110
|
+
<div class="ds tile-content">
|
|
111
|
+
<p class="figure">{tile.figure}</p>
|
|
112
|
+
{#if tile.detail}<p class="muted">{tile.detail}</p>{/if}
|
|
113
|
+
</div>
|
|
114
|
+
</div>
|
|
115
|
+
</li>
|
|
116
|
+
{/each}
|
|
117
|
+
</ul>
|
|
118
|
+
</section>
|
|
119
|
+
|
|
120
|
+
<section aria-labelledby="releases-title" class="section">
|
|
121
|
+
<h2 id="releases-title"><%- msg("dashboard.overview.releases", "Releases") %></h2>
|
|
122
|
+
<ul class="cards">
|
|
123
|
+
{#each RELEASES as release (release.name)}
|
|
124
|
+
<li>
|
|
125
|
+
<div class="ds card">
|
|
126
|
+
<div class="ds card-header">{release.name}</div>
|
|
127
|
+
<div class="ds card-content">
|
|
128
|
+
<% if (intl) { -%>
|
|
129
|
+
<p>{t(release.summaryKey)}</p>
|
|
130
|
+
<p class="muted">{t("dashboard.releases.detail", { channel: t(CHANNEL_KEYS[release.channel]), kernel: release.kernel })}</p>
|
|
131
|
+
<% } else { -%>
|
|
132
|
+
<p>{release.summary}</p>
|
|
133
|
+
<p class="muted">{`${CHANNEL_LABELS[release.channel]} · kernel ${release.kernel}`}</p>
|
|
134
|
+
<% } -%>
|
|
135
|
+
</div>
|
|
136
|
+
<div class="ds card-footer">
|
|
137
|
+
<Button importance="secondary" type="button"><%- msg("dashboard.overview.releaseNotes", "Release notes") %></Button>
|
|
138
|
+
<Button form={instancesFormId} icon={plusIcon} importance="primary" type="submit"><%- msg("dashboard.overview.launch", "Launch") %></Button>
|
|
139
|
+
</div>
|
|
140
|
+
</div>
|
|
141
|
+
</li>
|
|
142
|
+
{/each}
|
|
143
|
+
</ul>
|
|
144
|
+
</section>
|
|
145
|
+
</ContentLayout>
|
|
146
|
+
|
|
147
|
+
{#snippet aside()}
|
|
148
|
+
<section aria-labelledby="activity-title" class="panel">
|
|
149
|
+
<h2 id="activity-title"><%- msg("dashboard.activity.heading", "Activity") %></h2>
|
|
150
|
+
<div class="ds timeline">
|
|
151
|
+
<div class="ds timeline-content">
|
|
152
|
+
{#each ACTIVITY as event (event.key)}
|
|
153
|
+
<div class={["ds timeline-event", event.criticality]}>
|
|
154
|
+
<div class="marker" aria-hidden="true"></div>
|
|
155
|
+
<div class="content">
|
|
156
|
+
<% if (intl) { -%>
|
|
157
|
+
<div class="actor">{"name" in event.actor ? event.actor.name : t(event.actor.key)}</div>
|
|
158
|
+
<% } else { -%>
|
|
159
|
+
<div class="actor">{event.actor}</div>
|
|
160
|
+
<% } -%>
|
|
161
|
+
<time class="datetime">{formatRelative(event.minutesAgo)}</time>
|
|
162
|
+
<% if (intl) { -%>
|
|
163
|
+
<div class="payload">{t(event.messageKey, event.values)}</div>
|
|
164
|
+
<% } else { -%>
|
|
165
|
+
<div class="payload">{event.message}</div>
|
|
166
|
+
<% } -%>
|
|
167
|
+
</div>
|
|
168
|
+
</div>
|
|
169
|
+
{/each}
|
|
170
|
+
</div>
|
|
171
|
+
</div>
|
|
172
|
+
</section>
|
|
173
|
+
{/snippet}
|
|
174
|
+
</ViewLayout>
|
|
175
|
+
|
|
176
|
+
<!-- @component
|
|
177
|
+
The dashboard's overview: status tiles, the releases on offer and the activity
|
|
178
|
+
feed. Tiles, cards and the timeline use the markup of React's `Tile`, `Card`
|
|
179
|
+
and `Timeline`, which the Svelte design system does not ship yet.
|
|
180
|
+
-->
|