TableNativePlugin

Reviewed By: passy

Differential Revision: D17258701

fbshipit-source-id: 0d622e63cc028969c9c6d51c5aa2cc8977aac151
This commit is contained in:
John Knox
2019-09-09 06:49:30 -07:00
committed by Facebook Github Bot
parent c8c027150a
commit b71ae59545
2 changed files with 28 additions and 22 deletions

View File

@@ -140,20 +140,23 @@ function buildRow(
} }
const oldColumns = const oldColumns =
previousRowData && previousRowData.columns previousRowData && previousRowData.columns
? Object.keys(previousRowData.columns).reduce((map, key) => { ? Object.keys(previousRowData.columns).reduce(
if (key !== 'id') { (map: {[key: string]: {value: any; isFilterable: boolean}}, key) => {
let value = null; if (key !== 'id') {
if (previousRowData && previousRowData.columns) { let value = null;
value = previousRowData.columns[key].value; if (previousRowData && previousRowData.columns) {
} value = previousRowData.columns[key].value;
}
map[key] = { map[key] = {
value, value,
isFilterable: true, isFilterable: true,
}; };
} }
return map; return map;
}, {}) },
{},
)
: {}; : {};
const columns = Object.keys(rowData.columns).reduce((map, key) => { const columns = Object.keys(rowData.columns).reduce((map, key) => {
if (rowData.columns && key !== 'id') { if (rowData.columns && key !== 'id') {
@@ -186,10 +189,13 @@ function renderToolbar(section: ToolbarSection) {
return [ return [
<Label>{item.label}</Label>, <Label>{item.label}</Label>,
<Select <Select
options={item.options.reduce((obj, item) => { options={item.options.reduce(
obj[item] = item; (obj: {[key: string]: string}, item) => {
return obj; obj[item] = item;
}, {})} return obj;
},
{},
)}
selected={item.value} selected={item.value}
onChange={() => {}} onChange={() => {}}
/>, />,
@@ -259,7 +265,7 @@ export default function createTableNativePlugin(id: string, title: string) {
): Partial<PersistedState> => { ): Partial<PersistedState> => {
if (message.method === 'updateRows') { if (message.method === 'updateRows') {
const newRows = []; const newRows = [];
const newData = {}; const newData: {[key: string]: NumberedRowData} = {};
for (const rowData of message.data.reverse()) { for (const rowData of message.data.reverse()) {
if (rowData.id == null) { if (rowData.id == null) {
@@ -312,14 +318,14 @@ export default function createTableNativePlugin(id: string, title: string) {
method === 'updateRows' method === 'updateRows'
? { ? {
method, method,
data, data: data || [],
} }
: {method}; : {method};
return this.typedPersistedStateReducer(persistedState, message); return this.typedPersistedStateReducer(persistedState, message);
} }
state = { state = {
selectedIds: [], selectedIds: [] as Array<ID>,
error: null, error: null,
}; };
@@ -366,7 +372,7 @@ export default function createTableNativePlugin(id: string, title: string) {
return; return;
} }
let paste = ''; let paste = '';
const mapFn = row => const mapFn = (row: TableBodyRow) =>
( (
(this.props.persistedState.tableMetadata && (this.props.persistedState.tableMetadata &&
Object.keys(this.props.persistedState.tableMetadata.columns)) || Object.keys(this.props.persistedState.tableMetadata.columns)) ||

View File

@@ -23,7 +23,7 @@ export const ErrorBlockContainer = styled(CodeBlock)({
*/ */
export default class ErrorBlock extends React.Component<{ export default class ErrorBlock extends React.Component<{
/** Error message to display. Error object's `stack` or `message` property is used. */ /** Error message to display. Error object's `stack` or `message` property is used. */
error: Error | string | void; error: Error | string | null;
/** Additional className added to the container. */ /** Additional className added to the container. */
className?: string; className?: string;
}> { }> {