-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
293 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import * as React from 'react'; | ||
|
||
import type { BaseShortcutProps } from '/types/BaseShortcutProps'; | ||
|
||
export const BaseShortcut = (props: BaseShortcutProps) => { | ||
console.debug('BaseShortcut props:', props); | ||
const { | ||
error, | ||
warning, | ||
} = props; | ||
return ( | ||
<div> | ||
<h1>{error ? 'Error' : 'Warning'}</h1> | ||
<p>{error || warning}</p> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
src/main/resources/site/content-types/baseShortcutProcessor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import type { Content } from '@enonic-types/core'; | ||
import type { ContentTypeProcessorFunction } from '/lib/enonic/react4xp/DataFetcher'; | ||
import type { BaseShortcutProps } from '/types/BaseShortcutProps'; | ||
|
||
// import { toStr } from '@enonic/js-utils/value/toStr'; | ||
import { | ||
exists, | ||
get as getContentByKey | ||
} from '/lib/xp/content'; | ||
import { pageUrl } from '/lib/xp/portal'; | ||
|
||
type BaseShortcutContent = Content<{ | ||
parameters: { | ||
name: string; | ||
value: string; | ||
}[]; | ||
target: string; | ||
}, 'base:shortcut'>; | ||
|
||
// declare global { | ||
// interface XpContent { | ||
// 'base:shortcut': BaseShortcutContent; | ||
// } | ||
// } | ||
|
||
export const baseShortcutProcessorWrapper = (dataFetcher): ContentTypeProcessorFunction<BaseShortcutContent> => (params) => { | ||
// log.info('baseShortcutProcessor params:%s', toStr(params)); | ||
const { | ||
content, | ||
component, // CAUTION: Important so it doesn't end up in passAlong. | ||
request, | ||
...passAlong | ||
} = params; | ||
const { type: contentType } = content; | ||
|
||
if ( contentType === 'base:shortcut' ) { | ||
const { data } = content; | ||
const { | ||
parameters = [], | ||
target: targetContentId, | ||
} = data; | ||
const { mode } = request; | ||
// When ok | ||
// In live and preview redirect | ||
// In edit and inline render the target content? | ||
// When not ok | ||
// In live show 404 | ||
// In edit show warning | ||
// In inline and preview show error | ||
if (targetContentId && exists({ key: targetContentId })) { | ||
if (mode === 'live' || mode === 'preview') { | ||
return { | ||
response: { | ||
redirect: `${pageUrl({ id: targetContentId })}${ | ||
parameters.length | ||
? `?${ | ||
parameters.map(({ | ||
name, | ||
value | ||
}) => `${name}=${value}`).join('&') | ||
}` | ||
: '' | ||
}` | ||
} | ||
}; | ||
} else { | ||
const targetContent = getContentByKey({ key: targetContentId }); | ||
const { | ||
component, | ||
response, | ||
} = dataFetcher.process({ | ||
...passAlong, | ||
content: targetContent, | ||
// component, // Gotten from content inside DataFetcher :) | ||
request, | ||
}); | ||
if (response) { | ||
return { | ||
response | ||
}; | ||
} | ||
// TODO Does this work? | ||
return { | ||
props: component['props'] | ||
}; | ||
} | ||
} | ||
|
||
if (mode === 'live') { | ||
return { | ||
response: { | ||
status: 404 | ||
} | ||
}; | ||
} | ||
|
||
if (!targetContentId) { | ||
if (mode === 'edit') { | ||
return { | ||
props: <BaseShortcutProps>{ | ||
warning: `Please select a target content for this shortcut.` | ||
} | ||
}; | ||
} | ||
// mode === 'inline' || mode === 'preview' | ||
return { | ||
props: <BaseShortcutProps>{ | ||
error: `Target content NOT selected for this shortcut!` | ||
} | ||
}; | ||
} else if (!exists({ key: targetContentId })) { | ||
return { | ||
props: <BaseShortcutProps>{ | ||
error: `Shortcut target content NOT found: ${targetContentId}!` | ||
} | ||
}; | ||
} | ||
} // base:shortcut | ||
|
||
const { | ||
data, | ||
} = content; | ||
return { | ||
props: data | ||
}; | ||
}; |
17 changes: 17 additions & 0 deletions
17
src/main/resources/site/content-types/portalSiteProcessor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { Site } from '@enonic-types/lib-content'; | ||
import type { ContentTypeProcessorFunction } from '/lib/enonic/react4xp/DataFetcher'; | ||
// import type { PortalSiteProps } from '/types/PortalSiteProps'; | ||
|
||
// import { toStr } from '@enonic/js-utils/value/toStr'; | ||
|
||
export const portalSiteProcessor: ContentTypeProcessorFunction< | ||
Site<Record<string, unknown>> | ||
> = (params) => { | ||
// log.info('portalSiteProcessor params:%s', toStr(params)); | ||
return { | ||
props: /*<PortalSiteProps>*/{ | ||
title: 'React4XP Starter', | ||
text: 'Welcome to the React4XP starter!', | ||
} | ||
}; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
import { DataFetcher } from '/lib/enonic/react4xp'; | ||
import { portalSiteProps } from '../content-types/portalSiteProps'; | ||
import { defaultPageProps } from '../pages/default/defaultProps'; | ||
import { twoColumnsProps } from '../layouts/twoColumns/twoColumnsProps'; | ||
import { exampleProps } from '../parts/example/exampleProps'; | ||
import { portalSiteProcessor } from '../content-types/portalSiteProcessor'; | ||
import { baseShortcutProcessorWrapper } from '../content-types/baseShortcutProcessor'; | ||
import { defaultPageProcessor } from '../pages/default/defaultPageProcessor'; | ||
import { twoColumnsProcessor } from '../layouts/twoColumns/twoColumnsProcessor'; | ||
import { exampleProcessor } from '../parts/example/exampleProcessor'; | ||
|
||
export const dataFetcher = new DataFetcher(); | ||
// dataFetcher.addUrlPath(/\/fisk\//, { toProps}); | ||
// dataFetcher.addUrlPath(/\/fisk\//, { processor}); | ||
|
||
dataFetcher.addContentType('portal:site', { toProps: portalSiteProps }); | ||
dataFetcher.addPage('com.enonic.app.react4xp:default', { toProps: defaultPageProps }); | ||
dataFetcher.addLayout('com.enonic.app.react4xp:twoColumns', { toProps: twoColumnsProps }); | ||
// dataFetcher.addPart('com.enonic.app.react4xp:example', { toProps: exampleProps }); | ||
// dataFetcher.addContentType('base:folder', { processor: portalSiteProps }); | ||
dataFetcher.addContentType('base:shortcut', { processor: baseShortcutProcessorWrapper(dataFetcher) }); | ||
// TODO dataFetcher.addContentType('portal:template-folder') | ||
dataFetcher.addContentType('portal:site', { processor: portalSiteProcessor }); | ||
dataFetcher.addPage('com.enonic.app.react4xp:default', { processor: defaultPageProcessor }); | ||
dataFetcher.addLayout('com.enonic.app.react4xp:twoColumns', { processor: twoColumnsProcessor }); | ||
dataFetcher.addPart('com.enonic.app.react4xp:example', { processor: exampleProcessor }); |
26 changes: 26 additions & 0 deletions
26
src/main/resources/site/layouts/twoColumns/twoColumnsProcessor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type { LayoutComponentProcessorFunction } from '/lib/enonic/react4xp/DataFetcher'; | ||
|
||
export const twoColumnsProcessor: LayoutComponentProcessorFunction = ({ | ||
component, | ||
}) => { | ||
const {regions} = component; | ||
// const {mode} = request; | ||
// log.info('mode:%s', mode); | ||
if (!regions.left) { | ||
regions.left = { | ||
components: [], | ||
name: 'left', | ||
}; | ||
} | ||
if (!regions.right) { | ||
regions.right = { | ||
components: [], | ||
name: 'right', | ||
}; | ||
} | ||
return { | ||
props: { | ||
regions | ||
} | ||
}; | ||
} |
20 changes: 0 additions & 20 deletions
20
src/main/resources/site/layouts/twoColumns/twoColumnsProps.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.