Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Feat: product filtering #119

Merged
merged 30 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
cf78d3a
hotfix: Show variants on new product (#108)
olivermrbl Sep 27, 2021
05a3d95
filter dropdown
pKorsholm Sep 30, 2021
3fe7bc2
tags working
pKorsholm Sep 30, 2021
29ff20d
ui update for dropdown
pKorsholm Sep 30, 2021
304f203
ui adjust
pKorsholm Sep 30, 2021
588505f
pr adjust
pKorsholm Sep 30, 2021
eddf40c
filter dropdown
pKorsholm Sep 30, 2021
b5de103
tags working
pKorsholm Sep 30, 2021
4019849
ui update for dropdown
pKorsholm Sep 30, 2021
19cc3f4
ui adjust
pKorsholm Sep 30, 2021
b3121d2
pr adjust
pKorsholm Sep 30, 2021
994abef
Merge branch 'feat/product-filtering' of https://github.com/medusajs/…
pKorsholm Oct 1, 2021
3524952
tags by id
pKorsholm Oct 1, 2021
559c335
Merge branch 'master' into develop
olivermrbl Oct 4, 2021
66b64fc
dont fail if products dont exist
pKorsholm Oct 8, 2021
9959cf4
fixed offsets and pagination
pKorsholm Oct 8, 2021
e36172b
review updates
pKorsholm Oct 11, 2021
a70a017
fetch tags only when tags are selected as filters
pKorsholm Oct 11, 2021
e7e9d20
make tags a filter object
pKorsholm Oct 11, 2021
4f8f0a8
null check for tags
pKorsholm Oct 11, 2021
b02b169
Merge branch 'develop' of https://github.com/medusajs/admin into develop
olivermrbl Oct 12, 2021
3f83556
filtering nulls
pKorsholm Oct 13, 2021
6aa3927
removed comments
pKorsholm Oct 13, 2021
7c1a81b
checkpoint
pKorsholm Oct 13, 2021
82ef62b
checkpoint
pKorsholm Oct 13, 2021
828ba49
working until every tag is deleted
pKorsholm Oct 13, 2021
88111bc
tooltip working
pKorsholm Oct 13, 2021
3e2f3fd
remove console.log
pKorsholm Oct 13, 2021
3123e42
Merge branch 'develop' of https://github.com/medusajs/admin into develop
olivermrbl Oct 13, 2021
892968f
fixed merge conflict
olivermrbl Oct 13, 2021
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
5 changes: 4 additions & 1 deletion src/components/filter-dropdown-item/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ const CollapseContainer = styled.div`
display: flex;
align-items: center;

// background-color: ${props => props.theme.colors.gray};
background-color: ${props => props.theme.colors.light};
border-bottom: 1px solid ${props => props.theme.colors.lightest};
padding: 7px;
padding-left: 10px;

${props =>
props.last &&
`
border-bottom:none;

margin-bottom: 0;
padding-bottom: 7px;
`}
Expand Down
3 changes: 2 additions & 1 deletion src/components/tag-input/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const StyledInput = styled.input`
}
`

const TagInput = ({ onChange, values, ...props }) => {
const TagInput = ({ onChange, values, onBlur = () => {}, ...props }) => {
const [isFocused, setFocused] = useState(false)
const [highlighted, setHighlighted] = useState(-1)
const containerRef = useRef()
Expand Down Expand Up @@ -111,6 +111,7 @@ const TagInput = ({ onChange, values, ...props }) => {
const handleBlur = () => {
setHighlighted(-1)
setFocused(false)
onBlur()
}

const handleFocus = () => {
Expand Down
1 change: 0 additions & 1 deletion src/components/tooltip/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ const StyledTooltip = styled(Tooltip)`
opacity: 1;
}
`

export default StyledTooltip
2 changes: 1 addition & 1 deletion src/components/variant-grid/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ const VariantGrid = ({ product, variants, onChange, edit, onEdit, onCopy }) => {
<tbody>
{variants.map(
(v, row) =>
v.id !== undefined && (
(v.id !== undefined || !product) && (
<tr key={row}>
{columns.map((c, col) => (
<Td
Expand Down
137 changes: 97 additions & 40 deletions src/domain/products/filter-dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,32 @@ import React, { useState, useRef, useEffect } from "react"
import styled from "@emotion/styled"
import { Flex, Box } from "rebass"

import TagInput from "../../components/tag-input"
import Button from "../../components/button"
import FilterDropdownItem from "../../components/filter-dropdown-item"

import Tooltip from "../../components/tooltip"
import ReactTooltip from "react-tooltip"
import { ReactComponent as Filter } from "../../assets/svg/filter.svg"
import { DateFilters } from "../../utils/filters"

const statusFilters = ["pending", "completed", "cancelled"]
const paymentFilters = ["awaiting", "captured", "refunded"]
const fulfillmentFilters = [
"not_fulfilled",
"partially_fulfilled",
"fulfilled",
"returned",
]
const statusFilters = ["proposed", "draft", "published", "rejected"]

const DropdownContainer = styled.div`
${props => `
display: ${props.isOpen ? "block" : "none"};
transform: translate3d(-15px, 32px, 0px);
transform: translate3d(-20px, 44px, 0px);
`};

position: absolute;
background-color: #fefefe;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
min-width: 300px;
box-shadow: 4px 8px 16px 8px rgba(0, 0, 0, 0.2);
z-index: 1;
top: 0;
border-radius: 5px;
right: 0;

max-height: 80vh;
overflow: auto;

&::before {
content: "";
Expand Down Expand Up @@ -80,26 +75,39 @@ const ButtonContainer = styled(Flex)`

const ProductsFilter = ({
setStatusFilter,
setPaymentFilter,
setFulfillmentFilter,
statusFilter,
setCollectionFilter,
collectionFilter,
collections,
setTagsFilter,
submitFilters,
clearFilters,
statusFilter,
fulfillmentFilter,
paymentFilter,
tagsFilter,
resetFilters,
sx,
...rest
}) => {
const [isOpen, setIsOpen] = useState(false)

const [tagsFocussed, setTagsFocussed] = useState(false)
const ref = useRef(null)
const tagsRef = useRef(null)

const handleClickOutside = event => {
if (ref.current && !ref.current.contains(event.target) && isOpen) {
setIsOpen(false)
}
}

const onSubmit = () => {
setIsOpen(false)
submitFilters()
}

const onClear = () => {
setIsOpen(false)
clearFilters()
}

const handleOpen = () => {
if (!isOpen) {
setIsOpen(true)
Expand All @@ -110,20 +118,18 @@ const ProductsFilter = ({

useEffect(() => {
document.addEventListener("click", handleClickOutside)
if (tagsFilter.invalidTagsMessage && tagsFocussed) {
ReactTooltip.show(tagsRef.current)
} else {
ReactTooltip.hide(tagsRef.current)
}
return () => {
document.removeEventListener("click", handleClickOutside)
}
})

const clear = () => {
setFulfillmentFilter({ open: false, filter: "" })
setPaymentFilter({ open: false, filter: "" })
setPaymentFilter({ open: false, filter: "" })
clearFilters()
}

return (
<Box style={{ position: "relative" }}>
<Box mr={2} style={{ position: "relative" }}>
<Button
sx={sx}
alignItems="center"
Expand All @@ -135,29 +141,80 @@ const ProductsFilter = ({
</Button>
<DropdownContainer ref={ref} isOpen={isOpen}>
<ButtonContainer p={2}>
<ClearButton onClick={() => clear()}>Clear</ClearButton>
<ClearButton onClick={() => onClear()}>Clear</ClearButton>
<Box ml="auto" />
<DoneButton onClick={() => submitFilters()}>Done</DoneButton>
<DoneButton variant="cta" onClick={() => onSubmit()}>
Done
</DoneButton>
</ButtonContainer>
<FilterDropdownItem
filterTitle="Status"
filters={statusFilters}
options={statusFilters}
filters={statusFilter.filter}
open={statusFilter.open}
setFilter={setStatusFilter}
/>

<FilterDropdownItem
filterTitle="Payment status"
filters={paymentFilters}
open={paymentFilter.open}
setFilter={setPaymentFilter}
/>
<FilterDropdownItem
filterTitle="Fulfillment status"
filters={fulfillmentFilters}
open={fulfillmentFilter.open}
setFilter={setFulfillmentFilter}
filterTitle="Collection"
options={collections}
filters={collectionFilter.filter}
open={collectionFilter.open}
setFilter={obj => {
setCollectionFilter(obj)
}}
/>
<Flex
width={1}
sx={{
fontSize: "12px",
lineHeight: "100%",
cursor: "pointer",
padding: "7px",
paddingBottom: "8px",
borderBottom: "hairline",
}}
onClick={() =>
setTagsFilter({ open: !tagsFilter.open, filter: tagsFilter.filter })
}
>
<input
type="checkbox"
id="Tags"
name="Tags"
value="Tags"
checked={tagsFilter.open}
style={{ marginRight: "5px" }}
/>
Tags
</Flex>
{tagsFilter.open && (
<Box
sx={{ fontSize: "10px", "& input": { fontSize: "12px" } }}
width={1}
p={2}
ref={tagsRef}
data-tip={tagsFilter.invalidTagsMessage || ""}
onBlur={() => setTagsFocussed(false)}
onFocus={() => setTagsFocussed(true)}
>
<TagInput
placeholder="Spring, summer..."
values={tagsFilter.filter || []}
onBlur={() => {
setTagsFocussed(false)
}}
onChange={values => {
setTagsFilter({
open: tagsFilter.open,
filter: values,
})
}}
/>
</Box>
)}
</DropdownContainer>
<Tooltip multiline={true} />
</Box>
)
}
Expand Down
Loading