Skip to content

Commit

Permalink
Fix editing attribute values on new attribute creation (#4266)
Browse files Browse the repository at this point in the history
* Fix editing/deleting attribute value when creating new dropdown attribute

* Add changeset

* Fix ternary as well
  • Loading branch information
Droniu authored and andrzejewsky committed Sep 27, 2023
1 parent c632511 commit dd06aca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/tough-badgers-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": patch
---

Fix editing/deleting attribute values when creating new dropdown attribute
12 changes: 7 additions & 5 deletions src/attributes/views/AttributeCreate/AttributeCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const AttributeDetails: React.FC<AttributeDetailsProps> = ({ params }) => {
const [updateMetadata] = useUpdateMetadataMutation({});
const [updatePrivateMetadata] = useUpdatePrivateMetadataMutation({});

const id = params.id
const id: number | undefined = params.id
? parseInt(params.id, 10) + pageInfo.startCursor
: undefined;

Expand All @@ -108,7 +108,7 @@ const AttributeDetails: React.FC<AttributeDetailsProps> = ({ params }) => {
React.useEffect(() => setValueErrors([]), [params.action]);

const handleValueDelete = () => {
if (id) {
if (id !== undefined) {
const newValues = remove(values[id], values, areValuesEqual);
setValues(newValues);
}
Expand All @@ -119,7 +119,7 @@ const AttributeDetails: React.FC<AttributeDetailsProps> = ({ params }) => {
if (isSelected(input, values, areValuesEqual)) {
setValueErrors([attributeValueAlreadyExistsError]);
} else {
if (id) {
if (id !== undefined) {
setValues(updateAtIndex(input, values, id));
}
closeModal();
Expand Down Expand Up @@ -254,14 +254,16 @@ const AttributeDetails: React.FC<AttributeDetailsProps> = ({ params }) => {
<AttributeValueDeleteDialog
attributeName=""
open={params.action === "remove-value"}
name={getStringOrPlaceholder(id ? values[id]?.name : "")}
name={getStringOrPlaceholder(
id !== undefined ? values[id]?.name : "",
)}
confirmButtonState="default"
onClose={closeModal}
onConfirm={handleValueDelete}
/>
<AttributeValueEditDialog
inputType={data.inputType}
attributeValue={id ? values[id] : null}
attributeValue={id !== undefined ? values[id] : null}
confirmButtonState="default"
disabled={false}
errors={valueErrors}
Expand Down

0 comments on commit dd06aca

Please sign in to comment.