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

Code optimization: change non change var to const from let #73

Merged
merged 1 commit into from
Nov 14, 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
18 changes: 9 additions & 9 deletions src/main/webui/src/app/TimeUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ export const TimeUtils = {
return 'never';
}

let hours = Math.floor(secs / (60 * 60));
const hours = Math.floor(secs / (60 * 60));

let mdiv = secs % (60 * 60);
let minutes = Math.floor(mdiv / 60);
const mdiv = secs % (60 * 60);
const minutes = Math.floor(mdiv / 60);

let sdiv = mdiv % 60;
let seconds = Math.ceil(sdiv);
const sdiv = mdiv % 60;
const seconds = Math.ceil(sdiv);

let out = '';
if (hours > 0){
Expand Down Expand Up @@ -66,7 +66,7 @@ export const TimeUtils = {
return 'never';
}

let date = new Date();
const date = new Date();
date.setTime(milliseconds);
return date.toLocaleString();
},
Expand All @@ -78,9 +78,9 @@ export const TimeUtils = {
if (secs < 1){
return 'never';
}
let nextDate = new Date(secs);
let toDay = new Date();
let total = nextDate.getTime() - toDay.getTime();
const nextDate = new Date(secs);
const toDay = new Date();
const total = nextDate.getTime() - toDay.getTime();
return TimeUtils.secondsToDuration(total / 1000);
}
};
36 changes: 18 additions & 18 deletions src/main/webui/src/app/components/CompUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

export const Utils = {
remoteOptions: store => {
let options = [];
const options = [];

if (store.allow_snapshots){
options.push({icon: 'S', title: 'Snapshots allowed'});
Expand All @@ -28,7 +28,7 @@ export const Utils = {
return options;
},
hostedOptions: store => {
let options = [];
const options = [];

if (store.allow_snapshots){
options.push({icon: 'S', title: 'Snapshots allowed'});
Expand All @@ -45,49 +45,49 @@ export const Utils = {
return options;
},
detailHref: key => {
let parts = key.split(':');
const parts = key.split(':');
return `/${parts[1]}/${parts[0]}/view/${parts[2]}`;
},
typeFromKey: key=>{
let parts = key.split(':');
const parts = key.split(':');
return parts[1];
},
packageTypeFromKey: key => {
let parts = key.split(':');
const parts = key.split(':');
return parts[0];
},
nameFromKey: key => {
let parts = key.split(':');
const parts = key.split(':');
return parts[parts.length-1];
},
storeHref: key => {
let parts = key.split(':');
const parts = key.split(':');

let hostAndPort = window.location.hostname;
if (window.location.port !== '' && window.location.port !== 80 && window.location.port !== 443){
hostAndPort += ':';
hostAndPort += window.location.port;
}
//
// let basepath = window.location.pathname;
// const basepath = window.location.pathname;
// basepath = basepath.replace('/app', '');
// basepath = basepath.replace(/index.html.*/, '');


let proto = window.location.protocol;
const proto = window.location.protocol;

// TODO: In-UI browser that allows simple searching
return `${proto}//${hostAndPort}/api/content/${parts[0]}/${parts[1]}/${parts[2]}`;
},
setDisableMap: listing => {
let disabledMap = {};
const disabledMap = {};

let items = listing.items;
const items = listing.items;
if (items) {
for(let i = 0; i<items.length; i++){
let item = items[i];
let parts = item.group.split(':');
let key = parts[0] + ':' + parts[1] + ':' + parts[2];
const item = items[i];
const parts = item.group.split(':');
const key = parts[0] + ':' + parts[1] + ':' + parts[2];
// console.log("DISABLED: " + key + " (until: " + item.expiration + ")");
disabledMap[key] = item.expiration;
}
Expand All @@ -96,7 +96,7 @@ export const Utils = {
},
isDisabled: (key, disabledMap) => {
if(disabledMap && disabledMap.size > 0){
let result = key in disabledMap;
const result = key in disabledMap;
return result;
}
return false;
Expand All @@ -119,13 +119,13 @@ export const Utils = {
return constituents;
},
searchByKeyForNewStores: (searchString, rawStoresList)=>{
let newListing=[];
const newListing=[];
rawStoresList.forEach(item=>item.key.toLowerCase().includes(searchString.toLowerCase()) && newListing.push(item));
return newListing;
},
isEmptyObj: obj => Object.keys(obj).length === 0 && obj.constructor === Object,
cloneObj: src => {
let target = {};
const target = {};
for (const prop in src) {
if (prop in src) {
target[prop] = src[prop];
Expand All @@ -134,7 +134,7 @@ export const Utils = {
return target;
},
logMessage: (message, ...params) => {
let allParams = [message];
const allParams = [message];
params.forEach(p => allParams.push(p));
Reflect.apply(console.log, undefined, allParams);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/webui/src/app/components/content/Hints.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ DisableTimeoutHint.propTypes = {
};

const PrefetchHint = ({children}) => {
let suggestion = children ? children:
const suggestion = children ? children:
'Integer to indicate the pre-fetching priority of the remote, higher means more eager to do the ' +
'pre-fetching of the content in the repo, 0 or below means disable the pre-fecthing.';

Expand All @@ -73,7 +73,7 @@ PrefetchHint.propTypes = {
};

const DurationHint = ({children}) => {
let suggestion = children ? children : "24h 36m 00s";
const suggestion = children ? children : "24h 36m 00s";
return <span className="hint">({`eg. ${suggestion}`})</span>;
};

Expand Down
6 changes: 3 additions & 3 deletions src/main/webui/src/app/components/content/RemoteList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ export default function RemoteList() {

init(state, setState);
// Utils.logMessage(state);
let listing = state.listing;
let disMap = state.disabledMap;
let orderBys = [
const listing = state.listing;
const disMap = state.disabledMap;
const orderBys = [
{value: 'key', text: 'Name'},
{value: 'url', text: 'Remote URL'}
];
Expand Down
8 changes: 4 additions & 4 deletions src/main/webui/src/app/components/content/RemoteView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ const init = (pkgType, storeName, setState) => {
const fetchStore = async () => {
const response = await jsonRest.get(storeUrl);
if (response.ok){
let raw = await response.json();
let store = Utils.cloneObj(raw);
const raw = await response.json();
const store = Utils.cloneObj(raw);
store.disabled = raw.disabled === undefined ? false : raw.disabled;
store.useX509 = raw.server_certificate_pem || raw.key_certificate_pem;
store.useProxy = raw.proxy_host && true;
Expand All @@ -42,7 +42,7 @@ const init = (pkgType, storeName, setState) => {
// get Store disablement data
const timeoutUrl = `/api/admin/schedule/store/${store.packageType}/${store.type}/${store.name}/disable-timeout`;
const timeoutResponse = await jsonRest.get(timeoutUrl);
let newStore = Utils.cloneObj(store);
const newStore = Utils.cloneObj(store);
if(timeoutResponse.ok){
const timeoutData = await timeoutResponse.json();
newStore.disableExpiration = timeoutData.expiration;
Expand Down Expand Up @@ -87,7 +87,7 @@ export default function RemoteView() {
});
const {packageType, name} = useParams();
init(packageType, name, setState);
let store = state.store;
const store = state.store;
if(!Utils.isEmptyObj(store)) {
return (
<div className="container-fluid">
Expand Down
2 changes: 1 addition & 1 deletion src/main/webui/src/app/components/nav/NavFooter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import React from 'react';

export default function NavFooter() {
// TODO: stats will be render based on the backend addons response, this is a mock;
let stats = {
const stats = {
version: "1.6.0",
commitId: "f472176",
builder: "ligangty",
Expand Down
16 changes: 8 additions & 8 deletions src/main/webui/src/content-browse/DirectoryListing.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ const getFullHost = () => {
};

const URLList = props => {
let elems = [];
const elems = [];
if(props.parentUrl){
let parentUrl = props.parentUrl.replace("/api/browse", "/browse");
const parentUrl = props.parentUrl.replace("/api/browse", "/browse");
elems.push(<li key="parent"><a href={parentUrl}>..</a></li>);
}
if(props.urls){
props.urls.forEach((urlResult, index)=>{
let source = `sources:\n${urlResult.sources.join("\n")}`;
let url = replaceUrl(urlResult.listingUrl);
let paths = urlResult.path.split('/');
let path = urlResult.path.endsWith("/")? paths[paths.length-2] + "/" : paths[paths.length-1];
const source = `sources:\n${urlResult.sources.join("\n")}`;
const url = replaceUrl(urlResult.listingUrl);
const paths = urlResult.path.split('/');
const path = urlResult.path.endsWith("/")? paths[paths.length-2] + "/" : paths[paths.length-1];
elems.push(<li key={"urlList"+index}><a className="item-link" title={source} href={url} path={urlResult.path}>{path}</a></li>);
});
}
Expand All @@ -63,7 +63,7 @@ URLList.propTypes = {

const Footer = props => {
const elems = props.sources && props.sources.map((src, index)=>{
let url = src.replace(/http(s{0,1}):\/\/.*?\//u, getFullHost()+"/");
const url = src.replace(/http(s{0,1}):\/\/.*?\//u, getFullHost()+"/");
return <li key={"footer"+index}><a className="source-link" title={url} href={url}>{url}</a></li>;
});
return(
Expand All @@ -81,7 +81,7 @@ Footer.propTypes = {
};

const getStoreKey = storeKey => {
let storeElems = storeKey.split(":");
const storeElems = storeKey.split(":");
return {
"packageType": storeElems[0],
"type": storeElems[1],
Expand Down
Loading