Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Consumer Parameters #1921

Merged
merged 133 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from 129 commits
Commits
Show all changes
133 commits
Select commit Hold shift + click to select a range
287979d
feat: add consumer parameters to publish
moritzkirstein Mar 16, 2023
5141789
fix: publish form validation
moritzkirstein Mar 16, 2023
5caeb6e
Merge remote-tracking branch 'origin/ocean/main' into feat/algorithm-…
moritzkirstein Mar 23, 2023
9e295cd
Merge remote-tracking branch 'upstream/main' into feat/algorithm-para…
LucaMilanese90 Apr 18, 2023
006ba5b
feat: update consumer parameters form
LucaMilanese90 Apr 25, 2023
00b81d3
feat: add consumer parameter types
LucaMilanese90 Apr 25, 2023
773c01e
feat: update consumer parameter validation
LucaMilanese90 Apr 25, 2023
b91409c
feat: add consumer parameters structure
LucaMilanese90 Apr 25, 2023
b9507dd
feat: add InputOptions error handling
LucaMilanese90 Apr 27, 2023
47d4d41
feat: update consumer parameters validation
LucaMilanese90 Apr 27, 2023
f1ac6f6
feat: update transformPublishFromToDdo
LucaMilanese90 Apr 27, 2023
afe4993
feat: add default options to parameter options
LucaMilanese90 Apr 27, 2023
69ecb57
fix: value handling for select and mutliselect
LucaMilanese90 Apr 27, 2023
d65c85c
feat: update "add new parameter" button label
LucaMilanese90 Apr 27, 2023
f159cad
feat: remove unused publish form sections
LucaMilanese90 Apr 28, 2023
12e4c23
chore: remove console.log
LucaMilanese90 Apr 28, 2023
32bcf36
chore: remove comments
LucaMilanese90 Apr 28, 2023
843a9f8
feat: remove multiselect
LucaMilanese90 Apr 28, 2023
d05a9c3
feat: add consumer parameters section label
LucaMilanese90 Apr 28, 2023
045f49c
feat: update types
LucaMilanese90 Apr 28, 2023
aa37125
feat: update edit form fields
LucaMilanese90 Apr 28, 2023
73fa000
feat: parse consumer parameters in edit form
LucaMilanese90 Apr 28, 2023
4eaa28e
feat: add consumer parameters field to edit
LucaMilanese90 Apr 28, 2023
3f30cda
feat: transform consumer parameters values before edit
LucaMilanese90 Apr 28, 2023
f8dbae3
feat: update "required" type to select
LucaMilanese90 Apr 29, 2023
ec27509
feat: update "required" type to select on edit form
LucaMilanese90 Apr 29, 2023
bf063dc
fix: error object access
LucaMilanese90 May 2, 2023
9a6e792
fix: edit flow crash
LucaMilanese90 May 3, 2023
b1146dd
fix: validation when consumer parameters are not selected
LucaMilanese90 May 3, 2023
7a53cbc
feat: update validation for default consumer parameters value
LucaMilanese90 May 3, 2023
475e0d6
fix: types
LucaMilanese90 May 3, 2023
a34a85e
feat: add service consumer parameters to publish form
LucaMilanese90 May 3, 2023
3321b47
chore: remove console.log
LucaMilanese90 May 3, 2023
ca78e3d
feat: add service consumer parameters edit
LucaMilanese90 May 3, 2023
22c106a
chore: remove comments
LucaMilanese90 May 3, 2023
6fdda18
fix: form edit metadata types
LucaMilanese90 May 3, 2023
4722e57
feat: add consume algo parameter structure
LucaMilanese90 May 5, 2023
7f4a5b9
feat: consumer parameter required default value condition
LucaMilanese90 May 5, 2023
847d1e9
Merge remote-tracking branch 'origin/feat/algorithm-parameters' into …
LucaMilanese90 May 5, 2023
247c43c
feat: add consumer parameter groups to assetActions
LucaMilanese90 May 5, 2023
7066fee
fix: consumer parameters grouping
LucaMilanese90 May 5, 2023
0edf550
feat: update consumer parameters alignment
LucaMilanese90 May 5, 2023
75b079e
feat: update types
LucaMilanese90 May 5, 2023
e3fe288
feat: allow service consumer parameters on dataset asset type
LucaMilanese90 May 5, 2023
bb6b787
feat: add consumer parameters to ddo updated values in edit form
LucaMilanese90 May 5, 2023
067870c
Merge remote-tracking branch 'origin/feat/algorithm-parameters' into …
LucaMilanese90 May 5, 2023
8b86938
feat: add "data service" consumer parameters to consumption form
LucaMilanese90 May 5, 2023
1334b66
feat: allow service parameters on all asset types
LucaMilanese90 May 6, 2023
f1275f9
Merge remote-tracking branch 'origin/feat/algorithm-parameters' into …
LucaMilanese90 May 6, 2023
bfcacaa
feat: update parameter consume form design
LucaMilanese90 May 8, 2023
b722b48
feat: update asset actions consume parameters location
LucaMilanese90 May 8, 2023
b130ab7
feat: add service parameters to download assets
LucaMilanese90 May 9, 2023
9cccb9a
refactor: consumer parameters actions
LucaMilanese90 May 9, 2023
910066f
refactor: form action name
LucaMilanese90 May 9, 2023
5ca9129
refactor: consumer parameters default input
LucaMilanese90 May 9, 2023
8400d34
refactor: consumer parameters select input
LucaMilanese90 May 9, 2023
29f034a
refactor: consumer parameter input
LucaMilanese90 May 9, 2023
3ea89d7
fix: props name
LucaMilanese90 May 9, 2023
c0a7218
refactor: variable naming
LucaMilanese90 May 9, 2023
ab56677
refactor: consumer parameters form validation
LucaMilanese90 May 9, 2023
5f936e1
refactor: rename consumer parameters types
LucaMilanese90 May 9, 2023
304690c
refactor: extract consumer parameters form data to separate file
LucaMilanese90 May 9, 2023
c1040e6
refactor: rename type
LucaMilanese90 May 9, 2023
1b60fb7
feat: controlled tabs for consumer params
moritzkirstein May 9, 2023
01e3fcc
Merge branch 'feat/algorithm-parameters' of https://github.com/deltaD…
LucaMilanese90 May 10, 2023
0e7d82c
feat: restore default value as required
LucaMilanese90 May 10, 2023
c577334
refactor: parse values before edit
LucaMilanese90 May 10, 2023
7cf5a6c
Merge remote-tracking branch 'origin/feat/algorithm-parameters' into …
LucaMilanese90 May 10, 2023
3971ec3
feat: add form to handle consumer parameters consumption
LucaMilanese90 May 10, 2023
026f3d2
feat: send consumer params with download request
LucaMilanese90 May 11, 2023
a39e387
feat: send consumer params with compute request
LucaMilanese90 May 11, 2023
43abe33
feat: handle compute form initialization
LucaMilanese90 May 11, 2023
086d20d
chore: remove unused dependency
LucaMilanese90 May 11, 2023
291c821
feat: handle download form data initialization
LucaMilanese90 May 11, 2023
9cf89d9
chore: remove console.log
LucaMilanese90 May 11, 2023
72d1951
feat: update types
LucaMilanese90 May 11, 2023
f1f888c
fix: consumer parameter value types
LucaMilanese90 May 12, 2023
2b2699a
feat: update ConsumerParameter type
LucaMilanese90 May 12, 2023
1dc88b2
Merge remote-tracking branch 'origin/feat/algorithm-parameters' into …
LucaMilanese90 May 12, 2023
cc7ff6d
feat: update ConsumerParameter type
LucaMilanese90 May 12, 2023
ae0f59e
chore: add comments
LucaMilanese90 May 12, 2023
7eb85ba
Merge remote-tracking branch 'origin/feat/algorithm-parameters' into …
LucaMilanese90 May 12, 2023
3322f25
refactor: consumer parameters inputs
LucaMilanese90 May 12, 2023
26c2cd0
Merge remote-tracking branch 'origin/feat/algorithm-parameters' into …
LucaMilanese90 May 12, 2023
8bd987c
refactor: rename data and algo service params
LucaMilanese90 May 12, 2023
fd4ef72
refactor: consumer parameters form
LucaMilanese90 May 12, 2023
0a7d785
refactor: consumer parameter form styling
LucaMilanese90 May 12, 2023
4010a7d
refactor: make headers input reusable as KeyValueInput
moritzkirstein May 16, 2023
f3c3a06
refactor: refactorings, reduce duplication (WIP)
moritzkirstein May 16, 2023
bb01fd4
Merge branch 'feat/algorithm-parameters' into feat/algorithm-paramete…
moritzkirstein May 16, 2023
aa0bcba
refactor: usercustomparameters consumption form creation/validation
moritzkirstein May 17, 2023
47d9059
refactor: return undefined consistently if property path not found on…
moritzkirstein May 17, 2023
8f1ccac
refactor: reuse fieldType and fieldOptions in DefaultInput
moritzkirstein May 17, 2023
023498d
fix: parse ddo consumer parameters for edit form
moritzkirstein May 17, 2023
8f32dd3
fix: asset view crash for assets w/o consumer params
moritzkirstein May 17, 2023
e5761c8
fix: publish preview for assets with no consumer params
moritzkirstein May 17, 2023
f34a93c
fix: revert accidential rename of algoService
moritzkirstein May 17, 2023
2fffba6
fix: revert publish navigation padding change
moritzkirstein May 17, 2023
113f930
Merge branch 'ocean/main' into feat/consumer-parameters
moritzkirstein May 18, 2023
48ed14c
feat: update consumer parameters' labels and helpers
LucaMilanese90 May 22, 2023
8d43373
fix: consumer parameters validation
LucaMilanese90 May 22, 2023
8a04058
feat: update consumer parameter helper wording
LucaMilanese90 May 22, 2023
cd17701
Merge pull request #35 from deltaDAO/feat/algorithm-parameters-consum…
moritzkirstein May 24, 2023
ac672e6
Merge branch 'ocean/main' of https://github.com/deltaDAO/Ocean-Market…
LucaMilanese90 May 30, 2023
d9e75ef
chore: merge conflicts
LucaMilanese90 May 30, 2023
befa473
feat: update types
LucaMilanese90 May 30, 2023
927c21e
fix: validate form on consumer parameter deletion
LucaMilanese90 May 30, 2023
40d9527
Merge pull request #37 from deltaDAO/chore/merge-conflicts
moritzkirstein Jun 1, 2023
3826675
feat: add key value input placeholder props
LucaMilanese90 Jun 1, 2023
0690836
Merge remote-tracking branch 'upstream/main' into feat/consumer-param…
LucaMilanese90 Jun 7, 2023
1aebda4
Merge remote-tracking branch 'upstream/main' into feat/consumer-param…
LucaMilanese90 Jun 7, 2023
c670509
fix: handle boolean type consumer parameters in consume form (#38)
LucaMilanese90 Jun 19, 2023
e8f4cd9
Update src/components/Publish/_validation.ts
LucaMilanese90 Jun 28, 2023
f549822
Update src/components/Asset/AssetActions/ConsumerParameters/FormConsu…
LucaMilanese90 Jun 28, 2023
f520907
Update src/components/Asset/Edit/_validation.ts
LucaMilanese90 Jun 28, 2023
4d89579
Update src/components/Asset/AssetActions/ConsumerParameters/index.tsx
LucaMilanese90 Jun 28, 2023
50f2627
Update src/components/Asset/AssetActions/ConsumerParameters/FormConsu…
LucaMilanese90 Jun 28, 2023
90ceb3b
Update src/components/@shared/FormInput/index.tsx
LucaMilanese90 Jun 28, 2023
26cebc7
Update src/components/@shared/FormInput/InputElement/ConsumerParamete…
LucaMilanese90 Jun 28, 2023
da4c0c3
Update src/components/@shared/FormInput/InputElement/ConsumerParamete…
LucaMilanese90 Jun 28, 2023
dbd6081
Update src/components/@shared/FormInput/InputElement/ConsumerParamete…
LucaMilanese90 Jun 28, 2023
4b46b19
Update src/components/@shared/FormInput/InputElement/ConsumerParamete…
LucaMilanese90 Jun 28, 2023
1f12a86
Update src/@utils/provider.ts
LucaMilanese90 Jun 28, 2023
9c8dc3c
fix: import paths
LucaMilanese90 Jun 28, 2023
161a28d
refactor: add consumer parameters validation types
LucaMilanese90 Jun 30, 2023
c776646
feat: add string length min/max to consumer parameters validation
LucaMilanese90 Jun 30, 2023
73e000c
feat: add cp description to consume form
LucaMilanese90 Jul 3, 2023
36e9e71
Merge remote-tracking branch 'upstream/main' into feat/consumer-param…
LucaMilanese90 Jul 5, 2023
d6bdd1e
feat: reduce character limit in CP tab title
LucaMilanese90 Jul 7, 2023
b9f9359
feat: update CP fields' placeholders and helpers
LucaMilanese90 Jul 10, 2023
b38a94a
Merge remote-tracking branch 'upstream/main' into feat/consumer-param…
LucaMilanese90 Jul 19, 2023
adeba3f
fix: show only relevant CPs in asset actions
LucaMilanese90 Sep 5, 2023
796f0c8
Merge remote-tracking branch 'upstream/main' into feat/consumer-param…
LucaMilanese90 Sep 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions content/pages/editMetadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@
"placeholder": "e.g. logistics",
"required": false
},
{
"name": "usesConsumerParameters",
"label": "Algorithm custom parameters",
"help": "Algorithm custom parameters are used to define required consumer input before running the algorithm in a Compute-to-Data environment.",
"type": "checkbox",
"options": ["This asset uses algorithm custom parameters"],
"required": false
},
{
"name": "paymentCollector",
"label": "Payment Collector Address",
Expand All @@ -199,6 +207,14 @@
],
"sortOptions": false,
"required": false
},
{
"name": "usesServiceConsumerParameters",
"label": "User defined parameters",
"help": "User defined parameters are used to filter or query the published asset.",
"type": "checkbox",
"options": ["This asset uses user defined parameters"],
"required": false
}
]
}
Expand Down
65 changes: 65 additions & 0 deletions content/publish/consumerParameters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"consumerParameters": {
"fields": [
{
"name": "consumerParameters",
"label": "Custom parameters",
"type": "consumerParameters",
"required": false,
"fields": [
{
"name": "name",
"label": "Parameter Name",
"placeholder": "custom_parameter",
jamiehewitt15 marked this conversation as resolved.
Show resolved Hide resolved
"help": "The name of the parameter to ask for. This will be the JSON key for this parameter.",
"type": "text",
"required": true
},

{
"name": "label",
"label": "Parameter Label",
"placeholder": "Custom Parameter",
"type": "text",
"required": true
},
{
"name": "description",
"label": "Description",
"placeholder": "A custom parameter changing the asset's behaviour.",
"type": "text",
"required": true
},
{
"name": "type",
"label": "Parameter Type",
"help": "The type of the parameter to ask for. This influences how the parameter is displayed for the consumer before the asset is used.",
"type": "select",
"options": ["number", "text", "boolean", "select"],
"required": true
},
{
"name": "options",
"label": "Select Options",
"placeholder": "Define the options for the user to select from",
"type": "creatableSelect",
"required": true
},
{
"name": "required",
"label": "Required",
"options": ["optional", "required"],
"type": "select",
"required": true
},
{
"name": "default",
"label": "Default Value",
"placeholder": "Define the default value for the current parameter",
"required": true
}
]
}
]
}
}
16 changes: 16 additions & 0 deletions content/publish/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@
"help": "Provide the entrypoint for your algorithm.",
"required": true
},
{
"name": "usesConsumerParameters",
"label": "Algorithm custom parameters",
"help": "Algorithm custom parameters are used to define required consumer input before running the algorithm in a Compute-to-Data environment.",
"type": "checkbox",
"options": ["This asset uses algorithm custom parameters"],
"required": false
},
{
"name": "termsAndConditions",
"label": "Terms & Conditions",
Expand Down Expand Up @@ -255,6 +263,14 @@
"options": ["Forever", "1 day", "1 week", "1 month", "1 year"],
"sortOptions": false,
"required": true
},
{
"name": "usesConsumerParameters",
"label": "User defined parameters",
"help": "User defined parameters are used to filter or query the published asset.",
"type": "checkbox",
"options": ["This asset uses user defined parameters"],
"required": false
}
]
},
Expand Down
2 changes: 2 additions & 0 deletions src/@types/AssetExtended.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ declare global {
interface AssetExtended extends Asset {
accessDetails?: AccessDetails
views?: number
metadata: MetadataExtended
services: ServiceExtended[]
}
}
33 changes: 32 additions & 1 deletion src/@utils/ddo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ import {
ComputeEditForm,
MetadataEditForm
} from '@components/Asset/Edit/_types'
import { FormPublishData } from '@components/Publish/_types'
import {
FormConsumerParameter,
FormPublishData
} from '@components/Publish/_types'
import {
Arweave,
Asset,
ConsumerParameter,
DDO,
FileInfo,
GraphqlQuery,
Expand Down Expand Up @@ -188,3 +192,30 @@ export function previewDebugPatch(

return buildValuesPreview
}

export function parseConsumerParameters(
consumerParameters: ConsumerParameter[]
): FormConsumerParameter[] {
if (!consumerParameters?.length) return []

return consumerParameters.map((param) => ({
...param,
required: param.required ? 'required' : 'optional',
options:
param.type === 'select'
? JSON.parse(param.options)?.map((option) => {
const key = Object.keys(option)[0]
return {
key,
value: option[key]
}
})
: [],
default:
param.type === 'boolean'
? param.default === 'true'
: param.type === 'number'
? Number(param.default)
: param.default
}))
}
24 changes: 24 additions & 0 deletions src/@utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,27 @@ export function sortAssets(items: Asset[], sorted: string[]) {
})
return items
}

export const isPlainObject = (object: any) => {
return object !== null && typeof object === 'object' && !Array.isArray(object)
}

export const getObjectPropertyByPath = (object: any, path = '') => {
if (!isPlainObject(object)) return undefined
path = path.replace(/\[(\w+)\]/g, '.$1') // convert indexes to properties
path = path.replace(/^\./, '') // strip a leading dot
const pathArray = path.split('.')
for (let i = 0, n = pathArray.length; i < n; ++i) {
const key = pathArray[i]
try {
if (key in object) {
object = object[key]
} else {
return undefined
}
} catch {
return undefined
}
}
return object
}
13 changes: 8 additions & 5 deletions src/@utils/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import {
ProviderComputeInitializeResults,
ProviderInstance,
UrlFile,
AbiItem
AbiItem,
UserCustomParameters
} from '@oceanprotocol/lib'
import { QueryHeader } from '@shared/FormInput/InputElement/Headers'
import { KeyValuePair } from '@shared/FormInput/InputElement/KeyValueInput'
import { Signer } from 'ethers'
import { getValidUntilTime } from './compute'

Expand Down Expand Up @@ -95,7 +96,7 @@ export async function getFileInfo(
providerUrl: string,
storageType: string,
query?: string,
headers?: QueryHeader[],
headers?: KeyValuePair[],
abi?: string,
chainId?: number,
method?: string
Expand Down Expand Up @@ -176,15 +177,17 @@ export async function downloadFile(
signer: Signer,
asset: AssetExtended,
accountId: string,
validOrderTx?: string
validOrderTx?: string,
userCustomParameters?: UserCustomParameters
) {
const downloadUrl = await ProviderInstance.getDownloadUrl(
asset.id,
asset.services[0].id,
0,
validOrderTx || asset.accessDetails.validOrderTx,
asset.services[0].serviceEndpoint,
signer
signer,
userCustomParameters
)
await downloadFileBrowser(downloadUrl)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React, { ReactElement } from 'react'
import Input, { InputProps } from '../..'
import { Field, useField } from 'formik'
import { FormConsumerParameter } from '@components/Publish/_types'

export default function DefaultInput({
index,
inputName,
...props
}: InputProps & {
index: number
inputName: string
}): ReactElement {
const [field] = useField<FormConsumerParameter[]>(inputName)
const fieldType = field.value[index]?.type
const fieldOptions = field.value[index]?.options

const getStringOptions = (
options: { key: string; value: string }[]
): string[] => {
if (!options?.length) return []

return options.map((option) => option.key)
}

return (
<Field
{...props}
component={Input}
type={fieldType === 'boolean' ? 'select' : fieldType}
options={
fieldType === 'boolean'
? ['true', 'false']
: fieldType === 'select'
? getStringOptions(fieldOptions)
: fieldOptions
}
/>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.actions {
display: flex;
justify-content: center;
gap: var(--spacer);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import React, { ReactElement } from 'react'
import Button from '@shared/atoms/Button'
import styles from './FormActions.module.css'
import { useField, useFormikContext } from 'formik'
import {
FormConsumerParameter,
FormPublishData
} from '@components/Publish/_types'
import { getObjectPropertyByPath } from '@utils/index'
import { defaultConsumerParam } from '.'
import { toast } from 'react-toastify'

export default function FormActions({
fieldName,
index,
onParameterAdded,
onParameterDeleted
}: {
fieldName: string
index: number
onParameterAdded?: (index: number) => void
onParameterDeleted?: (previousIndex: number) => void
}): ReactElement {
const { errors, setFieldTouched, validateField } =
useFormikContext<FormPublishData>()
const [field, meta, helpers] = useField<FormConsumerParameter[]>(fieldName)

const setParamPropsTouched = (index: number, touched = true) => {
Object.keys(defaultConsumerParam).forEach((param) => {
setFieldTouched(`${field.name}[${index}].${param}`, touched)
})
}

const addParameter = (index: number) => {
// validate parameter before allowing the creation of a new one
validateField(field.name)
setParamPropsTouched(index)

// Check errors on current tab before creating a new param
if (getObjectPropertyByPath(errors, `${field.name}[${index}]`)) {
toast.error(
'Cannot add new parameter. Current parameter definition contains errors.'
)
return
}

helpers.setValue([...field.value, { ...defaultConsumerParam }])

onParameterAdded && onParameterAdded(field.value.length)
}

const deleteParameter = (index: number) => {
helpers.setValue(field.value.filter((p, i) => i !== index))

const previousIndex = Math.max(0, index - 1)
onParameterDeleted && onParameterDeleted(previousIndex)
}

return (
<div className={styles.actions}>
<Button
style="ghost"
size="small"
disabled={field.value.length === 1}
onClick={(e) => {
e.preventDefault()
deleteParameter(index)
}}
>
Delete parameter
</Button>
<Button
style="primary"
size="small"
onClick={(e) => {
e.preventDefault()
addParameter(index)
}}
>
Add new parameter
</Button>
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.container {
position: relative;
}

.container.hasError * {
border-color: var(--brand-alert-red);
}

.hasError label {
color: var(--brand-alert-red);
}

.error {
composes: error from '../../index.module.css';
top: 100%;
}
Loading