diff --git a/pages/_app.tsx b/pages/_app.tsx index c9bf43c9c1f4f09c23470510985082069a12c074..94ceb6fc1c8a20c94c5118357455af81e43df139 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -137,7 +137,7 @@ const App = (props: React.PropsWithChildren) => { resources={[{ name: 'fdo', list: '/fdo', - show: '/fdo/show/:id', + show: '/fdo/show/:prefix/:suffix', create: '/fdo/create', meta: { icon: logo @@ -151,6 +151,7 @@ const App = (props: React.PropsWithChildren) => { } }, { name: 'profiles', + identifier: 'profiles', list: '/profiles', show: '/profiles/show/:id', meta: { @@ -158,7 +159,7 @@ const App = (props: React.PropsWithChildren) => { } }, { name: 'info', - // show: '/info', + identifier: 'info', list: '/info', meta: { label: 'About', diff --git a/pages/fdo/create/index.tsx b/pages/fdo/create/index.tsx index f9ed32774ea24c215e1cec01edfa3d28ab192865..d7ca06451756338dbe34d5e3b670ca9bbf17e09c 100644 --- a/pages/fdo/create/index.tsx +++ b/pages/fdo/create/index.tsx @@ -1,11 +1,15 @@ import React from 'react' +import { Authenticated } from '@refinedev/core' import { FdoCreate } from '../../../src/components/fdos' import { GetServerSideProps } from 'next' import { serverSideTranslations } from 'next-i18next/serverSideTranslations' const CreateFDO = () => { - return <FdoCreate/> + return ( + <Authenticated key="fdo-create"> + <FdoCreate/> + </Authenticated>) } export default CreateFDO diff --git a/pages/fdo/show/[id]/index.tsx b/pages/fdo/show/[prefix]/[suffix].tsx similarity index 82% rename from pages/fdo/show/[id]/index.tsx rename to pages/fdo/show/[prefix]/[suffix].tsx index 830062bb06c918b58e37cd8c8d2b4802fc12ee99..638036758ebb2a0fd6e2edaad247cd9df08cd8e4 100644 --- a/pages/fdo/show/[id]/index.tsx +++ b/pages/fdo/show/[prefix]/[suffix].tsx @@ -3,7 +3,7 @@ import React from 'react' import { ErrorComponent } from '../../../../src/components/ErrorComponent' import { GetServerSideProps } from 'next' import { serverSideTranslations } from 'next-i18next/serverSideTranslations' -import { useShow, useTranslate } from '@refinedev/core' +import { useShow, useTranslate, useParsed, useCustom, useApiUrl } from '@refinedev/core' import { Show } from '@refinedev/mui' import { Typography } from '@mui/material' import CircularProgress from '@mui/material/CircularProgress' @@ -13,8 +13,13 @@ import Chip from '@mui/material/Chip' import Link from '@mui/material/Link' const ShowFDO = () => { + const { params } = useParsed() + const showId = `${params?.prefix}/${params?.suffix}` + const apiUrl = useApiUrl() const t = useTranslate() - const { queryResult: { isError, error, isLoading, data }, showId } = useShow({ + const { data, isLoading, isError, error } = useCustom({ + url: `${apiUrl}/fdo/${showId}`, + method: 'get', errorNotification: () => false, queryOptions: { retry: false @@ -26,6 +31,7 @@ const ShowFDO = () => { return <ErrorComponent message={t('fdo.show.handle_not_found', 'Handle not found.')} /> } + console.log('show', data) const handleUrl = `https://hdl.handle.net/${showId}` return ( diff --git a/pages/repositories/show/[id].tsx b/pages/repositories/show/[id].tsx new file mode 100644 index 0000000000000000000000000000000000000000..845798d0fd66d807d009c0b27d6cc1a6f5f86d69 --- /dev/null +++ b/pages/repositories/show/[id].tsx @@ -0,0 +1,13 @@ +import { useGetToPath, useParsed, useGo } from '@refinedev/core' +import Button from '@mui/material/Button' + +export const ShowInfo = () => { + const { params } = useParsed() + const go = useGo() + + return <Button onClick={() => { go({ to: { resource: 'info', action: 'show', id: 'asdf', meta: { prefix: 'prefix2', suffix: 'blub' } }, type: 'push' }) }}> + { 'id(' + params?.id + ')'} + </Button> +} + +export default ShowInfo diff --git a/src/api/api.ts b/src/api/api.ts index b0f308edbee999af4044c62c65750e6a018de118..33732766120f4f30b564d8ebe0fdac44c5a6c4f8 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -513,15 +513,19 @@ export const FDOsApiAxiosParamCreator = function (configuration?: Configuration) }, /** * Resolve a pid. - * @param {string} pid Persistent Identifier + * @param {string} prefix Persistent Identifier Prefix + * @param {string} suffix Persistent Identifier Suffix * @param {*} [options] Override http request option. * @throws {RequiredError} */ - resolvePID: async (pid: string, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => { - // verify required parameter 'pid' is not null or undefined - assertParamExists('resolvePID', 'pid', pid) - const localVarPath = `/fdo/{pid}` - .replace(`{${"pid"}}`, encodeURIComponent(String(pid))); + resolvePID: async (prefix: string, suffix: string, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => { + // verify required parameter 'prefix' is not null or undefined + assertParamExists('resolvePID', 'prefix', prefix) + // verify required parameter 'suffix' is not null or undefined + assertParamExists('resolvePID', 'suffix', suffix) + const localVarPath = `/fdo/{prefix}/{suffix}` + .replace(`{${"prefix"}}`, encodeURIComponent(String(prefix))) + .replace(`{${"suffix"}}`, encodeURIComponent(String(suffix))); // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); let baseOptions; @@ -570,12 +574,13 @@ export const FDOsApiFp = function(configuration?: Configuration) { }, /** * Resolve a pid. - * @param {string} pid Persistent Identifier + * @param {string} prefix Persistent Identifier Prefix + * @param {string} suffix Persistent Identifier Suffix * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async resolvePID(pid: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<ResolvePID200Response>> { - const localVarAxiosArgs = await localVarAxiosParamCreator.resolvePID(pid, options); + async resolvePID(prefix: string, suffix: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<ResolvePID200Response>> { + const localVarAxiosArgs = await localVarAxiosParamCreator.resolvePID(prefix, suffix, options); const localVarOperationServerIndex = configuration?.serverIndex ?? 0; const localVarOperationServerBasePath = operationServerMap['FDOsApi.resolvePID']?.[localVarOperationServerIndex]?.url; return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); @@ -603,12 +608,13 @@ export const FDOsApiFactory = function (configuration?: Configuration, basePath? }, /** * Resolve a pid. - * @param {string} pid Persistent Identifier + * @param {string} prefix Persistent Identifier Prefix + * @param {string} suffix Persistent Identifier Suffix * @param {*} [options] Override http request option. * @throws {RequiredError} */ - resolvePID(pid: string, options?: any): AxiosPromise<ResolvePID200Response> { - return localVarFp.resolvePID(pid, options).then((request) => request(axios, basePath)); + resolvePID(prefix: string, suffix: string, options?: any): AxiosPromise<ResolvePID200Response> { + return localVarFp.resolvePID(prefix, suffix, options).then((request) => request(axios, basePath)); }, }; }; @@ -635,13 +641,14 @@ export class FDOsApi extends BaseAPI { /** * Resolve a pid. - * @param {string} pid Persistent Identifier + * @param {string} prefix Persistent Identifier Prefix + * @param {string} suffix Persistent Identifier Suffix * @param {*} [options] Override http request option. * @throws {RequiredError} * @memberof FDOsApi */ - public resolvePID(pid: string, options?: RawAxiosRequestConfig) { - return FDOsApiFp(this.configuration).resolvePID(pid, options).then((request) => request(this.axios, this.basePath)); + public resolvePID(prefix: string, suffix: string, options?: RawAxiosRequestConfig) { + return FDOsApiFp(this.configuration).resolvePID(prefix, suffix, options).then((request) => request(this.axios, this.basePath)); } } diff --git a/src/components/fdos/create.tsx b/src/components/fdos/create.tsx index 5762661ab98fd9d26f00a7fb60f0654b96f1df21..227bdd51b47da8971844bc340a9a4d1aa98a8a9c 100644 --- a/src/components/fdos/create.tsx +++ b/src/components/fdos/create.tsx @@ -1,4 +1,4 @@ -import { IResourceComponentsProps, useList, HttpError, useGetIdentity } from '@refinedev/core' +import { useGo, IResourceComponentsProps, useList, HttpError, useGetIdentity } from '@refinedev/core' import { Create, SaveButton } from '@refinedev/mui' import { useTheme, styled } from '@mui/material/styles' @@ -141,6 +141,7 @@ const StepData: React.FC<any> = ({ register, errors }) => { } export const FdoCreate: React.FC<IResourceComponentsProps> = () => { + const go = useGo() const accessToken = useAccessToken() console.log('accessToken: ', accessToken) @@ -149,7 +150,6 @@ export const FdoCreate: React.FC<IResourceComponentsProps> = () => { saveButtonProps, refineCore: { formLoading, onFinish, - redirect, mutationResult: { data, error, isLoading } }, register, @@ -159,9 +159,10 @@ export const FdoCreate: React.FC<IResourceComponentsProps> = () => { steps: { currentStep, gotoStep } } = formRet - if (data) { - console.log('redirect', data.data.pid) - redirect('show', data.data.pid) + if (data?.data?.pid) { + const prefix = data?.data?.pid?.split('/', 1)[0] + const suffix = data?.data?.pid?.substring(prefix.length + 1) + go({ to: { resource: 'fdo', action: 'show', id: data?.data?.pid, meta: { prefix, suffix } }, type: 'push' }) } const onSubmit = (data: any) => { diff --git a/src/components/fdos/list.tsx b/src/components/fdos/list.tsx index ca688a14ca49e96ee0ff20a9583dc29d221a1c3e..bab89da72bbfc41f228bd644d9870488c79d72e3 100644 --- a/src/components/fdos/list.tsx +++ b/src/components/fdos/list.tsx @@ -16,13 +16,14 @@ const columns: Array<GridColDef<OperationsLogRecord>> = [ field: 'operation', headerName: 'Operation', type: 'string', - width: 200 + width: 120 }, { field: 'id', headerName: 'FDO', - type: 'string', - width: 200 + minWidth: 200, + flex: 1, + type: 'string' } ] diff --git a/src/providers/dataProvider.tsx b/src/providers/dataProvider.tsx index c392dea7c9858d5727ac00499e793a1e257d465a..2a905a747287a31cdee2e643f6ab282e62395a7d 100644 --- a/src/providers/dataProvider.tsx +++ b/src/providers/dataProvider.tsx @@ -55,6 +55,23 @@ const apiDataProvider = (apiUrl: string): DataProvider => { const _fallBack = dataProvider(apiUrl) return { + custom: async ({ + url, + method, + filters, + sorters, + payload, + query, + headers, + meta + }) => { + if (method === 'get') { + return { data: (await getNewlyCreated(url)).data.data } + } else { + throw new Error('Not implemented') + } + }, + getOne: async ({ resource, id, meta }) => { const data = await callOperation(resource, 'get', { id, meta }) return { data: data.data }