From d10630426908121a26e58c61652ff93c73afeb15 Mon Sep 17 00:00:00 2001 From: nidhigarg-bmw Date: Fri, 26 Apr 2024 17:34:56 +0530 Subject: [PATCH 1/2] feat(table): add sprting --- package.json | 4 +- .../Toolbar/SearchAndFilterButtonToolbar.tsx | 61 ++++++++++++++++++- .../components/Toolbar/SortImage/index.tsx | 52 ++++++++++++++++ src/components/basic/Table/index.tsx | 9 +++ 4 files changed, 122 insertions(+), 4 deletions(-) create mode 100644 src/components/basic/Table/components/Toolbar/SortImage/index.tsx diff --git a/package.json b/package.json index 6233b0a9..7bb84815 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "@catena-x/portal-shared-components", - "version": "2.1.44", + "name": "@nidhi.garg/portal-shared-components", + "version": "2.1.45", "description": "Catena-X Portal Shared Components", "author": "Catena-X Contributors", "license": "Apache-2.0", diff --git a/src/components/basic/Table/components/Toolbar/SearchAndFilterButtonToolbar.tsx b/src/components/basic/Table/components/Toolbar/SearchAndFilterButtonToolbar.tsx index 27e5d592..eb5f8e5c 100644 --- a/src/components/basic/Table/components/Toolbar/SearchAndFilterButtonToolbar.tsx +++ b/src/components/basic/Table/components/Toolbar/SearchAndFilterButtonToolbar.tsx @@ -27,6 +27,8 @@ import { ViewSelector } from '../../../ViewSelector' import type { view } from '../../../ViewSelector' import { Typography } from '../../../Typography' import type { SelectedFilter } from './UltimateToolbar' +import { SortOption } from '../../../SortOption' +import SortImage from './SortImage' export interface SearchAndFilterButtonToolbarProps extends ToolbarProps { placeholder?: string @@ -35,6 +37,9 @@ export interface SearchAndFilterButtonToolbarProps extends ToolbarProps { filterViews?: view[] defaultFilter?: string onFilter?: (selectedFilter: SelectedFilter) => void + defaultSortOption?: string + sortOptions?: { label: string, value: string }[] + onSortClick?: (value: string) => void descriptionText?: string autoFocus?: boolean } @@ -49,12 +54,33 @@ export const SearchAndFilterButtonToolbar = ({ searchDebounce = 500, filterViews, defaultFilter = '', + defaultSortOption, + sortOptions, + onSortClick, descriptionText, autoFocus, }: SearchAndFilterButtonToolbarProps) => { + // defaultSortOption = 'demo' + // sortOptions = [{ + // label: 'test', + // value: 'test' + // }, + // { + // label: 'demo', + // value: 'demo' + // }] + + // onSortClick = (value: string) => { + // console.log('value', value) + // defaultSortOption = value + // } + + // console.log('sortOption', defaultSortOption) + const [searchInputText, setSearchInputText] = useState( searchExpr ?? (searchInputData != null ? searchInputData.text : '') ) + const [showModal, setShowModal] = useState(false) const { spacing } = useTheme() @@ -108,8 +134,8 @@ export const SearchAndFilterButtonToolbar = ({ padding: spacing(2, 0, 6, 0), display: 'flex', alignItems: 'center', - justifyContent: 'space-between', - flexDirection: 'column', + justifyContent: 'center', + flexDirection: 'row', marginTop: '40px', } @@ -140,6 +166,37 @@ export const SearchAndFilterButtonToolbar = ({ )} + { + sortOptions && defaultSortOption && + <> + { + setShowModal(!showModal) + }} + selected={showModal} + /> + + { + onSortClick?.(value) + setShowModal(false) + }} + /> + + + } + {descriptionText && ( + + + ) +} diff --git a/src/components/basic/Table/index.tsx b/src/components/basic/Table/index.tsx index 70e3878a..e7ea5ad1 100644 --- a/src/components/basic/Table/index.tsx +++ b/src/components/basic/Table/index.tsx @@ -65,6 +65,9 @@ export interface TableProps extends DataGridProps { descriptionText?: string defaultFilter?: string filterViews?: view[] + defaultSortOption?: string + sortOptions?: {label: string, value: string}[] + onSortClick?: (value: string) => void alignCell?: string error?: { status: number @@ -101,6 +104,9 @@ export const Table = ({ descriptionText, defaultFilter, filterViews, + defaultSortOption, + sortOptions, + onSortClick, alignCell = 'center', error, reload, @@ -124,6 +130,9 @@ export const Table = ({ descriptionText, defaultFilter, filterViews, + defaultSortOption, + sortOptions, + onSortClick, autoFocus, } From aa239cf2f16aef7fcbca4dd05f8d76de8fbf68df Mon Sep 17 00:00:00 2001 From: nidhigarg-bmw Date: Mon, 29 Apr 2024 10:20:48 +0530 Subject: [PATCH 2/2] feat(table): fix code smell error --- .../Table/components/Toolbar/SearchAndFilterButtonToolbar.tsx | 4 ++-- .../basic/Table/components/Toolbar/SortImage/index.tsx | 2 +- src/components/basic/Table/index.tsx | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/components/basic/Table/components/Toolbar/SearchAndFilterButtonToolbar.tsx b/src/components/basic/Table/components/Toolbar/SearchAndFilterButtonToolbar.tsx index 0c5ab8d6..307c3983 100644 --- a/src/components/basic/Table/components/Toolbar/SearchAndFilterButtonToolbar.tsx +++ b/src/components/basic/Table/components/Toolbar/SearchAndFilterButtonToolbar.tsx @@ -27,7 +27,7 @@ import { ViewSelector } from '../../../ViewSelector' import type { View } from '../../../ViewSelector' import { Typography } from '../../../Typography' import type { SelectedFilter } from './UltimateToolbar' -import { SortOption } from '../../../SortOption' +import { SortOption, type SortOptionsType } from '../../../SortOption' import SortImage from './SortImage' export interface SearchAndFilterButtonToolbarProps extends ToolbarProps { @@ -38,7 +38,7 @@ export interface SearchAndFilterButtonToolbarProps extends ToolbarProps { defaultFilter?: string onFilter?: (selectedFilter: SelectedFilter) => void defaultSortOption?: string - sortOptions?: { label: string, value: string }[] + sortOptions?: SortOptionsType[] onSortClick?: (value: string) => void descriptionText?: string autoFocus?: boolean diff --git a/src/components/basic/Table/components/Toolbar/SortImage/index.tsx b/src/components/basic/Table/components/Toolbar/SortImage/index.tsx index 83ed2846..8efa8ca4 100644 --- a/src/components/basic/Table/components/Toolbar/SortImage/index.tsx +++ b/src/components/basic/Table/components/Toolbar/SortImage/index.tsx @@ -26,7 +26,7 @@ interface SortIconProps { selected?: boolean } -export default function SortImage({ onClick, selected }: SortIconProps) { +export default function SortImage({ onClick, selected }: Readonly) { return ( void alignCell?: string error?: {