Skip to content

Commit 54c932e

Browse files
authored
Merge pull request #71 from ligangty/2.0-refactor
Add skeleton for Group and Hosted pages
2 parents 044c198 + a02e6ae commit 54c932e

7 files changed

Lines changed: 90 additions & 538 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Copyright (C) 2023 Red Hat, Inc. (https://github.com/Commonjava/indy-ui-service)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import React, {useState, useEffect} from 'react';
18+
import {useLocation, useNavigate, useParams} from 'react-router-dom';
19+
import {PropTypes} from 'prop-types';
20+
import {StoreEditControlPanel as EditControlPanel} from './StoreControlPanels.jsx';
21+
import {DisableTimeoutHint, DurationHint, PrefetchHint, Hint} from './Hints.jsx';
22+
import {PackageTypeSelect} from './CommonPageWidget.jsx';
23+
// import ViewJsonDebugger from './Debugger.jsx';
24+
import {Utils} from '../CompUtils.js';
25+
// import Filters from '../Filters.js';
26+
import {TimeUtils} from '../../TimeUtils.js';
27+
import {jsonRest} from '../../RestClient.js';
28+
29+
30+
export default function GroupEdit() {
31+
const [state, setState] = useState({
32+
store: {},
33+
storeView: {}
34+
});
35+
36+
return <div>This is not implemented yet!</div>;
37+
}

src/main/webui/src/app/components/content/GroupList.jsx

Lines changed: 4 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -22,130 +22,11 @@ import ListControl from "./ListControl.jsx";
2222
import {ListJsonDebugger} from './Debugger.jsx';
2323
import {LocalURLSection, StoreNameSection} from './CommonPageWidget.jsx';
2424

25-
const init = function (state, setState){
26-
useEffect(()=>{
27-
Utils.getStores(state, setState, "group");
28-
}, [state.listing]);
29-
};
30-
31-
32-
const createNew = () => {
33-
// mock
34-
};
35-
36-
const hideAll = () => {
37-
// mock
38-
};
39-
40-
const handleSearch = (event, rawList, setState) => {
41-
setState({
42-
listing: Utils.searchByKeyForNewStores(event.target.value, rawList)
43-
});
44-
};
45-
46-
const handleDebug = (event, setState) => {
47-
setState({
48-
enableDebug: event.target.checked
49-
});
50-
};
51-
52-
const GroupListItem = ({store, storeClass, disableMap}) => {
53-
const [hideCons, setHideCons] = useState(true);
54-
let constituents = store.constituents ? Utils.reConstituents(store) : undefined;
55-
return (
56-
<div className="store-listing-item">
57-
<StoreNameSection store={store} storeClass={storeClass} />
58-
<div className="fieldset">
59-
<div>
60-
<LocalURLSection storeKey={store.key} />
61-
<div className="options-field field right-half">
62-
<div className="inline-label">
63-
{store.constituents && store.constituents.length} Constituent(s) [
64-
<span className="option">
65-
{
66-
hideCons ?
67-
<a href="#" onClick={event => {
68-
event.preventDefault();
69-
setHideCons(false);
70-
}}>+</a> :
71-
<a href="#" onClick={event => {
72-
event.preventDefault();
73-
setHideCons(true);
74-
}}>-</a>
75-
}
76-
</span>
77-
]
78-
</div>
79-
{
80-
!hideCons && constituents &&
81-
<ol className="content-panel subsection">
82-
{
83-
constituents.map(item => {
84-
let itemStoreClass = Utils.isDisabled(item.key, disableMap)? "disabled-store":"enabled-store";
85-
return (
86-
<li key={item.key}>
87-
<Link to={`/${item.type}/${item.packageType}/view/${item.name}`}>
88-
<span className={itemStoreClass}>{item.key}</span>
89-
</Link>
90-
{
91-
item.type==='remote' &&
92-
<div className="subfields">
93-
<span className="description field">(Remote URL: <a target="_new" href={Utils.storeHref(item.key)}>{Utils.storeHref(item.key)}</a>)</span>
94-
</div>
95-
}
96-
</li>
97-
);
98-
})
99-
}
100-
</ol>
101-
}
102-
</div>
103-
</div>
104-
<div className="description field"><span>{store.description}</span></div>
105-
</div>
106-
</div>
107-
);
108-
};
109-
110-
GroupListItem.propTypes={
111-
store: PropTypes.object.isRequired,
112-
storeClass: PropTypes.string,
113-
disableMap: PropTypes.object
114-
};
115-
116-
export default function GroupList() {
25+
export default function GruopList() {
11726
const [state, setState] = useState({
118-
listing: [],
119-
rawListing: [],
120-
disabledMap: {},
121-
enableDebug: false,
27+
store: {},
28+
raw: {},
12229
message: ''
12330
});
124-
init(state, setState);
125-
let listing = state.listing;
126-
let disMap = state.disabledMap;
127-
128-
return (
129-
<div className="container-fluid">
130-
<ListControl
131-
useHideAll={true} handleHideAll={hideAll}
132-
useSearch={true} handleSearch={handleSearch}
133-
useDebug={true} handleDebug={handleDebug}
134-
handleCreateNew={createNew} />
135-
<div className="content-panel">
136-
<div className="store-listing">
137-
{
138-
listing.map(store => {
139-
let storeClass = Utils.isDisabled(store.key, disMap)? "disabled-store":"enabled-store";
140-
return (
141-
<GroupListItem key={store.key} store={store} storeClass={storeClass} disableMap={disMap} />
142-
);
143-
})
144-
}
145-
</div>
146-
</div>
147-
148-
<ListJsonDebugger enableDebug={state.enableDebug} jsonObj={state.listing} />
149-
</div>
150-
);
31+
return <div>This is not implemented yet!</div>;
15132
}

src/main/webui/src/app/components/content/GroupView.jsx

Lines changed: 4 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -24,187 +24,11 @@ import {Filters} from '../Filters.js';
2424
import {TimeUtils} from '../../TimeUtils.js';
2525
import {jsonGet} from '../../RestClient.js';
2626

27-
const getDisTimeouts = (store, state, setState) => {
28-
jsonGet({
29-
url: '/api/admin/schedule/store/all/disable-timeout',
30-
done: response => {
31-
let newStore = Utils.cloneObj(store);
32-
let disabledMap = Utils.setDisableMap(response, state.listing);
33-
let expiration = disabledMap[store.key];
34-
if(expiration){
35-
newStore.disableExpiration = expiration;
36-
}
37-
setState({
38-
store: newStore,
39-
disabledMap
40-
});
41-
},
42-
fail: () => {
43-
Utils.logMessage("disable timeout getting failed");
44-
setState({
45-
store
46-
});
47-
}
48-
});
49-
};
50-
51-
const getStore = (state, setState) => {
52-
const [packageType, name] = useParams();
53-
let getUrl = `/api/admin/stores/${packageType}/group/${name}`;
54-
jsonGet({
55-
url: getUrl,
56-
done: response => {
57-
let raw = response;
58-
let store = Utils.cloneObj(raw);
59-
store.disabled = raw.disabled === undefined ? false : raw.disabled;
60-
setState({
61-
raw
62-
});
63-
getDisTimeouts(store, state, setState);
64-
},
65-
fail: errorText => {
66-
setState({
67-
message: JSON.parse(errorText).error
68-
});
69-
}
70-
});
71-
};
72-
73-
const init = function (state, setState){
74-
useEffect(()=>{
75-
getStore(state, setState);
76-
}, [state.raw]);
77-
};
78-
79-
80-
const handlers = {
81-
handleDisable: () => {
82-
// Mock
83-
},
84-
85-
handleEnable: () => {
86-
// Mock
87-
},
88-
89-
handleEdit: () => {
90-
// Mock
91-
},
92-
93-
handleCreate: () => {
94-
// Mock
95-
},
96-
97-
handleRemove: () => {
98-
// Mock
99-
}
100-
};
10127
export default function GroupView() {
10228
const [state, setState] = useState({
103-
raw: {}, store: {}, disableMap: [], message: ''
29+
store: {},
30+
raw: {},
31+
message: ''
10432
});
105-
106-
init(state, setState);
107-
let store = state.store;
108-
109-
if(!Utils.isEmptyObj(store)) {
110-
return (
111-
<div className="container-fluid">
112-
<div className="control-panel">
113-
<ControlPanel
114-
enabled={!store.disabled} handleEnable={handlers.handleEnable}
115-
handleDisable={handlers.handleDisable}
116-
handleEdit={handlers.handleEdit}
117-
handleCreate={handlers.handleCreate}
118-
handleRemove={handlers.handleRemove} />
119-
</div>
120-
121-
<div className="content-panel">
122-
<div className="fieldset-caption">Basics</div>
123-
<BasicSection store={store} />
124-
125-
<div className="fieldset-caption">Description</div>
126-
<div className="fieldset">
127-
<div className="text-field">
128-
<textarea readOnly className="text-description" value={store.description} />
129-
</div>
130-
</div>
131-
132-
<div className="fieldset-caption">Constituents</div>
133-
<div className="fieldset">
134-
{
135-
store.constituents && store.constituents.length>0 &&
136-
137-
<ol className="detail-value detail-value-list">
138-
{
139-
store.constituents.map(item=>{
140-
let href = Utils.detailHref(item);
141-
let isDisabled = Utils.isDisabled(item, state.disabledMap);
142-
let storeClassName = isDisabled? 'disabled-store': 'enabled-store';
143-
return (
144-
<li key={item} className="detail-value-list-item">
145-
{
146-
href?
147-
<Link to={href}>
148-
<span className={storeClassName} >{item}</span>
149-
</Link>:
150-
<span>{item}</span>
151-
}
152-
</li>
153-
);
154-
})
155-
}
156-
</ol>
157-
}
158-
</div>
159-
</div>
160-
{
161-
// <ViewJsonDebugger enableDebug={false} storeJson={store} rawJson={raw} />
162-
}
163-
</div>
164-
);
165-
}
166-
return null;
33+
return <div>This is not implemented yet!</div>;
16734
}
168-
169-
const BasicSection = ({store})=> <div className="fieldset">
170-
<div className="detail-field">
171-
<label>Package Type:</label>
172-
<span className="key">{store.packageType}</span>
173-
</div>
174-
<div className="detail-field">
175-
<label>Name:</label>
176-
<span className="key">{store.name}</span>
177-
</div>
178-
<div className="detail-field">
179-
<span>{Filters.checkmark(!store.disabled)}</span>
180-
<label>Enabled?</label>
181-
{
182-
store.disabled && store.disableExpiration &&
183-
<span className="hint">Set to automatically re-enable at {TimeUtils.timestampToDateFormat(store.disableExpiration)}</span>
184-
}
185-
</div>
186-
<div className="detail-field">
187-
<span>{Filters.checkmark(store.prepend_constituent)}</span>
188-
<label>Prepend Constituents?</label>
189-
<span className="hint">If enabled, all new constituents which are added not manually(like promotion) will be at the top of constituents list</span>
190-
</div>
191-
<div className="sub-fields">
192-
<div className="detail-field">
193-
<label>Disable Timeout:</label>
194-
<span>{store.disable_timeout}</span>
195-
<DisableTimeoutHint />
196-
</div>
197-
</div>
198-
<div className="detail-field">
199-
<label>Local URL:</label>
200-
{
201-
// TODO: is this store.demo still available now?
202-
store.demo ?
203-
<span>{Utils.storeHref(store.key)}</span> :
204-
<span><a href={Utils.storeHref(store.key)} target="_new">{Utils.storeHref(store.key)}</a></span>
205-
}
206-
</div>
207-
</div>;
208-
BasicSection.propTypes = {
209-
store: PropTypes.object.isRequired
210-
};

0 commit comments

Comments
 (0)