Skip to content

Commit

Permalink
Update next-image types and fix image imports (#15921)
Browse files Browse the repository at this point in the history
Images are now imported as objects with a src attribute.

Test Plan
yarn ts
  • Loading branch information
salazarm authored Aug 18, 2023
1 parent 9660abf commit 47735b7
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 128 deletions.
49 changes: 49 additions & 0 deletions js_modules/dagster-ui/packages/app-oss/custom-next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* eslint-disable import/no-default-export */
/// <reference types="next" />

type StaticImageData = {
src: string;
height: number;
width: number;
placeholder?: string;
};

declare module '*.svg' {
const content: StaticImageData;
export default content;
}

declare module '*.jpg' {
const content: StaticImageData;
export default content;
}

declare module '*.jpeg' {
const content: StaticImageData;
export default content;
}

declare module '*.gif' {
const content: StaticImageData;
export default content;
}

declare module '*.webp' {
const content: StaticImageData;
export default content;
}

declare module '*.ico' {
const content: StaticImageData;
export default content;
}

declare module '*.bmp' {
const content: StaticImageData;
export default content;
}

declare module '*.avif' {
const content: StaticImageData;
export default content;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ export default function Document() {
{/* Not sure if we need the following script */}
<script
id="webpack-nonce-setter"
nonce="NONCE-PLACEHOLDER"
dangerouslySetInnerHTML={{__html: `__webpack_nonce__ = 'NONCE-PLACEHOLDER';`}}
/>
{isDev ? <meta httpEquiv="Content-Security-Policy" content={getSecurityPolicy()} /> : null}
<script
type="application/json"
id="initialization-data"
nonce="NONCE-PLACEHOLDER"
dangerouslySetInnerHTML={{
__html: `
{
Expand Down
72 changes: 0 additions & 72 deletions js_modules/dagster-ui/packages/app-oss/src/react-app-env.d.ts

This file was deleted.

13 changes: 4 additions & 9 deletions js_modules/dagster-ui/packages/app-oss/src/typings.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/* eslint-disable import/no-default-export */

/// <reference types="next" />

declare module '@vx/gradient';
declare module '@vx/group';
declare module '@vx/network';
Expand Down Expand Up @@ -26,28 +30,19 @@ interface Navigator extends NavigatorClipboard {}

declare module '*.json' {
const value: any;
// eslint-disable-next-line import/no-default-export
export default value;
}

declare module '*.mp4' {
const src: string;
// eslint-disable-next-line import/no-default-export
export default src;
}

declare module '*.svg' {
const content: any;
// eslint-disable-next-line import/no-default-export
export default content;
}

declare module 'worker-loader!*' {
class WebpackWorker extends Worker {
constructor();
}

// eslint-disable-next-line import/no-default-export
export default WebpackWorker;
}

Expand Down
4 changes: 2 additions & 2 deletions js_modules/dagster-ui/packages/app-oss/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
"lib": ["dom", "dom.iterable", "esnext"],
"incremental": true
},
"include": ["src", "next.config.js"],
"exclude": ["node_modules"]
"include": ["src", "custom-next-env.d.ts"],
"exclude": ["node_modules", "next-env.d.ts"]
}
49 changes: 49 additions & 0 deletions js_modules/dagster-ui/packages/ui-components/custom-next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* eslint-disable import/no-default-export */
/// <reference types="next" />

type StaticImageData = {
src: string;
height: number;
width: number;
placeholder?: string;
};

declare module '*.svg' {
const content: StaticImageData;
export default content;
}

declare module '*.jpg' {
const content: StaticImageData;
export default content;
}

declare module '*.jpeg' {
const content: StaticImageData;
export default content;
}

declare module '*.gif' {
const content: StaticImageData;
export default content;
}

declare module '*.webp' {
const content: StaticImageData;
export default content;
}

declare module '*.ico' {
const content: StaticImageData;
export default content;
}

declare module '*.bmp' {
const content: StaticImageData;
export default content;
}

declare module '*.avif' {
const content: StaticImageData;
export default content;
}
Original file line number Diff line number Diff line change
Expand Up @@ -310,19 +310,6 @@ export const Icons = {
zoom_out,
} as const;

// TODO: Find more elegant solution
const copy: any = Icons;
Object.keys(copy).forEach((key) => {
let img = copy[key];
if (typeof img === 'object' && 'default' in img) {
// in Dagster UI but not in Storybook due to webpack config differences
img = (img as {default: any}).default;
} else if (img.src) {
img = img.src;
}
copy[key] = img;
});

const SVGS_WITH_COLORS = new Set([(slack as any).src]);

export type IconName = keyof typeof Icons;
Expand All @@ -342,11 +329,7 @@ interface Props {

export const Icon = React.memo((props: Props) => {
const {name, size = 16, style} = props;
let img = Icons[name] || '';
if (typeof img === 'object' && 'default' in img) {
// in Dagster UI but not in Storybook due to webpack config differences
img = (img as {default: any}).default;
}
const img = Icons[name].src || '';
const color: string | null = props.color || (SVGS_WITH_COLORS.has(img) ? null : Colors.Dark);
return (
<IconWrapper
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion js_modules/dagster-ui/packages/ui-components/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
"noFallthroughCasesInSwitch": true
},
"exclude": ["node_modules", "lib"],
"include": ["src", "types"]
"include": ["src", "custom-next-env.d.ts"]
}
12 changes: 6 additions & 6 deletions js_modules/dagster-ui/packages/ui-core/src/graph/OpTags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -416,10 +416,10 @@ export const OpTags = React.memo(({tags, style, reduceColor, reduceText}: OpTags
return (
<OpTagsContainer style={style}>
{tags.map((tag) => {
const known = (KNOWN_TAGS as any)[coerceToStandardLabel(tag.label)];
const known = KNOWN_TAGS[coerceToStandardLabel(tag.label) as keyof typeof KNOWN_TAGS];
const text = known?.content || tag.label;
const color = known?.color || generateColorForLabel(tag.label);
const textcolor = known?.reversed ? Colors.Gray900 : Colors.White;
const textcolor = 'reversed' in known ? Colors.Gray900 : Colors.White;
return (
<Box
key={tag.label}
Expand All @@ -433,18 +433,18 @@ export const OpTags = React.memo(({tags, style, reduceColor, reduceText}: OpTags
fontWeight: reduceColor ? 500 : 700,
}}
>
{known?.icon && (
{'icon' in known && (
<OpTagIconWrapper
role="img"
$size={16}
$img={known?.icon}
$color={reduceColor ? (known?.reversed ? Colors.Gray900 : color) : textcolor}
$img={known.icon.src}
$color={reduceColor ? ('reversed' in known ? Colors.Gray900 : color) : textcolor}
//$color={reduceColor ? color : textcolor}
$rotation={null}
aria-label={tag.label}
/>
)}
{known?.icon && reduceText ? undefined : text}
{'icon' in known && reduceText ? undefined : text}
</Box>
);
})}
Expand Down
Loading

2 comments on commit 47735b7

@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-storybook ready!

✅ Preview
https://dagit-storybook-2j400z4ra-elementl.vercel.app

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

@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-q0b6hhjc1-elementl.vercel.app

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

Please sign in to comment.