Skip to content

Commit

Permalink
feature: Add interactive reader to dictAreaModal (#5122)
Browse files Browse the repository at this point in the history
* feat: add interactive reader to dictAreaModal
  • Loading branch information
anovazzi1 authored Dec 6, 2024
1 parent 70bb9cb commit 4ff7488
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion src/frontend/src/modals/dictAreaModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,45 @@ export default function DictAreaModal({
navigator.clipboard.writeText(JSON.stringify(copy));
};

const handleChangeType = (type: "array" | "object") => {
setComponentValue((value) => {
if (type === "array") {
if (value && Object.keys(value).length > 0) {
return [value];
}
return [];
}
if (value && Array.isArray(value) && value.length > 0) {
return value[0];
}
return {};
});
};

const IteractiveReader = () => {
return (
<span>
Customize your dictionary, adding or editing key-value pairs as needed.
Supports adding new{" "}
<span
onClick={() => handleChangeType("object")}
className="cursor-pointer underline"
>
objects &#123; &#125;
</span>{" "}
or{" "}
<span
onClick={() => handleChangeType("array")}
className="cursor-pointer underline"
>
arrays [].
</span>
</span>
);
};

const renderHeader = () => (
<BaseModal.Header description={onChange ? CODE_DICT_DIALOG_SUBTITLE : null}>
<BaseModal.Header description={onChange ? IteractiveReader() : null}>
<span className="pr-2">
{onChange ? "Edit Dictionary" : "View Dictionary"}
</span>
Expand Down

0 comments on commit 4ff7488

Please sign in to comment.