1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-18 12:54:27 +01:00

(merge) Merge remote-tracking branch 'origin/product-store_integration' into product-store

This commit is contained in:
Sylvain 2022-10-05 10:21:35 +02:00
commit 185b4f1459
7 changed files with 25 additions and 10 deletions

View File

@ -36,11 +36,12 @@ class API::ProductCategoriesController < API::ApiController
def position
authorize @product_category
render json: @product_category, status: :not_modified and return if @product_category.position == params[:position]
if @product_category.insert_at(params[:position])
render :show
else
render json: @product_category.errors, status: :unprocessable_entity
render json: @product_category.errors.full_messages, status: :unprocessable_entity
end
end

View File

@ -113,9 +113,13 @@ export const ProductCategoriesTree: React.FC<ProductCategoriesTreeProps> = ({ pr
if (activeData.offset === 'down' && sortedId === active.id && activeData.index < newIndex && active.id !== over.id) {
category = { ...category, parent_id: Number(over.id) };
droppedItem = category;
newPosition = 1;
} else if (activeData.offset === 'down' && sortedId === active.id && (activeData.index > newIndex || active.id === over.id)) {
category = { ...category, parent_id: getPreviousAdopter(over.id) };
const adopter = getPreviousAdopter(over.id);
const siblingsLength = getChildren(adopter)?.length | 0;
category = { ...category, parent_id: adopter };
droppedItem = category;
newPosition = siblingsLength + 1;
}
return category;
});
@ -129,14 +133,15 @@ export const ProductCategoriesTree: React.FC<ProductCategoriesTreeProps> = ({ pr
if (activeData.offset === 'down' && sortedId === active.id && activeData.index < newIndex) {
category = { ...category, parent_id: Number(over.id) };
droppedItem = category;
newPosition = 0;
newPosition = 1;
} else if (activeData.offset === 'down' && sortedId === active.id && activeData.index > newIndex) {
category = { ...category, parent_id: getPreviousAdopter(over.id) };
droppedItem = category;
newPosition = getChildren(getPreviousAdopter(over.id))?.length || 0;
newPosition = getChildren(getPreviousAdopter(over.id))?.length || 1;
} else if (sortedId === active.id) {
category = { ...category, parent_id: null };
droppedItem = category;
newPosition = getCategory(over.id).position + 1;
}
return category;
});
@ -153,7 +158,7 @@ export const ProductCategoriesTree: React.FC<ProductCategoriesTreeProps> = ({ pr
if (sortedId === active.id) {
category = { ...category, parent_id: Number(over.id) };
droppedItem = category;
newPosition = 0;
newPosition = 1;
}
return category;
});
@ -166,7 +171,7 @@ export const ProductCategoriesTree: React.FC<ProductCategoriesTreeProps> = ({ pr
} else if (sortedId === active.id && activeData.offset === 'down') {
category = { ...category, parent_id: getPreviousAdopter(over.id) };
droppedItem = category;
newPosition = getChildren(getPreviousAdopter(over.id))?.length || 0;
newPosition = getChildren(getPreviousAdopter(over.id))?.length || 1;
}
return category;
});
@ -182,6 +187,7 @@ export const ProductCategoriesTree: React.FC<ProductCategoriesTreeProps> = ({ pr
if (sortedId === active.id) {
category = { ...category, parent_id: null };
droppedItem = category;
newPosition = getCategory(getCategory(over.id).parent_id).position + 1;
}
return category;
});
@ -219,15 +225,17 @@ export const ProductCategoriesTree: React.FC<ProductCategoriesTreeProps> = ({ pr
}
// [B]:Child
if (overStatus === 'child') {
const parent = newOrder.find(c => c.id === getCategory(over.id).parent_id);
if (activeData.index < newIndex) {
const parent = newOrder.find(c => c.id === getCategory(over.id).parent_id);
newIndex = newOrder.findIndex(c => c.id === getChildren(parent.id).pop().id);
const newIdsOrder = arrayMove(currentIdsOrder, activeData.index, newIndex);
newOrder = newIdsOrder.map(sortedId => getCategory(sortedId));
newPosition = parent.position;
} else {
newIndex = currentIdsOrder.indexOf(getCategory(over.id).parent_id);
const newIdsOrder = arrayMove(currentIdsOrder, activeData.index, newIndex);
newOrder = newIdsOrder.map(sortedId => getCategory(sortedId));
newPosition = parent.position;
}
}
// insert children back

View File

@ -52,6 +52,7 @@ const ProductCategories: React.FC<ProductCategoriesProps> = ({ onSuccess, onErro
.then(c => {
ProductCategoryAPI
.updatePosition(c, position)
.then(refreshCategories)
.catch(error => onError(error));
})
.catch(error => onError(error));

View File

@ -156,7 +156,7 @@ export const ShowOrder: React.FC<ShowOrderProps> = ({ orderId, currentUser, onSu
<div className="cart">
<label>{t('app.shared.store.show_order.cart')}</label>
<div>
<div className='store-cart-list'>
{order.order_items_attributes.map(item => (
<article className='store-cart-list-item' key={item.id}>
<div className='picture'>

View File

@ -91,6 +91,10 @@
color: var(--gray-hard-light);
}
}
.actions {
grid-template-columns: auto;
grid-auto-flow: column;
}
}
.subgrid {

View File

@ -164,6 +164,7 @@
}
}
aside {
justify-self: stretch;
margin: 2.4rem 0;
grid-row: 4 / 5;
top: 4rem;
@ -198,7 +199,7 @@
grid-template-areas: "min min min"
"minus input plus"
"btn btn btn";
grid-template-columns: repeat(4, minmax(0, min-content));
grid-template-columns: min-content 1fr min-content;
justify-content: center;
gap: 1.6rem;
border-top: 1px solid var(--gray-soft-dark);

View File

@ -14,5 +14,5 @@ class ProductCategory < ApplicationRecord
has_many :products, dependent: :nullify
acts_as_list scope: :parent, top_of_list: 0
acts_as_list scope: :parent, top_of_list: 1
end