From 45fd0fb639f05db6115be6823d42b85672c0891d Mon Sep 17 00:00:00 2001 From: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com> Date: Fri, 31 Mar 2023 12:09:11 +0200 Subject: [PATCH] fix(admin-ui): Always show categories in product page (#3655) * fix(admin-ui): Always show categories in product page * Create .changeset/tasty-timers-drive.md * add disabled classes --- .changeset/tasty-timers-drive.md | 5 +++ .../forms/product/organize-form/index.tsx | 12 ++++-- .../components/multiselect/index.tsx | 43 ++++++++++++++----- .../domain/product-categories/pages/index.tsx | 4 +- 4 files changed, 47 insertions(+), 17 deletions(-) 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 0000000000..890c4fe99e --- /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 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 01145cafe1..462b9c5ceb 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 + disabled?: boolean isOpen: boolean selected: Record options: NestedMultiselectOption[] @@ -45,7 +47,15 @@ type InputProps = { * Multiselect input area */ function Input(props: InputProps) { - const { isOpen, selected, openPopup, resetSelected, options } = props + const { + placeholder, + isOpen, + selected, + openPopup, + resetSelected, + options, + disabled, + } = props const selectedCount = Object.keys(selected).length const selectedOption = useMemo(() => { @@ -65,7 +75,11 @@ function Input(props: InputProps) { return (
{!!selectedCount && ( @@ -84,7 +98,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 +372,10 @@ function NestedMultiselect(props: NestedMultiselectProps) { resetSelected={resetSelected} selected={selected} options={options} + placeholder={placeholder} + disabled={!options?.length} /> - {isOpen && ( + {isOpen && !!options?.length && (