Skip to content

Commit

Permalink
Redesign custom ui urls
Browse files Browse the repository at this point in the history
  • Loading branch information
akucharska committed Oct 16, 2024
1 parent ee1a574 commit 72524f0
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 39 deletions.
2 changes: 2 additions & 0 deletions public/extensions/extensions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ general:
backendUrls:
post: http://127.0.0.1:8001/api/v1/namespaces/ak/services/nginx-service/proxy/data.json
get: /api/secrets
url: /api/service-offerings
query: sm_secret_name=sap-btp-service-operator&sm_secret_namespace=kyma-system
host: http://localhost:8000
features:
disableDefaultColumns: true
Expand Down
8 changes: 6 additions & 2 deletions src/components/Extensibility/ExtensibilityList.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,13 @@ export const ExtensibilityListCore = ({
apiGroup: resource?.group,
apiVersion: resource?.version,
hasDetailsView: !!resMetaData?.details,
getUrl: backendUrls?.get,
customUIUrl: backendUrls?.host,
});

listProps.customUIUrl = {
host: backendUrls?.host,
url: backendUrls?.url,
query: backendUrls?.query,
};
const resourceTitle = resMetaData?.general?.name;
listProps.resourceTitle = exists('name')
? t('name')
Expand Down Expand Up @@ -137,6 +140,7 @@ export const ExtensibilityListCore = ({
disableCreate={disableCreate}
disableEdit={disableEdit}
disableDelete={disableDelete}
disableDefaultColumns={disableDefaultColumns}
createResourceForm={ExtensibilityCreate}
sortBy={defaultSortOptions =>
sortBy(jsonata, sortOptions, t, defaultSortOptions)
Expand Down
18 changes: 5 additions & 13 deletions src/resources/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,21 @@ export const usePrepareListProps = ({
apiGroup,
apiVersion,
hasDetailsView,
getUrl,
customUIUrl,
}) => {
const { namespaceId } = useParams();
const queryParams = new URLSearchParams(window.location.search);
const { i18n, t } = useTranslation();

const api = apiGroup ? `apis/${apiGroup}/${apiVersion}` : `api/${apiVersion}`;
const resourceUrl = getUrl
? getUrl
: namespaceId && namespaceId !== '-all-'
? `/${api}/namespaces/${namespaceId}/${resourceType?.toLowerCase()}`
: `/${api}/${resourceType?.toLowerCase()}`;
const resourceUrl =
namespaceId && namespaceId !== '-all-'
? `/${api}/namespaces/${namespaceId}/${resourceType?.toLowerCase()}`
: `/${api}/${resourceType?.toLowerCase()}`;

return {
hasDetailsView,
readOnly: queryParams.get('readOnly') === 'true',
resourceUrl,
isAbsolute: !!getUrl,
customUIUrl: customUIUrl,
resourceType: resourceCustomType || pluralize(resourceType || ''),
resourceTitle: i18n.exists(resourceI18Key) ? t(resourceI18Key) : '',
namespace: namespaceId,
Expand All @@ -69,16 +64,13 @@ export const usePrepareDetailsProps = ({
resourceName,
namespaceId,
showYamlTab,
getUrl,
}) => {
const encodedResourceName = encodeURIComponent(resourceName);
const queryParams = new URLSearchParams(window.location.search);
const { i18n, t } = useTranslation();
const api = apiGroup ? `apis/${apiGroup}/${apiVersion}` : `api/${apiVersion}`;
const resourceUrl = resourceName
? getUrl
? getUrl
: namespaceId
? namespaceId
? `/${api}/namespaces/${namespaceId}/${resourceType?.toLowerCase()}/${encodedResourceName}`
: `/${api}/${resourceType?.toLowerCase()}/${encodedResourceName}`
: '';
Expand Down
2 changes: 0 additions & 2 deletions src/shared/components/ResourcesList/ResourcesList.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ function Resources(props) {
resourceUrl,
skipDataLoading,
isCompact,
isAbsolute,
customUIUrl,
} = props;
useWindowTitle(prettifyNamePlural(resourceTitle, resourceType), {
Expand All @@ -158,7 +157,6 @@ function Resources(props) {
{
pollingInterval: 3000,
skip: skipDataLoading,
isAbsolute: isAbsolute,
customUIUrl,
},
);
Expand Down
35 changes: 15 additions & 20 deletions src/shared/hooks/BackendAPI/useFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ import { getClusterConfig } from '../../../state/utils/getBackendInfo';
import { clusterState, ActiveClusterState } from '../../../state/clusterAtom';

export type FetchFn = ({
isAbsolute,
customUIUrl,
relativeUrl,
abortController,
init,
}: {
isAbsolute?: string;
customUIUrl?: string;
customUIUrl?: any;
relativeUrl: string;
init?: any;
abortController?: AbortController;
Expand All @@ -28,14 +26,12 @@ export const createFetchFn = ({
authData: AuthDataState;
cluster: ActiveClusterState;
}): FetchFn => async ({
isAbsolute,
customUIUrl,
relativeUrl,
abortController,
init,
}: {
isAbsolute?: string;
customUIUrl?: string;
customUIUrl?: any;
relativeUrl: string;
init?: any;
abortController?: AbortController;
Expand All @@ -50,22 +46,21 @@ export const createFetchFn = ({
};
const { backendAddress, customUIBackendAddress } = getClusterConfig();

let preparedCustomUIUrl =
customUIUrl?.url && customUIUrl?.host
? customUIBackendAddress +
customUIUrl?.url +
'?customUIUrl=' +
customUIUrl?.host
: '';
if (preparedCustomUIUrl) {
preparedCustomUIUrl = preparedCustomUIUrl + '&' + customUIUrl.query;
}

try {
const response = await fetch(
isAbsolute
? customUIBackendAddress +
relativeUrl +
(customUIUrl ? `?customUIUrl=${customUIUrl}` : '')
: backendAddress + relativeUrl,
isAbsolute
? {
...init,
headers: {
...init.headers,
'X-Cluster-Url': 'http://localhost:8000',
},
}
: init,
preparedCustomUIUrl ? preparedCustomUIUrl : backendAddress + relativeUrl,
init,
);
if (response.ok) {
return response;
Expand Down
2 changes: 0 additions & 2 deletions src/shared/hooks/BackendAPI/useGet.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const useGetHook = processDataFn =>
onDataReceived,
skip,
errorTolerancy = undefined,
isAbsolute = false,
customUIUrl,
} = {},
) {
Expand Down Expand Up @@ -65,7 +64,6 @@ const useGetHook = processDataFn =>
requestData.current[currentRequestId] = { start: Date.now() };
const response = await fetch({
relativeUrl: path,
isAbsolute: isAbsolute,
customUIUrl: customUIUrl,
abortController: abortController.current,
});
Expand Down

0 comments on commit 72524f0

Please sign in to comment.