Remember resized column sizes
Summary: Adds a global inside managed table where, whenever a table key is provided, the column sizes are stored. Then if a new table is constructed with the same key, it will get the sizes from before. Reviewed By: danielbuechele Differential Revision: D15181762 fbshipit-source-id: 98b5a14f8805075928cbe51511609b8b58c512fd
This commit is contained in:
committed by
Facebook Github Bot
parent
16ed255e2d
commit
70edb08999
@@ -41,6 +41,10 @@ export type ManagedTableProps = {|
|
|||||||
* Row definitions.
|
* Row definitions.
|
||||||
*/
|
*/
|
||||||
rows: TableRows,
|
rows: TableRows,
|
||||||
|
/*
|
||||||
|
* Globally unique key for persisting data between uses of a table such as column sizes.
|
||||||
|
*/
|
||||||
|
tableKey?: string,
|
||||||
/**
|
/**
|
||||||
* Whether the table has a border.
|
* Whether the table has a border.
|
||||||
*/
|
*/
|
||||||
@@ -60,7 +64,7 @@ export type ManagedTableProps = {|
|
|||||||
*/
|
*/
|
||||||
columnOrder?: TableColumnOrder,
|
columnOrder?: TableColumnOrder,
|
||||||
/**
|
/**
|
||||||
* Size of the columns.
|
* Initial size of the columns.
|
||||||
*/
|
*/
|
||||||
columnSizes?: TableColumnSizes,
|
columnSizes?: TableColumnSizes,
|
||||||
/**
|
/**
|
||||||
@@ -135,6 +139,8 @@ const Container = styled(FlexColumn)(props => ({
|
|||||||
flexGrow: 1,
|
flexGrow: 1,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
const globalTableState: {[string]: TableColumnSizes} = {};
|
||||||
|
|
||||||
class ManagedTable extends React.Component<
|
class ManagedTable extends React.Component<
|
||||||
ManagedTableProps,
|
ManagedTableProps,
|
||||||
ManagedTableState,
|
ManagedTableState,
|
||||||
@@ -159,7 +165,10 @@ class ManagedTable extends React.Component<
|
|||||||
JSON.parse(window.localStorage.getItem(this.getTableKey()) || 'null') ||
|
JSON.parse(window.localStorage.getItem(this.getTableKey()) || 'null') ||
|
||||||
this.props.columnOrder ||
|
this.props.columnOrder ||
|
||||||
Object.keys(this.props.columns).map(key => ({key, visible: true})),
|
Object.keys(this.props.columns).map(key => ({key, visible: true})),
|
||||||
columnSizes: this.props.columnSizes || {},
|
columnSizes:
|
||||||
|
this.props.tableKey && globalTableState[this.props.tableKey]
|
||||||
|
? globalTableState[this.props.tableKey]
|
||||||
|
: {},
|
||||||
highlightedRows: this.props.highlightedRows || new Set(),
|
highlightedRows: this.props.highlightedRows || new Set(),
|
||||||
sortOrder: null,
|
sortOrder: null,
|
||||||
shouldScrollToBottom: Boolean(this.props.stickyBottom),
|
shouldScrollToBottom: Boolean(this.props.stickyBottom),
|
||||||
@@ -330,6 +339,13 @@ class ManagedTable extends React.Component<
|
|||||||
[id]: width,
|
[id]: width,
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
if (!this.props.tableKey) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!globalTableState[this.props.tableKey]) {
|
||||||
|
globalTableState[this.props.tableKey] = {};
|
||||||
|
}
|
||||||
|
globalTableState[this.props.tableKey][id] = width;
|
||||||
};
|
};
|
||||||
|
|
||||||
scrollToBottom() {
|
scrollToBottom() {
|
||||||
|
|||||||
Reference in New Issue
Block a user