Fix add remove button for multifield attributes
This commit is contained in:
parent
6cdb83d730
commit
96a88fe865
@ -426,21 +426,23 @@ function AddRemoveButtonsMultiValuedAttribute(props: {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{hasRemove && (
|
{hasRemove && (
|
||||||
<button
|
<>
|
||||||
id={`kc-remove${idPostfix}`}
|
<button
|
||||||
type="button"
|
id={`kc-remove${idPostfix}`}
|
||||||
className="pf-c-button pf-m-inline pf-m-link"
|
type="button"
|
||||||
onClick={() =>
|
className="pf-c-button pf-m-inline pf-m-link"
|
||||||
dispatchFormAction({
|
onClick={() =>
|
||||||
action: "update",
|
dispatchFormAction({
|
||||||
name: attribute.name,
|
action: "update",
|
||||||
valueOrValues: values.filter((_, i) => i !== fieldIndex)
|
name: attribute.name,
|
||||||
})
|
valueOrValues: values.filter((_, i) => i !== fieldIndex)
|
||||||
}
|
})
|
||||||
>
|
}
|
||||||
{msg("remove")}
|
>
|
||||||
{hasRemove ? <> | </> : null}
|
{msg("remove")}
|
||||||
</button>
|
</button>
|
||||||
|
{hasAdd ? <> | </> : null}
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
{hasAdd && (
|
{hasAdd && (
|
||||||
<button
|
<button
|
||||||
|
24
src/tools/structuredCloneButFunctions.ts
Normal file
24
src/tools/structuredCloneButFunctions.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import "minimal-polyfills/Object.fromEntries";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Functionally equivalent to structuredClone but
|
||||||
|
* functions are not cloned but kept as is.
|
||||||
|
* (as opposed to structuredClone that chokes if it encounters a function)
|
||||||
|
*/
|
||||||
|
export function structuredCloneButFunctions<T>(o: T): T {
|
||||||
|
if (!(o instanceof Object)) {
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof o === "function") {
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (o instanceof Array) {
|
||||||
|
return o.map(structuredCloneButFunctions) as any;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Object.fromEntries(
|
||||||
|
Object.entries(o).map(([key, value]) => [key, structuredCloneButFunctions(value)])
|
||||||
|
) as any;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user