Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
fetsorn committed May 16, 2022
2 parents 48aaee3 + ba1e366 commit f823c18
Show file tree
Hide file tree
Showing 20 changed files with 860 additions and 60 deletions.
12 changes: 3 additions & 9 deletions frontend/craco.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,13 @@ module.exports = {
"@pages": path.resolve(__dirname, "./src/pages"),
"@workers": path.resolve(__dirname, "./src/workers"),
},
resolve: {
fallback: {
buffer: require.resolve('buffer/'),
util: require.resolve("util/"),
},
},
plugins: {
add: [
new CopyPlugin({
patterns: [
{ from: "**/*.wasm", to: "static/js/[name][ext]", context: "node_modules/@fetsorn/" },
{ from: "**/*.wasm", to: "static/js/[name][ext]", context: "node_modules/@ffmpeg/" },
{ from: "**/*.wasm", to: "static/js/[name][ext]", context: "node_modules/@hpcc-js/" },
{ context: "node_modules/@fetsorn/", from: "**/*.wasm", to: "static/js/[name][ext]" },
{ context: "node_modules/@ffmpeg/", from: "**/*.wasm", to: "static/js/[name][ext]" },
{ context: "node_modules/@hpcc-js/", from: "**/*.wasm", to: "static/js/[name][ext]" },
],
}),
],
Expand Down
13 changes: 10 additions & 3 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@
"private": true,
"dependencies": {
"@craco/craco": "^6.4.3",
"@fetsorn/csvs-js": "0.3.6",
"@fetsorn/csvs-js": "0.4.6",
"@fetsorn/ged2dot": "^0.1.3",
"@fetsorn/ppt": "^0.0.1",
"@ffmpeg/core": "^0.10.0",
"@ffmpeg/ffmpeg": "^0.10.1",
"@hpcc-js/wasm": "^1.14.1",
"@isomorphic-git/lightning-fs": "^4.4.1",
"buffer": "^6.0.3",
"cfb": "0.10.0",
"classnames": "^2.3.1",
"copy-webpack-plugin": "^10.2.4",
"crypto-browserify": "^3.12.0",
"docx4js": "^3.2.20",
"https-browserify": "^1.0.0",
"isomorphic-git": "^1.10.4",
"jest": "^27.5.1",
Expand All @@ -22,18 +25,22 @@
"normalize.css": "^8.0.1",
"os-browserify": "^0.3.0",
"path-browserify": "^1.0.1",
"process": "^0.11.10",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-draggable": "^4.4.4",
"react-router-dom": "^6.2.1",
"react-scripts": "^5.0.0-next.47",
"rtf.js": "^3.0.8",
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"util": "^0.12.4"
"util": "^0.12.4",
"word-extractor": "^1.0.4",
"zlib-browserify": "^0.0.3"
},
"scripts": {
"start": "craco start",
"build": "craco build",
"build": "GENERATE_SOURCEMAP=false craco --max_old_space_size=1024 build",
"test": "craco test"
},
"eslintConfig": {
Expand Down
9 changes: 9 additions & 0 deletions frontend/plugins/craco-compatibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ const overrideWebpackConfig = ({ context, webpackConfig, pluginOptions }) => {
Buffer: ['buffer', 'Buffer'],
}),
)
webpackConfig.plugins.push(
new webpack.ProvidePlugin({
process: 'process/browser',
}),
)
// Add polyfill libraries
webpackConfig.resolve.fallback = {
// For WASM
Expand All @@ -23,6 +28,10 @@ const overrideWebpackConfig = ({ context, webpackConfig, pluginOptions }) => {
https: require.resolve('https-browserify'),
path: require.resolve('path-browserify'),
fs: false,
buffer: require.resolve("buffer/"),
util: require.resolve("util/"),
zlib: require.resolve('zlib-browserify'),
// process: require.resolve('process/browser'),
}
// Fix unrecognized change / caching problem
webpackConfig.cache.buildDependencies.config.push(
Expand Down
31 changes: 31 additions & 0 deletions frontend/src/components/DropdownMenu/DropdownMenu.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { useState } from 'react'
import cn from 'classnames'
import styles from './DropdownMenu.module.css'

const DropdownMenu = ({ label, menuItems }) => {
const [opened, setOpened] = useState(false)

const toggle = () => {
setOpened(!opened)
}

const handleClick = (callback) => {
return () => {
setOpened(false)
callback()
}
}

return (
<div class={styles.dropdown}>
<button class={cn(styles.dropdownButton, { [styles.opened]: opened })} onClick={toggle}>{label}</button>
<div class={cn(styles.menu, { [styles.opened]: opened })}>
{menuItems.map((item) => (
<button class={styles.menuItem} onClick={handleClick(item.onClick)}>{item.label}</button>
))}
</div>
</div>
)
}

export default DropdownMenu
139 changes: 139 additions & 0 deletions frontend/src/components/DropdownMenu/DropdownMenu.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/* dropdown */

.dropdown {
display: inline-block;

position: relative;
}

/* dropdownButton */

.dropdownButton {
border: none;
border-radius: calc(var(--rem) * 1.5);

padding-top: calc(var(--rem) * 3);
padding-bottom: calc(var(--rem) * 3);
padding-left: calc(var(--rem) * 6);
padding-right: calc(var(--rem) * 6);

background-color: var(--color-button-default);

font-family: var(--title-font);
font-weight: 400;
font-size: calc(var(--rem) * 4);
line-height: calc(var(--rem) * 5.5);
color: var(--color-font-accent);

cursor: pointer;
}

.dropdownButton:hover {
background-color: var(--color-button-hover);
}

.dropdownButton:active {
background-color: var(--color-button-active);
}

.dropdownButton:focus {
outline: var(--rem) solid var(--color-button-focus);
}

.dropdownButton::after {
content: '';
display: inline-block;

width: 0;
height: 0;

margin-left: calc(var(--rem) * 2);

border-left: calc(var(--rem) * 1.5) solid transparent;
border-right: calc(var(--rem) * 1.5) solid transparent;
border-top: calc(var(--rem) * 1.5) solid currentColor;
border-bottom: none;

vertical-align: middle;
}

.dropdownButton.opened::after {
content: '';
display: inline-block;

width: 0;
height: 0;

margin-left: calc(var(--rem) * 2);

border-left: calc(var(--rem) * 1.5) solid transparent;
border-right: calc(var(--rem) * 1.5) solid transparent;
border-top: none;
border-bottom: calc(var(--rem) * 1.5) solid currentColor;

vertical-align: middle;
}

/* menu */

.menu {
position: absolute;
top: calc(var(--rem) * 14);
z-index: 10;

display: none;
box-sizing: border-box;

border-radius: calc(var(--rem) * 1.5);
padding: var(--rem);
min-width: 100%;

grid-auto-rows: max-content;
gap: var(--rem);

box-shadow: var(--rem) var(--rem) calc(var(--rem) * 4) var(--color-shadow);

background-color: var(--color-background);
}

.menu.opened {
display: grid;
}

/* menuItem */

.menuItem {
border: none;
border-radius: calc(var(--rem) * 1.5);

padding-top: calc(var(--rem) * 1);
padding-bottom: calc(var(--rem) * 1);
padding-left: calc(var(--rem) * 3);
padding-right: calc(var(--rem) * 3);

background-color: transparent;

font-family: var(--title-font);
font-weight: 400;
font-size: calc(var(--rem) * 4);
line-height: calc(var(--rem) * 5.5);
color: var(--color-font-base);

cursor: pointer;
}

.menuItem:hover {
background-color: var(--color-button-hover);
color: var(--color-font-accent);
}

.menuItem:active {
background-color: var(--color-button-active);
color: var(--color-font-accent);
}

.menuItem:focus {
background-color: var(--color-button-hover);
color: var(--color-font-accent);
outline: none;
}
1 change: 1 addition & 0 deletions frontend/src/components/DropdownMenu/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './DropdownMenu'
124 changes: 124 additions & 0 deletions frontend/src/components/Panel/Panel.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import { useEffect, useState, useMemo } from 'react'
import { useNavigate } from "react-router-dom"
import { Button, DropdownMenu } from '@components'
import { paramsToObject, objectToParams } from './utils'
import styles from './Panel.module.css'

const Panel = ({ schema: rawSchema, worker, reloadPage }) => {
const [params, setParams] = useState({})
const [options, setOptions] = useState({})
const navigate = useNavigate()

const addField = (prop) => (
() => {
const searchParams = new URLSearchParams(window.location.search)
const value = searchParams.has(prop) ? searchParams.get(prop) : ""

console.log(options)
console.log(addedFields)
setParams({ ...params, [prop]: value })
}
)

const removeField = (prop) => (
() => {
const newParams = { ...params }
delete newParams[prop]
setParams(newParams)
}
)

const onChangeField = (prop) => (
(e) => {
const newParams = {...params}
newParams[prop] = e.target.value
setParams(newParams)
}
)

const search = async () => {
const searchParams = objectToParams(params)

navigate({
pathname: window.location.pathname,
search: "?" + searchParams.toString()
})

await reloadPage()
}

const schema = useMemo(() => (
Object.keys(rawSchema).reduce((acc, key) => (
rawSchema[key]?.hasOwnProperty('parent') // without root of schema
? [...acc, { ...rawSchema[key], name: key }]
: acc
), [])
), [rawSchema])

const notAddedFields = useMemo(() => (
schema.filter((item) => !params?.hasOwnProperty(item.name))
), [schema, params])

const addedFields = useMemo(() => (
Object.keys(params).reduce((acc, key) => (
rawSchema[key]?.hasOwnProperty('parent')
? [ ...acc, { key, value: params[key] }]
: acc
), [])
), [params, rawSchema])

const menuItems = useMemo(() => (
notAddedFields.map((field) => (
{ label: field.name, onClick: addField(field.name) }
))
// eslint-disable-next-line react-hooks/exhaustive-deps
), [notAddedFields])

useEffect(() => (
(async () => {
var _options = {}
for (const param of schema) {
_options[param.name] = await worker.queryOptions(param.name)
}
setOptions(_options)
})()
), [schema])

useEffect(() => {
const searchParams = new URLSearchParams(window.location.search)
setParams(paramsToObject(searchParams))
}, [])

return (
<>
<form className={styles.form}>
{addedFields.map(({ key, value }) => (
<div>
<label>{key}</label>
<span onClick={removeField(key)}> X</span>
<br/>
<input
className={styles.input}
type="text"
list={`${key}_list`}
value={value}
placeholder={key}
onChange={onChangeField(key)}
/>
<datalist id={`${key}_list`}>
{options[key]?.map(option => (
<option value={option}/>
))}
</datalist>
</div>
))}
</form>
<DropdownMenu
label=''
menuItems={menuItems}
/>
<Button type="button" onClick={search}>Search</Button>
</>
)}

export default Panel
Loading

0 comments on commit f823c18

Please sign in to comment.