1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Prevent creation of dynamic components where withInjectables use type parameters to make React not re-mount because of dynamic components being different (#4808)

Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne Savolainen 2022-02-03 12:26:14 +01:00 committed by GitHub
parent 6ebfd76644
commit 09824a6e01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 42 deletions

View File

@ -138,23 +138,25 @@ class NonInjectedKubeObjectListLayout<K extends KubeObject> extends React.Compon
}
}
const InjectedKubeObjectListLayout = withInjectables<
Dependencies,
KubeObjectListLayoutProps<KubeObject>
>(
NonInjectedKubeObjectListLayout,
{
getProps: (di, props) => ({
clusterFrameContext: di.inject(clusterFrameContextInjectable),
subscribeToStores: di.inject(kubeWatchApiInjectable).subscribeStores,
...props,
}),
},
);
export function KubeObjectListLayout<K extends KubeObject>(
props: KubeObjectListLayoutProps<K>,
) {
const InjectedKubeObjectListLayout = withInjectables<
Dependencies,
KubeObjectListLayoutProps<K>
>(
NonInjectedKubeObjectListLayout,
{
getProps: (di, props) => ({
clusterFrameContext: di.inject(clusterFrameContextInjectable),
subscribeToStores: di.inject(kubeWatchApiInjectable).subscribeStores,
...props,
}),
},
);
return <InjectedKubeObjectListLayout {...props} />;
}

View File

@ -108,25 +108,25 @@ class NonInjectedKubeObjectMenu<TKubeObject extends KubeObject> extends React.Co
}
}
const InjectedKubeObjectMenu = withInjectables<Dependencies, KubeObjectMenuProps<KubeObject>>(
NonInjectedKubeObjectMenu,
{
getProps: (di, props) => ({
clusterName: di.inject(clusterNameInjectable),
apiManager: di.inject(apiManagerInjectable),
createEditResourceTab: di.inject(createEditResourceTabInjectable),
hideDetails: di.inject(hideDetailsInjectable),
kubeObjectMenuItems: di.inject(kubeObjectMenuItemsInjectable, {
kubeObject: props.object,
}),
...props,
}),
},
);
export function KubeObjectMenu<T extends KubeObject>(
props: KubeObjectMenuProps<T>,
) {
const InjectedKubeObjectMenu = withInjectables<Dependencies, KubeObjectMenuProps<T>>(
NonInjectedKubeObjectMenu,
{
getProps: (di, props) => ({
clusterName: di.inject(clusterNameInjectable),
apiManager: di.inject(apiManagerInjectable),
createEditResourceTab: di.inject(createEditResourceTabInjectable),
hideDetails: di.inject(hideDetailsInjectable),
kubeObjectMenuItems: di.inject(kubeObjectMenuItemsInjectable, {
kubeObject: props.object,
}),
...props,
}),
},
);
return <InjectedKubeObjectMenu {...props} />;
}

View File

@ -246,18 +246,18 @@ class NonInjectedTable<Item> extends React.Component<TableProps<Item> & Dependen
}
}
const InjectedTable = withInjectables<Dependencies, TableProps<any>>(
NonInjectedTable,
{
getProps: (di, props) => ({
model: di.inject(tableModelInjectable),
...props,
}),
},
);
export function Table<Item>(props: TableProps<Item>) {
const InjectedTable = withInjectables<Dependencies, TableProps<Item>>(
NonInjectedTable,
{
getProps: (di, props) => ({
model: di.inject(tableModelInjectable),
...props,
}),
},
);
return <InjectedTable {...props} />;
}