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

CB-4628 remove unused logic #2367

Merged
merged 7 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
27 changes: 10 additions & 17 deletions webapp/packages/core-blocks/src/FormControls/Filter.m.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,36 @@
min-height: 24px;
}
.inputField {
display: none;
display: block;
width: 300px;
&.max {
width: 100%;
}
&.toggled {
display: block;
}

& .input {
& input {
padding-right: 40px !important;
}

}
.iconButton {
position: absolute;
right: 0;
top: 0;
right: 4px;
top: 4px;
margin: 0;
width: 24px;
height: 24px;
border-radius: 2px;
cursor: auto;

&.toggled {
right: 4px;
top: 4px;
}
&.cross {
&.cross svg {
width: 16px;
height: 16px;
top: 8px;
right: 8px;
}

&.cross.manualMode {
right: 32px;
}
}

.toggleMode {
.manualMode {
composes: theme-background-primary theme-text-on-primary from global;
cursor: pointer;
}
68 changes: 32 additions & 36 deletions webapp/packages/core-blocks/src/FormControls/Filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* you may not use this file except in compliance with the License.
*/
import { observer } from 'mobx-react-lite';
import { useCallback, useEffect, useState } from 'react';
import { useCallback } from 'react';

import { IconButton } from '../IconButton';
import { s } from '../s';
Expand All @@ -16,12 +16,12 @@ import filterStyle from './Filter.m.css';
import { InputField } from './InputField';

interface BaseProps {
toggleMode?: boolean;
placeholder?: string;
disabled?: boolean;
max?: boolean;
className?: string;
onToggle?: (status: boolean) => void;
onFilter?: (value: string) => void;
onClean?: () => void;
Wroud marked this conversation as resolved.
Show resolved Hide resolved
onKeyDown?: (event: React.KeyboardEvent<HTMLInputElement>) => void;
onClick?: (event: React.MouseEvent<HTMLDivElement>) => void;
}
Expand All @@ -44,19 +44,18 @@ export const Filter = observer<ControlledProps | ObjectsProps<any, any>>(functio
state,
name,
value: valueControlled,
toggleMode,
placeholder,
disabled,
max,
className,
onFilter,
onClean,
onChange,
onToggle,
onKeyDown,
onClick,
}) {
const styles = useS(filterStyle);
const [inputRef, ref] = useFocus<HTMLInputElement>({});
const [toggled, setToggled] = useState(!toggleMode);
const [inputRef] = useFocus<HTMLInputElement>({});

const filter = useCallback(
(value: string | number, name?: string) => {
Expand All @@ -73,55 +72,52 @@ export const Filter = observer<ControlledProps | ObjectsProps<any, any>>(functio
[onChange, state],
);

const toggle = useCallback(() => {
if (!toggleMode) {
return;
}

if (toggled) {
filter('');
}

setToggled(!toggled);
let value: any = valueControlled;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add type please


if (onToggle) {
onToggle(!toggled);
}
}, [toggleMode, toggled, onToggle, filter]);
if (state && name !== undefined && name in state) {
value = state[name];
}

useEffect(() => {
if (toggled && toggleMode) {
ref.reference?.focus();
function handleKeyDown(event: React.KeyboardEvent<HTMLInputElement>) {
if (event.key === 'Enter' && onFilter) {
onFilter(value);
}
}, [toggled, toggleMode, ref.reference]);

let value: any = valueControlled;
onKeyDown?.(event);
}

if (state && name !== undefined && name in state) {
value = state[name];
function clean() {
filter('', name);
if (onClean) {
onClean();
}
}

const manualMode = !!onFilter;
const edited = !!String(value);

return (
<div className={s(styles, { filterContainer: true }, className)} onClick={onClick}>
<InputField
ref={inputRef}
className={s(styles, { inputField: true, max, toggled })}
className={s(styles, { inputField: true, max })}
placeholder={placeholder}
disabled={disabled}
name={name}
value={value}
onChange={filter}
onKeyDown={onKeyDown}
onKeyDown={handleKeyDown}
/>
{String(value) ? (

{edited && <IconButton className={s(styles, { iconButton: true, cross: true, manualMode })} name="cross" disabled={disabled} onClick={clean} />}

{(!edited || manualMode) && (
<IconButton
className={s(styles, { iconButton: true, cross: true, toggleMode })}
name="cross"
className={s(styles, { iconButton: true, manualMode })}
name="search"
disabled={disabled}
onClick={() => filter('', name)}
onClick={onFilter ? () => onFilter(value) : undefined}
/>
) : (
<IconButton className={s(styles, { iconButton: true, toggled, toggleMode })} name="search" disabled={disabled} onClick={toggle} />
)}
</div>
);
Expand Down
Loading