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

[Asset-graph] Rename a few props #25949

Merged
merged 5 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import {useAssetLayout} from '../graph/asyncGraphLayout';
import {closestNodeInDirection, isNodeOffscreen} from '../graph/common';
import {AssetGroupSelector} from '../graphql/types';
import {useQueryAndLocalStoragePersistedState} from '../hooks/useQueryAndLocalStoragePersistedState';
import {useUpdatingRef} from '../hooks/useUpdatingRef';
import {
GraphExplorerOptions,
OptionsOverlay,
Expand Down Expand Up @@ -107,6 +108,8 @@ export const AssetGraphExplorer = (props: Props) => {

const {explorerPath, onChangeExplorerPath} = props;

const explorerPathRef = useUpdatingRef(explorerPath);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a ref to avoid changing the callback every render.


const {button, filterBar, groupsFilter, kindFilter, filterFn, filteredAssetsLoading} =
useAssetGraphExplorerFilters({
nodes: React.useMemo(
Expand All @@ -115,7 +118,19 @@ export const AssetGraphExplorer = (props: Props) => {
),
loading: fetchResult.loading,
viewType: props.viewType,
explorerPath: explorerPath.opsQuery,
assetSelection: explorerPath.opsQuery,
setAssetSelection: React.useCallback(
(assetSelection: string) => {
onChangeExplorerPath(
{
...explorerPathRef.current,
opsQuery: assetSelection,
},
'push',
);
},
[explorerPathRef, onChangeExplorerPath],
),
clearExplorerPath: React.useCallback(() => {
onChangeExplorerPath(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import {FilterTag, FilterTagHighlightedText} from '../ui/BaseFilters/useFilter';
export const AssetGraphFilterBar = ({
activeFiltersJsx,
right,
explorerPath,
clearExplorerPath,
clearAssetSelection,
assetSelection,
}: {
activeFiltersJsx: JSX.Element[];
right?: JSX.Element;
clearExplorerPath: () => void;
explorerPath: string;
clearAssetSelection: () => void;
assetSelection: string;
}) => {
if (!activeFiltersJsx.length && !explorerPath) {
if (!activeFiltersJsx.length && !assetSelection) {
return null;
}
return (
Expand All @@ -23,17 +23,17 @@ export const AssetGraphFilterBar = ({
>
<Box flex={{gap: 12, alignItems: 'center', direction: 'row', grow: 1}}>
{activeFiltersJsx}
{explorerPath ? (
{assetSelection ? (
<FilterTag
label={
<Box flex={{direction: 'row', alignItems: 'center'}}>
Asset selection is&nbsp;
<FilterTagHighlightedText tooltipText={explorerPath}>
{explorerPath}
<FilterTagHighlightedText tooltipText={assetSelection}>
{assetSelection}
</FilterTagHighlightedText>
</Box>
}
onRemove={clearExplorerPath}
onRemove={clearAssetSelection}
/>
) : null}
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@ import {useAssetCatalogFiltering} from 'shared/assets/useAssetCatalogFiltering.o

import {AssetGraphViewType, GraphNode} from './Utils';

type Props = {
export type Props = {
nodes: GraphNode[];
clearExplorerPath: () => void;
explorerPath: string;
clearAssetSelection: () => void;
setAssetSelection: (selection: string) => void;
salazarm marked this conversation as resolved.
Show resolved Hide resolved
assetSelection: string;
viewType: AssetGraphViewType;
loading: boolean;
};

export function useAssetGraphExplorerFilters({
nodes,
viewType,
explorerPath,
assetSelection,
loading,
clearExplorerPath,
clearAssetSelection,
}: Props) {
const ret = useAssetCatalogFiltering({
assets: nodes,
Expand All @@ -30,8 +31,8 @@ export function useAssetGraphExplorerFilters({
filterBar: (
<AssetGraphFilterBar
activeFiltersJsx={ret.activeFiltersJsx}
explorerPath={explorerPath}
clearExplorerPath={clearExplorerPath}
assetSelection={assetSelection}
clearAssetSelection={clearAssetSelection}
/>
),
};
Expand Down