Skip to content

Commit

Permalink
feat(publish): copy and link mode
Browse files Browse the repository at this point in the history
  • Loading branch information
soofstad committed Mar 1, 2024
1 parent ad0ef8c commit 8d8de10
Show file tree
Hide file tree
Showing 15 changed files with 281 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "Archive",
"type": "CORE:Blueprint",
"extends": ["CORE:NamedEntity"],
"attributes": [
{
"name": "publishedReports",
"type": "dmss://system/SIMOS/BlueprintAttribute",
"attributeType": "PLUGINS:dm-core-plugins/common/Meta",
"dimensions": "*"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "PublishWrapper",
"type": "CORE:Blueprint",
"extends": ["CORE:Entity"],
"attributes": [
{
"name": "report",
"type": "dmss://system/SIMOS/BlueprintAttribute",
"attributeType": "./Report"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Report",
"type": "CORE:Blueprint",
"extends": ["CORE:NamedEntity"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"_id": "45dcc280-8350-4bef-bf75-ff09db23732c",
"type": "dmss://DemoDataSource/plugins/publish/Archive",
"name": "archive",
"publishedReports": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"type": "./PublishWrapper",
"name": "publishWrapper",
"report": {
"type": "./Report",
"name": "Minority",
"description": "This is a report that might get published"
}
}
9 changes: 9 additions & 0 deletions example/app/data/DemoDataSource/recipes/meta.recipe.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"type": "CORE:RecipeLink",
"_blueprintPath_": "PLUGINS:dm-core-plugins/common/Meta",
"initialUiRecipe": {
"name": "Meta",
"plugin": "@development-framework/dm-core-plugins/meta",
"type": "CORE:UiRecipe"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"type": "CORE:RecipeLink",
"_blueprintPath_": "/plugins/publish/PublishWrapper",
"initialUiRecipe": {
"name": "SingleView",
"type": "CORE:UiRecipe",
"plugin": "@development-framework/dm-core-plugins/single_view",
"config": {
"type": "CORE:InlineRecipeViewConfig",
"scope": "report",
"recipe": {
"name": "Publish",
"plugin": "@development-framework/dm-core-plugins/publish",
"type": "CORE:UiRecipe",
"config": {
"type": "PLUGINS:dm-core-plugins/publish/PublishConfig",
"destination": "dmss://DemoDataSource/plugins/publish",
"linkDestination": "dmss://DemoDataSource/plugins/publish/archive.publishedReports",
"mode": "copy&link",
"description": "Create a copy of the report, and a link in the list of official reports."
}
}
}
}
}
27 changes: 24 additions & 3 deletions packages/dm-core-plugins/blueprints/publish/PublishConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,41 @@
"attributeType": "string"
},
{
"name": "publishDestination",
"name": "destination",
"type": "dmss://system/SIMOS/BlueprintAttribute",
"attributeType": "string",
"description": "A reference/Id to where the published copy should be added."
},
{
"name": "publishWrapper",
"name": "linkDestination",
"type": "dmss://system/SIMOS/BlueprintAttribute",
"attributeType": "string",
"description": "A reference/Id to where a link to the published document should be added."
},
{
"name": "wrapper",
"type": "dmss://system/SIMOS/BlueprintAttribute",
"description": "A blueprint for which an entity of will serve as a wrapper for the published document",
"attributeType": "string",
"optional": true
},
{
"name": "publishWrapperAttribute",
"name": "description",
"type": "dmss://system/SIMOS/BlueprintAttribute",
"description": "A text to inform the user what the publish action does",
"attributeType": "string",
"optional": true
},
{
"name": "mode",
"type": "dmss://system/SIMOS/BlueprintAttribute",
"description": "Which mode the publish plugin should operate in. One of 'copy' | 'link'| 'copy&link'",
"attributeType": "string",
"default": "copy&link",
"optional": true
},
{
"name": "wrapperAttribute",
"type": "dmss://system/SIMOS/BlueprintAttribute",
"description": "Name of attribute in the 'publishWrapper'-blueprint of which the document will be placed.",
"attributeType": "string",
Expand Down
28 changes: 17 additions & 11 deletions packages/dm-core-plugins/src/meta/MetaPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { DateTime } from 'luxon'
export const MetaPlugin = (props: IUIPlugin) => {
const { document, isLoading, error } = useDocument<TGenericObject>(
props.idReference,
0
1
)

if (isLoading) return <Loading />
Expand All @@ -23,11 +23,6 @@ export const MetaPlugin = (props: IUIPlugin) => {

const meta: TMeta = document._meta_

if (document.type !== 'dmss://system/Plugins/dm-core-plugins/common/Meta')
throw new Error(
'The meta plugin only supports entities of type "Meta" at this stage'
)

return (
<>
<Table className={'w-full'}>
Expand All @@ -37,6 +32,7 @@ export const MetaPlugin = (props: IUIPlugin) => {
<Table.Cell>Created time</Table.Cell>
<Table.Cell>Last modified by</Table.Cell>
<Table.Cell>Last modified time</Table.Cell>
<Table.Cell>Note</Table.Cell>
</Table.Row>
</Table.Head>
<Table.Body>
Expand Down Expand Up @@ -73,16 +69,26 @@ export const MetaPlugin = (props: IUIPlugin) => {
)
: '-'}
</Table.Cell>
<Table.Cell>{meta?.versionNote}</Table.Cell>
</Table.Row>
</Table.Body>
</Table>
{/*This empty div wrapper is kind of a hack to avoid EntityView take the same height as the entire plugin*/}
<div>
<EntityView
{...props}
type={document.content.type}
idReference={`${props.idReference}.content`}
/>
{document.type ===
'dmss://system/Plugins/dm-core-plugins/common/Meta' ? (
<EntityView
{...props}
type={document.content.type}
idReference={`${props.idReference}.content`}
/>
) : (
<EntityView
{...props}
type={document.type}
idReference={props.idReference}
/>
)}
</div>
</>
)
Expand Down
28 changes: 14 additions & 14 deletions packages/dm-core-plugins/src/publish/PublishPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import { useState } from 'react'
export const PublishPlugin = (
props: IUIPlugin & {
config: {
publishDestination: string
publishWrapper?: string
publishWrapperAttribute?: string
destination: string
linkDestination?: string
description?: string
wrapper?: string
wrapperAttribute?: string
mode?: 'copy' | 'link' | 'copy&link'
}
}
) => {
const { idReference } = props
const [showPublishDialog, setShowPublishDialog] = useState<boolean>(false)

return (
Expand All @@ -31,18 +33,16 @@ export const PublishPlugin = (
<Icon data={approve} />
</Button>
<CopyLinkDialog
title={'Publish report?'}
title={'Publish report'}
description={props.config.description}
buttonText={'Publish'}
destination={props.config.publishDestination}
mode={'copy'}
// Defaults to using a "Meta"-entity as a wrapper. Can be overridden with config
wrapper={
props.config.publishWrapper ||
'dmss://system/Plugins/dm-core-plugins/common/Meta'
}
wrapperAttribute={props.config.publishWrapperAttribute || 'content'}
destination={props.config.destination}
linkTarget={props.config.linkDestination}
mode={props.config.mode || 'copy&link'}
wrapper={props.config.wrapper}
wrapperAttribute={props.config.wrapperAttribute || 'content'}
hideProvidedFields={true}
idReference={idReference}
idReference={props.idReference}
open={showPublishDialog}
setOpen={setShowPublishDialog}
/>
Expand Down
Loading

0 comments on commit 8d8de10

Please sign in to comment.