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
feat: adds theming to support multiple instances of the platform #1242
Changes from all commits
45cbb82
4c0cfae
163f67d
a5f1e78
c89c2f6
f070728
0e0d6ee
920dd3b
95ba43e
045d719
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,41 @@ | ||
import React, { Component } from 'react' | ||
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. Lift primary application out of |
||
import { observer, Provider } from 'mobx-react' | ||
import { ThemeProvider } from 'styled-components' | ||
import { GlobalStyle } from './themes/app.globalStyles' | ||
import { RootStore } from './stores' | ||
import ErrorBoundary from './common/ErrorBoundary' | ||
import { Routes } from './pages' | ||
|
||
const rootStore = new RootStore() | ||
|
||
/** | ||
* Additional store and db exports for use in modern context consumers | ||
* @example const {userStore} = useCommonStores() | ||
*/ | ||
export const rootStoreContext = React.createContext<RootStore>(rootStore) | ||
export const useCommonStores = () => | ||
React.useContext<RootStore>(rootStoreContext) | ||
export const dbContext = React.createContext({ db: rootStore.dbV2 }) | ||
export const useDB = () => React.useContext(dbContext) | ||
|
||
@observer | ||
export class App extends Component { | ||
render() { | ||
return ( | ||
<> | ||
<Provider {...rootStore.stores}> | ||
<ThemeProvider | ||
theme={rootStore.stores.themeStore.currentTheme.styles} | ||
> | ||
<> | ||
<ErrorBoundary> | ||
<Routes /> | ||
</ErrorBoundary> | ||
<GlobalStyle /> | ||
</> | ||
</ThemeProvider> | ||
</Provider> | ||
</> | ||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { Component } from 'react' | ||
|
||
import { Image, ImageProps } from 'rebass' | ||
import { Image, ImageProps } from 'rebass/styled-components' | ||
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. suggestion: We have a mixture of Rebass does allow you to specifically use We can easily reverse this decision and switch towards Emotion dropping Styled Components but this needs to be consistent! 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. I remember at one time the lead frontend (Benj) had wanted to move to emotion, but as we had only just moved from material -> styled components seemed like one step too far. Would definitely be outside scope of the PR to make a switch so seems like a sensible option until such a time if we did decide (npm trends still has styled-components way more popular but I have no strong opinion on the matter otherwise) |
||
import { inject, observer } from 'mobx-react' | ||
import { ProfileTypeLabel } from 'src/models/user_pp.models' | ||
import Workspace from 'src/pages/User/workspace/Workspace' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,83 @@ | ||
import { SITE, VERSION, DEV_SITE_ROLE } from 'src/config/config' | ||
import Text from 'src/components/Text' | ||
import theme from 'src/themes/styled.theme' | ||
import { UserRole } from 'src/models' | ||
import { Flex, Box } from 'rebass' | ||
import { Flex, Box } from 'rebass/styled-components' | ||
import Select from 'react-select' | ||
import { observer } from 'mobx-react-lite' | ||
import { useCommonStores } from 'src' | ||
|
||
/** | ||
* A simple header component that reminds developers that they are working on a dev | ||
* version of the platform, and provide the option to toggle between different dev sites | ||
*/ | ||
const DevSiteHeader = () => ( | ||
<> | ||
{devSites.find(s => s.value === SITE) && ( | ||
<Flex | ||
data-cy="devSiteHeader" | ||
bg={theme.colors.red2} | ||
width={1} | ||
py={1} | ||
px={1} | ||
alignItems="center" | ||
style={{ zIndex: 3001 }} | ||
> | ||
<Text color={'white'} medium txtcenter flex="1"> | ||
This is a dev version of the platform (v{VERSION}) | ||
</Text> | ||
<Flex data-cy="devSiteRoleSelectContainer" alignItems="center" ml={2}> | ||
<Text color={'white'} medium mr="1" title={SITE}> | ||
View as: | ||
const DevSiteHeader = observer(() => { | ||
const { themeStore } = useCommonStores().stores | ||
const { themeOptions } = themeStore | ||
const theme = themeStore.currentTheme.styles | ||
return ( | ||
<> | ||
{devSites.find(s => s.value === SITE) && ( | ||
<Flex | ||
data-cy="devSiteHeader" | ||
bg={theme.colors.red2} | ||
width={1} | ||
py={1} | ||
px={1} | ||
alignItems="center" | ||
style={{ zIndex: 3001 }} | ||
> | ||
<Text color={'white'} medium txtcenter flex="1"> | ||
This is a dev version of the platform (v{VERSION}) | ||
</Text> | ||
<Box width="150px" mr={3}> | ||
<Select | ||
options={siteRoles} | ||
placeholder="Role" | ||
defaultValue={ | ||
siteRoles.find(s => s.value === DEV_SITE_ROLE) || siteRoles[0] | ||
} | ||
onChange={(s: any) => setSiteRole(s.value)} | ||
/> | ||
</Box> | ||
<Flex data-cy="devSiteRoleSelectContainer" alignItems="center" ml={2}> | ||
<Text color={'white'} medium mr="1" title={SITE}> | ||
View as: | ||
</Text> | ||
<Box width="150px" mr={3}> | ||
<Select | ||
options={siteRoles} | ||
placeholder="Role" | ||
defaultValue={ | ||
siteRoles.find(s => s.value === DEV_SITE_ROLE) || siteRoles[0] | ||
} | ||
onChange={(s: any) => setSiteRole(s.value)} | ||
/> | ||
</Box> | ||
</Flex> | ||
<Flex data-cy="devSiteSelectContainer" alignItems="center"> | ||
<Text color={'white'} medium mr="1" title={SITE}> | ||
Site: | ||
</Text> | ||
<Box width="130px"> | ||
<Select | ||
options={devSites} | ||
placeholder="Site" | ||
defaultValue={devSites.find(s => s.value === SITE)} | ||
onChange={(s: any) => setSite(s.value)} | ||
/> | ||
</Box> | ||
</Flex> | ||
<Flex data-cy="themeSelectContainer" alignItems="center" ml={2}> | ||
<Text color={'white'} medium ml="1" mr="1" title={SITE}> | ||
Theme: | ||
</Text> | ||
<Box width="190px"> | ||
<Select | ||
options={themeOptions} | ||
placeholder="Site" | ||
defaultValue={themeOptions[0]} | ||
onChange={(s: any) => themeStore.setActiveTheme(s.value)} | ||
/> | ||
</Box> | ||
</Flex> | ||
</Flex> | ||
<Flex data-cy="devSiteSelectContainer" alignItems="center"> | ||
<Text color={'white'} medium mr="1" title={SITE}> | ||
Site: | ||
</Text> | ||
<Box width="130px"> | ||
<Select | ||
options={devSites} | ||
placeholder="Site" | ||
defaultValue={devSites.find(s => s.value === SITE)} | ||
onChange={(s: any) => setSite(s.value)} | ||
/> | ||
</Box> | ||
</Flex> | ||
</Flex> | ||
)} | ||
</> | ||
) | ||
)} | ||
</> | ||
) | ||
}) | ||
// we have 2 different dev sites, only show this component when on one and provide select | ||
const devSites = [ | ||
{ value: 'localhost', label: 'Dev' }, | ||
{ value: 'dev_site', label: 'Development' }, | ||
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. Thanks for fixing this, was wondering why I hadn't seen it recently :S |
||
{ value: 'preview', label: 'Preview' }, | ||
] | ||
// dev site users can use either a default user profile or mock another admin role | ||
|
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.
question Not sure what/why with this line item; removing unless someone says no…
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.
I think that might have been related to storybook back when all package installs were hoisted to top-level, but as we now have
nmHoistingLimits: workspaces
I expect fine to remove