Allow to Edit only When There Is Primary Key in Table

Summary: To be able to edit correct cell, identifiers are needed. Assume that the primary key is unique, this should be safe to allow the query to find exactly one row to edit

Reviewed By: jknoxville

Differential Revision: D21788239

fbshipit-source-id: b09d1b6da1b46cbc961f08010467e973546acbef
This commit is contained in:
Chaiwat Ekkaewnumchai
2020-06-02 01:44:21 -07:00
committed by Facebook GitHub Bot
parent b57612a116
commit 54bf6440de
2 changed files with 26 additions and 2 deletions

View File

@@ -37,7 +37,11 @@ import {DatabaseClient} from './ClientProtocol';
import ButtonNavigation from './ButtonNavigation';
import DatabaseDetailSidebar from './DatabaseDetailSidebar';
import DatabaseStructure from './DatabaseStructure';
import {convertStringToValue, constructUpdateQuery} from './UpdateQueryUtil';
import {
convertStringToValue,
constructUpdateQuery,
isUpdatable,
} from './UpdateQueryUtil';
import sqlFormatter from 'sql-formatter';
import dateFormat from 'dateformat';
@@ -94,6 +98,7 @@ type Page = {
count: number;
total: number;
highlightedRows: Array<number>;
editable: boolean;
};
export type Structure = {
@@ -495,6 +500,10 @@ export default class DatabasesPlugin extends FlipperPlugin<
indexesColumns: event.indexesColumns,
indexesValues: event.indexesValues,
},
currentPage: {
...state.currentPage!,
editable: isUpdatable(event.columns, event.rows),
},
};
},
],
@@ -812,6 +821,7 @@ export default class DatabasesPlugin extends FlipperPlugin<
count: data.count,
total: data.total,
highlightedRows: [],
editable: false,
});
})
.catch((e) => {
@@ -1127,7 +1137,7 @@ export default class DatabasesPlugin extends FlipperPlugin<
<DatabaseDetailSidebar
columnLabels={page.columns}
columnValues={page.rows[page.highlightedRows[0]]}
onSave={this.onRowEdited.bind(this)}
onSave={page.editable ? this.onRowEdited.bind(this) : undefined}
/>
)}
</FlexRow>