changed to use ui-shared (#27848)
Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
This commit is contained in:
parent
63bd46b8cd
commit
60d4c15a79
3 changed files with 47 additions and 124 deletions
|
@ -22,7 +22,10 @@ const allTimes: TimeUnit[] = [
|
||||||
{ unit: "day", label: "times.days", multiplier: 86400 },
|
{ unit: "day", label: "times.days", multiplier: 86400 },
|
||||||
];
|
];
|
||||||
|
|
||||||
export type TimeSelectorProps = Omit<TextInputProps, "onChange"> &
|
export type TimeSelectorProps = Omit<
|
||||||
|
TextInputProps,
|
||||||
|
"onChange" | "defaultValue"
|
||||||
|
> &
|
||||||
Pick<DropdownProps, "menuAppendTo"> & {
|
Pick<DropdownProps, "menuAppendTo"> & {
|
||||||
value?: number;
|
value?: number;
|
||||||
units?: Unit[];
|
units?: Unit[];
|
||||||
|
|
|
@ -5,12 +5,12 @@ import {
|
||||||
FormGroup,
|
FormGroup,
|
||||||
Switch,
|
Switch,
|
||||||
} from "@patternfly/react-core";
|
} from "@patternfly/react-core";
|
||||||
import { Controller, UseFormReturn } from "react-hook-form";
|
import { Controller, FormProvider, UseFormReturn } from "react-hook-form";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
import { useConfirmDialog } from "../../components/confirm-dialog/ConfirmDialog";
|
|
||||||
import { HelpItem } from "ui-shared";
|
import { HelpItem } from "ui-shared";
|
||||||
import { TimeSelector } from "../../components/time-selector/TimeSelector";
|
import { DefaultSwitchControl } from "../../components/SwitchControl";
|
||||||
|
import { useConfirmDialog } from "../../components/confirm-dialog/ConfirmDialog";
|
||||||
|
import { TimeSelectorControl } from "../../components/time-selector/TimeSelectorControl";
|
||||||
|
|
||||||
export type EventsType = "admin" | "user";
|
export type EventsType = "admin" | "user";
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ export const EventConfigForm = ({
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<FormProvider {...form}>
|
||||||
<DisableConfirm />
|
<DisableConfirm />
|
||||||
<FormGroup
|
<FormGroup
|
||||||
hasNoPaddingTop
|
hasNoPaddingTop
|
||||||
|
@ -84,60 +84,24 @@ export const EventConfigForm = ({
|
||||||
{eventsEnabled && (
|
{eventsEnabled && (
|
||||||
<>
|
<>
|
||||||
{type === "admin" && (
|
{type === "admin" && (
|
||||||
<FormGroup
|
<DefaultSwitchControl
|
||||||
hasNoPaddingTop
|
name="adminEventsDetailsEnabled"
|
||||||
label={t("includeRepresentation")}
|
label={t("includeRepresentation")}
|
||||||
fieldId="includeRepresentation"
|
labelIcon={t("includeRepresentationHelp")}
|
||||||
labelIcon={
|
|
||||||
<HelpItem
|
|
||||||
helpText={t("includeRepresentationHelp")}
|
|
||||||
fieldLabelId="includeRepresentation"
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<Controller
|
|
||||||
name="adminEventsDetailsEnabled"
|
|
||||||
defaultValue={false}
|
|
||||||
control={control}
|
|
||||||
render={({ field }) => (
|
|
||||||
<Switch
|
|
||||||
data-testid="includeRepresentation"
|
|
||||||
id="includeRepresentation"
|
|
||||||
label={t("on")}
|
|
||||||
labelOff={t("off")}
|
|
||||||
isChecked={field.value}
|
|
||||||
onChange={field.onChange}
|
|
||||||
aria-label={t("includeRepresentation")}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</FormGroup>
|
|
||||||
)}
|
|
||||||
<FormGroup
|
|
||||||
label={t("expiration")}
|
|
||||||
fieldId="expiration"
|
|
||||||
labelIcon={
|
|
||||||
<HelpItem
|
|
||||||
helpText={t("expirationHelp")}
|
|
||||||
fieldLabelId="expiration"
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<Controller
|
|
||||||
name={
|
|
||||||
type === "user" ? "eventsExpiration" : "adminEventsExpiration"
|
|
||||||
}
|
|
||||||
defaultValue=""
|
|
||||||
control={control}
|
|
||||||
render={({ field }) => (
|
|
||||||
<TimeSelector
|
|
||||||
value={field.value}
|
|
||||||
onChange={field.onChange}
|
|
||||||
units={["minute", "hour", "day"]}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
)}
|
||||||
|
<TimeSelectorControl
|
||||||
|
name={
|
||||||
|
type === "user" ? "eventsExpiration" : "adminEventsExpiration"
|
||||||
|
}
|
||||||
|
label={t("expiration")}
|
||||||
|
labelIcon={t("expirationHelp")}
|
||||||
|
defaultValue=""
|
||||||
|
units={["minute", "hour", "day"]}
|
||||||
|
controller={{
|
||||||
|
defaultValue: "",
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
<ActionGroup>
|
<ActionGroup>
|
||||||
|
@ -174,6 +138,6 @@ export const EventConfigForm = ({
|
||||||
{type === "user" ? t("clearUserEvents") : t("clearAdminEvents")}
|
{type === "user" ? t("clearUserEvents") : t("clearAdminEvents")}
|
||||||
</Button>
|
</Button>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
</>
|
</FormProvider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,16 +1,7 @@
|
||||||
import {
|
import { ActionGroup, Button, SelectVariant } from "@patternfly/react-core";
|
||||||
ActionGroup,
|
import { FormProvider, UseFormReturn } from "react-hook-form";
|
||||||
Button,
|
|
||||||
FormGroup,
|
|
||||||
Select,
|
|
||||||
SelectOption,
|
|
||||||
SelectVariant,
|
|
||||||
} from "@patternfly/react-core";
|
|
||||||
import { useState } from "react";
|
|
||||||
import { Controller, UseFormReturn } from "react-hook-form";
|
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { SelectControl } from "ui-shared";
|
||||||
import { HelpItem } from "ui-shared";
|
|
||||||
import { useServerInfo } from "../../context/server-info/ServerInfoProvider";
|
import { useServerInfo } from "../../context/server-info/ServerInfoProvider";
|
||||||
|
|
||||||
type EventListenersFormProps = {
|
type EventListenersFormProps = {
|
||||||
|
@ -24,66 +15,31 @@ export const EventListenersForm = ({
|
||||||
}: EventListenersFormProps) => {
|
}: EventListenersFormProps) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const {
|
const {
|
||||||
control,
|
|
||||||
formState: { isDirty },
|
formState: { isDirty },
|
||||||
} = form;
|
} = form;
|
||||||
|
|
||||||
const [selectEventListenerOpen, setSelectEventListenerOpen] = useState(false);
|
|
||||||
const serverInfo = useServerInfo();
|
const serverInfo = useServerInfo();
|
||||||
const eventListeners = serverInfo.providers?.eventsListener.providers;
|
const eventListeners = serverInfo.providers?.eventsListener.providers;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<FormProvider {...form}>
|
||||||
<FormGroup
|
<SelectControl
|
||||||
hasNoPaddingTop
|
name="eventsListeners"
|
||||||
label={t("eventListeners")}
|
label={t("eventListeners")}
|
||||||
fieldId={"kc-eventListeners"}
|
labelIcon={t("eventListenersHelpTextHelp")}
|
||||||
labelIcon={
|
controller={{
|
||||||
<HelpItem
|
defaultValue: "",
|
||||||
helpText={t("eventListenersHelpTextHelp")}
|
}}
|
||||||
fieldLabelId="eventListeners"
|
className="kc_eventListeners_select"
|
||||||
/>
|
chipGroupProps={{
|
||||||
}
|
numChips: 3,
|
||||||
>
|
expandedText: t("hide"),
|
||||||
<Controller
|
collapsedText: t("showRemaining"),
|
||||||
name="eventsListeners"
|
}}
|
||||||
defaultValue=""
|
variant={SelectVariant.typeaheadMulti}
|
||||||
control={control}
|
options={Object.keys(eventListeners!)}
|
||||||
render={({ field }) => (
|
typeAheadAriaLabel="Select"
|
||||||
<Select
|
/>
|
||||||
name="eventsListeners"
|
|
||||||
className="kc_eventListeners_select"
|
|
||||||
data-testid="eventListeners-select"
|
|
||||||
chipGroupProps={{
|
|
||||||
numChips: 3,
|
|
||||||
expandedText: t("hide"),
|
|
||||||
collapsedText: t("showRemaining"),
|
|
||||||
}}
|
|
||||||
variant={SelectVariant.typeaheadMulti}
|
|
||||||
typeAheadAriaLabel="Select"
|
|
||||||
onToggle={(isOpen) => setSelectEventListenerOpen(isOpen)}
|
|
||||||
selections={field.value}
|
|
||||||
onSelect={(_, selectedValue) => {
|
|
||||||
const option = selectedValue.toString();
|
|
||||||
const changedValue = field.value.includes(option)
|
|
||||||
? field.value.filter((item: string) => item !== option)
|
|
||||||
: [...field.value, option];
|
|
||||||
field.onChange(changedValue);
|
|
||||||
}}
|
|
||||||
onClear={(operation) => {
|
|
||||||
operation.stopPropagation();
|
|
||||||
field.onChange([]);
|
|
||||||
}}
|
|
||||||
isOpen={selectEventListenerOpen}
|
|
||||||
aria-label={"selectEventsListeners"}
|
|
||||||
>
|
|
||||||
{Object.keys(eventListeners!).map((event) => (
|
|
||||||
<SelectOption key={event} value={event} />
|
|
||||||
))}
|
|
||||||
</Select>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</FormGroup>
|
|
||||||
<ActionGroup>
|
<ActionGroup>
|
||||||
<Button
|
<Button
|
||||||
variant="primary"
|
variant="primary"
|
||||||
|
@ -101,6 +57,6 @@ export const EventListenersForm = ({
|
||||||
{t("revert")}
|
{t("revert")}
|
||||||
</Button>
|
</Button>
|
||||||
</ActionGroup>
|
</ActionGroup>
|
||||||
</>
|
</FormProvider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue