Skip to content

Commit

Permalink
getVisibleFeatureRows -> useVisibleFeatureRows (#23667)
Browse files Browse the repository at this point in the history
## Summary & Motivation

Converting this to a hook so that the cloud version can use react
context to conditionally add flags.

## How I Tested These Changes

local host cloud
  • Loading branch information
salazarm authored Aug 15, 2024
1 parent 2cf045d commit de4702a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Icon} from '@dagster-io/ui-components';
import {useState} from 'react';
import {getVisibleFeatureFlagRows} from 'shared/app/getVisibleFeatureFlagRows.oss';
import {useVisibleFeatureFlagRows} from 'shared/app/useVisibleFeatureFlagRows.oss';

import {useFeatureFlags} from './Flags';
import {TopNavButton} from './TopNavButton';
Expand All @@ -10,6 +10,8 @@ export const UserSettingsButton = () => {
const {flagSettingsPage} = useFeatureFlags();
const [isOpen, setIsOpen] = useState(false);

const visibleFlags = useVisibleFeatureFlagRows();

if (flagSettingsPage) {
return null;
}
Expand All @@ -22,7 +24,7 @@ export const UserSettingsButton = () => {
<UserSettingsDialog
isOpen={isOpen}
onClose={() => setIsOpen(false)}
visibleFlags={getVisibleFeatureFlagRows()}
visibleFlags={visibleFlags}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {FeatureFlag} from 'shared/app/FeatureFlags.oss';
/**
* Open-source feature flags to be displayed in Dagster UI "User settings"
*/
export const getVisibleFeatureFlagRows = () => [
export const useVisibleFeatureFlagRows = () => [
{
key: 'Display resources in navigation sidebar',
flagType: FeatureFlag.flagSidebarResources,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
SearchResultType,
isAssetFilterSearchResultType,
} from './types';
import {assertUnreachable} from '../app/Util';
import {isCanonicalComputeKindTag, isCanonicalStorageKindTag} from '../graph/KindTags';
import {KNOWN_TAGS, TagIcon} from '../graph/OpTags';

Expand Down Expand Up @@ -54,8 +55,12 @@ const iconForType = (type: SearchResultType | AssetFilterSearchResultType): Icon
return 'tag';
case AssetFilterSearchResultType.StorageKind:
return 'storage_kind';
default:
case SearchResultType.Page:
return 'source';
case AssetFilterSearchResultType.Column:
return 'view_column';
default:
assertUnreachable(type);
}
};

Expand All @@ -73,8 +78,10 @@ const assetFilterPrefixString = (type: AssetFilterSearchResultType): string => {
return 'Group';
case AssetFilterSearchResultType.StorageKind:
return 'Storage kind';
case AssetFilterSearchResultType.Column:
return 'Column';
default:
return '';
assertUnreachable(type);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {PYTHON_ERROR_FRAGMENT} from '../app/PythonErrorFragment';
import {displayNameForAssetKey, isHiddenAssetGroupJob} from '../asset-graph/Utils';
import {assetDetailsPathForKey} from '../assets/assetDetailsPathForKey';
import {buildStorageKindTag, isCanonicalStorageKindTag} from '../graph/KindTags';
import {DefinitionTag, buildDefinitionTag} from '../graphql/types';
import {AssetOwner, DefinitionTag, buildDefinitionTag} from '../graphql/types';
import {buildTagString} from '../ui/tagAsString';
import {buildRepoPathForHuman} from '../workspace/buildRepoAddress';
import {repoAddressAsURLString} from '../workspace/repoAddressAsString';
Expand All @@ -41,7 +41,7 @@ export const linkToAssetTableWithStorageKindFilter = (storageKind: string) => {
})}`;
};

export const linkToAssetTableWithTagFilter = (tag: DefinitionTag) => {
export const linkToAssetTableWithTagFilter = (tag: Omit<DefinitionTag, '__typename'>) => {
return `/assets?${qs.stringify({
tags: JSON.stringify([tag]),
})}`;
Expand All @@ -53,6 +53,18 @@ export const linkToAssetTableWithOwnerFilter = (owner: string) => {
})}`;
};

export const linkToAssetTableWithAssetOwnerFilter = (owner: AssetOwner) => {
return `/assets?${qs.stringify({
owners: JSON.stringify([owner]),
})}`;
};

export const linkToAssetTableWithColumnsFilter = (columns: string[]) => {
return `/assets?${qs.stringify({
columns: JSON.stringify(columns),
})}`;
};

export const linkToCodeLocation = (repoAddress: RepoAddress) => {
return `/locations/${repoAddressAsURLString(repoAddress)}/assets`;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Box, Icon} from '@dagster-io/ui-components';
import {useState} from 'react';
import {useLocation} from 'react-router-dom';
import {getVisibleFeatureFlagRows} from 'shared/app/getVisibleFeatureFlagRows.oss';
import {useVisibleFeatureFlagRows} from 'shared/app/useVisibleFeatureFlagRows.oss';

import {UserSettingsDialog} from '../app/UserSettingsDialog/UserSettingsDialog';
import {SideNavItem, SideNavItemConfig} from '../ui/SideNavItem';
Expand Down Expand Up @@ -68,7 +68,7 @@ export const SettingsLeftPane = () => {
<UserSettingsDialog
isOpen={showUserSettings}
onClose={() => setShowUserSettings(false)}
visibleFlags={getVisibleFeatureFlagRows()}
visibleFlags={useVisibleFeatureFlagRows()}
/>
</>
</Box>
Expand Down

1 comment on commit de4702a

@github-actions
Copy link

Choose a reason for hiding this comment

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

Deploy preview for dagit-core-storybook ready!

✅ Preview
https://dagit-core-storybook-p99shgoiw-elementl.vercel.app

Built with commit de4702a.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.