-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #367 from komarovalexander/dev
Header Filter improvements: Items customization & Item text customization & custom filter
- Loading branch information
Showing
16 changed files
with
229 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/Demos/HeaderFilterLogicDemo/HeaderFilterLogicDemo.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import HeaderFilterLogicDemo from './HeaderFilterLogicDemo'; | ||
import React from 'react'; | ||
import { createRoot } from 'react-dom/client'; | ||
|
||
it('renders without crashing', () => { | ||
const div = document.createElement('div'); | ||
const root = createRoot(div!); | ||
root.render(<HeaderFilterLogicDemo />); | ||
root.unmount(); | ||
}); |
115 changes: 115 additions & 0 deletions
115
src/Demos/HeaderFilterLogicDemo/HeaderFilterLogicDemo.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import { DataType, Table } from '../../lib'; | ||
import { FilteringMode, SortDirection, SortingMode } from '../../lib/enums'; | ||
|
||
import React from 'react'; | ||
|
||
const dataArray: any[] = [ | ||
{ | ||
id: 1, | ||
name: 'Mike Wazowski', | ||
score: 80, | ||
passed: true, | ||
nextTry: new Date(2021, 10, 8), | ||
departments: [{ name: 'Department A', id: 1 }, { name: 'Department B', id: 2 }] | ||
}, | ||
{ | ||
id: 2, | ||
name: 'Billi Bob', | ||
score: 55, | ||
passed: false, | ||
nextTry: new Date(2021, 10, 8), | ||
departments: [{ name: 'Department C', id: 3 }] | ||
}, | ||
{ | ||
id: 3, | ||
name: 'Tom Williams', | ||
score: 55, | ||
passed: false, | ||
nextTry: new Date(2021, 11, 8), | ||
departments: [{ name: 'Department A', id: 1 }] | ||
}, | ||
{ | ||
id: 4, | ||
name: 'Kurt Cobain', | ||
score: 75, | ||
passed: true, | ||
nextTry: new Date(2021, 12, 9) | ||
}, | ||
{ | ||
id: 5, | ||
name: 'Marshall Bruce', | ||
score: 77, | ||
passed: true, | ||
nextTry: new Date(2021, 11, 12) | ||
}, | ||
{ | ||
id: 6, | ||
name: 'Sunny Fox', | ||
score: 33, | ||
passed: false, | ||
nextTry: new Date(2021, 10, 9) | ||
}, | ||
]; | ||
|
||
const HeaderFilterLogicDemo = () => { | ||
return ( | ||
<Table | ||
columns={[ | ||
{ | ||
key: 'name', | ||
title: 'Name', dataType: DataType.String, | ||
sortDirection: SortDirection.Descend, | ||
isFilterable: false | ||
}, | ||
{ | ||
key: 'score', | ||
title: 'Score', dataType: DataType.Number | ||
}, | ||
{ | ||
key: 'passed', | ||
title: 'Passed', | ||
dataType: DataType.Boolean | ||
}, | ||
{ | ||
key: 'nextTry', | ||
dataType: DataType.Date, | ||
title: 'Next Try', | ||
}, | ||
{ | ||
key: 'departments', | ||
dataType: DataType.Object, | ||
title: 'Departments', | ||
filter: (value: { name: string; id: number; }[], filterValues: { name: string; id: number; }[]) => { | ||
return filterValues?.some(x => value?.some(v => v.id === x.id)); | ||
}, | ||
headerFilterListItems: ({ data }) => { | ||
const departments: any[] | undefined = data?.reduce((acc, item) => [...acc, ...item.departments || []], []); | ||
const departmentsUniqueByKey = departments?.filter((item: any, index) => { | ||
return departments?.findIndex(i => i.id === item.id) === index; | ||
}); | ||
return departmentsUniqueByKey || []; | ||
} | ||
}, | ||
]} | ||
data={dataArray} | ||
sortingMode={SortingMode.Single} | ||
filteringMode={FilteringMode.HeaderFilter} | ||
format={({ column, value }) => { | ||
if (column.dataType === DataType.Date) { | ||
return value && value.toLocaleDateString('en', { month: '2-digit', day: '2-digit', year: 'numeric' }); | ||
} | ||
if (column.key === 'departments') { | ||
return value?.map((d: any) => d.name).join(', '); | ||
} | ||
}} | ||
childComponents={{ | ||
popupContentItemText: { | ||
content: ({ item }) => item.name | ||
} | ||
}} | ||
rowKeyField={'id'} | ||
/> | ||
); | ||
}; | ||
|
||
export default HeaderFilterLogicDemo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/lib/Components/PopupContentItemText/PopupContentItemText.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import PopupContentItemText from './PopupContentItemText'; | ||
import React from 'react'; | ||
import { createRoot } from 'react-dom/client'; | ||
|
||
const props: any = { | ||
column: {key: 'field'}, | ||
childComponents: {}, | ||
dispatch: () => {}, | ||
item: '' | ||
}; | ||
|
||
it('renders without crashing', () => { | ||
const div = document.createElement('div'); | ||
const root = createRoot(div!); | ||
root.render(<PopupContentItemText {...props} />); | ||
root.unmount(); | ||
}); |
23 changes: 23 additions & 0 deletions
23
src/lib/Components/PopupContentItemText/PopupContentItemText.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import * as React from 'react'; | ||
|
||
import { IPopupContentItemProps } from '../../props'; | ||
import { getElementCustomization } from '../../Utils/ComponentUtils'; | ||
|
||
const PopupContentItemText: React.FC<IPopupContentItemProps> = (props) => { | ||
const { | ||
childComponents, | ||
item | ||
} = props; | ||
|
||
const { elementAttributes, content } = getElementCustomization({ | ||
className: 'ka-popup-content-item-value' | ||
}, props, childComponents?.popupContentItemText); | ||
|
||
return ( | ||
<div {...elementAttributes}> | ||
{content || item.toString()} | ||
</div> | ||
) | ||
} | ||
|
||
export default PopupContentItemText; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.