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

Add content resource in rest client for DirectoryListing #126

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 8 additions & 2 deletions src/main/webui/src/app/utils/RestClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ const storeAPIEndpoint = (pkgType, type, name) => `${BASE_API_PATH}/${pkgType}/$

const handleResponse = async response => {
if (response.ok){
const store = await response.json();
return {result: store, success: true};
const result = await response.json();
return {result, success: true};
}
const responseMsg = await response.text();
if(responseMsg){
Expand Down Expand Up @@ -92,6 +92,12 @@ const IndyRest = {
return handleResponse(response);
}
},
contentRes: {
browse: async dirPath => {
const response = await jsonRest.get(`/api${dirPath}`);
return handleResponse(response);
}
},
disableRes: {
getAllStoreTimeout: async () => {
const response = await jsonRest.get('/api/admin/schedule/store/all/disable-timeout');
Expand Down
16 changes: 9 additions & 7 deletions src/main/webui/src/content-browse/DirectoryListing.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import React, {useState, useEffect} from 'react';
import {PropTypes} from 'prop-types';
import {styles} from './style.js';
import {jsonRest} from '#utils/RestClient.js';
import {IndyRest} from '#utils/RestClient.js';

const {contentRes} = IndyRest;

const replaceUrl = url =>{
if (url.includes("api/browse")){
Expand Down Expand Up @@ -111,18 +113,18 @@ export default function DirectoryListing () {

useEffect(()=>{
const fetchData = async () => {
const response = await jsonRest.get(`/api${document.location.pathname}`);
if(response.ok){
const data = await response.json();
const res = await contentRes.browse(document.location.pathname);
if(res.success){
const data = res.result;
setState({
isLoaded: true,
data
});
}else{
response.text().then(error=>setState({
setState({
isLoaded: true,
error
}));
error: res.error.message
});
}
};
fetchData();
Expand Down
Loading