Change Key of LRU Plugins to Only Name
Summary: Plugin keys which are used to record the least recently used plugins to show on sidebar on android emulators depend on the port (connected order), so it can cause unexpected order (swapping between two devices). This will ensure that for the same app it will have the same order regardless of device it is running Reviewed By: jknoxville Differential Revision: D17395033 fbshipit-source-id: 94ef4ef51bd5545f2ef7ce47bf8bc931d0140dbd
This commit is contained in:
committed by
Facebook Github Bot
parent
d297b7bae2
commit
22351311ae
@@ -239,11 +239,12 @@ const reducer = (state: State = INITAL_STATE, action: Actions): State => {
|
||||
}
|
||||
|
||||
const userPreferredApp = selectedApp || state.userPreferredApp;
|
||||
const selectedAppName = extractAppNameFromAppId(userPreferredApp);
|
||||
// Need to recreate an array to make sure that it doesn't refer to the
|
||||
// array that is showed in on the screen and the array that is kept for
|
||||
// least recently used plugins reference
|
||||
const LRUPlugins = [
|
||||
...((userPreferredApp && state.userLRUPlugins[userPreferredApp]) || []),
|
||||
...((selectedAppName && state.userLRUPlugins[selectedAppName]) || []),
|
||||
];
|
||||
const idxLRU =
|
||||
(selectedPlugin && LRUPlugins.indexOf(selectedPlugin)) || -1;
|
||||
@@ -257,10 +258,10 @@ const reducer = (state: State = INITAL_STATE, action: Actions): State => {
|
||||
...payload,
|
||||
userPreferredApp: userPreferredApp,
|
||||
userPreferredPlugin: selectedPlugin,
|
||||
userLRUPlugins: selectedApp
|
||||
userLRUPlugins: selectedAppName
|
||||
? {
|
||||
...state.userLRUPlugins,
|
||||
[selectedApp]: LRUPlugins,
|
||||
[selectedAppName]: LRUPlugins,
|
||||
}
|
||||
: {...state.userLRUPlugins},
|
||||
};
|
||||
@@ -274,7 +275,8 @@ const reducer = (state: State = INITAL_STATE, action: Actions): State => {
|
||||
const {userPreferredApp, userPreferredPlugin, userLRUPlugins} = state;
|
||||
let {selectedApp, selectedPlugin} = state;
|
||||
|
||||
payload.lessPlugins = userLRUPlugins[payload.id] || [];
|
||||
const appName = extractAppNameFromAppId(payload.id);
|
||||
payload.lessPlugins = (appName && userLRUPlugins[appName]) || [];
|
||||
if (
|
||||
userPreferredApp &&
|
||||
userPreferredPlugin &&
|
||||
@@ -393,13 +395,14 @@ const reducer = (state: State = INITAL_STATE, action: Actions): State => {
|
||||
}
|
||||
case 'CLIENT_SHOW_MORE_OR_LESS': {
|
||||
const {payload} = action;
|
||||
const appName = extractAppNameFromAppId(payload);
|
||||
|
||||
return {
|
||||
...state,
|
||||
clients: state.clients.map((client: Client) => {
|
||||
if (client.id === payload) {
|
||||
if (appName && extractAppNameFromAppId(client.id) === appName) {
|
||||
client.showAllPlugins = !client.showAllPlugins;
|
||||
client.lessPlugins = state.userLRUPlugins[payload] || [];
|
||||
client.lessPlugins = state.userLRUPlugins[appName] || [];
|
||||
}
|
||||
return client;
|
||||
}),
|
||||
@@ -472,3 +475,10 @@ export const userPreferredPlugin = (payload: string): Action => ({
|
||||
type: 'SELECT_USER_PREFERRED_PLUGIN',
|
||||
payload,
|
||||
});
|
||||
|
||||
function extractAppNameFromAppId(appId: string | null): string | null {
|
||||
const nameRegex = /([^#]+)#/;
|
||||
const matchedRegex = appId ? appId.match(nameRegex) : null;
|
||||
// Expect the name of the app to be on the first matching
|
||||
return matchedRegex && matchedRegex[1];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user