-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from gimlet-io/flux-state-in-footer
Flux state in footer
- Loading branch information
Showing
9 changed files
with
710 additions
and
41 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import React, { useState, useRef, useEffect } from 'react'; | ||
import { FunnelIcon, XMarkIcon } from '@heroicons/react/24/outline' | ||
|
||
function FilterBar(props) { | ||
return ( | ||
<div className="w-full"> | ||
<div className="relative"> | ||
<div className="absolute inset-y-0 left-0 flex items-center pl-3"> | ||
<FunnelIcon className="h-5 w-5 text-neutral-400" aria-hidden="true" /> | ||
{props.filters.map(filter => ( | ||
<Filter key={filter.property + filter.value} filter={filter} deleteFilter={props.deleteFilter} /> | ||
))} | ||
<FilterInput addFilter={props.addFilter} /> | ||
</div> | ||
<div className="block w-full rounded-lg border-0 bg-white py-1.5 pl-10 pr-3 text-neutral-900 ring-1 ring-inset ring-neutral-300 placeholder:text-neutral-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6"> | ||
| ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default FilterBar; | ||
|
||
function Filter(props) { | ||
const { filter } = props; | ||
return ( | ||
<span className="ml-1 text-blue-50 bg-blue-600 rounded-full pl-3 pr-1" aria-hidden="true"> | ||
<span>{filter.property}</span>: <span>{filter.value}</span> | ||
<span className="ml-1 px-1 bg-blue-400 rounded-full "> | ||
<XMarkIcon className="cursor-pointer text-white inline h-3 w-3" aria-hidden="true" onClick={() => props.deleteFilter(filter)}/> | ||
</span> | ||
</span> | ||
) | ||
} | ||
|
||
function FilterInput(props) { | ||
const [active, setActive] = useState(false) | ||
const [property, setProperty] = useState("") | ||
const [value, setValue] = useState("") | ||
const properties=["Repository", "Service", "Namespace", "Owner", "Starred", "Domain"] | ||
const { addFilter } = props; | ||
const inputRef = useRef(null); | ||
|
||
const reset = () => { | ||
setActive(false) | ||
setProperty("") | ||
setValue("") | ||
} | ||
|
||
useEffect(() => { | ||
if (property !== "") { | ||
inputRef.current.focus(); | ||
} | ||
}); | ||
|
||
return ( | ||
<span className="relative w-48 ml-2"> | ||
<span className="items-center flex"> | ||
{property !== "" && | ||
<span>{property}: </span> | ||
} | ||
<input | ||
ref={inputRef} | ||
key={property} | ||
className={`${property ? "ml-10" : "" }block border-0 border-t border-b border-neutral-300 pt-1.5 pb-1 px-1 text-neutral-900 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6`} | ||
placeholder='Enter Filter' | ||
value={value} | ||
onChange={(e) => setValue(e.target.value)} | ||
onFocus={() => {setActive(true)}} | ||
onBlur={() => { | ||
setTimeout(() => { | ||
setActive(false); | ||
if (value !== "") { | ||
if (property === "") { | ||
addFilter({property: "Repository", value: value}) | ||
} else { | ||
addFilter({property, value}) | ||
} | ||
reset() | ||
} else { | ||
if (property !== "") { | ||
reset() | ||
} | ||
} | ||
}, 200);} | ||
} | ||
onKeyUp={(e) => { | ||
if (e.keyCode === 13){ | ||
setActive(false) | ||
if (property === "") { | ||
addFilter({property: "Repository", value: value}) | ||
} else { | ||
addFilter({property, value}) | ||
} | ||
reset() | ||
} | ||
if (e.keyCode === 27){ | ||
reset() | ||
// inputRef.current.blur(); | ||
} | ||
}} | ||
type="search" | ||
/> | ||
</span> | ||
{active && property === "" && | ||
<div className="z-10 absolute bg-blue-100 w-48 p-2 text-blue-800"> | ||
<ul className=""> | ||
{properties.map(p => ( | ||
<li | ||
key={p} | ||
className="cursor-pointer hover:bg-blue-200" | ||
onClick={() => {setProperty(p); setActive(false); }}> | ||
{p} | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
} | ||
</span> | ||
) | ||
} |
Oops, something went wrong.