Fix the import and export of the createtable plugin

Summary:
Before this diff, plugins made with createTablePlugin would not be exportable as it uses ImmutableJS's Map which is not serializable. In the custom serializer we just handle the normal map, not the immutableJS one. Thus to tackle this I overrode the serializer and deserializer methods to handle it.

Before this diff the funnellogger import didn't work.
{F221607733}

Reviewed By: mweststrate

Differential Revision: D18352298

fbshipit-source-id: 57d4f3e19f38c12a30e75167646ae43ac8690e08
This commit is contained in:
Pritesh Nandgaonkar
2019-11-08 06:19:39 -08:00
committed by Facebook Github Bot
parent f4a42cc4ea
commit 19937c4b83

View File

@@ -24,6 +24,7 @@ import {List, Map as ImmutableMap} from 'immutable';
import React from 'react';
import {KeyboardActions} from './MenuBar';
import {TableBodyRow} from './ui';
import {Idler} from './utils/Idler';
type ID = string;
@@ -99,6 +100,34 @@ export function createTablePlugin<T extends RowData>(props: Props<T>) {
}
};
static serializePersistedState: (
persistedState: PersistedState<T>,
statusUpdate?: (msg: string) => void,
idler?: Idler,
pluginName?: string,
) => Promise<string> = async (
persistedState: PersistedState<T>,
_statusUpdate?: (msg: string) => void,
_idler?: Idler,
_pluginName?: string,
) => {
const serializable = {
rows: persistedState.rows,
datas: persistedState.datas.toArray(),
};
return JSON.stringify(serializable);
};
static deserializePersistedState: (
serializedString: string,
) => PersistedState<T> = (serializedString: string) => {
const parse = JSON.parse(serializedString);
return {
rows: List(parse.rows) as TableRows_immutable,
datas: ImmutableMap(parse.datas) as ImmutableMap<ID, T>,
};
};
state: State = {
selectedIds: [],
};
@@ -166,7 +195,6 @@ export function createTablePlugin<T extends RowData>(props: Props<T>) {
render() {
const {columns, columnSizes} = props;
const {rows} = this.props.persistedState;
return (
<FlexColumn grow={true}>
<SearchableTable_immutable