Skip to content

Commit

Permalink
[Fix] sturcture gallery update
Browse files Browse the repository at this point in the history
  • Loading branch information
poon-bmk committed Apr 23, 2020
1 parent 8ec048c commit 105a0eb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
45 changes: 38 additions & 7 deletions app/pages/embedded-widget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
TextField,
Theme,
Typography,
darken,
} from '@material-ui/core'
import HomeIcon from '@material-ui/icons/Home'
import NavigateBeforeIcon from '@material-ui/icons/NavigateBefore'
Expand Down Expand Up @@ -130,10 +131,16 @@ const useStyles = makeStyles((theme: Theme) =>
paddingLeft: theme.spacing(4),
},
parameterLayout: {
height: '100%',
// height: '100%',
overflow: 'auto',
height: '75vh',
padding: theme.spacing(2),
},
root: {},
structureJsonContainer: {
backgroundColor: darken(theme.palette.background.paper, 0.06),
width: '100%',
},
tabContainer: {
backgroundColor: theme.palette.background.paper || '',
},
Expand Down Expand Up @@ -332,6 +339,21 @@ const WidgetManager: IStatelessPage<{
type: 'IFRAME_QUERY_PARAMS_CHANGE',
})
}
React.useEffect(() => {
const iframeObject = _.get(iframeRef, 'current')
? (_.get(iframeRef, 'current') as HTMLIFrameElement)
: null
if (iframeObject && iframeObject.contentWindow) {
const newStructureData = structure
iframeObject.contentWindow.postMessage(
{
action: 'setStructure',
data: newStructureData,
},
'*',
)
}
}, [structure])

const handleStructureChange = (name: string, type: string, value: any) => {
dispatch({
Expand Down Expand Up @@ -523,12 +545,7 @@ const WidgetManager: IStatelessPage<{
onParameterChange={handleQueryParamChange}
type='queryParams'
/>
<WidgetManagerStructure
structures={structure}
selectedWidget={selectedWidget}
onParameterChange={handleStructureChange}
type='structure'
/>

<Grid container justify='flex-end'>
<Fab
variant='extended'
Expand All @@ -544,6 +561,20 @@ const WidgetManager: IStatelessPage<{
</Fab>
</Grid>
</form>
<WidgetManagerStructure
structures={structure}
selectedWidget={selectedWidget}
onParameterChange={handleStructureChange}
type='structure'
/>
<Grid
container
className={classes.structureJsonContainer}
>
<Grid item xs='auto' style={{ width: '100%' }}>
<pre>{JSON.stringify(structure, null, 2)}</pre>
</Grid>
</Grid>
</Paper>
</Grid>
)}
Expand Down
8 changes: 4 additions & 4 deletions app/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import environment from '@environment'
import * as _ from 'lodash'
import qs from 'qs'
import { MessageListenerService } from '@services/MessageListenerService'

import defaultsDeep from 'lodash/defaultsDeep'
interface IPostMessage {
message?: string
name?: string
Expand All @@ -16,7 +16,7 @@ interface IPostMessage {
export function toNaturalName(s: string) {
return _.chain(s)
.words()
.map(v => _.capitalize(v))
.map((v) => _.capitalize(v))
.join(' ')
.value()
}
Expand Down Expand Up @@ -84,9 +84,9 @@ export const validQueryParams = (
prefixError = 'Need the',
) => {
return _.chain(neededParams)
.filter(value => !_.get(queryParams, value))
.filter((value) => !_.get(queryParams, value))
.map((v, k) => {
return `${prefixError} ${v}`
})
.value()
}
}

0 comments on commit 105a0eb

Please sign in to comment.