Skip to content

An open source alternative to Tableau. Embeddable visual analytic

Enhance filter rules input and style improvements (#111)

Brucesharkf815d076229f
diff --git a/packages/desktop/package.json b/packages/desktop/package.json
index 468e19e1..68fc1742 100644
--- a/packages/desktop/package.json
+++ b/packages/desktop/package.json
@@ -10,7 +10,7 @@
"tauri": "tauri"
},
"dependencies": {
- "@kanaries/graphic-walker": "0.3.10",
+ "@kanaries/graphic-walker": "0.3.11",
"@tauri-apps/api": "^1.1.0",
"react": "^17.x",
"react-dom": "^17.x"
diff --git a/packages/graphic-walker/package.json b/packages/graphic-walker/package.json
index a4cd2f50..bbc16aed 100644
--- a/packages/graphic-walker/package.json
+++ b/packages/graphic-walker/package.json
@@ -38,6 +38,7 @@
"@heroicons/react": "^2.0.8",
"@kanaries/react-beautiful-dnd": "0.0.2",
"@kanaries/web-data-loader": "^0.1.7",
+ "@tailwindcss/forms": "^0.5.4",
"autoprefixer": "^10.3.5",
"i18next": "^21.9.1",
"i18next-browser-languagedetector": "^6.1.5",
diff --git a/packages/graphic-walker/src/components/modal.tsx b/packages/graphic-walker/src/components/modal.tsx
index 9785d0ff..a8b3bd74 100644
--- a/packages/graphic-walker/src/components/modal.tsx
+++ b/packages/graphic-walker/src/components/modal.tsx
@@ -5,15 +5,15 @@ import { Fragment, useState } from "react";
import { Dialog, Transition } from "@headlessui/react";
import { ExclamationTriangleIcon, XMarkIcon } from "@heroicons/react/24/outline";
-const Background = styled.div({
- position: "fixed",
- left: 0,
- top: 0,
- width: "100vw",
- height: "100vh",
- backdropFilter: "blur(1px)",
- zIndex: 25535,
-});
+const Background = styled.div`
+ position: fixed;
+ left: 0;
+ top: 0;
+ width: 100vw;
+ height: 100vh;
+ backdrop-filter: blur(1px);
+ z-index: 25535;
+`;
const Container = styled.div`
width: 98%;
diff --git a/packages/graphic-walker/src/fields/filterField/filterEditDialog.tsx b/packages/graphic-walker/src/fields/filterField/filterEditDialog.tsx
index 12fbdf46..3fb6781c 100644
--- a/packages/graphic-walker/src/fields/filterField/filterEditDialog.tsx
+++ b/packages/graphic-walker/src/fields/filterField/filterEditDialog.tsx
@@ -1,4 +1,3 @@
-import { CheckCircleIcon } from "@heroicons/react/24/outline";
import { observer } from "mobx-react-lite";
import React from "react";
import { useTranslation } from "react-i18next";
@@ -9,6 +8,7 @@ import { useGlobalStore } from "../../store";
import Tabs, { RuleFormProps } from "./tabs";
import DefaultButton from "../../components/button/default";
import PrimaryButton from "../../components/button/primary";
+import DropdownSelect from "../../components/dropdownSelect";
const QuantitativeRuleForm: React.FC<RuleFormProps> = ({ field, onChange }) => {
return <Tabs field={field} onChange={onChange} tabs={["range", "one of"]} />;
@@ -23,7 +23,7 @@ const OrdinalRuleForm: React.FC<RuleFormProps> = ({ field, onChange }) => {
};
const TemporalRuleForm: React.FC<RuleFormProps> = ({ field, onChange }) => {
- return <Tabs field={field} onChange={onChange} tabs={["one of", "temporal range"]} />;
+ return <Tabs field={field} onChange={onChange} tabs={["temporal range", "one of"]} />;
};
const EmptyForm: React.FC<RuleFormProps> = () => <React.Fragment />;
@@ -71,6 +71,28 @@ const FilterEditDialog: React.FC = observer(() => {
vizStore.closeFilterEditing();
}, [editingFilterIdx, uncontrolledField]);
+ const allFieldOptions = React.useMemo(() => {
+ return [...draggableFieldState.dimensions, ...draggableFieldState.measures].map((d) => ({
+ label: d.name,
+ value: d.fid,
+ }));
+ }, [draggableFieldState]);
+
+ const handleSelectFilterField = (fieldKey) => {
+ const existingFilterIdx = draggableFieldState.filters.findIndex((field) => field.fid === fieldKey)
+ if (existingFilterIdx >= 0) {
+ vizStore.setFilterEditing(existingFilterIdx);
+ } else {
+ const sourceKey = draggableFieldState.dimensions.find((field) => field.fid === fieldKey)
+ ? "dimensions"
+ : "measures"
+ const sourceIndex = sourceKey === "dimensions"
+ ? draggableFieldState.dimensions.findIndex((field) => field.fid === fieldKey)
+ : draggableFieldState.measures.findIndex((field) => field.fid === fieldKey);
+ vizStore.moveField(sourceKey, sourceIndex, "filters", 0);
+ }
+ };
+
const Form = field
? ({
quantitative: QuantitativeRuleForm,
@@ -82,12 +104,15 @@ const FilterEditDialog: React.FC = observer(() => {
return uncontrolledField ? (
<Modal show={Boolean(uncontrolledField)} title={t("editing")} onClose={() => vizStore.closeFilterEditing()}>
- <div className="p-4">
- <h2 className="text-base font-semibold py-2 outline-none">{t("form.name")}</h2>
- <span className="inline-flex items-center rounded-full bg-indigo-100 px-3 py-0.5 text-sm font-medium text-indigo-800">
- {uncontrolledField.name}
- </span>
- <h3 className="text-base font-semibold py-2 outline-none">{t("form.rule")}</h3>
+ <div className="px-4 py-1">
+ <div className="py-1">{t("form.name")}</div>
+ <DropdownSelect
+ buttonClassName="w-96"
+ className="mb-2"
+ options={allFieldOptions}
+ selectedKey={uncontrolledField.fid}
+ onSelect={handleSelectFilterField}
+ />
<Form field={uncontrolledField} onChange={handleChange} />
<div className="mt-4">
<PrimaryButton
diff --git a/packages/graphic-walker/src/fields/filterField/slider.tsx b/packages/graphic-walker/src/fields/filterField/slider.tsx
index 61b73aa3..06f7c21d 100644
--- a/packages/graphic-walker/src/fields/filterField/slider.tsx
+++ b/packages/graphic-walker/src/fields/filterField/slider.tsx
@@ -1,81 +1,75 @@
-import React from 'react';
+import React, { useEffect } from 'react';
import styled from 'styled-components';
import { filter, fromEvent, map, throttleTime } from 'rxjs';
+import { useTranslation } from 'react-i18next';
-const SliderContainer = styled.div({
- display: 'flex',
- flexDirection: 'column',
- alignItems: 'stretch',
- justifyContent: 'stretch',
- overflow: 'hidden',
- paddingBlock: '1em',
-
- '> .output': {
- display: 'flex',
- flexDirection: 'row',
- flexWrap: 'wrap',
- alignItems: 'stretch',
- justifyContent: 'space-between',
-
- '> output': {
- userSelect: 'none',
- minWidth: '4em',
- paddingInline: '0.5em',
- textAlign: 'center',
- },
- },
-});
+const SliderContainer = styled.div`
+ display: flex;
+ flex-direction: column;
+ align-items: stretch;
+ justify-content: stretch;
+ overflow: hidden;
+ padding-block: 1em;
-const SliderElement = styled.div({
- marginInline: '1em',
- paddingBlock: '10px',
- flexGrow: 1,
- flexShrink: 1,
- display: 'flex',
- flexDirection: 'row',
- alignItems: 'center',
- justifyContent: 'stretch',
-});
+ > .output {
+ display: flex;
+ justify-content: space-between;
+ margin-top: 1em;
-const SliderTrack = styled.div({
- flexGrow: 1,
- flexShrink: 1,
- backgroundColor: '#ccc',
- border: '1px solid #aaa',
- height: '10px',
- borderRadius: '5px',
- position: 'relative',
-});
+ > output {
+ width: 100%;
+ }
-const SliderThumb = styled.div({
- position: 'absolute',
- top: '50%',
- cursor: 'ew-resize',
- backgroundColor: '#e2e2e2',
- backgroundImage: `
- linear-gradient(#666, #666 4%, transparent 4%, transparent 96%, #666 95%),
- linear-gradient(90deg, #666, #666 10%, transparent 10%, transparent 90%, #666 90%)
- `,
- width: '10px',
- height: '20px',
- borderRadius: '2px',
- outline: 'none',
-
- ':hover': {
- backgroundColor: '#fff',
- },
-});
+ > output:first-child {
+ margin-right: 0.5em;
+ }
+
+ > output:last-child {
+ margin-left: 0.5em;
+ }
+ }
+`;
-const SliderSlice = styled.div({
- backgroundColor: '#fff',
- position: 'absolute',
- height: '100%',
- borderRadius: '5px',
+const SliderElement = styled.div`
+ margin-inline: 0.5em;
+ padding: 1em;
+ flex-grow: 1;
+ flex-shrink: 1;
+ display: flex;
+ flex-direction: row;
+ align-items: center;
+ justify-content: stretch;
+`;
- ':hover': {
- backgroundColor: '#fff',
- },
-});
+const SliderTrack = styled.div`
+ flex-grow: 1;
+ flex-shrink: 1;
+ background-color: #ccc;
+ height: 5px;
+ border-radius: 3px;
+ position: relative;
+`;
+
+const SliderThumb = styled.div`
+ position: absolute;
+ top: 50%;
+ cursor: ew-resize;
+ background-color: #fff;
+ width: 2em;
+ height: 2em;
+ border-radius: 1em;
+ outline: none;
+ box-shadow: 0 4px 6px 2px rgba(0, 0, 0, 0.1);
+
+ &:hover {
+ background-color: #fff;
+ }
+`;
+
+const SliderSlice = styled.div`
+ position: absolute;
+ height: 100%;
+`;
const nicer = (range: readonly [number, number], value: number): string => {
@@ -84,12 +78,40 @@ const nicer = (range: readonly [number, number], value: number): string => {
return precision === undefined ? `${value}` : value.toFixed(precision).replace(/\.?0+$/, '');
};
+interface ValueInputProps {
+ min: number;
+ max: number;
+ value: number;
+ resetValue: number;
+ onChange: (value: number) => void;
+}
+
+const ValueInput: React.FC<ValueInputProps> = props => {
+ const { min, max, value, resetValue, onChange } = props;
+ const handleSubmitValue = (value) => {
+ if (!isNaN(value) && value <= max && value >= min) {
+ onChange(value);
+ } else {
+ onChange(resetValue);
+ }
+ }
+ return (
+ <input
+ type="number"
+ min={min}
+ max={max}
+ className="block w-full rounded-md border-0 py-1 px-2 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-1 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6"
+ value={value}
+ onChange={(e) => handleSubmitValue(Number(e.target.value))}
+ />
+ )
+}
+
interface SliderProps {
min: number;
max: number;
value: readonly [number, number];
onChange: (value: readonly [number, number]) => void;
- isDateTime?: boolean;
}
const Slider: React.FC<SliderProps> = React.memo(function Slider ({
@@ -97,7 +119,6 @@ const Slider: React.FC<SliderProps> = React.memo(function Slider ({
max,
value,
onChange,
- isDateTime = false,
}) {
const [dragging, setDragging] = React.useState<'left' | 'right' | null>(null);
const trackRef = React.useRef<HTMLDivElement | null>(null);
@@ -110,7 +131,9 @@ const Slider: React.FC<SliderProps> = React.memo(function Slider ({
const mouseOffsetRef = React.useRef(0);
- React.useEffect(() => {
+ const { t } = useTranslation();
+
+ useEffect(() => {
if (dragging) {
const stop = (ev?: MouseEvent) => {
setDragging(null);
@@ -166,14 +189,6 @@ const Slider: React.FC<SliderProps> = React.memo(function Slider ({
return (
<SliderContainer>
- <div className="output">
- <output htmlFor="slider:min">
- {isDateTime ? `${new Date(value[0])}` : nicer([min, max], value[0])}
- </output>
- <output htmlFor="slider:max">
- {isDateTime ? `${new Date(value[1])}` : nicer([min, max], value[1])}
- </output>
- </div>
<SliderElement>
<SliderTrack
ref={e => trackRef.current = e}
@@ -181,6 +196,7 @@ const Slider: React.FC<SliderProps> = React.memo(function Slider ({
<SliderSlice
role="presentation"
ref={e => sliceRef.current = e}
+ className="bg-indigo-600"
style={{
left: `${range[0] * 100}%`,
width: `${(range[1] - range[0]) * 100}%`,
@@ -193,7 +209,7 @@ const Slider: React.FC<SliderProps> = React.memo(function Slider ({
aria-valuemin={min}
aria-valuemax={max}
aria-valuenow={value[0]}
- aria-valuetext={isDateTime ? `${new Date(value[0])}` : nicer([min, max], value[0])}
+ aria-valuetext={nicer([min, max], value[0])}
tabIndex={-1}
onMouseDown={ev => {
if (ev.buttons === 1) {
@@ -202,7 +218,7 @@ const Slider: React.FC<SliderProps> = React.memo(function Slider ({
}
}}
style={{
- left: `${range[0] * 100}%`,
+ left: `calc(1em + ${range[0] * 100}%)`,
transform: 'translate(-100%, -50%)',
}}
/>
@@ -213,7 +229,7 @@ const Slider: React.FC<SliderProps> = React.memo(function Slider ({
aria-valuemin={min}
aria-valuemax={max}
aria-valuenow={value[1]}
- aria-valuetext={isDateTime ? `${new Date(value[1])}` : nicer([min, max], value[1])}
+ aria-valuetext={nicer([min, max], value[1])}
tabIndex={-1}
onMouseDown={ev => {
if (ev.buttons === 1) {
@@ -222,12 +238,38 @@ const Slider: React.FC<SliderProps> = React.memo(function Slider ({
}
}}
style={{
- left: `${range[1] * 100}%`,
+ left: `calc(${range[1] * 100}% - 1em)`,
transform: 'translate(0, -50%)',
}}
/>
</SliderTrack>
</SliderElement>
+ <div className="output">
+ <output htmlFor="slider:min">
+ <div className="my-1">{t('filters.range.start_value')}</div>
+ {
+ <ValueInput
+ min={min}
+ max={value[1]}
+ value={value[0]}
+ resetValue={min}
+ onChange={(newValue) => onChange([newValue, value[1]])}
+ />
+ }
+ </output>
+ <output htmlFor="slider:max">
+ <div className="my-1">{t('filters.range.end_value')}</div>
+ {
+ <ValueInput
+ min={value[0]}
+ max={max}
+ value={value[1]}
+ resetValue={max}
+ onChange={(newValue) => onChange([value[0], newValue])}
+ />
+ }
+ </output>
+ </div>
</SliderContainer>
);
});
diff --git a/packages/graphic-walker/src/fields/filterField/tabs.tsx b/packages/graphic-walker/src/fields/filterField/tabs.tsx
index 5a89bf53..bfc2c108 100644
--- a/packages/graphic-walker/src/fields/filterField/tabs.tsx
+++ b/packages/graphic-walker/src/fields/filterField/tabs.tsx
@@ -1,107 +1,127 @@
import { observer } from 'mobx-react-lite';
-import React from 'react';
+import React, { useMemo, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import styled from 'styled-components';
import type { IFilterField, IFilterRule } from '../../interfaces';
import { useGlobalStore } from '../../store';
-import PureTabs from '../../components/tabs/defaultTab';
import Slider from './slider';
-
export type RuleFormProps = {
field: IFilterField;
onChange: (rule: IFilterRule) => void;
};
-const Container = styled.div({
- marginBlock: '1em',
- marginInline: '2em',
+const Container = styled.div`
+ margin-block: 1em;
- '> .btn-grp': {
- display: 'flex',
- flexDirection: 'row',
- marginBlock: '0.4em 0.6em',
+ > .btn-grp {
+ display: flex;
+ flex-direction: row;
+ margin-block: 1em;
- '> *': {
- marginInlineStart: '0.6em',
+ > * {
+ margin-inline-start: 0.6em;
- '&:first-child': {
- marginInlineStart: 0,
+ &:first-child: {
+ margin-inline-start: 0;
},
},
},
-});
-
-export const Button = styled.button({
- '&:hover': {
- backgroundColor: 'rgba(243, 244, 246, 0.5)',
- },
- color: 'rgb(55, 65, 81)',
- boxShadow: '1px 1px 2px #0002, inset 2px 2px 4px #0001',
- paddingBlock: '0.2em',
- paddingInline: '0.5em',
- userSelect: 'none',
- cursor: 'pointer',
-});
-
-const Table = styled.div({
- display: 'grid',
- gridTemplateColumns: '4em auto max-content',
- maxHeight: '30vh',
- overflowY: 'scroll',
- '& > *': {
- marginBlock: '2px',
- paddingInline: '4px',
- whiteSpace: 'nowrap',
- overflow: 'hidden',
- textOverflow: 'ellipsis',
- userSelect: 'none',
- },
- '& > input, & > *[for]': {
- cursor: 'pointer',
- },
-});
-
-const TabsContainer = styled.div({
- display: 'flex',
- flexDirection: 'column',
- alignItems: 'stretch',
- justifyContent: 'stretch',
-});
+`;
+
+export const Button = styled.button`
+ :hover: {
+ background-color: rgba(243, 244, 246, 0.5);
+ };
+ color: rgb(55, 65, 81);
+ border: 1px solid rgb(226 232 240);
+ border-radius: 0.5em;
+ padding-block: 0.4em;
+ padding-inline: 1em;
+ user-select: none;
+ font-weight: bold;
+ cursor: pointer;
+`;
+
+const Table = styled.div`
+ display: grid;
+ grid-template-columns: 4em auto max-content;
+ max-height: 30vh;
+ overflow-y: scroll;
+
+ & > * {
+ padding-block: 0.6em;
+ padding-inline: 0.2em;
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ user-select: none;
+ border-bottom: 0.8px solid rgb(226 232 240);
+ }
+
+ & > input,
+ & > *[for] {
+ cursor: pointer;
+ }
+`;
+
+const TabsContainer = styled.div`
+ display: flex;
+ flex-direction: column;
+ align-items: stretch;
+ justify-content: stretch;
+`;
+
+const CalendarInputContainer = styled.div`
+ display: flex;
+ padding-block: 1em;
+ width: 100%;
+
+ > .calendar-input {
+ width: 100%;
+ }
+
+ > .calendar-input:first-child {
+ margin-right: 0.5em;
+ }
+
+ > .calendar-input:last-child {
+ margin-left: 0.5em;
+ }
+`;
+
+const TabPanel = styled.div``;
+
+const TabItem = styled.div``;
+
+const StatusCheckbox: React.FC<{currentNum: number; totalNum: number; onChange: () => void}> = props => {
+ const { currentNum, totalNum, onChange } = props;
+ const checkboxRef = useRef(null);
-const TabList = styled.div({
- display: 'flex',
- flexDirection: 'row',
- alignItems: 'stretch',
- justifyContent: 'flex-start',
- overflow: 'hidden',
-});
-
-const TabHeader = styled.label({
- outline: 'none',
- userSelect: 'none',
- paddingBlock: '0.4em',
- paddingInline: '1em 2em',
- borderWidth: '1px',
- borderRadius: '4px 4px 0 0',
- position: 'relative',
-
- '&[aria-selected]': {
- borderBottomColor: '#0000',
- zIndex: 15,
- },
- '&[aria-selected=false]': {
- backgroundColor: '#f8f8f8',
- borderBottomColor: '#e2e2e2',
- cursor: 'pointer',
- zIndex: 14,
- },
-});
-
-const TabPanel = styled.div({});
+ React.useEffect(() => {
+ if (!checkboxRef.current) return;
+ const checkboxRefDOM = (checkboxRef.current as HTMLInputElement)
+ if (currentNum === totalNum) {
+ checkboxRefDOM.checked = true;
+ checkboxRefDOM.indeterminate = false;
+ } else if (currentNum < totalNum && currentNum > 0) {
+ checkboxRefDOM.indeterminate = true;
+ } else if (currentNum === 0) {
+ checkboxRefDOM.checked = false;
+ checkboxRefDOM.indeterminate = false;
+ }
+ }, [currentNum, totalNum])
-const TabItem = styled.div({});
+ return (
+ <input
+ type="checkbox"
+ className="h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-600"
+ ref={checkboxRef}
+ onChange={() => onChange()}
+ />
+ )
+}
export const FilterOneOfRule: React.FC<RuleFormProps & { active: boolean }> = observer(({
active,
@@ -121,7 +141,7 @@ export const FilterOneOfRule: React.FC<RuleFormProps & { active: boolean }> = ob
}, new Map<string | number, number>());
}, [dataSource, field]);
- const { t } = useTranslation('translation', { keyPrefix: 'filters' });
+ const { t } = useTranslation('translation');
React.useEffect(() => {
if (active && field.rule?.type !== 'one of') {
@@ -132,19 +152,86 @@ export const FilterOneOfRule: React.FC<RuleFormProps & { active: boolean }> = ob
}
}, [active, onChange, field, count]);
+ const handleToggleFullOrEmptySet = () => {
+ if (!field.rule || field.rule.type !== 'one of') return;
+ const curSet = field.rule.value;
+ onChange({
+ type: 'one of',
+ value: new Set<number | string>(
+ curSet.size === count.size
+ ? []
+ : count.keys()
+ ),
+ });
+ }
+ const handleToggleReverseSet = () => {
+ if (!field.rule || field.rule.type !== 'one of') return;
+ const curSet = field.rule.value;
+ onChange({
+ type: 'one of',
+ value: new Set<number | string>(
+ [...count.keys()].filter(key => !curSet.has(key))
+ ),
+ });
+ }
+ const handleSelectValue = (value, checked) => {
+ if (!field.rule || field.rule?.type !== 'one of') return;
+ const rule: IFilterRule = {
+ type: 'one of',
+ value: new Set(field.rule.value)
+ };
+ if (checked) {
+ rule.value.add(value);
+ } else {
+ rule.value.delete(value);
+ }
+ onChange(rule);
+ }
+
+ const selectedValueSum = useMemo(() => {
+ if (!field.rule) return 0;
+ return [...field.rule.value].reduce<number>((sum, key) => {
+ const s = dataSource.filter(which => which[field.fid] === key).length;
+ return sum + s;
+ }, 0)
+ }, [field.rule?.value])
+
return field.rule?.type === 'one of' ? (
<Container>
- <Table>
- <label className="header">
- {t('header.visibility')}
- </label>
- <label className="header">
- {t('header.value')}
+ <div>{t('constant.filter_type.one_of')}</div>
+ <div className="text-gray-500">{t('constant.filter_type.one_of_desc')}</div>
+ <div className="btn-grp">
+ <Button
+ onClick={() => handleToggleFullOrEmptySet()}
+ >
+ {
+ field.rule.value.size === count.size
+ ? t('filters.btn.unselect_all')
+ : t('filters.btn.select_all')
+ }
+ </Button>
+ <Button
+ onClick={() => handleToggleReverseSet()}
+ >
+ {t('filters.btn.reverse')}
+ </Button>
+ </div>
+ <Table className="bg-slate-50">
+ <div className="flex justify-center items-center">
+ <StatusCheckbox
+ currentNum={field.rule.value.size}
+ totalNum={count.size}
+ onChange={handleToggleFullOrEmptySet}
+ />
+ </div>
+ <label className="header text-gray-500">
+ {t('filters.header.value')}
</label>
- <label className="header">
- {t('header.count')}
+ <label className="header text-gray-500">
+ {t('filters.header.count')}
</label>
</Table>
+ {/* <hr /> */}
<Table>
{
[...count.entries()].map(([value, count], idx) => {
@@ -152,31 +239,17 @@ export const FilterOneOfRule: React.FC<RuleFormProps & { active: boolean }> = ob
return (
<React.Fragment key={idx}>
- <input
- type="checkbox"
- checked={field.rule?.type === 'one of' && field.rule.value.has(value)}
- id={id}
- aria-describedby={`${id}_label`}
- title={String(value)}
- onChange={({ target: { checked } }) => {
- if (field.rule?.type !== 'one of') {
- return;
- }
-
- const rule: IFilterRule = {
- type: 'one of',
- value: new Set(field.rule.value)
- };
-
- if (checked) {
- rule.value.add(value);
- } else {
- rule.value.delete(value);
- }
-
- onChange(rule);
- }}
- />
+ <div className="flex justify-center items-center">
+ <input
+ type="checkbox"
+ className="h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-600"
+ checked={field.rule?.type === 'one of' && field.rule.value.has(value)}
+ id={id}
+ aria-describedby={`${id}_label`}
+ title={String(value)}
+ onChange={({ target: { checked } }) => handleSelectValue(value, checked)}
+ />
+ </div>
<label
id={`${id}_label`}
htmlFor={id}
@@ -197,60 +270,45 @@ export const FilterOneOfRule: React.FC<RuleFormProps & { active: boolean }> = ob
<Table className="text-gray-600">
<label></label>
<label>
- {t('selected_keys', { count: field.rule.value.size })}
+ {t('filters.selected_keys', { count: field.rule.value.size })}
</label>
<label>
- {[...field.rule.value].reduce<number>((sum, key) => {
- const s = dataSource.filter(which => which[field.fid] === key).length;
-
- return sum + s;
- }, 0)}
+ {selectedValueSum}
</label>
</Table>
- <div className="btn-grp">
- <Button
- onClick={() => {
- if (field.rule?.type === 'one of') {
- const curSet = field.rule.value;
-
- onChange({
- type: 'one of',
- value: new Set<number | string>(
- curSet.size === count.size
- ? []
- : count.keys()
- ),
- });
- }
- }}
- >
- {
- field.rule.value.size === count.size
- ? t('btn.unselect_all')
- : t('btn.select_all')
- }
- </Button>
- <Button
- onClick={() => {
- if (field.rule?.type === 'one of') {
- const curSet = field.rule.value;
-
- onChange({
- type: 'one of',
- value: new Set<number | string>(
- [...count.keys()].filter(key => !curSet.has(key))
- ),
- });
- }
- }}
- >
- {t('btn.reverse')}
- </Button>
- </div>
</Container>
) : null;
});
+interface CalendarInputProps {
+ min: number;
+ max: number;
+ value: number;
+ onChange: (value: number) => void;
+}
+
+const CalendarInput: React.FC<CalendarInputProps> = props => {
+ const { min, max, value, onChange } = props;
+ const dateStringFormatter = (timestamp: number) => {
+ return new Date(timestamp).toISOString().slice(0, 19);
+ }
+ const handleSubmitDate = (value) => {
+ if (new Date(value).getTime() <= max && new Date(value).getTime() >= min) {
+ onChange(new Date(value).getTime())
+ }
+ }
+ return (
+ <input
+ className="block w-full rounded-md border-0 py-1 px-2 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-1 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6"
+ type="datetime-local"
+ min={dateStringFormatter(min)}
+ max={dateStringFormatter(max)}
+ defaultValue={dateStringFormatter(value)}
+ onChange={(e) => handleSubmitDate(e.target.value)}
+ />
+ )
+}
+
export const FilterTemporalRangeRule: React.FC<RuleFormProps & { active: boolean }> = observer(({
active,
field,
@@ -259,6 +317,8 @@ export const FilterTemporalRangeRule: React.FC<RuleFormProps & { active: boolean
const { commonStore } = useGlobalStore();
const { currentDataset: { dataSource } } = commonStore;
+ const { t } = useTranslation('translation');
+
const sorted = React.useMemo(() => {
return dataSource.reduce<number[]>((list, d) => {
try {
@@ -293,14 +353,29 @@ export const FilterTemporalRangeRule: React.FC<RuleFormProps & { active: boolean
}, []);
return field.rule?.type === 'temporal range' ? (
- <Container>
- <Slider
- min={min}
- max={max}
- value={field.rule.value}
- onChange={handleChange}
- isDateTime
- />
+ <Container className="overflow-visible">
+ <div>{t('constant.filter_type.temporal_range')}</div>
+ <div className="text-gray-500">{t('constant.filter_type.temporal_range_desc')}</div>
+ <CalendarInputContainer>
+ <div className="calendar-input">
+ <div className="my-1">{t('filters.range.start_value')}</div>
+ <CalendarInput
+ min={min}
+ max={field.rule.value[1]}
+ value={field.rule.value[0]}
+ onChange={(value) => handleChange([value, field.rule?.value[1]])}
+ />
+ </div>
+ <div className="calendar-input">
+ <div className="my-1">{t('filters.range.end_value')}</div>
+ <CalendarInput
+ min={field.rule.value[0]}
+ max={max}
+ value={field.rule.value[1]}
+ onChange={(value) => handleChange([field.rule?.value[0], value])}
+ />
+ </div>
+ </CalendarInputContainer>
</Container>
) : null;
});
@@ -313,6 +388,8 @@ export const FilterRangeRule: React.FC<RuleFormProps & { active: boolean }> = ob
const { commonStore } = useGlobalStore();
const { currentDataset: { dataSource } } = commonStore;
+ const { t } = useTranslation('translation', { keyPrefix: 'constant.filter_type' });
+
const sorted = React.useMemo(() => {
return dataSource.map(d => d[field.fid]).sort((a, b) => a - b);
}, [dataSource, field]);
@@ -339,6 +416,8 @@ export const FilterRangeRule: React.FC<RuleFormProps & { active: boolean }> = ob
return field.rule?.type === 'range' ? (
<Container>
+ <div>{t('range')}</div>
+ <div className="text-gray-500">{t('range_desc')}</div>
<Slider
min={min}
max={max}
@@ -355,6 +434,21 @@ const filterTabs: Record<IFilterRule['type'], React.FC<RuleFormProps & { active:
'temporal range': FilterTemporalRangeRule,
};
+const tabOptionDict = {
+ "one of": {
+ key: "one_of",
+ descKey: "one_of_desc"
+ },
+ "range": {
+ key: "range",
+ descKey: "range_desc"
+ },
+ "temporal range": {
+ key: "temporal_range",
+ descKey: "temporal_range_desc"
+ }
+};
+
export interface TabsProps extends RuleFormProps {
tabs: IFilterRule['type'][];
}
@@ -366,19 +460,42 @@ const Tabs: React.FC<TabsProps> = observer(({ field, onChange, tabs }) => {
const { t } = useTranslation('translation', { keyPrefix: 'constant.filter_type' });
const [which, setWhich] = React.useState(field.rule?.type ?? tabs[0]!);
-
+ React.useEffect(() => {
+ if (!tabs.includes(which)) setWhich(tabs[0]);
+ }, [tabs])
+
return (
<TabsContainer>
- <PureTabs
- selectedKey={which}
- tabs={tabs.map(tab => ({
- key: tab,
- label: t(tab.replaceAll(/ /g, '_')),
- }))}
- onSelected={sk => {
- setWhich(sk as typeof which);
- }}
- />
+ <div>
+ {
+ tabs.map((option) => {
+ return (
+ <div className="flex my-2" key={option}>
+ <div className="align-top">
+ <input
+ type="radio"
+ className="h-4 w-4 border-gray-300 text-indigo-600 focus:ring-indigo-600"
+ id={option}
+ checked={option === which}
+ onChange={e => setWhich((e.target as HTMLInputElement).value as typeof which)}
+ name="filter_type"
+ value={option}
+ />
+ </div>
+ <div className="ml-3">
+ <label htmlFor={option}>
+ {t(tabOptionDict[option].key)}
+ </label>
+ <div className="text-gray-500">
+ {t(tabOptionDict[option].descKey)}
+ </div>
+ </div>
+ </div>
+ )
+ })
+ }
+ </div>
+ <hr className="my-0.5"/>
<TabPanel>
{
tabs.map((tab, i) => {
@@ -387,8 +504,8 @@ const Tabs: React.FC<TabsProps> = observer(({ field, onChange, tabs }) => {
return draggableFieldState === null ? null : (
<TabItem
key={i}
- id={`filter-panel-${tab.replaceAll(/ /g, '_')}`}
- aria-labelledby={`filter-tab-${tab.replaceAll(/ /g, '_')}`}
+ id={`filter-panel-${tabOptionDict[tab]}`}
+ aria-labelledby={`filter-tab-${tabOptionDict[tab]}`}
role="tabpanel"
hidden={which !== tab}
tabIndex={0}
diff --git a/packages/graphic-walker/src/locales/en-US.json b/packages/graphic-walker/src/locales/en-US.json
index 4f3513a4..4e4cfb3e 100644
--- a/packages/graphic-walker/src/locales/en-US.json
+++ b/packages/graphic-walker/src/locales/en-US.json
@@ -83,9 +83,12 @@
"variance": "Variance"
},
"filter_type": {
- "one_of": "One-Of",
+ "one_of": "Value set",
+ "one_of_desc": "Select values specified",
"range": "Range",
- "temporal_range": "Date Range"
+ "range_desc": "Select values in a range [start, end]",
+ "temporal_range": "Date Range",
+ "temporal_range_desc": "Select values in a date range [start, end]"
}
},
"App": {
@@ -165,7 +168,7 @@
"filters": {
"to_edit": "Edit This Rule",
"empty_rule": "! (empty rule)",
- "editing": "Edit Rule",
+ "editing": "Filter Rule Settings",
"form": {
"name": "Field",
"rule": "Rule"
@@ -182,6 +185,10 @@
"reverse": "Reverse Selection",
"confirm": "Confirm",
"cancel": "Cancel"
+ },
+ "range": {
+ "start_value": "Start Value",
+ "end_value": "End Value"
}
},
"explain": {
diff --git a/packages/graphic-walker/src/locales/ja-JP.json b/packages/graphic-walker/src/locales/ja-JP.json
index 8aec3d76..16d5be42 100644
--- a/packages/graphic-walker/src/locales/ja-JP.json
+++ b/packages/graphic-walker/src/locales/ja-JP.json
@@ -82,9 +82,12 @@
"variance": "分散"
},
"filter_type": {
- "one_of": "1つ以上",
+ "one_of": "値のセット",
+ "one_of_desc": "指定された値を選択します",
"range": "範囲",
- "temporal_range": "日付範囲"
+ "range_desc": "範囲 [開始, 終了] 内の値を選択します",
+ "temporal_range": "日付範囲",
+ "temporal_range_desc": "日付範囲 [開始, 終了] 内の値を選択します"
}
},
"App": {
@@ -164,7 +167,7 @@
"filters": {
"to_edit": "このルールを編集",
"empty_rule": "! (空のルール)",
- "editing": "ルールを編集",
+ "editing": "フィルタールールの設定",
"form": {
"name": "フィールド",
"rule": "ルール"
@@ -181,6 +184,10 @@
"reverse": "選択を反転する",
"confirm": "確認",
"cancel": "キャンセル"
+ },
+ "range": {
+ "start_value": "開始値",
+ "end_value": "終了値"
}
},
"explain": {
diff --git a/packages/graphic-walker/src/locales/zh-CN.json b/packages/graphic-walker/src/locales/zh-CN.json
index 4afc6d08..b674b580 100644
--- a/packages/graphic-walker/src/locales/zh-CN.json
+++ b/packages/graphic-walker/src/locales/zh-CN.json
@@ -84,8 +84,11 @@
},
"filter_type": {
"one_of": "按值筛选",
+ "one_of_desc": "选择指定的值",
"range": "按范围筛选",
- "temporal_range": "按日期范围筛选"
+ "range_desc": "选择范围内的值 [开始, 结束]",
+ "temporal_range": "按日期范围筛选",
+ "temporal_range_desc": "选择日期范围内的值 [开始, 结束]"
}
},
"App": {
@@ -165,7 +168,7 @@
"filters": {
"to_edit": "编辑这条规则",
"empty_rule": "! (空的规则)",
- "editing": "编辑规则",
+ "editing": "筛选器规则设定",
"form": {
"name": "字段",
"rule": "规则"
@@ -182,6 +185,10 @@
"reverse": "选择反向",
"confirm": "确认",
"cancel": "取消"
+ },
+ "range": {
+ "start_value": "起始值",
+ "end_value": "终止值"
}
},
"explain": {
diff --git a/packages/graphic-walker/tailwind.config.js b/packages/graphic-walker/tailwind.config.js
index cfd32308..350556d5 100644
--- a/packages/graphic-walker/tailwind.config.js
+++ b/packages/graphic-walker/tailwind.config.js
@@ -23,5 +23,7 @@ module.exports = {
pattern: /text-([a-z]+)-(500)/,
}
],
- plugins: [],
+ plugins: [
+ require('@tailwindcss/forms'),
+ ],
}
diff --git a/yarn.lock b/yarn.lock
index c2f5f3c9..8bce2bf0 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -612,6 +612,13 @@
estree-walker "^1.0.1"
picomatch "^2.2.2"
+"@tailwindcss/forms@^0.5.4":
+ version "0.5.4"
+ resolved "https://registry.npmmirror.com/@tailwindcss/forms/-/forms-0.5.4.tgz#5316a782fd95369eb5b6fd01d46323b3dce656a2"
+ integrity sha512-YAm12D3R7/9Mh4jFbYSMnsd6jG++8KxogWgqs7hbdo/86aWjjlIEvL7+QYdVELmAI0InXTpZqFIg5e7aDVWI2Q==
+ dependencies:
+ mini-svg-data-uri "^1.2.3"
+
"@tauri-apps/api@^1.1.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@tauri-apps/api/-/api-1.2.0.tgz#1f196b3e012971227f41b98214c846430a4eb477"
@@ -1745,6 +1752,11 @@ micromatch@^4.0.4, micromatch@^4.0.5:
braces "^3.0.2"
picomatch "^2.3.1"
+mini-svg-data-uri@^1.2.3:
+ version "1.4.4"
+ resolved "https://registry.npmmirror.com/mini-svg-data-uri/-/mini-svg-data-uri-1.4.4.tgz#8ab0aabcdf8c29ad5693ca595af19dd2ead09939"
+ integrity sha512-r9deDe9p5FJUPZAk3A59wGH7Ii9YrjjWw0jmw/liSbHl2CHiyXj6FcDXDu2K3TjVAXqiJdaw3xxwlZZr9E6nHg==
+
minimist@^1.2.6:
version "1.2.8"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c"