Skip to content

Commit

Permalink
feat: add notes for creation of apps and integrations in widget edit …
Browse files Browse the repository at this point in the history
…modal
  • Loading branch information
Meierschlumpf committed Oct 15, 2024
1 parent ba81e5e commit 8f1723e
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 9 deletions.
9 changes: 9 additions & 0 deletions packages/translation/src/lang/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ export default {
tryAgain: "Try again",
loading: "Loading",
},
here: "here",
iconPicker: {
label: "Icon URL",
header: "Type name or objects to filter for icons... Homarr will search through {countIcons} icons for you.",
Expand Down Expand Up @@ -1157,6 +1158,14 @@ export default {
},
},
},
integration: {
noData: "No integration found",
description: "Click {here} to create a new integration",
},
app: {
noData: "No app found",
description: "Click {here} to create a new app",
},
error: {
action: {
logs: "Check logs for more details",
Expand Down
25 changes: 20 additions & 5 deletions packages/widgets/src/_inputs/widget-app-input.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
"use client";

import { memo, useMemo } from "react";
import Link from "next/link";
import type { SelectProps } from "@mantine/core";
import { Group, Loader, Select } from "@mantine/core";
import { Anchor, Group, Loader, Select, Text } from "@mantine/core";
import { IconCheck } from "@tabler/icons-react";

import type { RouterOutputs } from "@homarr/api";
import { clientApi } from "@homarr/api/client";
import { useI18n } from "@homarr/translation/client";

import type { CommonWidgetInputProps } from "./common";
import { useWidgetInputTranslation } from "./common";
import { useFormContext } from "./form";

export const WidgetAppInput = ({ property, kind, options }: CommonWidgetInputProps<"app">) => {
const t = useWidgetInputTranslation(kind, property);
export const WidgetAppInput = ({ property, kind }: CommonWidgetInputProps<"app">) => {
const t = useI18n();
const tInput = useWidgetInputTranslation(kind, property);
const form = useFormContext();
const { data: apps, isPending } = clientApi.app.selectable.useQuery();

Expand All @@ -24,10 +27,11 @@ export const WidgetAppInput = ({ property, kind, options }: CommonWidgetInputPro

return (
<Select
label={t("label")}
label={tInput("label")}
searchable
limit={10}
leftSection={<MemoizedLeftSection isPending={isPending} currentApp={currentApp} />}
nothingFoundMessage={t("widget.common.app.noData")}
renderOption={renderSelectOption}
data={
apps?.map((app) => ({
Expand All @@ -36,7 +40,18 @@ export const WidgetAppInput = ({ property, kind, options }: CommonWidgetInputPro
iconUrl: app.iconUrl,
})) ?? []
}
description={options.withDescription ? t("description") : undefined}
inputWrapperOrder={["label", "input", "description", "error"]}
description={
<Text size="xs">
{t("widget.common.app.description", {
here: (
<Anchor size="xs" component={Link} target="_blank" href="/manage/apps/new">
{t("common.here")}
</Anchor>
),
})}
</Text>
}
{...form.getInputProps(`options.${property}`)}
/>
);
Expand Down
3 changes: 1 addition & 2 deletions packages/widgets/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,9 @@ const optionsFactory = {
values: [] as string[],
validate: input?.validate,
}),
app: (input?: Omit<CommonInput<string>, "defaultValue">) => ({
app: () => ({
type: "app" as const,
defaultValue: "",
withDescription: input?.withDescription ?? false,
}),
};

Expand Down
30 changes: 28 additions & 2 deletions packages/widgets/src/widget-integration-select.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"use client";

import type { FocusEventHandler } from "react";
import Link from "next/link";
import {
Anchor,
Avatar,
CheckIcon,
CloseButton,
Expand Down Expand Up @@ -86,7 +88,23 @@ export const WidgetIntegrationSelect = ({
return (
<Combobox store={combobox} onOptionSubmit={handleValueSelect} withinPortal={false}>
<Combobox.DropdownTarget>
<PillsInput pointer onClick={() => combobox.toggleDropdown()} {...props}>
<PillsInput
inputWrapperOrder={["label", "input", "description", "error"]}
description={
<Text size="xs">
{t("widget.common.integration.description", {
here: (
<Anchor size="xs" component={Link} target="_blank" href="/manage/integrations">
{t("common.here")}
</Anchor>
),
})}
</Text>
}
pointer
onClick={() => combobox.toggleDropdown()}
{...props}
>
<Pill.Group>
{values.length > 0 ? values : <Input.Placeholder>{t("common.multiSelect.placeholder")}</Input.Placeholder>}

Expand All @@ -108,7 +126,15 @@ export const WidgetIntegrationSelect = ({
</Combobox.DropdownTarget>

<Combobox.Dropdown>
<Combobox.Options>{options}</Combobox.Options>
<Combobox.Options>
{options.length >= 1 ? (
options
) : (
<Text p={4} size="sm" ta="center" c="var(--mantine-color-dimmed)">
{t("widget.common.integration.noData")}
</Text>
)}
</Combobox.Options>
</Combobox.Dropdown>
</Combobox>
);
Expand Down

0 comments on commit 8f1723e

Please sign in to comment.