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

Filter Icon update #1793 #1807

Merged
merged 5 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const AdvancedFilterButton: FC<IButtonComponentProps> = (props) => {
const buttonStyle = {
...localStyle,
...{ color: props.buttonType !== 'primary' && !props.danger ? styles.primaryColor : '' },
padding: "3px",
border: hasFilters ? `1px solid ${styles.primaryColor}` : 'none',
};

Expand Down Expand Up @@ -60,25 +61,28 @@ export const AdvancedFilterButton: FC<IButtonComponentProps> = (props) => {
const filterIcon = icon ? <IconComponent /> : defaultIcon;

return (
<Badge
count={tableFilter?.length}
color={isFiltering || props.readOnly ? styles.disabledColor : styles.primaryColor}
size="small"
title={filterColumns?.join(' ')}
>
<Button
type={props.buttonType}
<span>
<Badge
count={tableFilter?.length}
color={isFiltering || props.readOnly ? styles.disabledColor : styles.primaryColor}
size="small"
title={filterColumns?.join(' ')}
onClick={startFilteringColumns}
className={styles.button}
danger={props.danger}
disabled={props.readOnly || isFiltering}
icon={filterIcon}
size={props.size}
style={isFiltering || props.readOnly ? {} : { ...buttonStyle }}
>
{props.label}
</Button>
</Badge>
<Button
type={props.buttonType}
title={filterColumns?.join(' ')}
onClick={startFilteringColumns}
className={styles.button}
danger={props.danger}
disabled={props.readOnly || isFiltering}
icon={filterIcon}
size={props.size}
style={isFiltering || props.readOnly ? {} : { ...buttonStyle }}
>
{props.label}
</Button>
</Badge>
</span>

);
};
Original file line number Diff line number Diff line change
@@ -1,21 +1,113 @@
import { createStyles } from "antd-style";

export const useStyles = createStyles(({ token, css, cx }) => {
const button = cx("filter-btn", css`
export const useStyles = createStyles(({ token, cx, css }) => {

const primaryColor = token.colorPrimary;
const secondaryColor = token.colorPrimaryBgHover;
const arrowLeft = "scroll-arrow-left";
const arrowRight = "scroll-arrow-right";
const tag = "tag";
const resultCount = "result-count";
const clearAllButton = "clear-all-button";

const wrapper = cx("filter-wrapper", css`
display: flex;
white-space: nowrap;
justify-content: center;
margin: 0 6px;

.${resultCount} {
margin: auto 6px auto auto;
text-align: end;
white-space: nowrap
}

.${clearAllButton} {
margin: auto auto auto 6px;
text-align: start;
white-space: nowrap
`);

const button = cx("filter-btn", css`
&.ant-btn-icon-only {
width: max-content;
height: max-content;
padding: 1px 1px;
}
`);
const primaryColor = token.colorPrimary;
const secondaryColor = token.colorPrimaryBgHover;
const disabledColor = token.colorTextDisabled;

return {
secondaryColor,
primaryColor,
disabledColor,
button
};
});

const disabledColor = token.colorTextDisabled;

const scrollableTagsContainer = cx("scrollable-tags-container", css`
max-width: 700px;
margin: 6px;
justify-content: center;
overflow: hidden;
display: flex;
position: relative;
user-select: none;
::-webkit-scrollbar {
display: none;
}

* {
-ms-overflow-style: none; /* for Internet Explorer, Edge */
scrollbar-width: none; /* for Firefox */
}

p {
white-space: nowrap;
}
.filters {
display: flex;
margin: 0 24px;
overflow-x: scroll;
scroll-behavior: smooth;
align-items: center;
}

.${arrowLeft}, .${arrowRight} {
color: ${token.colorPrimary};
cursor: pointer;
position: absolute;
height: 100%;
top: 0;
width: 24px;
justify-content: center;
display: flex;
}

.hidden {
display: none;
}

.${arrowLeft} {
left: 0;
border-radius: 4px 0 0 4px;
}

.${arrowRight} {
right: 0;
border-radius: 0 4px 4px 0;
}

.${tag} {
color: ${token.colorPrimary};
marginBottom: .32em;
vertical-align: middle;
`);

return {
secondaryColor,
primaryColor,
arrowLeft,
arrowRight,
tag,
wrapper,
scrollableTagsContainer,
disabledColor,
button,
resultCount,
clearAllButton
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@ import { ITableFilter } from '@/providers/dataTable/interfaces';
import { LeftOutlined, RightOutlined } from '@ant-design/icons';
import { Button, Tag } from 'antd';
import React, { FC, useEffect, useRef } from 'react';
import { useStyles } from '../advancedFilterButton/style';

export interface IFilterListProps {
filters?: ITableFilter[];
clearFilters?: () => void;
removeColumnFilter?: (columnId: string) => void;
styles: any;
rows: number;
}

export const FilterList: FC<IFilterListProps> = ({ filters, clearFilters, styles, removeColumnFilter, rows }) => {
export const FilterList: FC<IFilterListProps> = ({ filters, clearFilters, removeColumnFilter, rows }) => {

const filtersRef = useRef(null);
const scrollbarLeftArrow = useRef(null);
const scrollbarRightArrow = useRef(null);
const { styles } = useStyles();

const manageArrows = () => {
if (!filtersRef.current) return;
Expand Down Expand Up @@ -75,7 +76,11 @@ export const FilterList: FC<IFilterListProps> = ({ filters, clearFilters, styles
}, [filtersRef.current]);

return (
<div style={{ textAlign: "center" }}>
<div className={styles.wrapper}>
<div className={styles.resultCount}>
{`Filters (${rows} results)`}
</div>

<div className={styles.scrollableTagsContainer}>
<LeftOutlined
ref={scrollbarLeftArrow}
Expand Down Expand Up @@ -103,14 +108,18 @@ export const FilterList: FC<IFilterListProps> = ({ filters, clearFilters, styles
onClick={scrollRight}
/>
</div>
{`Filters (${rows} results): `}
<Button
onClick={clearFilters}
type='link'
style={{ padding: "0 4px", marginRight: "2em", height: "max-content" }}
>
clear all
</Button>

<div className={styles.clearAllButton}>
{filters.length > 1 &&
<Button
onClick={clearFilters}
type='link'
className={styles.clearAllButton}
>
clear all
</Button>
}
</div>
</div>
);
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createGlobalStyle, createStyles } from "antd-style";
import { createGlobalStyle } from "antd-style";
import { sheshaStyles } from '@/styles';


Expand Down Expand Up @@ -78,77 +78,4 @@ export const GlobalTableStyles = createGlobalStyle`
}
}
}
`;


export const useStyles = createStyles(({ token, cx, css }) => {

const primaryColor = token.colorPrimary;
const secondaryColor = token.colorPrimaryBgHover;
const arrowLeft = "scroll-arrow-left";
const arrowRight = "scroll-arrow-right";
const tag = "tag";

const scrollableTagsContainer = cx("scrollable-tags-container", css`
max-width: 700px;
margin: 6px auto;
justify-content: center;
overflow: hidden;
display: flex;
position: relative;
user-select: none;
::-webkit-scrollbar {
display: none;
}

* {
-ms-overflow-style: none; /* for Internet Explorer, Edge */
scrollbar-width: none; /* for Firefox */
}

.filters {
display: flex;
margin: 0 24px;
overflow-x: scroll;
scroll-behavior: smooth;
}

.${arrowLeft}, .${arrowRight} {
color: ${token.colorPrimary};
cursor: pointer;
position: absolute;
height: 100%;
top: 0;
width: 24px;
justify-content: center;
display: flex;
}

.hidden {
display: none;
}

.${arrowLeft} {
left: 0;
border-radius: 4px 0 0 4px;
}

.${arrowRight} {
right: 0;
border-radius: 0 4px 4px 0;
}

.${tag} {
color: ${token.colorPrimary};
marginBottom: .32em;
`);

return {
secondaryColor,
primaryColor,
arrowLeft,
arrowRight,
tag,
scrollableTagsContainer
};
});
`;
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ import {
DatatableColumnsSelector,
} from '@/components';
import {
useDataTable,
useDataTableStore,
useForm,
useFormData,
useGlobalState,
useSheshaApplication,
} from '@/providers';
import { GlobalTableStyles, useStyles } from './styles/styles';
import { GlobalTableStyles } from './styles/styles';
import { Alert } from 'antd';
import { useDeepCompareEffect } from '@/hooks/useDeepCompareEffect';
import { FilterList } from '../filterList/filterList';
Expand All @@ -35,7 +36,6 @@ export const TableWrapper: FC<ITableComponentProps> = (props) => {
const { data: formData } = useFormData();
const { globalState } = useGlobalState();
const { anyOfPermissionsGranted } = useSheshaApplication();
const { styles } = useStyles();
const isDesignMode = formMode === 'designer';
const {
getRepository,
Expand All @@ -49,9 +49,10 @@ export const TableWrapper: FC<ITableComponentProps> = (props) => {
clearFilters,
removeColumnFilter,
tableFilter,
tableData
} = useDataTableStore();

const { totalRows } = useDataTable();

requireColumns(); // our component requires columns loading. it's safe to call on each render

const repository = getRepository();
Expand Down Expand Up @@ -99,7 +100,7 @@ export const TableWrapper: FC<ITableComponentProps> = (props) => {
allowFullCollapse
>
<GlobalTableStyles />
{tableFilter?.length > 0 && <FilterList filters={tableFilter} rows={tableData?.length} clearFilters={clearFilters} styles={styles} removeColumnFilter={removeColumnFilter} />}
{tableFilter?.length > 0 && <FilterList filters={tableFilter} rows={totalRows} clearFilters={clearFilters} removeColumnFilter={removeColumnFilter} />}
<DataTable
onMultiRowSelect={setMultiSelectedRow}
selectedRowIndex={selectedRow?.index}
Expand Down