Add support for deleting a shared preference (#1018)

Summary:
This change makes it possible to remove preferences. I also added a `Delete` context menu option to `DataInspector` because I needed it to implement this feature. passy confirmed that it makes sense to add this because delete is a common action.

Fixes https://github.com/facebook/flipper/issues/451
Pull Request resolved: https://github.com/facebook/flipper/pull/1018

Reviewed By: jknoxville

Differential Revision: D21086308

Pulled By: passy

fbshipit-source-id: 551ff0908d5e6c93f58d6012b42e1ee3531de997
This commit is contained in:
Michal Zielinski
2020-04-17 08:58:14 -07:00
committed by Facebook GitHub Bot
parent 9b8974eeb3
commit 2d1870cf7d
5 changed files with 71 additions and 0 deletions

View File

@@ -209,6 +209,21 @@ export default class extends FlipperPlugin<SharedPreferencesState> {
});
};
onSharedPreferencesDeleted = (path: Array<string>) => {
this.client
.call('deleteSharedPreference', {
sharedPreferencesName: this.state.selectedPreferences,
preferenceName: path[0],
})
.then((results: SharedPreferences) => {
const update = {
name: this.state.selectedPreferences,
preferences: results,
};
this.dispatchAction({update, type: 'UpdateSharedPreferences'});
});
};
render() {
const selectedPreferences = this.state.selectedPreferences;
if (selectedPreferences == null) {
@@ -241,6 +256,7 @@ export default class extends FlipperPlugin<SharedPreferencesState> {
<ManagedDataInspector
data={entry.preferences}
setValue={this.onSharedPreferencesChanged}
onDelete={this.onSharedPreferencesDeleted}
/>
</InspectorColumn>
<ChangelogColumn>