Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1908135: move quick search modal inside topology container #7560

Merged
merged 2 commits into from
Dec 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 13 additions & 2 deletions frontend/packages/console-shared/src/hooks/useIsMobile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,21 @@ export const useIsMobile = () => {
setIsMobile(e.matches);
};

mobileResolutionMatch.addEventListener('change', updateIsMobile);
// support safari with fallback to addListener / removeListener
if (mobileResolutionMatch.addEventListener) {
mobileResolutionMatch.addEventListener('change', updateIsMobile);
} else {
mobileResolutionMatch.addListener(updateIsMobile);
}

// Remove event listener on cleanup
return () => mobileResolutionMatch.removeEventListener('change', updateIsMobile);
return () => {
if (mobileResolutionMatch.removeEventListener) {
mobileResolutionMatch.removeEventListener('change', updateIsMobile);
} else {
mobileResolutionMatch.removeListener(updateIsMobile);
}
};
}, []); // Empty array ensures that effect is only run on mount

return isMobile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
left: 0;
right: 0;
}
&__hint-background{
&__hint-background {
background: var(--pf-global--Color--light-100);
border: 1px solid var(--pf-global--BorderColor--light-100);
border-radius: 8px;
Expand Down Expand Up @@ -99,4 +99,9 @@
min-height: initial;
}
}

.pf-c-backdrop {
position: absolute;
background: none;
}
}
18 changes: 11 additions & 7 deletions frontend/packages/topology/src/components/page/TopologyView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const ConnectedTopologyView: React.FC<ComponentProps> = ({
onSupportedFiltersChange,
onSupportedKindsChange,
}) => {
const [viewContainer, setViewContainer] = React.useState<HTMLElement>(null);
const { setTopologyFilters: onFiltersChange } = React.useContext(FilterContext);
const [filteredModel, setFilteredModel] = React.useState<Model>();
const [selectedEntity, setSelectedEntity] = React.useState<GraphElement>(null);
Expand Down Expand Up @@ -236,11 +237,6 @@ export const ConnectedTopologyView: React.FC<ComponentProps> = ({
[filteredModel, namespace, onSelect, viewType],
);

const topologyFilterBar = React.useMemo(
() => <TopologyFilterBar viewType={viewType} visualization={visualization} />,
[viewType, visualization],
);

const topologySideBar = React.useMemo(
() => getTopologySideBar(visualization, selectedEntity, () => onSelect()),
[onSelect, selectedEntity, visualization],
Expand All @@ -258,9 +254,17 @@ export const ConnectedTopologyView: React.FC<ComponentProps> = ({
return (
<div className="odc-topology">
<Stack>
<StackItem isFilled={false}>{topologyFilterBar}</StackItem>
<StackItem isFilled={false}>
<TopologyFilterBar
viewType={viewType}
visualization={visualization}
viewContainer={viewContainer}
/>
</StackItem>
<StackItem isFilled className={containerClasses}>
<div className="pf-topology-content">{viewContent}</div>
<div ref={setViewContainer} className="pf-topology-content">
{viewContent}
</div>
{topologySideBar.sidebar}
</StackItem>
</Stack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ import QuickSearchController from './QuickSearchController';

interface QuickSearchProps {
namespace: string;
viewContainer?: HTMLElement;
}

const QuickSearch: React.FC<QuickSearchProps> = ({ namespace }) => {
return (
<CatalogServiceProvider namespace={namespace}>
{(catalogService: CatalogService) => (
<QuickSearchController {...catalogService} namespace={namespace} />
)}
</CatalogServiceProvider>
);
};
const QuickSearch: React.FC<QuickSearchProps> = ({ namespace, viewContainer }) => (
<CatalogServiceProvider namespace={namespace}>
{(catalogService: CatalogService) => (
<QuickSearchController
{...catalogService}
namespace={namespace}
viewContainer={viewContainer}
/>
)}
</CatalogServiceProvider>
);

export default QuickSearch;
export default React.memo(QuickSearch);
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import QuickSearchModal from './QuickSearchModal';

type QuickSearchControllerProps = CatalogService & {
namespace: string;
viewContainer?: HTMLElement;
};

const QuickSearchController: React.FC<QuickSearchControllerProps> = ({
namespace,
searchCatalog,
loaded,
viewContainer,
}) => {
const [isQuickSearchActive, setIsQuickSearchActive] = React.useState<boolean>(false);

Expand Down Expand Up @@ -43,6 +45,7 @@ const QuickSearchController: React.FC<QuickSearchControllerProps> = ({
namespace={namespace}
allCatalogItemsLoaded={loaded}
searchCatalog={searchCatalog}
viewContainer={viewContainer}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface QuickSearchModalProps {
closeModal: () => void;
allCatalogItemsLoaded: boolean;
searchCatalog: (query: string) => CatalogItem[];
viewContainer?: HTMLElement;
}

const QuickSearchModal: React.FC<QuickSearchModalProps> = ({
Expand All @@ -18,18 +19,20 @@ const QuickSearchModal: React.FC<QuickSearchModalProps> = ({
closeModal,
searchCatalog,
allCatalogItemsLoaded,
viewContainer,
}) => {
const { t } = useTranslation();

return (
return viewContainer ? (
<Modal
variant={ModalVariant.medium}
aria-label={t('topology~Quick search')}
isOpen={isOpen}
showClose={false}
position="top"
positionOffset="30%"
positionOffset="15%"
hasNoBodyWrapper
appendTo={viewContainer}
>
<QuickSearchModalBody
allCatalogItemsLoaded={allCatalogItemsLoaded}
Expand All @@ -38,7 +41,7 @@ const QuickSearchModal: React.FC<QuickSearchModalProps> = ({
closeModal={closeModal}
/>
</Modal>
);
) : null;
};

export default QuickSearchModal;
4 changes: 3 additions & 1 deletion frontend/packages/topology/src/filters/TopologyFilterBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type StateProps = {
type OwnProps = {
visualization?: Visualization;
viewType: TopologyViewType;
viewContainer?: HTMLElement;
};

type TopologyFilterBarProps = StateProps & OwnProps;
Expand All @@ -53,6 +54,7 @@ const TopologyFilterBar: React.FC<TopologyFilterBarProps> = ({
visualization,
viewType,
namespace,
viewContainer,
}) => {
const { t } = useTranslation();
const { filters, setTopologyFilters: onFiltersChange } = React.useContext(FilterContext);
Expand All @@ -74,7 +76,7 @@ const TopologyFilterBar: React.FC<TopologyFilterBarProps> = ({
<Toolbar className="co-namespace-bar odc-topology-filter-bar">
<ToolbarContent>
<ToolbarItem>
<QuickSearch namespace={namespace} />
<QuickSearch namespace={namespace} viewContainer={viewContainer} />
</ToolbarItem>
<ToolbarGroup variant={ToolbarGroupVariant['filter-group']}>
<ToolbarItem>
Expand Down