Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
soofstad committed Jun 19, 2024
1 parent f01c324 commit 8bc0f66
Show file tree
Hide file tree
Showing 34 changed files with 230 additions and 82 deletions.
4 changes: 2 additions & 2 deletions example/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ services:
ENVIRONMENT: ${ENVIRONMENT:-local}
RESET_DATA_SOURCE: "off"
SECRET_KEY: sg9aeUM5i1JO4gNN8fQadokJa3_gXQMLBjSGGYcfscs= # Don't reuse this in production...
# volumes:
# - ../../data-modelling-storage-service/src:/code/src
volumes:
- ../../data-modelling-storage-service/src:/code/src
ports:
- '5000:5000'
depends_on:
Expand Down
8 changes: 7 additions & 1 deletion example/src/ViewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ function ViewPage() {
)
}

return <EntityView idReference={idReference} type={document.type} />
return (
<EntityView
idReference={idReference}
type={document.type}
entity={document}
/>
)
}

export default ViewPage
5 changes: 2 additions & 3 deletions example/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import '@development-framework/dm-core-plugins/dist/main.css'
import React from 'react'
import 'react-toastify/dist/ReactToastify.min.css'
import './main.css'

Expand All @@ -26,13 +25,13 @@ const authConfig = {
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement)

root.render(
<React.StrictMode>
<div>
{authEnabled ? (
<AuthProvider authConfig={authConfig}>
<App />
</AuthProvider>
) : (
<App />
)}
</React.StrictMode>
</div>
)
6 changes: 4 additions & 2 deletions example/src/plugins/marmo-ui/containers/views/SignalPlot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ const ESSPlotPlugin = (props: { document: TGenericObject }) => {
}

const SignalPlot_Component = (props: IUIPlugin) => {
const { idReference } = props
const { idReference, entity } = props
const { document, isLoading, error } = useDocument<TGenericObject>(
idReference,
1
1,
true,
entity
)

if (isLoading) return <Loading />
Expand Down
4 changes: 3 additions & 1 deletion packages/dm-core-plugins/src/form/FormPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import { Form } from './components/Form'
export const FormPlugin = (props: IUIPlugin) => {
const { document, isLoading, updateDocument, error } = useDocument<any>(
props.idReference,
0
0,
true,
props.entity
)

// react-hook-form is unable to rerender when the document is updated.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
TInlineRecipeViewConfig,
TReferenceViewConfig,
TValidEntity,
TViewConfig,
} from '@development-framework/dm-core'
import { external_link } from '@equinor/eds-icons'
Expand All @@ -11,19 +12,22 @@ export const OpenObjectButton = ({
viewId,
viewConfig,
idReference,
entity,
}: {
viewId: string
viewConfig: TViewConfig | TReferenceViewConfig | TInlineRecipeViewConfig
idReference?: string
entity?: TValidEntity
}) => {
const { onOpen } = useRegistryContext()
console.log(entity)

return (
<TooltipButton
title='Open in tab'
compact
button-variant='ghost_icon'
button-onClick={() => onOpen?.(viewId, viewConfig, idReference)}
button-onClick={() => onOpen?.(viewId, viewConfig, entity, idReference)}
icon={external_link}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const ArrayComplexTemplate = (props: TArrayTemplate) => {
onOpen?.(
namePath,
getOpenViewConfig(uiAttribute, namePath),
getValues(namePath),
idReference
)
}
Expand All @@ -56,6 +57,7 @@ export const ArrayComplexTemplate = (props: TArrayTemplate) => {
<OpenObjectButton
viewId={namePath}
viewConfig={getOpenViewConfig(uiAttribute, namePath)}
entity={getValues(namePath)}
/>
)}
{attribute.optional &&
Expand Down Expand Up @@ -88,6 +90,7 @@ export const ArrayComplexTemplate = (props: TArrayTemplate) => {
idReference={`${idReference}.${namePath}`}
onOpen={onOpen}
viewConfig={getExpandViewConfig(uiAttribute)}
entity={getValues(namePath)}
/>
</ComplexAttributeTemplate.Content>
</ComplexAttributeTemplate>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const ObjectModelContainedTemplate = (
onOpen?.(
namePath,
getOpenViewConfig(uiAttribute, namePath),
value,
idReference
)
}
Expand All @@ -61,6 +62,7 @@ export const ObjectModelContainedTemplate = (
viewId={namePath}
idReference={idReference}
viewConfig={getOpenViewConfig(uiAttribute, namePath)}
entity={value}
/>
)}
{attribute.optional &&
Expand Down Expand Up @@ -103,6 +105,7 @@ export const ObjectModelContainedTemplate = (
idReference={`${idReference}.${attribute.name}`}
onOpen={onOpen}
viewConfig={getExpandViewConfig(uiAttribute)}
entity={value}
onChange={(data: Record<string, unknown>) =>
setValue(
namePath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const ObjectModelUncontainedTemplate = (
objectIsNotEmpty={referenceExists}
setIsExpanded={setIsExpanded}
onOpen={() =>
onOpen?.(namePath, getOpenViewConfig(uiAttribute), address)
onOpen?.(namePath, getOpenViewConfig(uiAttribute), value, address)
}
icon={link}
uiAttribute={uiAttribute}
Expand Down Expand Up @@ -98,6 +98,7 @@ export const ObjectModelUncontainedTemplate = (
idReference={address ?? ''}
onOpen={onOpen}
viewConfig={getExpandViewConfig(uiAttribute)}
entity={value}
/>
</ComplexAttributeTemplate.Content>
</ComplexAttributeTemplate>
Expand Down
15 changes: 12 additions & 3 deletions packages/dm-core-plugins/src/grid/GridElement.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ViewCreator } from '@development-framework/dm-core'
import { TValidEntity, ViewCreator } from '@development-framework/dm-core'
import { Typography } from '@equinor/eds-core-react'
import React from 'react'
import styled from 'styled-components'
Expand Down Expand Up @@ -32,11 +32,19 @@ type TGridItemProps = {
showItemBorders: boolean
onSubmit?: (data: any) => void
onChange?: (data: any) => void
entity?: TValidEntity
}

export const GridElement = (props: TGridItemProps): React.ReactElement => {
const { idReference, item, itemBorder, showItemBorders, onSubmit, onChange } =
props
const {
idReference,
item,
itemBorder,
showItemBorders,
onSubmit,
onChange,
entity,
} = props

return (
<Element
Expand All @@ -49,6 +57,7 @@ export const GridElement = (props: TGridItemProps): React.ReactElement => {
{item?.title && <Typography variant='h4'>{item.title}</Typography>}
<div className='flex-layout-container'>
<ViewCreator
entity={entity}
idReference={idReference}
viewConfig={item.viewConfig}
onSubmit={onSubmit}
Expand Down
4 changes: 4 additions & 0 deletions packages/dm-core-plugins/src/grid/GridItems.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { TValidEntity } from '@development-framework/dm-core'
import { GridElement } from './GridElement'
import { TGridItem, TItemBorder } from './types'

Expand All @@ -9,6 +10,7 @@ type GridItemsProps = {
showItemBorders: boolean
onSubmit?: (data: any) => void
onChange?: (data: any) => void
entity?: TValidEntity
}

export const GridItems = (props: GridItemsProps) => {
Expand All @@ -20,10 +22,12 @@ export const GridItems = (props: GridItemsProps) => {
showItemBorders,
onChange,
onSubmit,
entity,
} = props
const elements = items.map((item: TGridItem, index) => {
return (
<GridElement
entity={entity}
key={`${idReference}-${index}`}
idReference={idReference}
item={item}
Expand Down
3 changes: 2 additions & 1 deletion packages/dm-core-plugins/src/grid/GridPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const defaultConfig: TGridPluginConfig = {
export const GridPlugin = (
props: IUIPlugin & { config: TGridPluginConfig }
): React.ReactElement => {
const { config, idReference, type, onSubmit, onChange } = props
const { config, idReference, type, onSubmit, onChange, entity } = props

const internalConfig: TGridPluginConfig = {
...defaultConfig,
Expand All @@ -54,6 +54,7 @@ export const GridPlugin = (
return (
<Grid className='dm-parent-plugin' {...internalConfig.size}>
<GridItems
entity={entity}
idReference={idReference}
items={internalConfig.items}
itemBorder={internalConfig.itemBorder}
Expand Down
15 changes: 13 additions & 2 deletions packages/dm-core-plugins/src/header/HeaderPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,24 @@ type TRecipeConfigAndPlugin = {
*/

export default (props: IUIPlugin): React.ReactElement => {
const { idReference, config: passedConfig, type } = props
const {
idReference,
config: passedConfig,
type,
entity: passedEntity,
} = props
const config: THeaderPluginConfig & { adminRole: string } = {
...defaultHeaderPluginConfig,
...passedConfig,
}
const [isMenuOpen, setIsMenuOpen] = useState<boolean>(false)
const [anchorEl, setAnchorEl] = useState<HTMLButtonElement | null>(null)
const { document: entity, isLoading } = useDocument<TApplication>(idReference)
const { document: entity, isLoading } = useDocument<TApplication>(
idReference,
0,
true,
passedEntity
)
const { uiRecipes, isLoading: isBlueprintLoading } = useBlueprint(type)
const { roles, role, dmssAPI, name } = useApplication()
const [aboutOpen, setAboutOpen] = useState(false)
Expand Down Expand Up @@ -216,6 +226,7 @@ export default (props: IUIPlugin): React.ReactElement => {
/>
<div className='flex-layout-container'>
<UIPlugin
entity={entity}
key={idReference + selectedRecipe.name}
idReference={idReference}
type={entity.type}
Expand Down
7 changes: 2 additions & 5 deletions packages/dm-core-plugins/src/job/JobCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ interface TJobPluginConfig {
}

export const JobCreate = (props: IUIPlugin & { config: TJobPluginConfig }) => {
const {
config,
idReference,
}: { config: TJobPluginConfig; idReference: string } = props
const { config, idReference, entity } = props
const { dmssAPI } = useApplication()
const { tokenData } = useContext(AuthContext)
const username = tokenData?.preferred_username ?? 'unknown user'
Expand All @@ -85,7 +82,7 @@ export const JobCreate = (props: IUIPlugin & { config: TJobPluginConfig }) => {

const { document: jobDocument, updateDocument } = useDocument<
TJob | TRecurringJob
>(jobTargetAddress, 0, false)
>(jobTargetAddress, 0, false, entity)

const {
start,
Expand Down
9 changes: 7 additions & 2 deletions packages/dm-core-plugins/src/list/ListPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const defaultConfig: TListConfig = {
}

export const ListPlugin = (props: IUIPlugin & { config?: TListConfig }) => {
const { idReference, config, type, onOpen } = props
const { idReference, config, type, onOpen, entity } = props
const internalConfig: TListConfig = {
...defaultConfig,
...config,
Expand All @@ -96,7 +96,11 @@ export const ListPlugin = (props: IUIPlugin & { config?: TListConfig }) => {
moveItem,
reloadData,
updateItem,
} = useList<TGenericObject>(idReference, internalConfig.resolveReferences)
} = useList<TGenericObject>(
idReference,
internalConfig.resolveReferences,
entity
)

const {
currentItems,
Expand Down Expand Up @@ -149,6 +153,7 @@ export const ListPlugin = (props: IUIPlugin & { config?: TListConfig }) => {
onOpen(
item.key,
view,
item.data,
item.idReference,
false,
config.saveExpanded
Expand Down
10 changes: 5 additions & 5 deletions packages/dm-core-plugins/src/table/Table/Table.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
TGenericObject,
TItem,
TValidEntity,
usePagination,
} from '@development-framework/dm-core'
import {
Expand Down Expand Up @@ -54,7 +54,7 @@ export function Table(props: TableProps) {
const [tableVariant, setTableVariant] = useState<TableVariantNameEnum>(
config.variant[0].name
)
const [sortedItems, setSortedItems] = useState<TItem<TGenericObject>[]>([])
const [sortedItems, setSortedItems] = useState<TItem<TValidEntity>[]>([])
const [sortColumn, setSortColumn] = useState<string | undefined>(undefined)
const [sortDirection, setSortDirection] =
useState<TTableSortDirection>('ascending')
Expand All @@ -79,7 +79,7 @@ export function Table(props: TableProps) {
}

const handleRemoveItem = async (
itemToDelete: TItem<TGenericObject>,
itemToDelete: TItem<TValidEntity>,
saveOnRemove?: boolean | undefined
) => {
setDeletingRow(itemToDelete.key)
Expand Down Expand Up @@ -130,7 +130,7 @@ export function Table(props: TableProps) {
setPage(0)
}

function reorderItems(reorderedItems: TItem<TGenericObject>[]) {
function reorderItems(reorderedItems: TItem<TValidEntity>[]) {
setItems(reorderedItems)
setDirtyState(true)
}
Expand Down Expand Up @@ -196,7 +196,7 @@ export function Table(props: TableProps) {
functionalityConfig={functionalityConfig}
idReference={props.idReference}
index={items.findIndex(
(it: TItem<TGenericObject>) => it.key === item.key
(it: TItem<TValidEntity>) => it.key === item.key
)}
item={item}
items={items}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function TableCell(props: TableCellProps) {

// TODO: Add more logic for creating better default values.
// If pointing to complex optional object, it has to be created.
const value = resolvePath(item.data || {}, column?.data, '')
const value = resolvePath(item.data || { type: 'unknown' }, column?.data, '')

if (typeof value === 'object') {
throw new Error(
Expand Down
Loading

0 comments on commit 8bc0f66

Please sign in to comment.