Skip to content

Commit

Permalink
[dagit] Ignore source assets for “Materialize All” button (#7196)
Browse files Browse the repository at this point in the history
  • Loading branch information
bengotow committed Mar 31, 2022
1 parent 8f271ef commit f064389
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {Description} from '../pipelines/Description';
import {instanceAssetsExplorerPathToURL} from '../pipelines/PipelinePathUtils';
import {PipelineReference} from '../pipelines/PipelineReference';
import {ASSET_NODE_FRAGMENT, ASSET_NODE_LIVE_FRAGMENT} from '../workspace/asset-graph/AssetNode';
import {LiveData, __ASSET_GROUP} from '../workspace/asset-graph/Utils';
import {isSourceAsset, LiveData, __ASSET_GROUP} from '../workspace/asset-graph/Utils';
import {buildRepoAddress} from '../workspace/buildRepoAddress';
import {RepoAddress} from '../workspace/types';

Expand Down Expand Up @@ -135,7 +135,7 @@ const JobGraphLink: React.FC<{
assetNode: AssetNodeDefinitionFragment;
direction: 'upstream' | 'downstream';
}> = ({direction, assetNode}) => {
if (assetNode.jobNames.length === 0 || !assetNode.opName) {
if (isSourceAsset(assetNode)) {
return null;
}
const populated =
Expand Down Expand Up @@ -185,7 +185,7 @@ const DefinitionLocation: React.FC<{
</Box>
)}

{assetNode.jobNames.length === 0 && !assetNode.opName && (
{isSourceAsset(assetNode) && (
<Caption style={{lineHeight: '16px', marginTop: 2}}>Source Asset</Caption>
)}
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
layoutGraph,
LiveData,
Node,
isSourceAsset,
} from './Utils';
import {AssetGraphLiveQuery, AssetGraphLiveQueryVariables} from './types/AssetGraphLiveQuery';
import {
Expand Down Expand Up @@ -222,7 +223,7 @@ const AssetGraphExplorerWithData: React.FC<
const lastSelectedNode = selectedGraphNodes[selectedGraphNodes.length - 1];
const launchGraphNodes = selectedGraphNodes.length
? selectedGraphNodes
: Object.values(assetGraphData.nodes);
: Object.values(assetGraphData.nodes).filter((a) => !isSourceAsset(a.definition));

const onSelectNode = React.useCallback(
async (e: React.MouseEvent<any>, assetKey: {path: string[]}, node: Node | null) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {LaunchRootExecutionButton} from '../../launchpad/LaunchRootExecutionButt
import {buildRepoAddress} from '../buildRepoAddress';

import {LaunchAssetChoosePartitionsDialog} from './LaunchAssetChoosePartitionsDialog';
import {isSourceAsset} from './Utils';

type AssetMinimal = {
assetKey: {path: string[]};
Expand All @@ -28,7 +29,7 @@ export const LaunchAssetExecutionButton: React.FC<{
);

let disabledReason = '';
if (!assets.every((a) => a.opName)) {
if (assets.some(isSourceAsset)) {
disabledReason = 'One or more source assets are selected and cannot be materialized.';
}
if (
Expand All @@ -38,19 +39,22 @@ export const LaunchAssetExecutionButton: React.FC<{
a.repository.location.name === repoAddress.location,
)
) {
disabledReason = 'Assets must be in the same repository to be materialized together.';
disabledReason =
disabledReason || 'Assets must be in the same repository to be materialized together.';
}

const everyAssetHasJob = (jobName: string) => assets.every((a) => a.jobNames.includes(jobName));
const jobsInCommon = assets[0] ? assets[0].jobNames.filter(everyAssetHasJob) : [];
const jobName = jobsInCommon.find((name) => name === preferredJobName) || jobsInCommon[0];
if (!jobName) {
disabledReason = 'Assets must be in the same job to be materialized together.';
disabledReason =
disabledReason || 'Assets must be in the same job to be materialized together.';
}

const partitionDefinition = assets[0]?.partitionDefinition;
if (assets.some((a) => a.partitionDefinition !== partitionDefinition)) {
disabledReason = 'Assets must share a partition definition to be materialized together.';
disabledReason =
disabledReason || 'Assets must share a partition definition to be materialized together.';
}

title = title || 'Refresh';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ export type IEdge = {
dashed: boolean;
};

export const isSourceAsset = (node: {jobNames: string[]; opName: string | null}) => {
return node.jobNames.length === 0 && !node.opName;
};

export const buildGraphData = (assetNodes: AssetNode[]) => {
const data: GraphData = {
nodes: {},
Expand Down Expand Up @@ -295,7 +299,6 @@ export const buildLiveData = (

const lastMaterialization = liveNode.assetMaterializations[0] || null;
const lastStepStart = lastMaterialization?.stepStats?.startTime || 0;
const isForeignNode = !liveNode.opName;
const isPartitioned = graphNode.definition.partitionDefinition;
const repo = repos.find(
(r) =>
Expand Down Expand Up @@ -323,7 +326,7 @@ export const buildLiveData = (
unstartedRunIds: runs?.unstartedRuns.map((r) => r.id) || [],
runsSinceMaterialization,
runWhichFailedToMaterialize,
computeStatus: isForeignNode
computeStatus: isSourceAsset(graphNode.definition)
? 'good' // foreign nodes are always considered up-to-date
: isPartitioned
? // partitioned nodes are not supported, need to compare materializations
Expand Down

0 comments on commit f064389

Please sign in to comment.