Skip to content

Commit

Permalink
Merge pull request #1569 from entando/ENG-5121_registry_param
Browse files Browse the repository at this point in the history
ENG-5121 implement active registry persistance
  • Loading branch information
ichalagashvili authored Nov 7, 2023
2 parents 2b40179 + cabb32a commit 1b5cbff
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/ui/component-repository/components/list/HubRegistrySwitcher.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, Fragment } from 'react';
import React, { useEffect, Fragment, useCallback } from 'react';
import { Row, Col, DropdownKebab, MenuItem, Icon } from 'patternfly-react';
import { useSelector, useDispatch } from 'react-redux';
import { FormattedMessage } from 'react-intl';
Expand All @@ -16,18 +16,21 @@ const DEFAULT_ECR_REGISTRY = {
url: '',
};

const ACTIVE_REGISTRY_KEY = 'activeRegistry';

const HubRegistrySwitcher = () => {
const activeRegistry = useSelector(getSelectedRegistry);
const registries = useSelector(getRegistries);
const dispatch = useDispatch();

const handleRegistryChange = (registry) => {
const handleRegistryChange = useCallback((registry) => {
if (registry.name !== activeRegistry.name) {
dispatch(setFetchedBundleGroups([]));
dispatch(setFetchedBundlesFromRegistry([]));
dispatch(setActiveRegistry(registry));
localStorage.setItem(ACTIVE_REGISTRY_KEY, registry.url);
}
};
}, [activeRegistry, dispatch]);

const handleNewRegistryClick = () => {
dispatch(setVisibleModal(ADD_NEW_REGISTRY_MODAL_ID));
Expand All @@ -48,9 +51,16 @@ const HubRegistrySwitcher = () => {
useEffect(() => { dispatch(fetchRegistries()); }, [dispatch]);

useEffect(() => {
handleRegistryChange(DEFAULT_ECR_REGISTRY);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
const activeRegistryUrl = localStorage.getItem(ACTIVE_REGISTRY_KEY);
if (activeRegistryUrl) {
const registry = registries.find(reg => reg.url === activeRegistryUrl);
if (registry) {
handleRegistryChange(registry);
}
} else {
handleRegistryChange(DEFAULT_ECR_REGISTRY);
}
}, [handleRegistryChange, registries]);

return (
<Row className="HubRegistrySwitcher">
Expand Down

0 comments on commit 1b5cbff

Please sign in to comment.