Skip to content

Commit

Permalink
Merge pull request #82 from ligangty/2.0-refactor
Browse files Browse the repository at this point in the history
Re-organize: move pages conponent to dedicated folders
  • Loading branch information
ligangty authored Nov 16, 2023
2 parents 9a186ab + af693b4 commit 2047454
Show file tree
Hide file tree
Showing 13 changed files with 254 additions and 237 deletions.
18 changes: 9 additions & 9 deletions src/main/webui/src/app/components/content/Main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

import React from 'react';
import {Route, Routes} from 'react-router-dom';
import RemoteList from './RemoteList.jsx';
import HostedList from './HostedList.jsx';
import GroupList from './GroupList.jsx';
import RemoteView from './RemoteView.jsx';
import HostedView from './HostedView.jsx';
import GroupView from './GroupView.jsx';
import RemoteEdit from './RemoteEdit.jsx';
import GroupEdit from './GroupEdit.jsx';
import HostedEdit from './HostedEdit.jsx';
import RemoteList from './remote/RemoteList.jsx';
import HostedList from './hosted/HostedList.jsx';
import GroupList from './group/GroupList.jsx';
import RemoteView from './remote/RemoteView.jsx';
import HostedView from './hosted/HostedView.jsx';
import GroupView from './group/GroupView.jsx';
import RemoteEdit from './remote/RemoteEdit.jsx';
import GroupEdit from './group/GroupEdit.jsx';
import HostedEdit from './hosted/HostedEdit.jsx';

// const browseCompatible=`<!--[if lt IE 7]>
// <p className="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
Expand Down
10 changes: 5 additions & 5 deletions src/main/webui/src/app/components/content/common/ListControl.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ export default function ListControl({handleCreateNew, useHideAll, handleHideAll,
<ul>
{
legends.map(option => <li key={option.title}>
<div>
<span className="key">{option.icon} </span>
<span>{option.title}</span>
</div>
</li>)
<div>
<span className="key">{option.icon} </span>
<span>{option.title}</span>
</div>
</li>)
}
</ul>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/**
* Copyright (C) 2023 Red Hat, Inc. (https://github.com/Commonjava/indy-ui-service)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import React from 'react';
import {PropTypes} from 'prop-types';
import {DisableTimeoutHint, PrefetchHint, Hint} from './Hints.jsx';
import {Filters} from '../../../utils/Filters.js';
import {Utils} from '../../../utils/AppUtils.js';
import {TimeUtils} from '../../../utils/TimeUtils.js';

export const StoreViewBasicSection = ({store})=>{
let authoritativeIndexHints = "Make the content index authoritative to this repository";
if(store.type==="hosted"){
authoritativeIndexHints += " (when readonly, this will be enabled automatically)";
}
return <div className="fieldset">
<div className="detail-field">
<label>Package Type:</label>
<span className="key">{store.packageType}</span>
</div>
<div className="detail-field">
<label>Name:</label>
<span className="key">{store.name}</span>
</div>
<div className="detail-field">
<span>{Filters.checkmark(!store.disabled)}</span>
<label>Enabled?</label>
{
store.disabled && store.disableExpiration &&
<span className="hint">Set to automatically re-enable at {TimeUtils.timestampToDateFormat(store.disableExpiration)}</span>
}
</div>
<div className="detail-field">
<span>{Filters.checkmark(store.authoritative_index)}</span>
<label>Authoritative index enabled?</label>
{
(store.type==="remote" || store.type==="hosted") && !store.authoritative_index &&
<span className="hint">{authoritativeIndexHints}</span>
}
</div>
<div className="sub-fields">
<div className="detail-field">
<label>Disable Timeout:</label>
<span>{store.disable_timeout}</span>
<DisableTimeoutHint />
</div>
</div>
<div className="detail-field">
<label>Local URL:</label>
{
// TODO: is this store.demo still available now?
store.demo ?
<span>{Utils.storeHref(store.key)}</span> :
<span><a href={Utils.storeHref(store.key)} target="_new">{Utils.storeHref(store.key)}</a></span>
}
</div>
<div className="detail-field">
<label>Remote URL:</label>
<span><a href={store.url} target="_new">{store.url}</a></span>
</div>
<div className="sub-fields">
<div className="detail-field">
<span>{Filters.checkmark(!store.is_passthrough)}</span>
<label>Allow Content Caching</label>
<span><Hint hintKey="passthrough" /></span>
</div>
{
!store.is_passthrough &&

<div>
<div className="detail-field">
<label>Content Cache Timeout:</label>
<span>{TimeUtils.secondsToDuration(store.cache_timeout_seconds)}</span>
</div>
<div className="detail-field">
<label>Metadata Cache Timeout:</label>
<span>{TimeUtils.secondsToDuration(store.metadata_timeout_seconds, true)}</span>
</div>
</div>

}
</div>

<div className="sub-fields">
<div className="detail-field">
<label>Pre-fetching Priority:</label>
<span>{store.prefetch_priority}</span>
<PrefetchHint />
</div>
<div className="detail-field">
<span>{Filters.checkmark(store.prefetch_rescan)}</span>
<label>Allow Pre-fetching Rescan?</label>
</div>
<div className="detail-field">
<label>Pre-fetching Listing Type:</label>
<span>{store.prefetch_listing_type}</span>
</div>
</div>
</div>;
};

StoreViewBasicSection.propTypes = {
store: PropTypes.object.isRequired
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,51 @@ import {PropTypes} from 'prop-types';
import {Utils} from '../../../utils/AppUtils';
import {jsonRest,http} from '../../../utils/RestClient';

const StoreViewControlPanel = function({store}){
const handleEnable = () =>{
// TODO: need to implement
};
const handleDisable = () =>{
// TODO: need to implement
};
const [enableText, enableHandler] = store.disabled?["Enable",handleEnable]:["Disable",handleDisable];
const navigate = useNavigate();

const [pkgType, storeType, storeName] = [store.packageType, store.type, store.name];
const storeUrl = `/api/admin/stores/${pkgType}/${storeType}/${storeName}`;
const handleRemove = async ()=>{
const response = await http.delete(storeUrl);
if(!response.ok && response.status >= 400){
// TODO: Some other way to handle errors?
response.text().then(error=>Utils.logMessage(error));
}
if(response.status===204){
// TODO: Some other way to show deletion success?
Utils.logMessage("Store deleted.");
}
navigate(`/${store.type}`);
};

return(
<div className="cp-row-group">
<div className="cp-row">
<button onClick={enableHandler}>{enableText}</button>
</div>
<div className="cp-row">
<button onClick={()=>navigate(`/${storeType}/${pkgType}/edit/${storeName}`)}>Edit</button>{' '}
<button onClick={()=>navigate(`/${storeType}/new`)}>New...</button>{' '}
<button name="del" onClick={handleRemove} className="del-button cp-button">
Delete
</button>
</div>
</div>
);
};

StoreViewControlPanel.propTypes={
store: PropTypes.object
};

const StoreEditControlPanel = ({mode, store}) =>{
const navigate = useNavigate();
const handleSave = () => {
Expand Down Expand Up @@ -84,49 +129,4 @@ StoreEditControlPanel.propTypes={
store: PropTypes.object
};

const StoreViewControlPanel = function({store}){
const handleEnable = () =>{
// TODO: need to implement
};
const handleDisable = () =>{
// TODO: need to implement
};
const [enableText, enableHandler] = store.disabled?["Enable",handleEnable]:["Disable",handleDisable];
const navigate = useNavigate();

const [pkgType, storeType, storeName] = [store.packageType, store.type, store.name];
const storeUrl = `/api/admin/stores/${pkgType}/${storeType}/${storeName}`;
const handleRemove = async ()=>{
const response = await http.delete(storeUrl);
if(!response.ok && response.status >= 400){
// TODO: Some other way to handle errors?
response.text().then(error=>Utils.logMessage(error));
}
if(response.status===204){
// TODO: Some other way to show deletion success?
Utils.logMessage("Store deleted.");
}
navigate(`/${store.type}`);
};

return(
<div className="cp-row-group">
<div className="cp-row">
<button onClick={enableHandler}>{enableText}</button>
</div>
<div className="cp-row">
<button onClick={()=>navigate(`/${storeType}/${pkgType}/edit/${storeName}`)}>Edit</button>{' '}
<button onClick={()=>navigate(`/${storeType}/new`)}>New...</button>{' '}
<button name="del" onClick={handleRemove} className="del-button cp-button">
Delete
</button>
</div>
</div>
);
};

StoreViewControlPanel.propTypes={
store: PropTypes.object
};

export {StoreEditControlPanel, StoreViewControlPanel};
export {StoreViewControlPanel, StoreEditControlPanel};
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
import React, {useState, useEffect} from 'react';
import {useLocation, useParams} from 'react-router-dom';
import {PropTypes} from 'prop-types';
import {StoreEditControlPanel as EditControlPanel} from './common/StoreControlPanels.jsx';
import {DisableTimeoutHint, DurationHint, PrefetchHint, Hint} from './common/Hints.jsx';
import {PackageTypeSelect} from './common/PackageTypeSelect.jsx';
import {StoreEditControlPanel as EditControlPanel} from '../common/StoreControlPanels.jsx';
import {DisableTimeoutHint, DurationHint, PrefetchHint, Hint} from '../common/Hints.jsx';
import {PackageTypeSelect} from '../common/PackageTypeSelect.jsx';
// import ViewJsonDebugger from './Debugger.jsx';
import {Utils} from '../../utils/AppUtils.js';
import {TimeUtils} from '../../utils/TimeUtils.js';
import {jsonRest} from '../../utils/RestClient.js';
import {Utils} from '../../../utils/AppUtils.js';
import {TimeUtils} from '../../../utils/TimeUtils.js';
import {jsonRest} from '../../../utils/RestClient.js';

const init = (pkgType, storeName, setState) => {
const getUrl = `/api/admin/stores/${pkgType}/remote/${storeName}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
*/

import React, {useEffect, useState} from 'react';
import {ListJsonDebugger} from './common/Debugger.jsx';
import ListControl from "./common/ListControl.jsx";
import {remoteOptionLegend as options} from "../ComponentConstants.js";
import {StoreListingWidget} from './common/StoreListingWidget.jsx';
import {Utils} from '../../utils/AppUtils.js';
import {jsonRest} from '../../utils/RestClient.js';
import {ListJsonDebugger} from '../common/Debugger.jsx';
import ListControl from "../common/ListControl.jsx";
import {remoteOptionLegend as options} from "../../ComponentConstants.js";
import {StoreListingWidget} from '../common/StoreListingWidget.jsx';
import {Utils} from '../../../utils/AppUtils.js';
import {jsonRest} from '../../../utils/RestClient.js';

const init = (state, setState) => {
useEffect(()=>{
Expand Down
Loading

0 comments on commit 2047454

Please sign in to comment.