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

added getById() to portForwardStore to eliminate direct items access from outside

Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com>
This commit is contained in:
Jim Ehrismann 2021-10-20 15:24:33 -04:00
parent 01faec3a05
commit b6a1e3b81c
2 changed files with 11 additions and 3 deletions

View File

@ -55,9 +55,7 @@ export class PortForwards extends React.Component<Props> {
get selectedPortForward() {
const { match: { params: { forwardport } } } = this.props;
return portForwardStore.items.find(pf => {
return pf.getForwardPort() == Number(forwardport);
});
return portForwardStore.getById(forwardport);
}
onDetails = (item: PortForwardItem) => {

View File

@ -81,6 +81,16 @@ export class PortForwardStore extends ItemStore<PortForwardItem> {
async removeSelectedItems() {
return Promise.all(this.selectedItems.map(removePortForward));
}
getById(id: string) {
const index = this.getIndexById(id);
if (index === -1) {
return null;
}
return this.getItems()[index];
}
}
interface PortForwardResult {