Skip to content

Commit e085c0f

Browse files
committed
History init
1 parent 5efb0ef commit e085c0f

File tree

8 files changed

+133
-9
lines changed

8 files changed

+133
-9
lines changed

.github/workflows/npm_build_test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ jobs:
7878
target-directory: 'view'
7979
target-branch: 'view'
8080
destination-github-username: 'lmangani'
81-
destination-repository-name: 'cloki'
81+
destination-repository-name: 'cLoki'
8282
user-email: [email protected]
8383
commit-message: Upgrade view to ${{steps.version.outputs.newTag}}
8484
- name: Deploy to gh-pages 🚀

package-lock.json

+7-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"jquery": "^3.6.0",
2626
"lodash": "^4.17.21",
2727
"moment": "^2.29.1",
28+
"nanoid": "^3.3.1",
2829
"react": "^17.0.2",
2930
"react-dom": "^17.0.2",
3031
"react-flot": "^1.3.0",

src/App.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { Provider } from "react-redux";
22
import store from './store/store';
3-
43
import MainView from "./components/MainView";
4+
import LocalStorageService from "./services/localStorage";
55

6-
export default function App() {
76

7+
export default function App() {
8+
window.LOCALSERVICE = LocalStorageService
89
return (
910
<Provider store={store}>
1011

src/components/LogView.js

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { connect } from "react-redux";
33
import { CircularProgress } from "@mui/material";
44
import * as moment from "moment";
55
import ClokiChart from "../plugins/charts";
6+
import SearchHistory from "../plugins/searchhistory";
67

78
const TAGS_LEVEL = {
89
critical: ['emerg', 'fatal', 'alert', 'crit', 'critical'],
@@ -129,6 +130,7 @@ class LogView extends Component {
129130

130131
</div>
131132
)}
133+
<SearchHistory/>
132134
{this.props.loading && (
133135
<CircularProgress
134136
className={"progress"}

src/plugins/searchhistory/index.js

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
3+
import styled from "@emotion/styled"
4+
import { createTheme, ThemeProvider } from "@mui/material";
5+
6+
import Drawer from '@mui/material/Drawer';
7+
8+
9+
export const theme = createTheme({
10+
palette: {
11+
mode: 'dark',
12+
primary: {
13+
main:'#fff'
14+
}
15+
}
16+
})
17+
18+
const SearchHistoryContainer = styled.div `
19+
20+
height:50px;
21+
background: #666;
22+
display:flex;
23+
`
24+
25+
const SearchHistoryDrawer = () => {
26+
27+
return(
28+
<ThemeProvider theme={theme}>
29+
<Drawer
30+
anchor={'bottom'}
31+
open={true}
32+
variant={'persistent'}
33+
>
34+
{/* history info will come in here */}
35+
</Drawer>
36+
</ThemeProvider>
37+
38+
)
39+
40+
}
41+
42+
43+
const SearchHistory = () => {
44+
45+
46+
return (
47+
<SearchHistoryDrawer/>
48+
)
49+
50+
51+
}
52+
53+
export default SearchHistory

src/services/localStorage.js

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { nanoid } from "nanoid";
2+
3+
export class LocalStorageService {
4+
5+
APP = "cloki-query";
6+
HISTORY_ITEM = this.APP + "-history";
7+
8+
getStorageItem(item) {
9+
return localStorage.getItem(item);
10+
}
11+
12+
setStorageItem(item, value) {
13+
localStorage.setItem(item, value);
14+
}
15+
16+
setHistoryItem(item) {
17+
const queryList = JSON.parse(this.getStorageItem(this.HISTORY_ITEM)) || [];
18+
/**
19+
* history item:
20+
* - starred <Boolean>
21+
* - data <Query>
22+
* - note ?
23+
*/
24+
const queryEntry = {
25+
id: nanoid(),
26+
date: Date.now(),
27+
starred: item?.starred || false,
28+
data: item?.data || '',
29+
};
30+
console.log(queryList)
31+
queryList.push(queryEntry)
32+
this.setStorageItem(this.HISTORY_ITEM, JSON.stringify(queryList));
33+
}
34+
35+
removeHistoryItem(id) {
36+
const queryList = this.getStorageItem(this.HISTORY_ITEM) || [];
37+
if (queryList?.length > 0) {
38+
let filteredList = queryList.filter((f) => f.id !== id);
39+
this.setStorageItem(this.HISTORY_ITEM, JSON.stringify(filteredList));
40+
}
41+
}
42+
43+
clearHistory() {
44+
const cleanup = [];
45+
this.setStorageItem(this.HISTORY_ITEM, JSON.stringify(cleanup));
46+
}
47+
48+
setStarred(id) {
49+
const queryList = this.getStorageItem(this.HISTORY_ITEM) || [];
50+
let found = queryList.find((f) => f.id === id);
51+
if (queryList.length > 0 && found) {
52+
const cleanup = [];
53+
queryList.forEach((query) => {
54+
if (query.id === id) {
55+
query.starred = !query.starred;
56+
}
57+
});
58+
this.setStorageItem(this.HISTORY_ITEM, JSON.stringify(cleanup));
59+
this.setStorageItem(this.HISTORY_ITEM, JSON.stringify(queryList));
60+
}
61+
}
62+
63+
64+
}
65+
66+
export default LocalStorageService;

src/theme/colors.js

Whitespace-only changes.

0 commit comments

Comments
 (0)