Skip to content

Commit

Permalink
update per feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
clairelin135 committed Mar 7, 2024
1 parent d81664a commit 0e3f279
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {gql, useQuery} from '@apollo/client';
import {Box, Colors, Page, Spinner} from '@dagster-io/ui-components';
import React from 'react';
import {useHistory, useParams} from 'react-router-dom';

import {AssetGlobalLineageLink, AssetPageHeader} from './AssetPageHeader';
import {AssetView} from './AssetView';
import {AssetsCatalogTable} from './AssetsCatalogTable';
import {WriteAssetVisitToLocalStorage} from './RecentlyVisitedAssetsStorage';
import {writeAssetVisitToLocalStorage} from './RecentlyVisitedAssetsStorage';
import {assetDetailsPathForKey} from './assetDetailsPathForKey';
import {
AssetsCatalogRootQuery,
Expand Down Expand Up @@ -45,6 +46,18 @@ export const AssetsCatalogRoot = () => {
currentPath && currentPath.length === 0 ? 'AssetsCatalogRoot' : 'AssetCatalogAssetView',
);

React.useEffect(() => {
// If the asset exists, add it to the recently visited list
if (
currentPath &&
currentPath.length &&
queryResult.loading === false &&
queryResult.data?.assetOrError.__typename === 'Asset'
) {
writeAssetVisitToLocalStorage({path: currentPath});
}
}, [currentPath, queryResult]);

if (queryResult.loading) {
return (
<Page>
Expand Down Expand Up @@ -83,10 +96,6 @@ export const AssetsCatalogRoot = () => {
);
}

// If the asset exists, add it to the recently visited list
if (currentPath && currentPath.length) {
WriteAssetVisitToLocalStorage({path: currentPath});
}
return <AssetView assetKey={{path: currentPath}} trace={trace} />;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import styled from 'styled-components';

import {AssetGlobalLineageButton, AssetPageHeader} from './AssetPageHeader';
import {ASSET_CATALOG_TABLE_QUERY} from './AssetsCatalogTable';
import {FetchRecentlyVisitedAssetsFromLocalStorage} from './RecentlyVisitedAssetsStorage';
import {fetchRecentlyVisitedAssetsFromLocalStorage} from './RecentlyVisitedAssetsStorage';
import {AssetTableFragment} from './types/AssetTableFragment.types';
import {
AssetCatalogTableQuery,
Expand Down Expand Up @@ -201,7 +201,7 @@ export const AssetsOverview = ({viewerName}: {viewerName?: string}) => {
const {
timezone: [timezone],
} = useContext(TimeContext);
const recentlyVisitedAssets = FetchRecentlyVisitedAssetsFromLocalStorage();
const recentlyVisitedAssets = fetchRecentlyVisitedAssetsFromLocalStorage();

if (assetsQuery.loading) {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {AssetKey} from './types';
const RECENTLY_VISITED_ASSETS_CACHE_SIZE = 10;
const RECENTLY_VISITED_ASSETS_STORAGE_KEY = 'recentlyVisitedAssets';

export function WriteAssetVisitToLocalStorage(assetKey: AssetKey) {
export function writeAssetVisitToLocalStorage(assetKey: AssetKey) {
if (typeof window !== 'undefined') {
const visitedAssetsStringified = localStorage.getItem(RECENTLY_VISITED_ASSETS_STORAGE_KEY);
const visitedAssets: AssetKey[] = visitedAssetsStringified
Expand All @@ -29,7 +29,7 @@ export function WriteAssetVisitToLocalStorage(assetKey: AssetKey) {
}
}

export function FetchRecentlyVisitedAssetsFromLocalStorage(): AssetKey[] {
export function fetchRecentlyVisitedAssetsFromLocalStorage(): AssetKey[] {
if (typeof window !== 'undefined') {
const visitedAssetsStringified = localStorage.getItem(RECENTLY_VISITED_ASSETS_STORAGE_KEY);
return visitedAssetsStringified ? JSON.parse(visitedAssetsStringified) : [];
Expand Down

0 comments on commit 0e3f279

Please sign in to comment.