Skip to content

Commit

Permalink
chore(meshconfig): implement delete entry
Browse files Browse the repository at this point in the history
  • Loading branch information
selankon committed Oct 10, 2024
1 parent 8fc09bb commit 21e06c4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ export const ConfigSection = ({
optionsComponent={<SectionEditOrDelete name={title} />}
>
{Object.entries(dropdown).map(([key, value]) => (
<OptionContainer key={key} section={title} keyString={key} />
<OptionContainer
key={key}
sectionName={title}
keyString={key}
/>
))}
</Collapsible>
);
Expand Down
53 changes: 28 additions & 25 deletions plugins/lime-plugin-mesh-wide-config/src/components/OptionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ const InputField = <TFieldValues extends FieldValues>({

export const OptionContainer = ({
keyString,
section,
sectionName,
}: {
section: string;
sectionName: string;
keyString: string;
}) => {
const { control, watch, setValue } = useFormContext();
const { control, watch, setValue, getFieldState } = useFormContext();
const [isEditing, setIsEditing] = useState(false);

const { toggleModal: toggleDeleteModal, actionModal: deletePropModal } =
Expand All @@ -56,8 +56,10 @@ export const OptionContainer = ({
useEditPropModal();
const { showToast } = useToast();

const name = `${section}[${keyString}]`;
const name = `${sectionName}[${keyString}]`;
const value = watch(name);
const section = watch(sectionName);

const [inputState, setInputState] = useState(value);

let _value = value;
Expand All @@ -83,19 +85,20 @@ export const OptionContainer = ({
onEdit={() => setIsEditing(true)}
onDelete={(e) => {
e.stopPropagation();
// todo(kon): a ver como eliminar
// deletePropModal(keyString, () => {
// console.log("delete stuff");
// toggleDeleteModal();
// showToast({
// text: (
// <Trans>Deleted {keyString}</Trans>
// ),
// onAction: () => {
// console.log("Undo action");
// },
// });
// });
deletePropModal(keyString, () => {
const newValues = { ...section };
delete newValues[keyString];
setValue(sectionName, newValues);
toggleDeleteModal();
showToast({
text: (
<Trans>Deleted {keyString}</Trans>
),
onAction: () => {
setValue(sectionName, section);
},
});
});
}}
/>
</div>
Expand Down Expand Up @@ -124,6 +127,14 @@ export const OptionContainer = ({
onClick={() => {
setValue(name, inputState);
setIsEditing(false);
showToast({
text: (
<Trans>
Edited{" "}
{keyString}
</Trans>
),
});
}}
outline={true}
>
Expand All @@ -134,14 +145,6 @@ export const OptionContainer = ({
onClick={() => {
setInputState(value);
setIsEditing(false);
showToast({
text: (
<Trans>
Edited{" "}
{keyString}
</Trans>
),
});
}}
outline={true}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const DrawForm = () => {
const { watch } = useFormContext<IMeshWideConfig>();
const formData = watch();

console.log("formData", formData);
return (
<>
{Object.entries(formData).map(([title, dropdown], index) => (
Expand Down

0 comments on commit 21e06c4

Please sign in to comment.