mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-15 20:17:22 +00:00
Merge pull request #311 from bknd-io/fix/admin-field-config
fix config reconciliation for specific field types, remove lodash
This commit is contained in:
@@ -14,9 +14,9 @@ export function isObject(value: unknown): value is Record<string, unknown> {
|
|||||||
|
|
||||||
export function omitKeys<T extends object, K extends keyof T>(
|
export function omitKeys<T extends object, K extends keyof T>(
|
||||||
obj: T,
|
obj: T,
|
||||||
keys_: readonly K[],
|
keys_: readonly K[] | K[] | string[],
|
||||||
): Omit<T, Extract<K, keyof T>> {
|
): Omit<T, Extract<K, keyof T>> {
|
||||||
const keys = new Set(keys_);
|
const keys = new Set(keys_ as readonly K[]);
|
||||||
const result = {} as Omit<T, Extract<K, keyof T>>;
|
const result = {} as Omit<T, Extract<K, keyof T>>;
|
||||||
for (const [key, value] of Object.entries(obj) as [keyof T, T[keyof T]][]) {
|
for (const [key, value] of Object.entries(obj) as [keyof T, T[keyof T]][]) {
|
||||||
if (!keys.has(key as K)) {
|
if (!keys.has(key as K)) {
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ import {
|
|||||||
ucFirstAllSnakeToPascalWithSpaces,
|
ucFirstAllSnakeToPascalWithSpaces,
|
||||||
s,
|
s,
|
||||||
stringIdentifier,
|
stringIdentifier,
|
||||||
|
pickKeys,
|
||||||
} from "bknd/utils";
|
} from "bknd/utils";
|
||||||
import {
|
import {
|
||||||
type TAppDataEntityFields,
|
type TAppDataEntityFields,
|
||||||
fieldsSchemaObject as originalFieldsSchemaObject,
|
fieldsSchemaObject as originalFieldsSchemaObject,
|
||||||
} from "data/data-schema";
|
} from "data/data-schema";
|
||||||
import { omit } from "lodash-es";
|
|
||||||
import { forwardRef, memo, useEffect, useImperativeHandle } from "react";
|
import { forwardRef, memo, useEffect, useImperativeHandle } from "react";
|
||||||
import { type FieldArrayWithId, type UseFormReturn, useFieldArray, useForm } from "react-hook-form";
|
import { type FieldArrayWithId, type UseFormReturn, useFieldArray, useForm } from "react-hook-form";
|
||||||
import { TbGripVertical, TbSettings, TbTrash } from "react-icons/tb";
|
import { TbGripVertical, TbSettings, TbTrash } from "react-icons/tb";
|
||||||
@@ -317,7 +317,6 @@ function EntityField({
|
|||||||
const name = watch(`fields.${index}.name`);
|
const name = watch(`fields.${index}.name`);
|
||||||
const { active, toggle } = useRoutePathState(routePattern ?? "", name);
|
const { active, toggle } = useRoutePathState(routePattern ?? "", name);
|
||||||
const fieldSpec = fieldSpecs.find((s) => s.type === type)!;
|
const fieldSpec = fieldSpecs.find((s) => s.type === type)!;
|
||||||
const specificData = omit(field.field.config, commonProps);
|
|
||||||
const disabled = fieldSpec.disabled || [];
|
const disabled = fieldSpec.disabled || [];
|
||||||
const hidden = fieldSpec.hidden || [];
|
const hidden = fieldSpec.hidden || [];
|
||||||
const dragDisabled = index === 0;
|
const dragDisabled = index === 0;
|
||||||
@@ -476,7 +475,7 @@ function EntityField({
|
|||||||
field={field}
|
field={field}
|
||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
setValue(`${prefix}.config`, {
|
setValue(`${prefix}.config`, {
|
||||||
...getValues([`fields.${index}.config`])[0],
|
...pickKeys(getValues([`${prefix}.config`])[0], commonProps),
|
||||||
...value,
|
...value,
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
@@ -520,7 +519,7 @@ const SpecificForm = ({
|
|||||||
readonly?: boolean;
|
readonly?: boolean;
|
||||||
}) => {
|
}) => {
|
||||||
const type = field.field.type;
|
const type = field.field.type;
|
||||||
const specificData = omit(field.field.config, commonProps);
|
const specificData = omitKeys(field.field.config ?? {}, commonProps);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<JsonSchemaForm
|
<JsonSchemaForm
|
||||||
|
|||||||
Reference in New Issue
Block a user