Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
28f4e2e
feat: functional header component
afshinm Nov 23, 2022
386d480
feat: functional footer component
afshinm Nov 23, 2022
c8949e4
chore: typescript > 4.1 config
afshinm Nov 24, 2022
e97dc15
chore: functional td component
afshinm Nov 24, 2022
faa42ce
feat: functional TH component
afshinm Nov 24, 2022
b17c358
feat: functional TR component
afshinm Nov 24, 2022
a80bb7f
feat: functional Resize component
afshinm Nov 24, 2022
8c9b0cf
feat: functional Shadow table
afshinm Nov 24, 2022
f00eccb
feat: functional HTMLElement
afshinm Nov 24, 2022
e83bf08
feat: functional pagination and search
afshinm Nov 26, 2022
62394f6
fix: shadow table and get widths fn
afshinm Nov 27, 2022
7ca6354
fix: typescript jsx settings
afshinm Nov 27, 2022
4a1e4c1
fix: pagination and removing sortRef
afshinm Nov 30, 2022
0c38258
feat: addin the state management hooks + refactoring the Search plugin
afshinm Dec 25, 2022
40d9d6b
feat: refactor Sort and delete the legacy Dispatcher/Store
afshinm Dec 25, 2022
91c1aa2
feat: refactor Sort and delete the legacy Dispatcher/Store
afshinm Dec 25, 2022
f702054
feat: functional RowSelection plugin
afshinm Dec 28, 2022
6df9fd8
feat: global state
afshinm Dec 28, 2022
4dde7aa
chore: fix tests
afshinm Dec 28, 2022
c453341
fix: functional ShadowTable + adding tableRef to state
afshinm Dec 29, 2022
32e6cf3
fix: simplify the Config
afshinm Dec 30, 2022
c5e6636
fix: default Config
afshinm Dec 30, 2022
b37210d
fix: th sort
afshinm Dec 30, 2022
c646035
fix: table width + resize plugin
afshinm Dec 31, 2022
533bab9
fix: nested columns sort
afshinm Dec 31, 2022
3fbc4f8
fix: simplify the Header interface
afshinm Dec 31, 2022
48afa89
chore: td tests
afshinm Dec 31, 2022
4bedd0e
chore: tr tests
afshinm Dec 31, 2022
39cfddb
chore: message-row tests
afshinm Dec 31, 2022
68eb0fd
chore: table tests
afshinm Dec 31, 2022
e9cc813
fix: table tests
afshinm Dec 31, 2022
a30ddc6
chore: table snapshots
afshinm Dec 31, 2022
fad8f02
chore: container tests
afshinm Dec 31, 2022
bbf72a6
chore: container snapshots
afshinm Dec 31, 2022
5f717e7
chore: search tests
afshinm Jan 1, 2023
ed9d6e3
chore: pagination tests
afshinm Jan 1, 2023
24add15
chore: container and grid tests
afshinm Jan 1, 2023
a9c7dd4
chore: plugin manager tests
afshinm Jan 1, 2023
2040b94
rebase
afshinm Jan 1, 2023
d8052a2
chore: event listener tests
afshinm Jan 1, 2023
16e8322
chore: event listener instance
afshinm Jan 1, 2023
6747356
fix: selection plugin configs
afshinm Jan 1, 2023
aa536b4
fix: eslint config
afshinm Jan 1, 2023
b305c51
fix: eslint config
afshinm Jan 1, 2023
ac577c2
chore: remove node 12
afshinm Jan 1, 2023
da0c99d
chore: fix search tests
afshinm Jan 1, 2023
9882fdf
chore: adding node 18
afshinm Jan 1, 2023
36f1cfc
chore: remove node 18
afshinm Jan 1, 2023
efb4142
chore: search input tests
afshinm Jan 1, 2023
86d67b1
tests: selection actions tests
afshinm Jan 1, 2023
4194741
fix: Store type
afshinm Jan 3, 2023
516c0fc
chore: code coverage job
afshinm Jan 3, 2023
0a9f57f
fix: Store type
afshinm Jan 3, 2023
daeaaa4
Update src/header.ts
afshinm Jan 10, 2023
95d8564
fix: remove the th setTimeout
afshinm Jan 10, 2023
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
Prev Previous commit
Next Next commit
fix: shadow table and get widths fn
  • Loading branch information
afshinm committed Jan 1, 2023
commit 62394f6f44db5e67a35a55dfb7aa29b04bf1f7ef
6 changes: 1 addition & 5 deletions 6 index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import { h, createElement, Component, createRef } from 'preact';
import { useEffect, useRef } from 'preact/hooks';
import { UserConfig, Config } from './src/config';
import {
PluginPosition,
PluginBaseComponent,
PluginBaseProps,
PluginPosition
} from './src/plugin';
import { BaseActions } from './src/view/base/actions';
import { ID } from './src/util/id';
Expand All @@ -30,8 +28,6 @@ export {
UserConfig,
Config,
PluginPosition,
PluginBaseComponent,
PluginBaseProps,
h,
createElement,
Component,
Expand Down
6 changes: 2 additions & 4 deletions 6 src/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { OneDArray, TColumn, TwoDArray } from './types';
import Base from './base';
import { Config, UserConfig } from './config';
import { px, width } from './util/width';
import { ShadowTable } from './view/table/shadow';
import { getShadowTableWidths, ShadowTable } from './view/table/shadow';
import {
Component,
ComponentChild,
createRef,
h,
Expand Down Expand Up @@ -78,7 +77,7 @@ class Header extends Base {

render(el, tempRef.current);

widths = shadowTable.current.widths();
widths = getShadowTableWidths(shadowTable.current);
}

for (const column of flatten(Header.tabularFormat(this.columns))) {
Expand Down Expand Up @@ -212,7 +211,6 @@ class Header extends Base {
if (column.plugin !== undefined) {
userConfig.plugin.add({
id: column.id,
props: {},
...column.plugin,
position: PluginPosition.Cell,
});
Expand Down
4 changes: 2 additions & 2 deletions 4 src/view/container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { Config, ConfigContext } from '../config';
import log from '../util/log';
import { PipelineProcessor } from '../pipeline/processor';
import { useEffect, useRef, useState } from 'preact/hooks';
import { useConfig } from '../hooks/useConfig';

export function Container(props: {
config: Config;
Expand All @@ -19,7 +18,7 @@ export function Container(props: {
width: string;
height: string;
}) {
const config = useConfig();
const config = props.config;
const [status, setStatus] = useState(Status.Loading);
const prevStatusRef = useRef(Status.Loading);
const [header, setHeader] = useState(props.header);
Expand All @@ -31,6 +30,7 @@ export function Container(props: {
// for the initial load
await processPipeline();

console.log('config', config)
if (config.header && data && data.length) {
// now that we have the data, let's adjust columns width
// NOTE: that we only calculate the columns width once
Expand Down
6 changes: 4 additions & 2 deletions 6 src/view/htmlElement.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { h } from 'preact';

export function HTMLElement(props: {
export interface HTMLContentProps {
content: string;
parentElement?: string;
}) {
}

export function HTMLElement(props: HTMLContentProps) {
return h(props.parentElement || 'span', {
dangerouslySetInnerHTML: { __html: props.content },
});
Expand Down
41 changes: 24 additions & 17 deletions 41 src/view/plugin/pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import PaginationLimit from '../../pipeline/limit/pagination';
import { classJoin, className } from '../../util/className';
import ServerPaginationLimit from '../../pipeline/limit/serverPagination';
import Tabular from '../../tabular';
import { PipelineProcessor } from '../../pipeline/processor';
import { useConfig } from '../../hooks/useConfig';
import { useEffect, useState } from 'preact/hooks';
import { useTranslator } from '../../i18n/language';
Expand All @@ -24,10 +23,18 @@ export interface PaginationConfig {
}

export function Pagination(props: PaginationConfig) {
props.summary = props.summary || true;
props.nextButton = props.nextButton || true;
props.prevButton = props.prevButton || true;
props.buttonsCount = props.buttonsCount || 3;
props.limit = props.limit || 10;
props.page = props.page || 0;
props.resetPageOnUpdate = props.resetPageOnUpdate || true;

let processor: PaginationLimit | ServerPaginationLimit;

const [currentPage, setCurrentPage] = useState(props.page || 0);
const [limit, setLimit] = useState(props.limit);
const [currentPage, setCurrentPage] = useState(props.page);
const [limit] = useState(props.limit);
const [total, setTotal] = useState(0);
const config = useConfig();
const _ = useTranslator();
Expand All @@ -36,7 +43,7 @@ export function Pagination(props: PaginationConfig) {
setTotal(tabular.length);
}

if (this.props.server) {
if (props.server) {
processor = new ServerPaginationLimit({
limit: limit,
page: currentPage,
Expand Down Expand Up @@ -189,33 +196,33 @@ export function Pagination(props: PaginationConfig) {
const renderSummary = () => {
return (
<Fragment>
{this.props.summary && this.state.total > 0 && (
{props.summary && total > 0 && (
<div
role="status"
aria-live="polite"
className={classJoin(
className('summary'),
this.config.className.paginationSummary,
config.className.paginationSummary,
)}
title={this._(
title={_(
'pagination.navigate',
this.state.page + 1,
this.pages,
currentPage + 1,
pages(),
)}
>
{this._('pagination.showing')}{' '}
<b>{this._(`${this.state.page * this.state.limit + 1}`)}</b>{' '}
{this._('pagination.to')}{' '}
{_('pagination.showing')}{' '}
<b>{_(`${currentPage * limit + 1}`)}</b>{' '}
{_('pagination.to')}{' '}
<b>
{this._(
{_(
`${Math.min(
(this.state.page + 1) * this.state.limit,
this.state.total,
(currentPage + 1) * limit,
total,
)}`,
)}
</b>{' '}
{this._('pagination.of')} <b>{this._(`${this.state.total}`)}</b>{' '}
{this._('pagination.results')}
{_('pagination.of')} <b>{_(`${total}`)}</b>{' '}
{_('pagination.results')}
</div>
)}
</Fragment>
Expand Down
97 changes: 48 additions & 49 deletions 97 src/view/table/shadow.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, RefObject } from 'preact';
import { RefObject } from 'preact';
import { className } from '../../util/className';
import { useEffect } from 'preact/hooks';

Expand All @@ -8,8 +8,6 @@ import { useEffect } from 'preact/hooks';
*/
export function ShadowTable(props: { tableRef?: RefObject<HTMLTableElement> }) {
let tableElement: HTMLTableElement;
let tableClassName: string;
let tableStyle: string;

useEffect(() => {
const tableRef = props.tableRef;
Expand All @@ -19,54 +17,8 @@ export function ShadowTable(props: { tableRef?: RefObject<HTMLTableElement> }) {
tableElement.style.width = '100%';
tableElement.style.zIndex = '-2147483640';
tableElement.style.visibility = 'hidden';

tableClassName = tableElement.className;
tableStyle = tableElement.style.cssText;
}, []);

const widths = (): {
[columnId: string]: { minWidth: number; width: number };
} => {
tableElement.className = `${tableClassName} ${className('shadowTable')}`;

tableElement.style.tableLayout = 'auto';
tableElement.style.width = 'auto';
tableElement.style.padding = '0';
tableElement.style.margin = '0';
tableElement.style.border = 'none';
tableElement.style.outline = 'none';

let obj = Array.from(
// TODO: should this be this.base?
tableElement.parentNode.querySelectorAll<HTMLElement>('thead th'),
).reduce((prev, current) => {
current.style.width = `${current.clientWidth}px`;

return {
[current.getAttribute('data-column-id')]: {
minWidth: current.clientWidth,
},
...prev,
};
}, {});

tableElement.className = tableClassName;
tableElement.style.cssText = tableStyle;
tableElement.style.tableLayout = 'auto';

obj = Array.from(
// TODO: should this be this.base?
tableElement.parentNode.querySelectorAll<HTMLElement>('thead th'),
).reduce((prev, current) => {
prev[current.getAttribute('data-column-id')]['width'] =
current.clientWidth;

return prev;
}, obj);

return obj;
};

if (props.tableRef.current) {
return (
<div
Expand All @@ -79,3 +31,50 @@ export function ShadowTable(props: { tableRef?: RefObject<HTMLTableElement> }) {

return null;
}


export function getShadowTableWidths(
tableElement: HTMLTableElement
): {
[columnId: string]: { minWidth: number; width: number };
} {
const tableClassName = tableElement.className;
const tableStyle = tableElement.style.cssText;
tableElement.className = `${tableClassName} ${className('shadowTable')}`;

tableElement.style.tableLayout = 'auto';
tableElement.style.width = 'auto';
tableElement.style.padding = '0';
tableElement.style.margin = '0';
tableElement.style.border = 'none';
tableElement.style.outline = 'none';

let obj = Array.from(
// TODO: should this be this.base?
tableElement.parentNode.querySelectorAll<HTMLElement>('thead th'),
).reduce((prev, current) => {
current.style.width = `${current.clientWidth}px`;

return {
[current.getAttribute('data-column-id')]: {
minWidth: current.clientWidth,
},
...prev,
};
}, {});

tableElement.className = tableClassName;
tableElement.style.cssText = tableStyle;
tableElement.style.tableLayout = 'auto';

obj = Array.from(
// TODO: should this be this.base?
tableElement.parentNode.querySelectorAll<HTMLElement>('thead th'),
).reduce((prev, current) => {
prev[current.getAttribute('data-column-id')]['width'] = current.clientWidth;

return prev;
}, obj);

return obj;
};
46 changes: 11 additions & 35 deletions 46 tests/jest/view/container.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,8 @@ describe('Container component', () => {

it('should attach styles', async () => {
config.update({
search: {
enabled: true,
},
pagination: {
enabled: true,
},
search: true,
pagination: true,
style: {
container: {
border: '1px solid #ccc',
Expand Down Expand Up @@ -90,12 +86,8 @@ describe('Container component', () => {

it('should attach classNames', async () => {
config.update({
search: {
enabled: true,
},
pagination: {
enabled: true,
},
search: true ,
pagination: true,
columns: [
{
name: 'c1',
Expand Down Expand Up @@ -146,9 +138,7 @@ describe('Container component', () => {

it('should render a container with searchable table', async () => {
config.update({
search: {
enabled: true,
},
search: true,
});

const container = mount(
Expand All @@ -165,11 +155,8 @@ describe('Container component', () => {

it('should render a container with sortable and paginated table', async () => {
config.update({
search: {
enabled: true,
},
search: true,
pagination: {
enabled: true,
limit: 5,
},
columns: [
Expand Down Expand Up @@ -240,12 +227,9 @@ describe('Container component', () => {
it('should not violate accessibility test', async () => {
config.update({
pagination: {
enabled: true,
limit: 1,
},
search: {
enabled: true,
},
search: true,
sort: true,
});

Expand Down Expand Up @@ -385,12 +369,8 @@ describe('Container component', () => {

it('should remove the EventEmitter listeners', async () => {
config.update({
search: {
enabled: true,
},
pagination: {
enabled: true,
},
search: true,
pagination: true,
columns: ['Name', 'Phone Number'],
sort: true,
});
Expand All @@ -416,12 +396,8 @@ describe('Container component', () => {

it('should unregister the processors', async () => {
config.update({
pagination: {
enabled: true,
},
search: {
enabled: true,
},
pagination: true,
search: true,
columns: ['Name', 'Phone Number'],
sort: true,
});
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.