-
Notifications
You must be signed in to change notification settings - Fork 1.4k
experiment: Frontend - Share v1 UI via coder/m submodule (Approach 1) #4
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| [submodule "m"] | ||
| path = m | ||
| url = https://github.com/coder/m |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import React from "react" | ||
| import ReactDOM from "react-dom" | ||
|
|
||
| // Code imported from 'Coder v1' | ||
| // Legacy components that we can re-use | ||
| import { CoderThemeProvider } from "@v1/product/coder/site/src/contexts/CoderThemeProvider" | ||
| import { UserContext, defaultAppState } from "@v1/product/coder/site/src/contexts/User" | ||
| import { SetupModeProvider } from "@v1/product/coder/site/src/contexts/SetupMode" | ||
|
|
||
| // A fun component to bring in as an example of re-using UI from 'v1': | ||
| import { ConfettiTransition } from "@v1/product/coder/site/src/pages/Onboarding/Activation/ConfettiTransition" | ||
|
|
||
| // And some other, simpler, componenents: | ||
| import { PrimaryButton } from "@v1/product/coder/site/src/components/Button" | ||
|
|
||
| // Helper function to scaffold providers that are needed to host the 'V1' UI | ||
| // Ultimately, we'd host the entire app (router and all) | ||
| const renderLegacyComponent = (component: JSX.Element) => { | ||
| const fetchSetupMode = async () => { | ||
| // Return an empty response for 'setup mode' | ||
| return { | ||
| body: null | ||
| } as any; | ||
| } | ||
|
|
||
| return <UserContext.Provider value={defaultAppState}> | ||
| <SetupModeProvider fetchSetupMode={fetchSetupMode}> | ||
| <CoderThemeProvider> | ||
| {component} | ||
| </CoderThemeProvider> | ||
| </SetupModeProvider> | ||
| </UserContext.Provider> | ||
| } | ||
|
|
||
| function component() { | ||
| const element = document.createElement('div'); | ||
|
|
||
| // Render the legacy UI | ||
| const ui = renderLegacyComponent(<div> | ||
| <ConfettiTransition /> | ||
| <div style={{ position: 'absolute', height: 250, left: 0, right: 0, bottom: 0 }}> | ||
| <PrimaryButton>A v1 button hosted in v2 app</PrimaryButton> | ||
| </div> | ||
| </div >) | ||
| ReactDOM.render(ui, element) | ||
|
|
||
| return element; | ||
| } | ||
|
|
||
| document.body.appendChild(component()); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| declare module "match-sorter" { | ||
| export enum rankings { | ||
| CASE_SENSITIVE_EQUAL = 9, | ||
| EQUAL = 8, | ||
| STARTS_WITH = 7, | ||
| WORD_STARTS_WITH = 6, | ||
| STRING_CASE = 5, | ||
| STRING_CASE_ACRONYM = 4, | ||
| CONTAINS = 3, | ||
| ACRONYM = 2, | ||
| MATCHES = 1, | ||
| NO_MATCH = 0, | ||
| } | ||
|
|
||
| export type KeyOptions<T> = (item: T) => string[] | string | ||
|
|
||
| export type ExtendedKeyOptions<T> = { key: KeyOptions<T> } & ( | ||
| | { maxRanking: number } | ||
| | { minRanking: number } | ||
| | { threshold: number } | ||
| ) | ||
|
|
||
| export interface Options<T> { | ||
| keys?: Array<ExtendedKeyOptions<T> | KeyOptions<T> | keyof T> | ||
| threshold?: number | ||
| keepDiacritics?: boolean | ||
| baseSort?: (a: T, b: T) => number | ||
| } | ||
|
|
||
| declare function matchSorter<T>(items: ReadonlyArray<T>, value: string, options?: Options<T>): T[] | ||
|
|
||
| export default matchSorter | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| /// <reference types="next" /> | ||
| /// <reference types="next/types/global" /> | ||
| /// <reference types="next/image-types/global" /> | ||
|
|
||
| // NOTE: This file should not be edited | ||
| // see https://nextjs.org/docs/basic-features/typescript for more information. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "outDir": "./dist/", | ||
| "noImplicitAny": true, | ||
| "module": "commonjs", | ||
| "target": "es5", | ||
| "jsx": "react", | ||
| "allowJs": true, | ||
| "downlevelIteration": true, | ||
| "esModuleInterop": true, | ||
| "resolveJsonModule": true, | ||
| "isolatedModules": true, | ||
| "paths": { | ||
| "@v1/*": [ | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These |
||
| "./../m/*" | ||
| ], | ||
| "lib/ts/*": [ | ||
| "./../m/lib/ts/*" | ||
| ], | ||
| "product/*": [ | ||
| "./../m/product/*" | ||
| ], | ||
| "lib/coderapi/legacy": [ | ||
| "./../m/lib/ts/coderapi/src/legacy/index.ts" | ||
| ], | ||
| "lib/coderapi/legacy/*": [ | ||
| "./../m/lib/ts/coderapi/src/legacy/*" | ||
| ], | ||
| "lib/coderapi": [ | ||
| "./../m/lib/ts/coderapi/src/index.ts" | ||
| ], | ||
| "lib/coderapi/*": [ | ||
| "./../m/lib/ts/coderapi/src/*" | ||
| ], | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| const path = require('path'); | ||
|
|
||
| module.exports = { | ||
| entry: './site/index.tsx', | ||
| module: { | ||
| rules: [ | ||
| { | ||
| test: /\.tsx?$/, | ||
| use: 'ts-loader', | ||
| exclude: /node_modules/, | ||
| }, | ||
| ], | ||
| }, | ||
| resolve: { | ||
| extensions: ['.tsx', '.ts', '.js'], | ||
| alias: { | ||
| '@v1': path.resolve(__dirname, '..', 'm'), | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And these aliases and modules are necessary for webpack (or next, on top of webpack) to pick up the nested modules |
||
| 'lib/coderapi': path.resolve(__dirname, '..', 'm', 'lib', 'ts', 'coderapi', 'src') | ||
| }, | ||
| modules: [ | ||
| 'node_modules', | ||
| path.resolve(__dirname, '..', 'm'), | ||
| path.resolve(__dirname, '..', 'm', 'lib'), | ||
| path.resolve(__dirname, '..', 'm', 'product', 'coder', 'site')] | ||
| }, | ||
| output: { | ||
| filename: 'bundle.js', | ||
| path: path.resolve(__dirname, 'dist'), | ||
| }, | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a couple of definition files that needed to be picked up to compile the 'v1' modules... If we go with this approach, I'll look for a nicer way to handle this.