From f5c20ae9339e379ce398aca2d4d8b419708b614a Mon Sep 17 00:00:00 2001 From: olivermrbl Date: Fri, 31 Mar 2023 11:06:30 +0200 Subject: [PATCH 1/3] fix(admin-ui): Always show categories in product page --- .../forms/product/organize-form/index.tsx | 12 +++++--- .../components/multiselect/index.tsx | 28 ++++++++++++------- .../domain/product-categories/pages/index.tsx | 4 +-- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/packages/admin-ui/ui/src/components/forms/product/organize-form/index.tsx b/packages/admin-ui/ui/src/components/forms/product/organize-form/index.tsx index 01145cafe1fbd..462b9c5ceb494 100644 --- a/packages/admin-ui/ui/src/components/forms/product/organize-form/index.tsx +++ b/packages/admin-ui/ui/src/components/forms/product/organize-form/index.tsx @@ -2,14 +2,14 @@ import { Controller } from "react-hook-form" import NestedMultiselect from "../../../../domain/categories/components/multiselect" import { FeatureFlag, - useFeatureFlag, + useFeatureFlag } from "../../../../providers/feature-flag-provider" import { Option } from "../../../../types/shared" import { NestedForm } from "../../../../utils/nested-form" import InputHeader from "../../../fundamentals/input-header" import { NextCreateableSelect, - NextSelect, + NextSelect } from "../../../molecules/select/next-select" import TagInput from "../../../molecules/tag-input" import useOrganizeData from "./use-organize-data" @@ -86,8 +86,7 @@ const OrganizeForm = ({ form }: Props) => { /> - {isFeatureEnabled(FeatureFlag.PRODUCT_CATEGORIES) && - categoriesOptions?.length ? ( + {isFeatureEnabled(FeatureFlag.PRODUCT_CATEGORIES) ? ( <> { return ( { } type InputProps = { + placeholder?: string isOpen: boolean selected: Record options: NestedMultiselectOption[] @@ -45,7 +46,8 @@ type InputProps = { * Multiselect input area */ function Input(props: InputProps) { - const { isOpen, selected, openPopup, resetSelected, options } = props + const { placeholder, isOpen, selected, openPopup, resetSelected, options } = + props const selectedCount = Object.keys(selected).length const selectedOption = useMemo(() => { @@ -84,7 +86,11 @@ function Input(props: InputProps) { )} - Categories + {selectedCount === 0 ? ( + + {placeholder ? placeholder : "Choose categories"} + + ) : null} void initiallySelected?: Record + placeholder?: string } /** * Nested multiselect container */ function NestedMultiselect(props: NestedMultiselectProps) { - const { options, initiallySelected, onSelect } = props + const { options, initiallySelected, onSelect, placeholder } = props const [isOpen, openPopup, closePopup] = useToggleState(false) const rootRef = React.useRef(null) @@ -353,8 +360,9 @@ function NestedMultiselect(props: NestedMultiselectProps) { resetSelected={resetSelected} selected={selected} options={options} + placeholder={placeholder} /> - {isOpen && ( + {isOpen && !!options?.length && ( Date: Fri, 31 Mar 2023 11:44:42 +0200 Subject: [PATCH 2/3] Create .changeset/tasty-timers-drive.md --- .changeset/tasty-timers-drive.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/tasty-timers-drive.md diff --git a/.changeset/tasty-timers-drive.md b/.changeset/tasty-timers-drive.md new file mode 100644 index 0000000000000..890c4fe99eafa --- /dev/null +++ b/.changeset/tasty-timers-drive.md @@ -0,0 +1,5 @@ +--- +"@medusajs/admin-ui": patch +--- + +fix(admin-ui): Always show categories in product page From 308f0fe1c4c43143399c64bc0ba0f5d4a3caba02 Mon Sep 17 00:00:00 2001 From: olivermrbl Date: Fri, 31 Mar 2023 11:55:54 +0200 Subject: [PATCH 3/3] add disabled classes --- .../components/multiselect/index.tsx | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/admin-ui/ui/src/domain/categories/components/multiselect/index.tsx b/packages/admin-ui/ui/src/domain/categories/components/multiselect/index.tsx index a5d01b93786ad..4accd5a1f69d3 100644 --- a/packages/admin-ui/ui/src/domain/categories/components/multiselect/index.tsx +++ b/packages/admin-ui/ui/src/domain/categories/components/multiselect/index.tsx @@ -35,6 +35,7 @@ const ToolTipContent = (props: { list: string[] }) => { type InputProps = { placeholder?: string + disabled?: boolean isOpen: boolean selected: Record options: NestedMultiselectOption[] @@ -46,8 +47,15 @@ type InputProps = { * Multiselect input area */ function Input(props: InputProps) { - const { placeholder, isOpen, selected, openPopup, resetSelected, options } = - props + const { + placeholder, + isOpen, + selected, + openPopup, + resetSelected, + options, + disabled, + } = props const selectedCount = Object.keys(selected).length const selectedOption = useMemo(() => { @@ -67,7 +75,11 @@ function Input(props: InputProps) { return (
{!!selectedCount && ( @@ -361,6 +373,7 @@ function NestedMultiselect(props: NestedMultiselectProps) { selected={selected} options={options} placeholder={placeholder} + disabled={!options?.length} /> {isOpen && !!options?.length && (