From 23c750835897a8a9aae63c4ed56215dda314cac9 Mon Sep 17 00:00:00 2001 From: Egor Savkin Date: Tue, 22 Aug 2023 12:41:32 +0800 Subject: [PATCH] Add popover for cart summary with options data Signed-off-by: Egor Savkin --- sass/css/_shop.scss | 23 ++++++++++++++++++ static/js/shop.jsx | 16 ++++-------- static/js/shop_components.jsx | 46 +++++++++++++++++++++++++++++++++-- 3 files changed, 72 insertions(+), 13 deletions(-) diff --git a/sass/css/_shop.scss b/sass/css/_shop.scss index 8e008d3..e217d25 100644 --- a/sass/css/_shop.scss +++ b/sass/css/_shop.scss @@ -261,6 +261,29 @@ button { width: 20px; padding-bottom: 3px; } + .alert-info { + padding-bottom: 0; + } + } + + .overlayVariant { + min-width: 100px; + height: 150px; + overflow-y: scroll; + position: absolute; + display: flex; + align-items: start; + justify-content: center; + text-align: left; + background-color: white; + color: black; + flex-direction: column; + cursor: pointer; + + p { + font-size: .875rem; + margin: 0; + } } thead, tbody, tfoot { diff --git a/static/js/shop.jsx b/static/js/shop.jsx index d0dcff0..a62b4f7 100644 --- a/static/js/shop.jsx +++ b/static/js/shop.jsx @@ -6,9 +6,7 @@ import { createRoot } from "react-dom/client"; import PropTypes from "prop-types"; import { DragDropContext, Droppable, Draggable } from "react-beautiful-dnd"; import { v4 as uuidv4 } from 'uuid'; -import { CustomizeButton } from "./shop_components.jsx"; -import { OverlayTrigger } from "react-bootstrap"; - +import { CustomizeButton, CustomizeData } from "./shop_components.jsx";import { OverlayTrigger } from "react-bootstrap"; const data = window.shop_data; const itemsUnfoldedList = Array.from(data.columns.backlog.categories.map(groupId => groupId.itemIds).flat()); @@ -1422,7 +1420,7 @@ class OrderSumary extends React.PureComponent { {summary.map((item, index) => { - let alert, warning, options; + let alert, warning, options, options_data; if (itemsData[index] && itemsData[index].warnings) { alert = itemsData[index]; @@ -1432,6 +1430,7 @@ class OrderSumary extends React.PureComponent { } } options = itemsData[index] && itemsData[index].options; + options_data = itemsData[index] && itemsData[index].options_data; return ( - ) : ( options ? - () : null + ) : ( (options && options_data) ? + ( ) : null )} {(!warning && !options) && ( @@ -1831,7 +1826,6 @@ class Shop extends React.PureComponent { }; const clonedCart = Array.from(this.state.columns.cart.items); const clonedCartData = Array.from(this.state.columns.cart.itemsData); - console.log(clonedCartData); for (const i in clonedCart) { const item = clonedCart[i]; const item_data = clonedCartData[i]; diff --git a/static/js/shop_components.jsx b/static/js/shop_components.jsx index bee55cb..4e6c154 100644 --- a/static/js/shop_components.jsx +++ b/static/js/shop_components.jsx @@ -2,11 +2,12 @@ import React, {Component} from "react"; import jsonLogic from 'json-logic-js'; -import { useState } from 'react'; +import {useState} from 'react'; // https://stackoverflow.com/a/70511311 const trueTypeOf = (obj) => Object.prototype.toString.call(obj).slice(8, -1).toLowerCase(); + class Radio extends Component { constructor(props) { super(props); @@ -276,7 +277,8 @@ export function CustomizeButton({options, data, target, id, big}) { return (
- +
); } + +export function CustomizeData({id, data}) { + const [show, setShow] = useState(false); + const [position, setPosition] = useState({x: 0, y: 0}); + + const handleClick = (event) => { + setPosition({x: event.clientX, y: event.clientY}); + setShow(!show); + }; + + const stringify = (value) => { + let value_type = trueTypeOf(value); + if (value_type === "string") { + return value; + } else if (value_type === "object") { + if (value.checked === false) { + return "off"; + } else if (value.checked === true && value.text) { + return value.text; + } + } + return JSON.stringify(value); + } + + return ( +
+ +
+
+ {Array.from(Object.entries(data).map(([key, value], _) => { + return (

{key}: {stringify(value)}

); + }))} +
+
+
+ ); +} +