Skip to content

Commit

Permalink
machbase/neo-web - fix refresh token & default value
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-lee0604 committed May 28, 2024
1 parent 4529a73 commit 98f685e
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 50 deletions.
6 changes: 3 additions & 3 deletions src/api/repository/machiot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ export const fetchMountTimeMinMax = async (aTargetInfo: any) => {
}
}

if (sData.data.rows.length === 0) {
if (!sData.data?.rows || sData.data.rows.length === 0) {
const sNowTime = moment().unix() * 1000000;
const sNowTimeMinMax = [moment(sNowTime).subtract(1, 'h').unix() * 1000000, sNowTime];
return sNowTimeMinMax;
Expand Down Expand Up @@ -369,7 +369,7 @@ export const fetchTimeMinMax = async (aTargetInfo: any) => {
}
}

if (sData.data.rows.length === 0) {
if (!sData.data?.rows || sData.data.rows.length === 0) {
const sNowTime = moment().unix() * 1000000;
const sNowTimeMinMax = [moment(sNowTime).subtract(1, 'h').unix() * 1000000, sNowTime];
return sNowTimeMinMax;
Expand Down Expand Up @@ -493,7 +493,7 @@ const getRollupTableList = async () => {
}
}
const sConvertArray: any = {};
if (sData.data.rows && sData.data.rows.length > 0) {
if (sData.data && sData.data.rows && sData.data.rows.length > 0) {
for (const [user, table, value] of sData.data.rows) {
if (!sConvertArray[user]) {
sConvertArray[user] = {};
Expand Down
6 changes: 3 additions & 3 deletions src/components/console/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const Console = ({ pSetTerminalSizes, pExtentionList, pTerminalSizes }: any) =>
/** return shell list */
const getShellList = useMemo((): any[] => {
const sExtensionListWithoutTerm = pExtentionList.filter((aExtension: any) => aExtension.type !== 'term');
return sExtensionListWithoutTerm.concat(sShellList);
return sExtensionListWithoutTerm.concat(sShellList ?? []);
}, [sShellList]);

useOutsideClick(MenuRef, () => setIsContextMenu(false));
Expand Down Expand Up @@ -150,8 +150,8 @@ const Console = ({ pSetTerminalSizes, pExtentionList, pTerminalSizes }: any) =>
{getShellList.map((aItem: any) => {
return (
<Menu.Item onClick={(aEvent: any) => addConsoleTab(aEvent, aItem)} key={aItem.id}>
{icons(aItem.icon)}
{aItem.label}
{icons(aItem?.icon) ?? ''}
{aItem?.label ?? ''}
</Menu.Item>
);
})}
Expand Down
1 change: 1 addition & 0 deletions src/components/editor/Body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ const Body = ({ pExtentionList, pSideSizes, pDraged, pGetInfo, pGetPath, pSetDra

useEffect(() => {
const expiredRt = () => {
localStorage.removeItem('refreshToken');
sNavigate('/login');
};
window.addEventListener('logoutEvent', expiredRt);
Expand Down
8 changes: 4 additions & 4 deletions src/components/inputs/TagSearchSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useMemo, useRef, useState } from 'react';
import { ArrowLeft, ArrowRight, Close, Search } from '@/assets/icons/Icon';
import { MdKeyboardDoubleArrowLeft, MdOutlineKeyboardArrowDown, MdOutlineKeyboardDoubleArrowRight } from 'react-icons/md';
import { ArrowLeft, ArrowRight, Search } from '@/assets/icons/Icon';
import { MdKeyboardDoubleArrowLeft, MdOutlineKeyboardArrowDown, MdOutlineKeyboardArrowUp, MdOutlineKeyboardDoubleArrowRight } from 'react-icons/md';
import { getTagPagination, getTagTotal } from '@/api/repository/machiot';
import { Input } from './Input';
import { Tooltip } from 'react-tooltip';
Expand Down Expand Up @@ -106,7 +106,7 @@ export const TagSearchSelect = ({ pTable, pCallback }: { pTable: string; pCallba
useOutsideClick(tagRef, () => sIsOpen && handleOutSideClick());

return (
<div ref={tagRef} className="tag-search-select-wrapper" id="tag-search-select-wrapper" style={{ backgroundColor: sIsOpen ? '#bd2222' : '#323644' }}>
<div ref={tagRef} className="tag-search-select-wrapper" id="tag-search-select-wrapper" style={{ backgroundColor: '#323644' }}>
<div
className="tag-search-select-open-btn-wrapper"
onClick={(e: any) => {
Expand All @@ -115,7 +115,7 @@ export const TagSearchSelect = ({ pTable, pCallback }: { pTable: string; pCallba
}}
>
{!sIsOpen && <MdOutlineKeyboardArrowDown />}
{sIsOpen && <Close />}
{sIsOpen && <MdOutlineKeyboardArrowUp />}
</div>
{sIsOpen && (
<div className="tag-search-select-content-wrapper">
Expand Down
2 changes: 1 addition & 1 deletion src/components/newBoard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ const NewBoard = (props: NewBoardProps) => {
/** return shell list */
const getShellList = useMemo((): any[] => {
const sExtensionListWithoutTerm = pExtentionList.filter((aExtension: any) => aExtension.type !== 'term');
return sExtensionListWithoutTerm.concat(sShellList);
return sExtensionListWithoutTerm.concat(sShellList ?? []);
}, [sShellList, pGetInfo]);

return (
Expand Down
68 changes: 35 additions & 33 deletions src/components/side/DBExplorer/DBExplorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,40 +36,42 @@ const DBExplorer = ({ pServer }: any) => {
if (aEvent) aEvent.stopPropagation();
setRefresh(sRefresh + 1);
const sData = await getTableList();
const U_NAME = getUserName();
const DB_NAME_LIST: string[] = Array.from(
new Set(U_NAME === 'sys' ? ['MACHBASEDB', ...sData.data.rows.map((aRow: any) => aRow[0])] : sData.data.rows.map((aRow: any) => aRow[0]))
);
const USER_NAME_LIST: string[] = Array.from(
new Set(U_NAME === 'sys' ? ['SYS', ...sData.data.rows.map((aRow: any) => aRow[1])] : sData.data.rows.map((aRow: any) => aRow[1]))
);
// DB > USER > TABLE > TYPE
let DB_LIST: any = [];
DB_NAME_LIST
? (DB_LIST = DB_NAME_LIST.map((aName: string) => {
return {
dbName: aName,
userList: USER_NAME_LIST.map((aUser: string) => {
return { userName: aUser, total: 0, tableList: { log: [], fixed: [], volatile: [], lookup: [], keyValue: [], tag: [] } };
}),
tableLen: 0,
};
}))
: null;
sData.data.rows.map((bRow: any) => {
DB_LIST.map((aDB: any, aIdx: number) => {
if (aDB.dbName === bRow[0]) {
DB_LIST[aIdx].tableLen++;
USER_NAME_LIST.map((aUser: string, bIdx: number) => {
if (bRow[1] === aUser) {
DB_LIST[aIdx]['userList'][bIdx].total++;
DB_LIST[aIdx]['userList'][bIdx].tableList[TableTypeConverter(bRow[4])].push(bRow);
}
});
}
if (sData && sData.data) {
const U_NAME = getUserName();
const DB_NAME_LIST: string[] = Array.from(
new Set(U_NAME === 'sys' ? ['MACHBASEDB', ...sData.data.rows.map((aRow: any) => aRow[0])] : sData.data.rows.map((aRow: any) => aRow[0]))
);
const USER_NAME_LIST: string[] = Array.from(
new Set(U_NAME === 'sys' ? ['SYS', ...sData.data.rows.map((aRow: any) => aRow[1])] : sData.data.rows.map((aRow: any) => aRow[1]))
);
// DB > USER > TABLE > TYPE
let DB_LIST: any = [];
DB_NAME_LIST
? (DB_LIST = DB_NAME_LIST.map((aName: string) => {
return {
dbName: aName,
userList: USER_NAME_LIST.map((aUser: string) => {
return { userName: aUser, total: 0, tableList: { log: [], fixed: [], volatile: [], lookup: [], keyValue: [], tag: [] } };
}),
tableLen: 0,
};
}))
: null;
sData.data.rows.map((bRow: any) => {
DB_LIST.map((aDB: any, aIdx: number) => {
if (aDB.dbName === bRow[0]) {
DB_LIST[aIdx].tableLen++;
USER_NAME_LIST.map((aUser: string, bIdx: number) => {
if (bRow[1] === aUser) {
DB_LIST[aIdx]['userList'][bIdx].total++;
DB_LIST[aIdx]['userList'][bIdx].tableList[TableTypeConverter(bRow[4])].push(bRow);
}
});
}
});
});
});
setDBList(DB_LIST);
setDBList(DB_LIST);
} else setDBList([]);
};

const setHiddenObj = (aEvent: any) => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/side/ReferenceList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const ReferenceList = ({ pServer }: any) => {
const init = async () => {
try {
const sData = await getReferenceList();
setReferences(sData.data.refs);
setReferences(sData?.data?.refs);
} catch (err) {
console.log(err);
}
Expand Down
8 changes: 5 additions & 3 deletions src/hooks/useToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ export const useToken = (callback: (val: boolean) => void) => {
const sRefreshToken = localStorage.getItem('refreshToken');

const checkExpire = () => {
if (!sRefreshToken) return false;
const sTmpRefreshToken = localStorage.getItem('refreshToken');
if (!sTmpRefreshToken) return false;
try {
const sBase64Url = sRefreshToken.split('.')[1];
const sBase64Url = sTmpRefreshToken.split('.')[1];
const sBase64 = sBase64Url.replace(/-/g, '+').replace(/_/g, '/');
const sJwtInfo = decodeURIComponent(
atob(sBase64)
Expand All @@ -33,7 +34,8 @@ export const useToken = (callback: (val: boolean) => void) => {
}, [callback]);

useEffect(() => {
if (sAccToken) {
const sTmpAccToken = localStorage.getItem('accessToken');
if (sTmpAccToken) {
const sRJWTStatus = checkExpire();
if (sRJWTStatus) return callback(true);
else return callback(false);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/DashboardChartCodeParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const NameValueFunc = (aChartType: string) => {
/** TIME_VALUE func */
const TimeValueFunc = () => {
return `(obj) => {
\t\t_chartOption.series[aIdx].data = obj.data.rows;
\t\t_chartOption.series[aIdx].data = obj?.data?.rows ?? [];
\t\t_chart.setOption(_chartOption);
\t}`;
};
Expand Down
2 changes: 1 addition & 1 deletion src/view/Home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ const Home = () => {

timer.current = setInterval(() => {
if (count > 60) {
clearInterval(timer.current);
localStorage.removeItem('accessToken');
localStorage.removeItem('refreshToken');
sNavigate('/login');
clearInterval(timer.current);
} else {
init();
count++;
Expand Down

0 comments on commit 98f685e

Please sign in to comment.