Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom label for user defined taxonomy fields #1027

Merged
merged 22 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add renderTag prop
  • Loading branch information
allisonking committed Aug 26, 2022
commit 4e149cc94d7898d0c1ce027905d2a3c158a76d20
27 changes: 19 additions & 8 deletions clients/ctl/admin-ui/src/features/common/AccordionTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ interface Props {
nodes: TreeNode[];
focusedKey?: string;
renderHover?: (node: TreeNode) => React.ReactNode;
renderTag?: (node: TreeNode) => React.ReactNode;
}
const AccordionTree = ({ nodes, focusedKey, renderHover }: Props) => {
const AccordionTree = ({
nodes,
focusedKey,
renderHover,
renderTag,
}: Props) => {
const [hoverNode, setHoverNode] = useState<TreeNode | undefined>(undefined);
/**
* Recursive function to generate the accordion tree
Expand Down Expand Up @@ -47,12 +53,16 @@ const AccordionTree = ({ nodes, focusedKey, renderHover }: Props) => {
if (node.children.length === 0) {
return (
<Box py={2} {...itemProps} data-testid={`item-${node.label}`}>
<Text
pl={5} // AccordionButton's caret is 20px, so use 5 to line this up
color={isFocused ? "complimentary.500" : undefined}
>
{node.label}
</Text>
<Box display="flex" alignItems="center">
<Text
pl={5} // AccordionButton's caret is 20px, so use 5 to line this up
color={isFocused ? "complimentary.500" : undefined}
mr={2}
>
{node.label}
</Text>
{renderTag ? renderTag(node) : null}
</Box>
{hoverContent}
</Box>
);
Expand All @@ -71,7 +81,8 @@ const AccordionTree = ({ nodes, focusedKey, renderHover }: Props) => {
color={isFocused ? "complimentary.500" : undefined}
>
<AccordionIcon />
{node.label}
<Text mr={2}>{node.label}</Text>
{renderTag ? renderTag(node) : null}
</AccordionButton>
{hoverContent}
</Box>
Expand Down
16 changes: 16 additions & 0 deletions clients/ctl/admin-ui/src/features/taxonomy/TaxonomyTabContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
Center,
SimpleGrid,
Spinner,
Tag,
Text,
useDisclosure,
useToast,
Expand All @@ -23,6 +24,20 @@ import { selectIsAddFormOpen, setIsAddFormOpen } from "./taxonomy.slice";
import TaxonomyFormBase from "./TaxonomyFormBase";
import { TaxonomyEntity, TaxonomyEntityNode } from "./types";

const CustomTag = ({ node }: { node: TaxonomyEntityNode }) => {
const { is_default: isDefault } = node;
return !isDefault ? (
<Tag
backgroundColor="gray.500"
color="white"
size="sm"
height="fit-content"
>
Custom
</Tag>
) : null;
};

interface Props {
useTaxonomy: () => TaxonomyHookData<TaxonomyEntity>;
}
Expand Down Expand Up @@ -129,6 +144,7 @@ const TaxonomyTabContent = ({ useTaxonomy }: Props) => {
node={node as TaxonomyEntityNode}
/>
)}
renderTag={(node) => <CustomTag node={node as TaxonomyEntityNode} />}
/>
{editEntity ? (
<TaxonomyFormBase
Expand Down