Skip to content

Commit

Permalink
Query builder (#22)
Browse files Browse the repository at this point in the history
Co-authored-by: Ameen Azeez <[email protected]>
  • Loading branch information
ameen4455 and Ameen Azeez authored Sep 29, 2022
1 parent e09aff2 commit 200735e
Show file tree
Hide file tree
Showing 26 changed files with 5,642 additions and 3,311 deletions.
7,924 changes: 4,906 additions & 3,018 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@
"react-scripts": "5.0.1",
"tailwindcss": "^3.1.3"
}
}
}
3 changes: 3 additions & 0 deletions src/assets/images/table-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions src/components/Button/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from "react";
import classNames from "classnames";

const Button = ({ children, disabled, onClick }) => {
return (
<button
onClick={onClick}
disabled={disabled}
className={classNames(
"py-2 leading-6 px-4 text-sm rounded-md disabled:opacity-75 bg-primary-200 text-gray-50"
)}
>
{children}
</button>
);
};

export default Button;
8 changes: 4 additions & 4 deletions src/components/Checkbox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import React from "react";

const Checkbox = ({ name, selected, onClick }) => {
return (
<div className="mx-1 my-1 flex">
<label className="px-5 w-full py-3 hover:bg-blue-50 rounded">
<div className="mx-2 flex">
<label className="px-5 w-full py-2 hover:bg-primary-400 rounded cursor-pointer">
<input
onChange={onClick}
type="checkbox"
checked={selected}
className="mb-1 h-5 w-5 mr-2 border-2 custom-focus border-gray-400 rounded-sm"
className="mb-1 h-4 w-4 text-secondary-700 ring-0 outline-0 focus bg-primary-700 mr-2 rounded-sm"
/>
<span className="font-semibold">{name}</span>
<span className="text-gray-200 text-sm">{name}</span>
</label>
</div>
);
Expand Down
46 changes: 29 additions & 17 deletions src/components/Dropdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,34 @@ import { Listbox } from "@headlessui/react";
import React from "react";
import { SelectorIcon } from "@heroicons/react/solid";

const Dropdown = ({ name, disabled, value, setValue }) => {
const Dropdown = ({ name, disabled, value, setValue, customStyle, Icon }) => {
const data = [
{
name: "1 sec",
name: "1s",
value: 1,
},
{
name: "2 sec",
name: "2s",
value: 2,
},
{
name: "5 sec",
name: "5s",
value: 5,
},
{
name: "10 sec",
name: "10s",
value: 10,
},
{
name: "20 sec",
name: "20s",
value: 20,
},
{
name: "1 min",
name: "1m",
value: 60,
},
{
name: "None",
name: "Off",
value: null,
},
];
Expand All @@ -42,21 +42,33 @@ const Dropdown = ({ name, disabled, value, setValue }) => {
</label>
<Listbox
as="div"
value={value}
value={disabled ? null : value}
onChange={setValue}
className="relative text-left ml-3 w-28"
className="relative text-left"
>
<Listbox.Button
disabled={disabled}
className={"input flex disabled:text-gray-300 mt-1 text-left"}
className={`${customStyle} input flex ${
disabled && "text-gray-400"
} mt-1 text-left`}
>
<div>
{disabled ? "None" : data.find((obj) => obj.value === value).name}
{disabled ? "Off" : data.find((obj) => obj.value === value).name}
</div>
<SelectorIcon
className="h-5 w-5 text-gray-500 ml-auto"
aria-hidden="true"
/>
{!Icon ? (
<SelectorIcon
className={`h-5 w-5 ${
disabled ? "text-gray-300" : "text-gray-500"
} ml-2`}
aria-hidden="true"
/>
) : (
<Icon
className={`h-5 w-5 ${
disabled ? "text-gray-300" : "text-gray-500"
} ml-2`}
/>
)}
</Listbox.Button>
<Listbox.Options
className={
Expand All @@ -71,7 +83,7 @@ const Dropdown = ({ name, disabled, value, setValue }) => {
active={active}
selected={selected}
// onClick={() => setValue(obj.value)}
className={`block custom-focus cursor-pointer hover:bg-bluePrimary hover:text-white text-sm font-semibold select-none py-2 px-4 text-gray-700`}
className={`block focus cursor-pointer hover:bg-bluePrimary hover:text-white text-sm font-semibold select-none py-2 px-4 text-gray-700`}
/>
)}
</Listbox.Option>
Expand Down
8 changes: 4 additions & 4 deletions src/components/Layout/Dialogue.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const HelpDialog = ({ isOpen, setIsOpen }) => {
style={{
boxShadow: "0px 2px 10px 3px rgba(0, 0, 0, 0.075)",
}}
className="w-56 py-12 px-14 rounded-lg custom-focus"
className="w-56 py-12 px-14 rounded-lg focus"
>
<img
src={SlackIcon}
Expand All @@ -86,7 +86,7 @@ const HelpDialog = ({ isOpen, setIsOpen }) => {
style={{
boxShadow: "0px 2px 10px 3px rgba(0, 0, 0, 0.075)",
}}
className="w-56 py-12 px-14 rounded-lg custom-focus"
className="w-56 py-12 px-14 rounded-lg focus"
>
<img
src={GitHubIcon}
Expand All @@ -102,13 +102,13 @@ const HelpDialog = ({ isOpen, setIsOpen }) => {
</a>

<a
href="https://www.parseable.io/docs"
href="https://www.parseable.io/docs/introduction"
target="_blank"
rel="noreferrer"
style={{
boxShadow: "0px 2px 10px 3px rgba(0, 0, 0, 0.075)",
}}
className="w-56 py-12 px-14 rounded-lg custom-focus"
className="w-56 py-12 px-14 rounded-lg focus"
>
<img
src={DocumentationIcon}
Expand Down
21 changes: 8 additions & 13 deletions src/components/Layout/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import React, { useState } from "react";

import Dialogue from "./Dialogue";
import Logo from "../../assets/images/Group 295.svg";
import StreamIcon from "../../assets/images/Icon awesome-stream (1).svg";
import UserIcon from "../../assets/images/Icon feather-user.svg";
import { useNavigate } from "react-router-dom";

Expand All @@ -19,7 +18,7 @@ const Navbar = ({ setSidebarOpen }) => {
return (
<>
<Dialogue isOpen={isHelpDialogueOpen} setIsOpen={setIsHelpDialogueOpen} />
<div className=" top-0 z-10 px-10 flex-shrink-0 flex h-16 bg-bluePrimary border-b-2 border-gray-500 shadow">
<div className=" top-0 z-10 px-5 flex-shrink-0 flex h-16 bg-bluePrimary border-b-2 border-gray-500 shadow">
<button
type="button"
className="px-4 border-r border-gray-200 text-gray-500 focus:outline-none focus:ring-2 focus:ring-inset focus:ring-bluePrimary md:hidden"
Expand All @@ -30,25 +29,21 @@ const Navbar = ({ setSidebarOpen }) => {
<span className="sr-only">Open sidebar</span>
<MenuAlt2Icon className="h-6 w-6" aria-hidden="true" />
</button>
<div className="flex-1 px-4 flex justify-between">
<div className="flex-1 flex justify-between">
<div className="flex-1 flex">
<img alt="" className="w-32" src={Logo} />
</div>
<div className="ml-4 flex items-center md:ml-6">
<button className="flex space-x-4 text-white font-medium h-full border-b-4 pl-7 pr-8 items-center justify-center border-white">
<img alt="" src={StreamIcon} className="w-6" />
<p>Streams</p>
</button>
<div className="ml-4 flex items-center md:ml-6">
<button
onClick={() => setIsHelpDialogueOpen(true)}
className={
"flex text-gray-400 py-5 px-7 text-sm border border-l-0 border-t-0 border-b-0 border-r-1 border-gray-400 custom-focus"
"flex text-gray-400 py-5 text-sm focus"
}
>
<QuestionMarkCircleIcon className="h-5 w-5 my-auto mr-2" />
<span className={"block mb-1"}>Help</span>
<QuestionMarkCircleIcon strokeWidth={1} className="h-5" />
<span className={"block ml-1"}>Help</span>
</button>
<div className="flex mx-8">
<div className="flex mr-8 ml-8">
<img alt="" className="w-3" src={UserIcon} />
<div className="ml-2 text-gray-400 text-sm">
{localStorage.getItem("username")?.length > 0
Expand All @@ -58,7 +53,7 @@ const Navbar = ({ setSidebarOpen }) => {
</div>
<div>
<LogoutIcon
className="text-gray-400 w-5 ml-6"
className="text-gray-400 w-5"
onClick={() => {
localStorage.removeItem("auth");
navigate("/");
Expand Down
12 changes: 2 additions & 10 deletions src/components/Layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,8 @@ export default function Layout({ children, labels }) {
setSidebarOpen={setSidebarOpen}
labels={labels}
/>
<div className="">
<div className="flex flex-col flex-1">
<main>
<div className="">
<div className="w-full">
<div className="">{children}</div>
</div>
</div>
</main>
</div>
<div className="flex">
{children}
</div>
</>
);
Expand Down
14 changes: 8 additions & 6 deletions src/components/Pill/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import React from "react";
import { XCircleIcon } from "@heroicons/react/solid";

const Pill = ({ text, onClose }) => {
const Pill = ({ text, onClose, equal }) => {
return (
<span className="relative block w-min py-1 pl-2 pr-6 truncate mr-1 bg-secondary-200 text-xs text-gray-800 font-semibold leading-3 rounded-md">
<span className={`relative block w-min py-1 pl-2 ${ onClose ? `pr-6 ${equal && `flex-1`}` : "pr-2"} max-w-[11rem] truncate mr-1 bg-gray-300 text-xs text-gray-700 font-semibold leading-3 rounded-md`}>
{text}
<XCircleIcon
onClick={onClose}
className="hover:text-gray-600 transform duration-200 text-red-700 w-4 absolute top-[0.125rem] right-1"
/>
{onClose && (
<XCircleIcon
onClick={onClose}
className="hover:text-gray-500 cursor-pointer transform duration-200 text-gray-700 w-4 absolute top-[0.125rem] right-1"
/>
)}
</span>
);
};
Expand Down
20 changes: 20 additions & 0 deletions src/components/PillFilter/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from "react";
import className from "classnames";

const PillFilter = ({ text, onClick, selected }) => {
return (
<div
onClick={() => onClick()}
className={className(
"block w-min py-2 px-3 max-w-[15rem] cursor-pointer hover:bg-gray-600 hover:text-gray-50 border-2 truncate mr-3 my-1 text-xs leading-3 rounded-xl",
{ "bg-gray-600 font-semibold text-gray-50 border-gray-600": selected },
{ "bg-gray-50 font-medium text-gray-600 border-gray-400": !selected }

)}
>
<span>{text}</span>
</div>
);
};

export default PillFilter;
67 changes: 67 additions & 0 deletions src/components/PillFilterList/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React, { useRef, useState } from "react";

import PillFilter from "../PillFilter";
import className from "classnames";

const useIsOverflow = (ref, callback) => {
const [isOverflow, setIsOverflow] = React.useState(undefined);

React.useLayoutEffect(() => {
const { current } = ref;
const trigger = () => {
const hasOverflow = current.scrollHeight > current.clientHeight;
setIsOverflow(hasOverflow);
if (callback) callback(hasOverflow);
};
if (current) {
trigger();
}
}, [callback, ref]);

return isOverflow;
};

export function PillFilterList({ x, onAdd, onRemove, values }) {
const [isOverflow, setIsOverflow] = useState(false);
const [selectedShowMore, setSelectedShowMore] = useState(false);
const [selected, setSelected] = useState(values);

const containerRef = useRef(null);

useIsOverflow(containerRef, (overflow) => setIsOverflow(overflow));

return (
<>
<div
ref={containerRef}
className={className("flex flex-wrap", {
"max-h-[5rem] overflow-hidden": !selectedShowMore,
})}
>
{x.map((x) => (
<PillFilter
text={x}
selected={selected.includes(x)}
onClick={() => {
if (selected.includes(x)) {
onRemove(x)
setSelected([...selected.filter((val) => val !== x)]);
} else {
onAdd(x)
setSelected([...selected, x]);
}
}}
/>
))}
</div>
<div>
{isOverflow && (
<PillFilter
onClick={() => setSelectedShowMore(true)}
text={"Show More"}
/>
)}
</div>
</>
);
}
4 changes: 2 additions & 2 deletions src/components/SearchableDropdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Combobox } from "@headlessui/react";
import DropdownButton from "../DropdownButton";
import { SelectorIcon } from "@heroicons/react/solid";

const SearchableDropdown = ({ data, setValue, value, label }) => {
const SearchableDropdown = ({ data, setValue, value, label, defaultValue }) => {
const [query, setQuery] = useState("");

const filteredData =
Expand All @@ -28,7 +28,7 @@ const SearchableDropdown = ({ data, setValue, value, label }) => {
setQuery(event.target.value);
}}
displayValue={function (val) {
return data.length && val ? val.name : "No data found";
return data && data.length && val ? val.name : defaultValue || "No data found";
}}
/>
<Combobox.Button className="absolute inset-y-0 right-0 flex items-center pr-2">
Expand Down
Loading

0 comments on commit 200735e

Please sign in to comment.