feat: change visibility in item options based on selected integration kinds (#949)
This commit is contained in:
@@ -92,8 +92,17 @@ export const WidgetEditModal = createModal<ModalProps<WidgetKind>>(({ actions, i
|
|||||||
{Object.entries(definition.options).map(([key, value]: [string, OptionsBuilderResult[string]]) => {
|
{Object.entries(definition.options).map(([key, value]: [string, OptionsBuilderResult[string]]) => {
|
||||||
const Input = getInputForType(value.type);
|
const Input = getInputForType(value.type);
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
if (
|
||||||
if (!Input || value.shouldHide?.(form.values.options as never)) {
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||||
|
!Input ||
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||||
|
value.shouldHide?.(
|
||||||
|
form.values.options as never,
|
||||||
|
innerProps.integrationData
|
||||||
|
.filter(({ id }) => form.values.integrationIds.includes(id))
|
||||||
|
.map(({ kind }) => kind),
|
||||||
|
)
|
||||||
|
) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { objectEntries } from "@homarr/common";
|
import { objectEntries } from "@homarr/common";
|
||||||
import type { WidgetKind } from "@homarr/definitions";
|
import type { IntegrationKind, WidgetKind } from "@homarr/definitions";
|
||||||
import type { ZodType } from "@homarr/validation";
|
import type { ZodType } from "@homarr/validation";
|
||||||
import { z } from "@homarr/validation";
|
import { z } from "@homarr/validation";
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ export type inferOptionsFromDefinition<TOptions extends WidgetOptionsRecord> = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
interface FieldConfiguration<TOptions extends WidgetOptionsRecord> {
|
interface FieldConfiguration<TOptions extends WidgetOptionsRecord> {
|
||||||
shouldHide: (options: inferOptionsFromDefinition<TOptions>) => boolean;
|
shouldHide: (options: inferOptionsFromDefinition<TOptions>, integrationKinds: IntegrationKind[]) => boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConfigurationInput<TOptions extends WidgetOptionsRecord> = Partial<
|
type ConfigurationInput<TOptions extends WidgetOptionsRecord> = Partial<
|
||||||
|
|||||||
Reference in New Issue
Block a user