diff --git a/example/app/data/DemoDataSource/recipes/plugins/list/task_list/task.recipe.json b/example/app/data/DemoDataSource/recipes/plugins/list/task_list/task.recipe.json index e358e6e01..41ccaa3dd 100644 --- a/example/app/data/DemoDataSource/recipes/plugins/list/task_list/task.recipe.json +++ b/example/app/data/DemoDataSource/recipes/plugins/list/task_list/task.recipe.json @@ -49,7 +49,7 @@ { "name": "List", "type": "CORE:UiRecipe", - "plugin": "table-plugin", + "plugin": "@development-framework/dm-core-plugins/list", "dimensions": "*", "config": { "type": "PLUGINS:dm-core-plugins/list/ListPluginConfig", diff --git a/example/src/plugins/table/TablePlugin.tsx b/example/src/plugins/table/TestUseListPlugin.tsx similarity index 94% rename from example/src/plugins/table/TablePlugin.tsx rename to example/src/plugins/table/TestUseListPlugin.tsx index bd8a24c91..7196dee43 100644 --- a/example/src/plugins/table/TablePlugin.tsx +++ b/example/src/plugins/table/TestUseListPlugin.tsx @@ -11,8 +11,8 @@ import { import React, { useMemo, useState } from 'react' import { Button } from '@equinor/eds-core-react' -const TablePlugin = (props: IUIPlugin) => { - const { idReference } = props +const TestUseListPlugin = (props: IUIPlugin) => { + const { idReference: address } = props const { items, @@ -26,7 +26,7 @@ const TablePlugin = (props: IUIPlugin) => { save, dirtyState, updateAttribute, - } = useList(idReference) + } = useList(address) const [paginationPage, setPaginationPage] = useState(0) const [paginationRowsPerPage, setPaginationRowsPerPage] = useState(10) @@ -113,4 +113,4 @@ const TablePlugin = (props: IUIPlugin) => { ) } -export { TablePlugin } +export { TestUseListPlugin } diff --git a/example/src/plugins/table/index.tsx b/example/src/plugins/table/index.tsx index 8b95aa50c..048047673 100644 --- a/example/src/plugins/table/index.tsx +++ b/example/src/plugins/table/index.tsx @@ -1,9 +1,9 @@ import { TUiPluginMap } from '@development-framework/dm-core' -import { TablePlugin } from './TablePlugin' +import { TestUseListPlugin } from './TestUseListPlugin' export default { - 'table-plugin': { - component: TablePlugin, + 'test-use-list-plugin': { + component: TestUseListPlugin, }, } as TUiPluginMap diff --git a/packages/dm-core/src/hooks/useList.tsx b/packages/dm-core/src/hooks/useList.tsx index 3d8d76fdf..36b39a6ab 100644 --- a/packages/dm-core/src/hooks/useList.tsx +++ b/packages/dm-core/src/hooks/useList.tsx @@ -64,23 +64,8 @@ export function useList(idReference: string): IUseListReturnType { address: idReference, depth: 0, }) - .then(async (response: any) => { - if (!attribute.contained) { - const resolved = await dmssAPI.documentGet({ - address: idReference, - depth: 1, - }) - const items = Object.values(response.data).map((data, index) => ({ - key: crypto.randomUUID(), - index: index, - // @ts-ignore - data: resolved.data[index], - reference: data, - })) - // @ts-ignore - setItems(items) - setError(null) - } else { + .then(async (response: AxiosResponse) => { + if (attribute.contained) { const items = Object.values(response.data).map((data, index) => ({ key: crypto.randomUUID(), index: index, @@ -90,6 +75,23 @@ export function useList(idReference: string): IUseListReturnType { // @ts-ignore setItems(items) setError(null) + } else { + const resolved = await dmssAPI.documentGet({ + address: idReference, + depth: 1, + }) + if (Array.isArray(resolved.data)) { + const items = Object.values(response.data).map((data, index) => ({ + key: crypto.randomUUID(), + index: index, + // @ts-ignore + data: resolved.data[index], + reference: data, + })) + // @ts-ignore + setItems(items) + setError(null) + } } }) .catch((error: AxiosError) => { @@ -199,12 +201,13 @@ export function useList(idReference: string): IUseListReturnType { const index = items.findIndex( (item: TItem) => item.key === itemToUpdate.key ) + const address = attribute?.contained + ? `${idReference}[${index}]` + : items[index].reference?.address + if (!address) return return dmssAPI .documentUpdate({ - // @ts-ignore - idAddress: attribute?.contained - ? `${idReference}[${index}]` - : items[index].reference?.address, + idAddress: address, data: JSON.stringify(newDocument), updateUncontained: false, }) @@ -261,16 +264,16 @@ export function useList(idReference: string): IUseListReturnType { } return { - items: items, + items, attribute, isLoading, error, + dirtyState, addItem, removeItem, addReference, updateItem, save, - dirtyState, updateAttribute, } }