@ossy/resources 1.12.0 → 1.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +10 -4
- package/src/AudioResource.jsx +4 -2
- package/src/CreateDirectory.jsx +4 -3
- package/src/CreateDocument.jsx +4 -3
- package/src/DocumentEdit.jsx +9 -6
- package/src/DocumentView.jsx +8 -4
- package/src/GenericResourceCard.jsx +4 -2
- package/src/GenericResourceDetail.jsx +9 -4
- package/src/GenericResourceForm.jsx +5 -2
- package/src/ImageResource.jsx +4 -2
- package/src/PDFResource.jsx +4 -2
- package/src/ResourceContentPage.jsx +4 -2
- package/src/ResourceDescription.jsx +4 -3
- package/src/ResourceDetails.jsx +9 -4
- package/src/ResourceDialogMove.jsx +4 -3
- package/src/ResourceFactory.jsx +6 -3
- package/src/ResourceGenericView.jsx +4 -2
- package/src/ResourceList.jsx +4 -2
- package/src/ResourcePanel.jsx +9 -12
- package/src/ResourceTags.jsx +4 -3
- package/src/ResourcesPage.jsx +4 -2
- package/src/UploadResources.jsx +4 -3
- package/src/VideoResource.jsx +4 -2
- package/src/create-page-view.action.js +1 -38
- package/src/create-page-view.task.js +38 -0
- package/src/create.action.js +1 -98
- package/src/create.task.js +100 -0
- package/src/delete.action.js +1 -31
- package/src/delete.task.js +31 -0
- package/src/en.translations.json +5 -5
- package/src/get-page-view-stats.action.js +1 -65
- package/src/get-page-view-stats.task.js +64 -0
- package/src/get.action.js +1 -14
- package/src/get.task.js +14 -0
- package/src/index.js +13 -4
- package/src/list.action.js +1 -19
- package/src/list.task.js +20 -0
- package/src/resource-create.page.jsx +4 -3
- package/src/resource.helpers.js +83 -0
- package/src/resources.action-media.js +18 -0
- package/src/resources.attach-media-urls.js +1 -1
- package/src/resources.events.js +1 -0
- package/src/resources.spec.js +54 -55
- package/src/search.action.js +1 -19
- package/src/search.task.js +20 -0
- package/src/server.js +4 -0
- package/src/sv.translations.json +5 -5
- package/src/update-access.action.js +1 -20
- package/src/update-access.task.js +22 -0
- package/src/update-content.action.js +1 -39
- package/src/update-content.task.js +41 -0
- package/src/update-location.action.js +1 -18
- package/src/update-location.task.js +20 -0
- package/src/update-name.action.js +1 -18
- package/src/update-name.task.js +20 -0
- package/src/upload-named-version.action.js +1 -42
- package/src/upload-named-version.task.js +46 -0
- package/src/item-access.api.js +0 -34
- package/src/item-content.api.js +0 -35
- package/src/item-location.api.js +0 -34
- package/src/item-name.api.js +0 -34
- package/src/item-version.api.js +0 -48
- package/src/item.api.js +0 -58
- package/src/list.api.js +0 -43
- package/src/page-views-stats.api.js +0 -23
- package/src/page-views.api.js +0 -23
- package/src/search.api.js +0 -27
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ossy/resources",
|
|
3
3
|
"description": "Resource domain — aggregate and events for the Ossy resource model",
|
|
4
|
-
"version": "1.12.
|
|
4
|
+
"version": "1.12.1",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./src/index.js",
|
|
8
8
|
"module": "./src/index.js",
|
|
9
9
|
"exports": {
|
|
10
|
-
".": "./src/index.js"
|
|
10
|
+
".": "./src/index.js",
|
|
11
|
+
"./server": "./src/server.js"
|
|
11
12
|
},
|
|
12
13
|
"scripts": {
|
|
13
14
|
"test": "NODE_OPTIONS=--experimental-vm-modules jest --verbose"
|
|
@@ -17,9 +18,14 @@
|
|
|
17
18
|
"ossy": {
|
|
18
19
|
"src": "./src"
|
|
19
20
|
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"@ossy/sdk-react": ">=1.0.0",
|
|
23
|
+
"@ossy/workspaces": ">=1.0.0",
|
|
24
|
+
"react": ">=19.0.0 <20.0.0"
|
|
25
|
+
},
|
|
20
26
|
"devDependencies": {
|
|
21
27
|
"@jest/globals": "^30.2.0",
|
|
22
|
-
"@ossy/platform": "^1.39.
|
|
28
|
+
"@ossy/platform": "^1.39.1",
|
|
23
29
|
"casual": "^1.6.2",
|
|
24
30
|
"jest": "^30.2.0"
|
|
25
31
|
},
|
|
@@ -31,5 +37,5 @@
|
|
|
31
37
|
"/src",
|
|
32
38
|
"README.md"
|
|
33
39
|
],
|
|
34
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "c0ba5d90749690634e4dc2705178ff8d89dd3070"
|
|
35
41
|
}
|
package/src/AudioResource.jsx
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import { metadata as GetResource } from './get.action.js'
|
|
3
|
+
import { useSdk } from '@ossy/sdk-react'
|
|
3
4
|
import { View } from '@ossy/design-system'
|
|
4
5
|
|
|
5
6
|
export const AudioResource = ({
|
|
6
7
|
resourceId,
|
|
7
8
|
onClose: _onClose
|
|
8
9
|
}) => {
|
|
9
|
-
const
|
|
10
|
+
const sdk = useSdk()
|
|
11
|
+
const { data: resource } = sdk.read(GetResource, { id: resourceId }, { enabled: !!resourceId })
|
|
10
12
|
|
|
11
13
|
return (
|
|
12
14
|
<View stack bordered>
|
package/src/CreateDirectory.jsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, { useState, useRef } from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import { createDirectory } from './resource.helpers.js'
|
|
3
|
+
import { useSdk } from '@ossy/sdk-react'
|
|
3
4
|
import {
|
|
4
5
|
Input,
|
|
5
6
|
Title,
|
|
@@ -14,7 +15,7 @@ import { useRouter } from '@ossy/router-react'
|
|
|
14
15
|
export const CreateDirectory = () => {
|
|
15
16
|
const { t } = useLocale()
|
|
16
17
|
const router = useRouter()
|
|
17
|
-
const
|
|
18
|
+
const sdk = useSdk()
|
|
18
19
|
const [directoryName, setDirectoryName] = useInputValue('')
|
|
19
20
|
const [error, setError] = useState()
|
|
20
21
|
const formRef = useRef()
|
|
@@ -34,7 +35,7 @@ export const CreateDirectory = () => {
|
|
|
34
35
|
return
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
formRef.current.reportValidity() && createDirectory({
|
|
38
|
+
formRef.current.reportValidity() && createDirectory(sdk, {
|
|
38
39
|
name: directoryName,
|
|
39
40
|
location: directoryLocation
|
|
40
41
|
})
|
package/src/CreateDocument.jsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, { useState } from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import { createDocument } from './resource.helpers.js'
|
|
3
|
+
import { useSdk } from '@ossy/sdk-react'
|
|
3
4
|
import { Alert, useLocale } from '@ossy/design-system'
|
|
4
5
|
import { useRouter } from '@ossy/router-react'
|
|
5
6
|
import { GenericResourceForm } from './GenericResourceForm.jsx'
|
|
@@ -9,7 +10,7 @@ export const CreateDocument = () => {
|
|
|
9
10
|
const router = useRouter()
|
|
10
11
|
const templateId = router.searchParams.templateId
|
|
11
12
|
const location = router.searchParams.location
|
|
12
|
-
const
|
|
13
|
+
const sdk = useSdk()
|
|
13
14
|
const [error, setError] = useState()
|
|
14
15
|
|
|
15
16
|
const onCancel = () => {
|
|
@@ -18,7 +19,7 @@ export const CreateDocument = () => {
|
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
const onSubmit = ({ name, content, type }) => {
|
|
21
|
-
createDocument({ type, location, name, content })
|
|
22
|
+
createDocument(sdk, { type, location, name, content })
|
|
22
23
|
.then(() => onCancel())
|
|
23
24
|
.catch((err) => setError(err?.message || t('resources.form.createFailed')))
|
|
24
25
|
}
|
package/src/DocumentEdit.jsx
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import { metadata as GetResource } from './get.action.js'
|
|
3
|
+
import { GetWorkspace } from '@ossy/workspaces'
|
|
4
|
+
import { useSdk } from '@ossy/sdk-react'
|
|
3
5
|
import {
|
|
4
6
|
Text,
|
|
5
7
|
View,
|
|
@@ -11,11 +13,12 @@ export const DocumentEdit = ({
|
|
|
11
13
|
resourceId,
|
|
12
14
|
form,
|
|
13
15
|
}) => {
|
|
14
|
-
const
|
|
16
|
+
const sdk = useSdk()
|
|
17
|
+
const { data: resource } = sdk.read(GetResource, { id: resourceId }, { enabled: !!resourceId })
|
|
18
|
+
const { data: workspace } = sdk.read(GetWorkspace)
|
|
19
|
+
const template = workspace?.resourceTemplates?.find(t => t.id === resource?.type)
|
|
15
20
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (template.fields && form.data) {
|
|
21
|
+
if (template?.fields && form.data) {
|
|
19
22
|
return (
|
|
20
23
|
<View style={{ padding: '16px 0' }}>
|
|
21
24
|
<Fields data={form.data} onChange={form.onChange} fields={template.fields} />
|
|
@@ -24,7 +27,7 @@ export const DocumentEdit = ({
|
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
// Loading
|
|
27
|
-
if (template
|
|
30
|
+
if (template?.fields && !form.data) {
|
|
28
31
|
return (
|
|
29
32
|
<DelayedRender>
|
|
30
33
|
<View style={{ padding: '16px 0' }}>
|
package/src/DocumentView.jsx
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import { pipe, keys, map } from 'ramda'
|
|
3
|
-
import {
|
|
3
|
+
import { metadata as GetResource } from './get.action.js'
|
|
4
|
+
import { GetWorkspace } from '@ossy/workspaces'
|
|
5
|
+
import { useSdk } from '@ossy/sdk-react'
|
|
4
6
|
import { Text, View } from '@ossy/design-system'
|
|
5
7
|
|
|
6
8
|
export const DocumentView = ({
|
|
7
9
|
resourceId
|
|
8
10
|
}) => {
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
+
const sdk = useSdk()
|
|
12
|
+
const { data: resource } = sdk.read(GetResource, { id: resourceId }, { enabled: !!resourceId })
|
|
13
|
+
const { data: workspace } = sdk.read(GetWorkspace)
|
|
14
|
+
const template = workspace?.resourceTemplates?.find(t => t.id === resource?.type)
|
|
11
15
|
|
|
12
16
|
return (
|
|
13
17
|
<View style={{ padding: '16px 0' }}>
|
|
14
18
|
<View gap="m">
|
|
15
19
|
{
|
|
16
|
-
!!resource?.content && (template
|
|
20
|
+
!!resource?.content && (template?.fields || [])
|
|
17
21
|
.map(field => ({ name: field.name, value: resource?.content?.[field.name] }))
|
|
18
22
|
.map(field => (
|
|
19
23
|
<View gap="s" key={field.name}>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import { metadata as GetResource } from './get.action.js'
|
|
3
|
+
import { useSdk } from '@ossy/sdk-react'
|
|
3
4
|
import { Slot, resourceSlot, View, Title, Text, DelayedRender } from '@ossy/design-system'
|
|
4
5
|
|
|
5
6
|
function GenericResourceCardFallback ({ resource }) {
|
|
@@ -16,7 +17,8 @@ function GenericResourceCardFallback ({ resource }) {
|
|
|
16
17
|
|
|
17
18
|
/** Card-sized resource preview — `resource:{type}/card`. */
|
|
18
19
|
export function GenericResourceCard ({ resourceId, resource: resourceProp }) {
|
|
19
|
-
const
|
|
20
|
+
const sdk = useSdk()
|
|
21
|
+
const { data: loaded } = sdk.read(GetResource, { id: resourceId }, { enabled: !!resourceId && !resourceProp })
|
|
20
22
|
const resource = resourceProp ?? loaded
|
|
21
23
|
|
|
22
24
|
if (!resource) {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import { metadata as GetResource } from './get.action.js'
|
|
3
|
+
import { GetWorkspace } from '@ossy/workspaces'
|
|
4
|
+
import { useSdk } from '@ossy/sdk-react'
|
|
3
5
|
import {
|
|
4
6
|
Slot,
|
|
5
7
|
resourceSlot,
|
|
@@ -12,8 +14,10 @@ import {
|
|
|
12
14
|
import { ResourceGenericView } from './ResourceGenericView.jsx'
|
|
13
15
|
|
|
14
16
|
function GenericResourceDetailFallback ({ resourceId }) {
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
+
const sdk = useSdk()
|
|
18
|
+
const { data: resource } = sdk.read(GetResource, { id: resourceId }, { enabled: !!resourceId })
|
|
19
|
+
const { data: workspace } = sdk.read(GetWorkspace)
|
|
20
|
+
const template = workspace?.resourceTemplates?.find(t => t.id === resource?.type)
|
|
17
21
|
|
|
18
22
|
if (!resource) {
|
|
19
23
|
return (
|
|
@@ -40,7 +44,8 @@ function GenericResourceDetailFallback ({ resourceId }) {
|
|
|
40
44
|
* registry; falls back to template fields or a minimal placeholder.
|
|
41
45
|
*/
|
|
42
46
|
export function GenericResourceDetail ({ resourceId }) {
|
|
43
|
-
const
|
|
47
|
+
const sdk = useSdk()
|
|
48
|
+
const { data: resource } = sdk.read(GetResource, { id: resourceId }, { enabled: !!resourceId })
|
|
44
49
|
|
|
45
50
|
if (!resource) {
|
|
46
51
|
return (
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, { useState } from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import { GetWorkspace } from '@ossy/workspaces'
|
|
3
|
+
import { useSdk } from '@ossy/sdk-react'
|
|
3
4
|
import {
|
|
4
5
|
Slot,
|
|
5
6
|
resourceSlot,
|
|
@@ -25,7 +26,9 @@ function GenericResourceFormFallback ({
|
|
|
25
26
|
submitLabel,
|
|
26
27
|
}) {
|
|
27
28
|
const { t } = useLocale()
|
|
28
|
-
const
|
|
29
|
+
const sdk = useSdk()
|
|
30
|
+
const { data: workspace } = sdk.read(GetWorkspace)
|
|
31
|
+
const template = workspace?.resourceTemplates?.find(t => t.id === templateId)
|
|
29
32
|
const [name, setName] = useInputValue(initialName)
|
|
30
33
|
const [content, setContent] = useState(initialContent)
|
|
31
34
|
const [error, setError] = useState()
|
package/src/ImageResource.jsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import { metadata as GetResource } from './get.action.js'
|
|
3
|
+
import { useSdk } from '@ossy/sdk-react'
|
|
3
4
|
import {
|
|
4
5
|
Image
|
|
5
6
|
} from '@ossy/design-system'
|
|
@@ -7,7 +8,8 @@ import {
|
|
|
7
8
|
export const ImageResource = ({
|
|
8
9
|
resourceId
|
|
9
10
|
}) => {
|
|
10
|
-
const
|
|
11
|
+
const sdk = useSdk()
|
|
12
|
+
const { data: resource } = sdk.read(GetResource, { id: resourceId }, { enabled: !!resourceId })
|
|
11
13
|
|
|
12
14
|
return (
|
|
13
15
|
<div style={{ display: 'flex', justifyContent: 'center', padding: 'var(--space-m) var(--space-s) var(--space-xl)' }}>
|
package/src/PDFResource.jsx
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import { metadata as GetResource } from './get.action.js'
|
|
3
|
+
import { useSdk } from '@ossy/sdk-react'
|
|
3
4
|
import { View } from '@ossy/design-system'
|
|
4
5
|
|
|
5
6
|
export const PDFResource = ({
|
|
6
7
|
resourceId
|
|
7
8
|
}) => {
|
|
8
|
-
const
|
|
9
|
+
const sdk = useSdk()
|
|
10
|
+
const { data: resource } = sdk.read(GetResource, { id: resourceId }, { enabled: !!resourceId })
|
|
9
11
|
|
|
10
12
|
return (
|
|
11
13
|
<View stack bordered>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import { metadata as GetResource } from './get.action.js'
|
|
3
|
+
import { AsyncStatus, useSdk } from '@ossy/sdk-react'
|
|
3
4
|
import { Switch, View, DelayedRender, Button, Icon, PageSection, Title, Text, Tags, ImageCard } from '@ossy/design-system'
|
|
4
5
|
import { useRouter } from '@ossy/router-react'
|
|
5
6
|
|
|
@@ -7,7 +8,8 @@ import { useRouter } from '@ossy/router-react'
|
|
|
7
8
|
export const ResourceContentPage = (props) => {
|
|
8
9
|
const router = useRouter()
|
|
9
10
|
const resourceId = router.params.resourceId
|
|
10
|
-
const
|
|
11
|
+
const sdk = useSdk()
|
|
12
|
+
const { status, data: resource } = sdk.read(GetResource, { id: resourceId }, { enabled: !!resourceId })
|
|
11
13
|
|
|
12
14
|
return (
|
|
13
15
|
<View {...props} slot="content" style={{ flexDirection: 'column', wrap: 'no-wrap', height: '100%' }}>
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import { metadata as GetResource } from './get.action.js'
|
|
3
|
+
import { useSdk } from '@ossy/sdk-react'
|
|
3
4
|
import { View, Text } from '@ossy/design-system'
|
|
4
5
|
|
|
5
6
|
export const ResourceDescription = ({ resourceId }) => {
|
|
6
|
-
const
|
|
7
|
-
const
|
|
7
|
+
const sdk = useSdk()
|
|
8
|
+
const { data: resource } = sdk.read(GetResource, { id: resourceId }, { enabled: !!resourceId })
|
|
8
9
|
|
|
9
10
|
const description = resource?.content?.description;
|
|
10
11
|
|
package/src/ResourceDetails.jsx
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import React, { useState } from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import { metadata as GetResource } from './get.action.js'
|
|
3
|
+
import { updateResourceAccess } from './resource.helpers.js'
|
|
4
|
+
import { GetWorkspace } from '@ossy/workspaces'
|
|
5
|
+
import { useSdk } from '@ossy/sdk-react'
|
|
3
6
|
import { Text, View } from '@ossy/design-system'
|
|
4
7
|
import { formatBytes } from './utils/format-bytes.js'
|
|
5
8
|
|
|
6
9
|
export const ResourceDetails = ({ resourceId }) => {
|
|
7
|
-
const
|
|
8
|
-
const
|
|
10
|
+
const sdk = useSdk()
|
|
11
|
+
const { data: resource } = sdk.read(GetResource, { id: resourceId }, { enabled: !!resourceId })
|
|
12
|
+
const { data: workspace } = sdk.read(GetWorkspace)
|
|
13
|
+
const template = workspace?.resourceTemplates?.find(t => t.id === resource?.type)
|
|
9
14
|
const [accessBusy, setAccessBusy] = useState(false)
|
|
10
15
|
const [accessError, setAccessError] = useState(null)
|
|
11
16
|
|
|
@@ -24,7 +29,7 @@ export const ResourceDetails = ({ resourceId }) => {
|
|
|
24
29
|
const next = event.target.checked ? 'public' : 'restricted'
|
|
25
30
|
setAccessError(null)
|
|
26
31
|
setAccessBusy(true)
|
|
27
|
-
|
|
32
|
+
updateResourceAccess(sdk, { id: resourceId, access: next })
|
|
28
33
|
.catch(() => setAccessError('Could not update access'))
|
|
29
34
|
.finally(() => setAccessBusy(false))
|
|
30
35
|
}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import { moveResource } from './resource.helpers.js'
|
|
3
|
+
import { useSdk } from '@ossy/sdk-react'
|
|
3
4
|
import { Button, View, Title, Input, Text, useInputValue } from '@ossy/design-system'
|
|
4
5
|
|
|
5
6
|
export const ResourceDialogMove = ({
|
|
6
7
|
resourceId,
|
|
7
8
|
onClose = () => {},
|
|
8
9
|
}) => {
|
|
9
|
-
const
|
|
10
|
+
const sdk = useSdk()
|
|
10
11
|
const [location, setLocation] = useInputValue('')
|
|
11
12
|
|
|
12
13
|
const onMove = () => {
|
|
13
|
-
moveResource(resourceId, location)
|
|
14
|
+
moveResource(sdk, resourceId, location)
|
|
14
15
|
.then(() => {
|
|
15
16
|
onClose()
|
|
16
17
|
})
|
package/src/ResourceFactory.jsx
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import { metadata as GetResource } from './get.action.js'
|
|
3
|
+
import { AsyncStatus, useSdk } from '@ossy/sdk-react'
|
|
4
|
+
import { GetWorkspace } from '@ossy/workspaces'
|
|
3
5
|
import { Guide, Text, DelayedRender } from '@ossy/design-system'
|
|
4
6
|
import { DocumentEdit } from './DocumentEdit.jsx'
|
|
5
7
|
import { ImageResource } from './ImageResource.jsx'
|
|
@@ -15,8 +17,9 @@ export const ResourceFactory = ({
|
|
|
15
17
|
onClose: _onClose,
|
|
16
18
|
form
|
|
17
19
|
}) => {
|
|
18
|
-
const
|
|
19
|
-
const {
|
|
20
|
+
const sdk = useSdk()
|
|
21
|
+
const { data: workspace } = sdk.read(GetWorkspace)
|
|
22
|
+
const { data: resource, status } = sdk.read(GetResource, { id: resourceId }, { enabled: !!resourceId })
|
|
20
23
|
|
|
21
24
|
console.log('ResourceFactory', { resourceId, mode, resource, status })
|
|
22
25
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import { metadata as GetResource } from './get.action.js'
|
|
3
|
+
import { useSdk } from '@ossy/sdk-react'
|
|
3
4
|
import {
|
|
4
5
|
View,
|
|
5
6
|
Icon,
|
|
@@ -8,7 +9,8 @@ import {
|
|
|
8
9
|
export const ResourceGenericView = ({
|
|
9
10
|
resourceId
|
|
10
11
|
}) => {
|
|
11
|
-
const
|
|
12
|
+
const sdk = useSdk()
|
|
13
|
+
const { data: resource } = sdk.read(GetResource, { id: resourceId }, { enabled: !!resourceId })
|
|
12
14
|
|
|
13
15
|
return (
|
|
14
16
|
<View stack bordered>
|
package/src/ResourceList.jsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import React, { useRef, useEffect } from 'react'
|
|
3
|
-
import {
|
|
3
|
+
import { useSdk } from '@ossy/sdk-react'
|
|
4
|
+
import { GetWorkspace } from '@ossy/workspaces'
|
|
4
5
|
import {
|
|
5
6
|
Dropdown,
|
|
6
7
|
DropZone,
|
|
@@ -156,7 +157,8 @@ function ResourceListItem({
|
|
|
156
157
|
}
|
|
157
158
|
|
|
158
159
|
function ResourceIcon({ ...resource }) {
|
|
159
|
-
const
|
|
160
|
+
const sdk = useSdk()
|
|
161
|
+
const { data: workspace } = sdk.read(GetWorkspace)
|
|
160
162
|
|
|
161
163
|
const resourceTemplates = (workspace.resourceTemplates || [])
|
|
162
164
|
.reduce((acc, curr) => ({ ...acc, [curr.id]: curr }), {})
|
package/src/ResourcePanel.jsx
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import React, { useState, useEffect } from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import { metadata as GetResource } from './get.action.js'
|
|
3
|
+
import { removeResource, updateResourceContent, renameResource } from './resource.helpers.js'
|
|
4
|
+
import { useSdk } from '@ossy/sdk-react'
|
|
3
5
|
import {
|
|
4
6
|
Title,
|
|
5
7
|
Overlay,
|
|
@@ -43,18 +45,13 @@ export const ResourcePanel = ({
|
|
|
43
45
|
extraPanels = [],
|
|
44
46
|
}) => {
|
|
45
47
|
const router = useRouter()
|
|
46
|
-
const
|
|
48
|
+
const sdk = useSdk()
|
|
47
49
|
const [overlay, setOverlay] = useState(Overlays.None)
|
|
48
50
|
const [error] = useState()
|
|
49
51
|
const [resourceName, setResourceName] = useInputValue('')
|
|
50
52
|
const [panelViewModes, setPanelViewModes] = useState(DefaultViewModes)
|
|
51
53
|
|
|
52
|
-
const {
|
|
53
|
-
resource,
|
|
54
|
-
removeResource,
|
|
55
|
-
updateResourceContent,
|
|
56
|
-
renameResource
|
|
57
|
-
} = useResource(resourceId)
|
|
54
|
+
const { data: resource = {} } = sdk.read(GetResource, { id: resourceId }, { enabled: !!resourceId })
|
|
58
55
|
|
|
59
56
|
const form = useForm({ defaultData: resource.content })
|
|
60
57
|
|
|
@@ -67,18 +64,18 @@ export const ResourcePanel = ({
|
|
|
67
64
|
|
|
68
65
|
const onRenameResource = () => {
|
|
69
66
|
if (resourceName === resource.name) return
|
|
70
|
-
renameResource(resourceName)
|
|
67
|
+
renameResource(sdk, resourceId, resourceName)
|
|
71
68
|
.then(() => setPanelViewModes(x => ({ ...x, 'panel-header': ViewMode.View })))
|
|
72
69
|
}
|
|
73
70
|
|
|
74
71
|
const onUpdateResource = () => {
|
|
75
|
-
updateResourceContent(form.data)
|
|
72
|
+
updateResourceContent(sdk, resourceId, form.data)
|
|
76
73
|
.then(() => setPanelViewModes(x => ({ ...x, 'panel-resource-content': ViewMode.View })))
|
|
77
74
|
.catch(() => alert('Something went wrong!'))
|
|
78
75
|
}
|
|
79
76
|
|
|
80
77
|
const onRemoveResource = () => {
|
|
81
|
-
removeResource()
|
|
78
|
+
removeResource(sdk, resourceId, resource?.location)
|
|
82
79
|
.then(onCloseResource)
|
|
83
80
|
}
|
|
84
81
|
|
|
@@ -253,7 +250,7 @@ export const ResourcePanel = ({
|
|
|
253
250
|
actions={[
|
|
254
251
|
{ label: 'Cancel', variant: "command", onClick: () => setOverlay(Overlays.None) },
|
|
255
252
|
{ label: 'Remove', variant: 'command-danger', onClick: () => {
|
|
256
|
-
removeResource(resourceId)
|
|
253
|
+
removeResource(sdk, resourceId, resource?.location)
|
|
257
254
|
setOverlay(Overlays.None)
|
|
258
255
|
}}
|
|
259
256
|
]}
|
package/src/ResourceTags.jsx
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import { metadata as GetResource } from './get.action.js'
|
|
3
|
+
import { useSdk } from '@ossy/sdk-react'
|
|
3
4
|
import { View, Tags, Text } from '@ossy/design-system'
|
|
4
5
|
|
|
5
6
|
export const ResourceTags = ({ resourceId }) => {
|
|
6
|
-
const
|
|
7
|
-
const
|
|
7
|
+
const sdk = useSdk()
|
|
8
|
+
const { data: resource } = sdk.read(GetResource, { id: resourceId }, { enabled: !!resourceId })
|
|
8
9
|
|
|
9
10
|
let resourceContentTags = resource?.content?.Tags || []
|
|
10
11
|
|
package/src/ResourcesPage.jsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import { SDK } from '@ossy/sdk'
|
|
3
|
-
import {
|
|
3
|
+
import { metadata as ListResources } from './list.action.js'
|
|
4
|
+
import { AsyncStatus, WorkspaceProvider, useSdk } from '@ossy/sdk-react'
|
|
4
5
|
import { Title, Text, Switch, View, ImageCard, Tags, useLocale } from '@ossy/design-system'
|
|
5
6
|
import { useRouter } from '@ossy/router-react'
|
|
6
7
|
|
|
@@ -18,7 +19,8 @@ const freeResourcesGridStyles = {
|
|
|
18
19
|
export const ResourcesPage= () => {
|
|
19
20
|
const router = useRouter()
|
|
20
21
|
const { t } = useLocale()
|
|
21
|
-
const
|
|
22
|
+
const sdk = useSdk()
|
|
23
|
+
const { status, data: resources = [] } = sdk.read(ListResources, { location: '/publications/images/' })
|
|
22
24
|
const tags = resources.flatMap(resource => resource?.content?.tags || [])
|
|
23
25
|
const tagsCount = tags.reduce((acc, t) => ({ ...acc, [t]: (acc?.[t] ?? 0) + 1 }), {})
|
|
24
26
|
|
package/src/UploadResources.jsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import { uploadFile } from './resource.helpers.js'
|
|
3
|
+
import { useSdk } from '@ossy/sdk-react'
|
|
3
4
|
import { Title, View, Text, useLocale } from '@ossy/design-system'
|
|
4
5
|
import { useRouter } from '@ossy/router-react'
|
|
5
6
|
import { Upload } from './Upload.jsx'
|
|
@@ -7,8 +8,8 @@ import { Upload } from './Upload.jsx'
|
|
|
7
8
|
export const UploadResources = () => {
|
|
8
9
|
const { t } = useLocale()
|
|
9
10
|
const router = useRouter()
|
|
11
|
+
const sdk = useSdk()
|
|
10
12
|
const location = router.searchParams.location
|
|
11
|
-
const { uploadFile } = useResources()
|
|
12
13
|
|
|
13
14
|
return (
|
|
14
15
|
<View gap="s" style={{ height: '100%' }}>
|
|
@@ -19,7 +20,7 @@ export const UploadResources = () => {
|
|
|
19
20
|
</View>
|
|
20
21
|
</View>
|
|
21
22
|
<Upload
|
|
22
|
-
onUpload={(file) => uploadFile(location, file)}
|
|
23
|
+
onUpload={(file) => uploadFile(sdk, location, file)}
|
|
23
24
|
onCancel={() => router.navigate(`@storage/home?location=${location}`)}
|
|
24
25
|
onDone={() => router.navigate(`@storage/home?location=${location}`)}
|
|
25
26
|
/>
|
package/src/VideoResource.jsx
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import { metadata as GetResource } from './get.action.js'
|
|
3
|
+
import { useSdk } from '@ossy/sdk-react'
|
|
3
4
|
import { View } from '@ossy/design-system'
|
|
4
5
|
|
|
5
6
|
export const VideoResource = ({
|
|
6
7
|
resourceId
|
|
7
8
|
}) => {
|
|
8
|
-
const
|
|
9
|
+
const sdk = useSdk()
|
|
10
|
+
const { data: resource } = sdk.read(GetResource, { id: resourceId }, { enabled: !!resourceId })
|
|
9
11
|
|
|
10
12
|
return (
|
|
11
13
|
<View stack bordered>
|
|
@@ -1,38 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { Resource, ResourcesEvents } from '@ossy/resources'
|
|
3
|
-
import { Workspace } from '@ossy/workspaces'
|
|
4
|
-
import { normalizeAndValidateDocumentContent } from '@ossy/platform'
|
|
5
|
-
|
|
6
|
-
export const id = 'resources/create-page-view'
|
|
7
|
-
export const access = 'workspace'
|
|
8
|
-
|
|
9
|
-
const PAGE_VIEW_TEMPLATE_ID = '@ossy/web/page-view'
|
|
10
|
-
const PAGE_VIEW_LOCATION = '/@ossy/analytics/page-views/'
|
|
11
|
-
|
|
12
|
-
export async function run({ payload, req }) {
|
|
13
|
-
const workspaceId = payload?.workspaceId ?? req?.workspaceId
|
|
14
|
-
if (!workspaceId) throw Object.assign(new Error('workspaceId is required'), { status: 400 })
|
|
15
|
-
|
|
16
|
-
const workspace = await Aggregate.Of(Workspace, workspaceId).then(Aggregate.View())
|
|
17
|
-
|
|
18
|
-
// Page-view template is a built-in; instantiate directly without schema validation
|
|
19
|
-
const contentInput = {
|
|
20
|
-
...(payload ?? {}),
|
|
21
|
-
userAgent: payload?.userAgent ?? req?.headers?.['user-agent'],
|
|
22
|
-
eventAt: payload?.eventAt ?? Date.now(),
|
|
23
|
-
path: payload?.path ?? '/',
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const event = ResourcesEvents.Created({
|
|
27
|
-
type: PAGE_VIEW_TEMPLATE_ID,
|
|
28
|
-
createdBy: payload?.userId ?? req?.userId ?? 'public',
|
|
29
|
-
belongsTo: workspace.id,
|
|
30
|
-
location: PAGE_VIEW_LOCATION,
|
|
31
|
-
name: `${Date.now()}`,
|
|
32
|
-
content: contentInput,
|
|
33
|
-
access: 'restricted',
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
const resource = await Aggregate.Of(Resource, event).then(Aggregate.View())
|
|
37
|
-
return { id: resource.id }
|
|
38
|
-
}
|
|
1
|
+
export const metadata = { id: 'resources/create-page-view', access: 'workspace' }
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Aggregate } from '@ossy/event-store'
|
|
2
|
+
import { Resource } from './resource.aggregate.js'
|
|
3
|
+
import { ResourcesEvents } from './resources.events.js'
|
|
4
|
+
import { Workspace } from '@ossy/workspaces/server'
|
|
5
|
+
import { normalizeAndValidateDocumentContent } from '@ossy/platform'
|
|
6
|
+
|
|
7
|
+
export const metadata = { id: 'resources/create-page-view' }
|
|
8
|
+
|
|
9
|
+
const PAGE_VIEW_TEMPLATE_ID = '@ossy/web/page-view'
|
|
10
|
+
const PAGE_VIEW_LOCATION = '/@ossy/analytics/page-views/'
|
|
11
|
+
|
|
12
|
+
export async function run({ payload, req }) {
|
|
13
|
+
const workspaceId = payload?.workspaceId ?? req?.workspaceId
|
|
14
|
+
if (!workspaceId) throw Object.assign(new Error('workspaceId is required'), { status: 400 })
|
|
15
|
+
|
|
16
|
+
const workspace = await Aggregate.Of(Workspace, workspaceId).then(Aggregate.View())
|
|
17
|
+
|
|
18
|
+
// Page-view template is a built-in; instantiate directly without schema validation
|
|
19
|
+
const contentInput = {
|
|
20
|
+
...(payload ?? {}),
|
|
21
|
+
userAgent: payload?.userAgent ?? req?.headers?.['user-agent'],
|
|
22
|
+
eventAt: payload?.eventAt ?? Date.now(),
|
|
23
|
+
path: payload?.path ?? '/',
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const event = ResourcesEvents.Created({
|
|
27
|
+
type: PAGE_VIEW_TEMPLATE_ID,
|
|
28
|
+
createdBy: payload?.userId ?? req?.userId ?? 'public',
|
|
29
|
+
belongsTo: workspace.id,
|
|
30
|
+
location: PAGE_VIEW_LOCATION,
|
|
31
|
+
name: `${Date.now()}`,
|
|
32
|
+
content: contentInput,
|
|
33
|
+
access: 'restricted',
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
const resource = await Aggregate.Of(Resource, event).then(Aggregate.View())
|
|
37
|
+
return { id: resource.id }
|
|
38
|
+
}
|