Skip to content
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/navbar overhaul #2072

Merged
merged 5 commits into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": ["cozy-app"],
"extends": ["cozy-app/react"],
"rules": {
"no-console": "off",
"react/display-name": "off"
Expand All @@ -12,5 +12,8 @@
"react": {
"version": "16.5.2"
}
},
"parserOptions": {
"project": "tsconfig.json"
}
}
JF-Cozy marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = {
}
]
],
ignore: ['**/*.spec.jsx', '**/*.spec.js']
ignore: ['**/*.spec.jsx', '**/*.spec.js', '**/*.spec.tsx', '**/*.spec.ts']
},
test: {
presets: [['cozy-app', { transformRuntime: { helpers: true } }]],
Expand Down
4 changes: 2 additions & 2 deletions docs/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ module.exports = {
alias: {
docs: __dirname
},
extensions: ['.jsx', '.js', '.json', '.styl']
extensions: ['.jsx', '.js', '.json', '.styl', '.ts', '.tsx']
},
module: {
rules: [
{
test: /\.jsx?$/,
test: /\.(js|jsx|ts|tsx)$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
Expand Down
22 changes: 13 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
"build:doc:config": "copyfiles -u 1 docs/*.md docs/_config.yml build",
"build:doc:kss": "kss --destination build/styleguide --title 'Cozy-UI Styleguide' --source stylus --builder node_modules/michelangelo/kss_styleguide/custom-template --homepage styleguide.md --css app.css",
"build:doc:react": "styleguidist build --config docs/styleguide.config.js",
"build": "env BABEL_ENV=transpilation babel react/ --out-dir transpiled/react --verbose",
"build": "env BABEL_ENV=transpilation babel --extensions .ts,.tsx,.js,.jsx react/ --out-dir transpiled/react --verbose",
"clean:doc:kss": "rm -rf build/styleguide",
"commitmsg": "commitlint -e $GIT_PARAMS",
"deploy:doc": "git-directory-deploy --directory build/ --branch gh-pages",
"makeSvgr": "scripts/generate-svgr-icon.sh",
"lint": "npm-run-all 'lint:*'",
"lint:commit": "git merge-base HEAD master && commitlint --from=$(git merge-base HEAD master) --to=HEAD || true",
"lint:js": "eslint 'react/**/*.jsx' 'react/**/*.js' 'docs/styleguide.config.js'",
"lint:js": "eslint 'react/**/*.jsx' 'react/**/*.js' 'react/**/*.ts' 'docs/styleguide.config.js'",
"lint:stylus": "stylint stylus --config .stylintrc",
"lint:md": "remark . -o -S",
"palette": "scripts/make-palette.sh",
Expand Down Expand Up @@ -68,7 +68,10 @@
],
"devDependencies": {
"@babel/cli": "7.11.5",
"@babel/core": "7.11.5",
"@babel/core": "7.16.12",
"@babel/helper-builder-react-jsx": "7.16.7",
"@babel/helper-define-map": "7.16.7",
"@babel/helper-regex": "7.10.5",
"@cozy/codemods": "^1.9.0",
"@material-ui/core": "4.12.3",
"@semantic-release/changelog": "5.0.1",
Expand All @@ -83,7 +86,7 @@
"babel-loader": "8.1.0",
"babel-plugin-css-modules-transform": "1.6.2",
"babel-plugin-inline-json-import": "0.3.2",
"babel-preset-cozy-app": "1.9.2",
"babel-preset-cozy-app": "2.0.2",
"browserslist-config-cozy": "0.4.0",
"commitlint": "7.6.1",
"commitlint-config-cozy": "0.6.0",
Expand All @@ -92,7 +95,7 @@
"cozy-device-helper": "^1.16.1",
"cozy-doctypes": "^1.69.0",
"cozy-harvest-lib": "^6.7.3",
"cozy-intent": "^1.6.0",
"cozy-intent": "1.13.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

est-ce que le remplacement de ^1.13.0 par 1.13.0 est voulu ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes il y a un probleme de resolution de path sur la 1.13.3

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah. Peut-on linker l'issue peut-être ? Est-il prévu après la résolution de l'issue de faire une 1.13.4 débuggué et repasser cozy-intent en ^1.13.4 dans cozy-ui ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes j'ai déjà commencé la résolution pour cela je pense qu'il est redondant de faire une issue

"cozy-sharing": "^3.10.0",
"cozy-stack-client": "27.19.1",
"css-loader": "0.28.11",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem que précédemment : pourquoi ce commit est nécessaire ici ? Est-ce qu'on peut ajouter de la description dans le commit message ?

Expand All @@ -101,8 +104,7 @@
"enzyme": "3.11.0",
"enzyme-adapter-react-16": "1.15.6",
"enzyme-to-json": "3.6.2",
"eslint": "4.19.1",
"eslint-config-cozy-app": "0.5.1",
"eslint-config-cozy-app": "4.0.0",
"express": "^4.17.1",
"focus-trap-react": "^6.0.0",
"git-directory-deploy": "1.5.1",
Expand Down Expand Up @@ -198,7 +200,9 @@
"js",
"jsx",
"json",
"styl"
"styl",
"ts",
"tsx"
],
"testPathIgnorePatterns": [
"/node_modules/",
Expand All @@ -211,7 +215,7 @@
"react-styleguidist/lib"
],
"transform": {
"^.+\\.jsx?$": "babel-jest"
"^.+\\.(ts|tsx|js|jsx)?$": "babel-jest"
},
"transformIgnorePatterns": [
"node_modules/(?!(react-styleguidist)/)"
Expand Down
37 changes: 30 additions & 7 deletions react/ActionMenu/index.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import React from 'react'
import ClickAwayListener from '@material-ui/core/ClickAwayListener'
import PropTypes from 'prop-types'
import React from 'react'
import cx from 'classnames'
import ClickAwayListener from '@material-ui/core/ClickAwayListener'
import styles from './styles.styl'
import { Media, Bd, Img } from '../Media'
import { usePopper } from 'react-popper'
import { useTheme } from '@material-ui/core'

import BottomDrawer from '../BottomDrawer'
import Radio from '../Radio'
import createDepreciationLogger from '../helpers/createDepreciationLogger'
import styles from './styles.styl'
import useBreakpoints from '../hooks/useBreakpoints'
import { Media, Bd, Img } from '../Media'
import { getCssVariableValue } from '../utils/color'
import Radio from '../Radio'
import { spacingProp } from '../Stack'
import { usePopper } from 'react-popper'
import createDepreciationLogger from '../helpers/createDepreciationLogger'
import { useSetFlagshipUI } from '../hooks/useSetFlagshipUi/useSetFlagshipUI'

const ActionMenuWrapper = ({
inline,
Expand Down Expand Up @@ -101,6 +104,26 @@ const ActionMenu = ({
anchorElRef,
containerElRef
}) => {
const theme = useTheme()
const sidebar = document.getElementById('sidebar')

useSetFlagshipUI(
acezard marked this conversation as resolved.
Show resolved Hide resolved
{
bottomBackground: theme.palette.background.paper,
bottomTheme: 'dark',
topOverlay: getCssVariableValue('overlay'), // TODO: refactor to semantic variable
topBackground: theme.palette.background.paper,
topTheme: 'light'
},
{
bottomBackground: theme.palette.background[sidebar ? 'default' : 'paper'],
bottomTheme: 'dark',
topOverlay: 'transparent',
topBackground: theme.palette.background.paper,
topTheme: 'dark'
}
)

if (placement)
logDepecratedPlacement(
'<ActionMenu placement /> is deprecated, use <ActionMenu popperOptions={{ placement }} /> instead'
Expand Down
1 change: 1 addition & 0 deletions react/AppSections/categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const multiGroupBy = (iter, grouper) => {
for (const obj of iter) {
const values = grouper(obj) || []
values.forEach(v => {
// eslint-disable-next-line no-prototype-builtins
if (!groups.hasOwnProperty(v)) groups[v] = []
groups[v].push(obj)
})
Expand Down
24 changes: 1 addition & 23 deletions react/BarContextProvider/index.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const IntentComponent = () => {
let render

try {
// eslint-disable-next-line react-hooks/rules-of-hooks
webviewIntent = useWebviewIntent()
render = webviewIntent.foo
} catch {
Expand Down Expand Up @@ -172,27 +173,4 @@ describe('BarContextProvider', () => {

expect(queryByText(mockVoidWebviewService)).toBeInTheDocument()
})

it('should not try to provide a cozy-intent context if one is provided', () => {
// Set Web context
trollepierre marked this conversation as resolved.
Show resolved Hide resolved
window.cozy.isFlagshipApp = false

const client = createMockClient({})
const mockStore = configureStore()
const store = mockStore(x => x)

const { queryByText } = render(
<Provider store={store}>
<CozyProvider client={client}>
<I18n lang="en" dictRequire={() => locales}>
<App webviewService={mockWebviewService}>
<IntentComponent />
</App>
</I18n>
</CozyProvider>
</Provider>
)

expect(queryByText(mockWebviewService.foo)).not.toBeInTheDocument()
})
})
44 changes: 41 additions & 3 deletions react/Dialog/index.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import React from 'react'
import { default as MUIDialog } from '@material-ui/core/Dialog'
import { RemoveScroll } from 'react-remove-scroll'
import { default as MUIDialog } from '@material-ui/core/Dialog'
import { useTheme } from '@material-ui/core'

import useBreakpoints from '../hooks/useBreakpoints'
import { useCozyTheme } from '../CozyTheme'
import themesStyles from '../../stylus/settings/palette.styl'
import { useSetFlagshipUI } from '../hooks/useSetFlagshipUi/useSetFlagshipUI'

const Dialog = props => {
const { isMobile, isTablet } = useBreakpoints()
Expand All @@ -21,12 +24,47 @@ const Dialog = props => {
(props.open || props.opened) && shouldBlockScroll
? RemoveScroll
: React.Fragment
const cozyTheme = useCozyTheme()
const theme = useTheme()
const cozBar = document.querySelector('.coz-bar-wrapper')
const sidebar = document.getElementById('sidebar')

const theme = useCozyTheme()
useSetFlagshipUI(
acezard marked this conversation as resolved.
Show resolved Hide resolved
props.fullScreen
? {
bottomBackground: theme.palette.background.paper,
bottomTheme: 'dark',
topBackground: theme.palette.background.paper,
topTheme: 'dark'
}
: {
bottomBackground: theme.palette.background.default,
bottomTheme: 'light',
bottomOverlay: 'rgba(0, 0, 0, 0.5)',
acezard marked this conversation as resolved.
Show resolved Hide resolved
topOverlay: 'rgba(0, 0, 0, 0.5)',
topBackground: theme.palette.background.paper,
topTheme: 'light'
},
{
bottomBackground: theme.palette.background[sidebar ? 'default' : 'paper'],
bottomTheme: 'dark',
bottomOverlay: 'transparent',
topOverlay: 'transparent',
topBackground:
cozBar && getComputedStyle(cozBar).getPropertyValue('background-color'),
acezard marked this conversation as resolved.
Show resolved Hide resolved
topTheme:
cozBar && cozBar.classList.contains('coz-theme-primary')
? 'light'
: 'dark'
}
)

return (
<Wrapper>
<MUIDialog className={themesStyles[`CozyTheme--${theme}`]} {...props} />
<MUIDialog
className={themesStyles[`CozyTheme--${cozyTheme}`]}
{...props}
/>
</Wrapper>
)
}
Expand Down
1 change: 1 addition & 0 deletions react/IntentIframe/IntentIframe.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class IntentIframe extends React.Component {
})
.start(this.intentViewer, this.onFrameLoaded)
.then(result => {
// eslint-disable-next-line promise/always-return
result ? onTerminate && onTerminate(result) : onCancel()
})
.catch(error => {
Expand Down
1 change: 1 addition & 0 deletions react/Popup/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { isMobileApp } from 'cozy-device-helper'
*/
// source https://stackoverflow.com/a/16861050
export function popupCenter(w, h) {
// eslint-disable-next-line no-redeclare
/* global screen */
// Fixes dual-screen position
// Most browsers Firefox
Expand Down
1 change: 1 addition & 0 deletions react/PopupOpener/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import PropTypes from 'prop-types'
// customized function to center a popup window
// source https://stackoverflow.com/a/16861050
export function openCenteredPopup(url, title, w, h) {
// eslint-disable-next-line no-redeclare
/* global screen */
var width =
window.innerWidth || document.documentElement.clientWidth || screen.width
Expand Down
3 changes: 2 additions & 1 deletion react/PushClientButton/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ const ButtonClient = props => {
return (
<a
href={href}
//eslint-disable-next-line react/jsx-no-target-blank
// eslint-disable-next-line react/jsx-no-target-blank
target="_blank"
className={cx(styles['c-btn-client'], className)}
onClick={onClick}
rel="noreferrer"
>
<figure>
<Icon icon={icon || DeviceLaptopIcon} size="32" />
Expand Down
2 changes: 2 additions & 0 deletions react/QuotaAlert/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ const QuotaAlert = ({ onClose }) => {
if (isMobileApp()) {
return <QuotaModalAlert onClose={onClose} />
}
// TODO: why is there a conditional hook here?
// eslint-disable-next-line react-hooks/rules-of-hooks
acezard marked this conversation as resolved.
Show resolved Hide resolved
const instanceInfo = useInstance(client)
return <QuotaModalAlert instance={instanceInfo} onClose={onClose} />
}
Expand Down
35 changes: 34 additions & 1 deletion react/SelectionBar/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { useEffect } from 'react'
import PropTypes from 'prop-types'
import cx from 'classnames'

Expand All @@ -11,6 +11,8 @@ import useBreakpoints from '../hooks/useBreakpoints'
import styles from './styles.styl'

import CrossIcon from 'cozy-ui/transpiled/react/Icons/Cross'
import { useWebviewIntent } from 'cozy-intent'
import { useTheme } from '@material-ui/core'

/*

Expand Down Expand Up @@ -39,6 +41,37 @@ const SelectionBar = ({ actions, selected, hideSelectionBar }) => {
action.displayCondition === undefined || action.displayCondition(selected)
)
})
const webviewIntent = useWebviewIntent()
const theme = useTheme()

// This component is always rendered but hidden with CSS if there is no selection
acezard marked this conversation as resolved.
Show resolved Hide resolved
// That is why we do not use useSetFlagship API here because that hook can not accept changing values
acezard marked this conversation as resolved.
Show resolved Hide resolved
useEffect(() => {
if (!webviewIntent || !theme) return
acezard marked this conversation as resolved.
Show resolved Hide resolved

selectedCount === 0 &&
webviewIntent &&
webviewIntent.call('setFlagshipUI', {
bottomBackground: theme.palette.background.default,
bottomTheme: 'dark'
})

selectedCount > 0 &&
webviewIntent &&
webviewIntent.call('setFlagshipUI', {
bottomBackground: theme.palette.grey[700],
bottomTheme: 'light'
})

return () =>
webviewIntent &&
theme &&
webviewIntent.call('setFlagshipUI', {
bottomBackground: theme.palette.background.default,
bottomTheme: 'dark'
})
}, [selectedCount, webviewIntent])

return (
<div
data-testid="selectionBar"
Expand Down
Loading