Skip to content
Snippets Groups Projects
Verified Commit a05bf288 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

FIX: routing with slashes

parent 300cb0b5
No related branches found
No related tags found
No related merge requests found
Pipeline #48762 passed
......@@ -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',
......
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
......
......@@ -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 (
......
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
......@@ -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));
}
}
......
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) => {
......
......@@ -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'
}
]
......
......@@ -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 }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment