Calculate Editable when Used

Summary:
In D21788243, John suggested the field should be calculated when needed not precomputed. This diff does so by moving calculation logic to the component and removing the field

This also fixes the crashing bug when switching to Structure tab, changing table, and switching back to Data tab.

Reviewed By: mweststrate

Differential Revision: D21906983

fbshipit-source-id: 5a9522a5ba3f504108282fb27deae25b5eadc693
This commit is contained in:
Chaiwat Ekkaewnumchai
2020-06-08 08:57:33 -07:00
committed by Facebook GitHub Bot
parent b81724b7b0
commit a50c373631

View File

@@ -98,7 +98,6 @@ type Page = {
count: number;
total: number;
highlightedRows: Array<number>;
editable: boolean;
};
export type Structure = {
@@ -500,10 +499,6 @@ export default class DatabasesPlugin extends FlipperPlugin<
indexesColumns: event.indexesColumns,
indexesValues: event.indexesValues,
},
currentPage: {
...state.currentPage!,
editable: isUpdatable(event.columns, event.rows),
},
};
},
],
@@ -821,7 +816,6 @@ export default class DatabasesPlugin extends FlipperPlugin<
count: data.count,
total: data.total,
highlightedRows: [],
editable: false,
});
})
.catch((e) => {
@@ -1137,7 +1131,15 @@ export default class DatabasesPlugin extends FlipperPlugin<
<DatabaseDetailSidebar
columnLabels={page.columns}
columnValues={page.rows[page.highlightedRows[0]]}
onSave={page.editable ? this.onRowEdited.bind(this) : undefined}
onSave={
this.state.currentStructure &&
isUpdatable(
this.state.currentStructure.columns,
this.state.currentStructure.rows,
)
? this.onRowEdited.bind(this)
: undefined
}
/>
)}
</FlexRow>