Skip to content

Commit c8a0dd9

Browse files
authored
Merge pull request #27 from SwapnilTechVariable/bug/v2-logs-related-frontend
Bug/v2 logs related frontend
2 parents e322219 + f4895b1 commit c8a0dd9

File tree

9 files changed

+137
-109
lines changed

9 files changed

+137
-109
lines changed

src/components.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export namespace Components {
3131
"togglesort": any;
3232
}
3333
interface CodeEditor {
34+
"formatter": Function;
3435
"onClickRun": Function;
3536
}
3637
interface DataTable {
@@ -606,6 +607,7 @@ declare namespace LocalJSX {
606607
"togglesort"?: any;
607608
}
608609
interface CodeEditor {
610+
"formatter"?: Function;
609611
"onClickRun"?: Function;
610612
}
611613
interface DataTable {

src/components/editorPage/code-editor/code-editor.tsx

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const TAB_LIST = [
1717
})
1818
export class CodeEditor {
1919
@Prop() onClickRun: Function;
20+
@Prop() formatter: Function;
2021

2122
@State() activeIndex: number = 0;
2223
@State() refreshLoading: boolean = false;
@@ -63,21 +64,21 @@ export class CodeEditor {
6364

6465
onCtrlShiftEnter() {
6566
let runTemp = this.onClickRun;
66-
return keymap.of([
67-
{
68-
key: 'Ctrl-Shift-Enter',
69-
run() {
70-
runTemp();
71-
return true;
72-
},
67+
return keymap.of([
68+
{
69+
key: 'Ctrl-Shift-Enter',
70+
run() {
71+
runTemp();
72+
return true;
7373
},
74-
]);
74+
},
75+
]);
7576
}
7677

7778
render() {
7879
return (
7980
<Host>
80-
<div class="w-full flex content-between" style={{ justifyContent: 'space-between' }}>
81+
<div class="px-3 w-full flex content-between" style={{ justifyContent: 'space-between' }}>
8182
<tabs-component activeIndex={this.activeIndex} tabslist={TAB_LIST} tabClickHandler={this.tabClickHandler}></tabs-component>
8283
<button
8384
class={this.btnClassType[`${this.refreshLoading}`]}
@@ -98,7 +99,7 @@ export class CodeEditor {
9899
</button>
99100
</div>
100101
{/* <tabs-component activeIndex={this.activeIndex} tabslist={TAB_LIST} tabClickHandler={this.tabClickHandler}></tabs-component> */}
101-
<div class="border border-gray-300 shadow-gray-300 p-3">
102+
<div class="border rounded-md border-gray-300 shadow-gray-300 p-3">
102103
<div style={{ maxHeight: '13rem', overflowY: 'auto' }} class="border-2">
103104
{TAB_LIST.map(item =>
104105
item.className === 'editor' ? (
@@ -110,17 +111,35 @@ export class CodeEditor {
110111
</div>
111112
{state.isError ? <p class="px-3 py-2 bg-red-200 text-red-800 border-l-4 border-red-600 w-full mt-4 mb-6">{state.errorMessage || 'Something went wrong!!!'}</p> : null}
112113
<div class="flex justify-between">
113-
<button
114-
title="Ctrl+Shift+Enter to run"
115-
disabled={state.syncVal === ''}
116-
onClick={() => this.onClickRun()}
117-
class="flex text-sm gap-2 items-center justify-center text-gray-600 border border-gray-300 px-3 mt-2 py-2 hover:bg-gray-200 disabled:text-gray-300 disabled:cursor-default disabled:hover:text-gray-200"
118-
>
119-
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
120-
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM9.555 7.168A1 1 0 008 8v4a1 1 0 001.555.832l3-2a1 1 0 000-1.664l-3-2z" clip-rule="evenodd" />
121-
</svg>
122-
Run
123-
</button>
114+
<div class="flex gap-4">
115+
<button
116+
title="Ctrl+Shift+Enter to run"
117+
disabled={state.syncVal === ''}
118+
onClick={() => this.onClickRun()}
119+
class="w-24 rounded-md flex text-sm gap-2 items-center justify-center text-gray-600 border border-gray-300 px-3 mt-2 py-2 hover:bg-gray-200 disabled:text-gray-300 disabled:cursor-default disabled:hover:text-gray-200"
120+
>
121+
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
122+
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM9.555 7.168A1 1 0 008 8v4a1 1 0 001.555.832l3-2a1 1 0 000-1.664l-3-2z" clip-rule="evenodd" />
123+
</svg>
124+
Run
125+
</button>
126+
127+
<button
128+
disabled={state.syncVal === ''}
129+
onClick={() => this.formatter()}
130+
class="flex w-24 rounded-md text-sm gap-2 items-center justify-center text-gray-600 border border-gray-300 px-3 mt-2 py-2 hover:bg-gray-200 disabled:text-gray-300 disabled:cursor-default disabled:hover:text-gray-200"
131+
>
132+
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
133+
<path
134+
stroke-linecap="round"
135+
stroke-linejoin="round"
136+
d="M14.25 9.75L16.5 12l-2.25 2.25m-4.5 0L7.5 12l2.25-2.25M6 20.25h12A2.25 2.25 0 0020.25 18V6A2.25 2.25 0 0018 3.75H6A2.25 2.25 0 003.75 6v12A2.25 2.25 0 006 20.25z"
137+
/>
138+
</svg>
139+
Format
140+
</button>
141+
</div>
142+
124143
<div>
125144
{state.isLoading && <loader-component></loader-component>}
126145
{state.timeTaken !== null && <p class="pt-4 font-semibold text-xs text-green-700">Executed in {state.timeTaken} ms</p>}

src/components/editorPage/code-editor/readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
| Property | Attribute | Description | Type | Default |
1111
| ------------ | --------- | ----------- | ---------- | ----------- |
12+
| `formatter` | -- | | `Function` | `undefined` |
1213
| `onClickRun` | -- | | `Function` | `undefined` |
1314

1415

src/components/editorPage/editor-page/editor-page.tsx

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { Component, h, Prop, State } from '@stencil/core';
33

44
import { isValidParameterJson } from '../../../utils/utils';
55
import state from '../store';
6+
import { formatQuery } from 'gremlint';
7+
import { formatJSON } from '../../../utils/utils';
68

79
@Component({
810
tag: 'editor-page',
@@ -44,13 +46,29 @@ export class EditorPage {
4446
});
4547
};
4648

47-
// animatingClass = ``
48-
4949
btnClassType = {
5050
true: `mr-4 animate-spin`,
5151
false: `mr-4`,
5252
};
5353

54+
formatter = () => {
55+
let transactionQuery = state.viewQuery.state.update();
56+
const query = transactionQuery.state.doc.toString().trim();
57+
58+
let transactionToFormatQuery = state.viewQuery.state.update({
59+
changes: { from: 0, to: state.viewQuery.state.doc.toString().length, insert: `${formatQuery(query)}` },
60+
});
61+
state.viewQuery.dispatch(transactionToFormatQuery);
62+
63+
let transactionParameter = state.viewParameter.state.update();
64+
const parameter = transactionParameter.state.doc.toString().trim();
65+
66+
let transactionToFormatParameter = state.viewParameter.state.update({
67+
changes: { from: 0, to: state.viewParameter.state.doc.toString().length, insert: `${formatJSON(JSON.parse(parameter))}` },
68+
});
69+
state.viewParameter.dispatch(transactionToFormatParameter);
70+
}
71+
5472
onClickRun = async () => {
5573
if (state.syncVal !== '') {
5674
state.selectedNodeName = null;
@@ -82,6 +100,7 @@ export class EditorPage {
82100
state.nodes = res.data.result;
83101
state.timeTaken = res.data.timeTaken;
84102
state.isFetchedData = true;
103+
this.formatter();
85104
} else {
86105
state.isError = true;
87106
state.errorMessage = error;
@@ -96,10 +115,9 @@ export class EditorPage {
96115
};
97116

98117
render() {
99-
console.debug({state})
100118
return (
101119
<div>
102-
<div class="w-full md:flex justify-center gap-4 mt-4">
120+
<div class="w-full md:flex justify-center gap-4 mt-4">
103121
<div>
104122
<aside class="w-full md:w-80" aria-label="Sidebar">
105123
<div class="w-full flex justify-between mb-4">
@@ -121,7 +139,7 @@ export class EditorPage {
121139
</div>
122140
<div class="w-full md:w-3/4">
123141
<h2 class="pb-3 font-mono text-lg font-bold leading-7 text-gray-600">Write your Gremlin Query Here</h2>
124-
<code-editor onClickRun={this.onClickRun}></code-editor>
142+
<code-editor formatter={this.formatter} onClickRun={this.onClickRun}></code-editor>
125143
{state.isFetchedData && state.nodes.length === 0 && !state.isLoading && !state.isError && (
126144
<div class="flex items-center bg-gray-500 text-white text-sm font-bold px-4 py-3" role="alert">
127145
<p>No Data Found in Database</p>

src/components/editorPage/store.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ onChange('nodes', value => {
7575
});
7676

7777
onChange('query', value => {
78-
console.log("l;kasjdkjashkdkjashdkk")
7978
if (state.viewQuery) {
8079
let transactionToAdd = state.viewQuery.state.update({
8180
changes: { from: 0, to: state.viewQuery.state.doc.toString().length, insert: `${value}` },

src/components/logsPage/logs-table/logs-table.tsx

Lines changed: 64 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,37 @@ export class LogsTable {
4242
this.from = (this.currentPage - 1) * this.limit + 1;
4343
this.to = this.currentPage * this.limit;
4444
}
45+
dataFormatter(id, item) {
46+
{
47+
if (id.click.clickable === false) {
48+
if (item[id.alias].length > 25 === true) {
49+
return item[id.alias].slice(0, 25) + '...';
50+
} else {
51+
if (/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z/.test(item[id.alias])) {
52+
return new Date(item[id.alias]).toString().split('(')[0]
53+
} else {
54+
if (id.alias === 'timeTaken') {
55+
return `${item[id.alias]} ms`;
56+
} else {
57+
return item[id.alias];
58+
}
59+
}
60+
}
61+
} else {
62+
if (id.alias === 'queryResult') {
63+
return (
64+
<a target="_blank" href={id.click.url + item[id.alias]} class="flex items-center py-1 px-4 text-base font-normal text-gray-900 rounded-lg bg-gray-200">
65+
<img class="h-4" src={id.click.icon} alt="icon" />
66+
<span class="px-2 ">View</span>
67+
</a>
68+
)}else if(id.alias === 'email'){
69+
return (<a href={id.click.url + item['ownerId']}>
70+
<span class="px-2 ">{item[id.alias]}</span>
71+
</a>)
72+
}
73+
}
74+
}
75+
}
4576

4677
render() {
4778
const trList = [];
@@ -103,22 +134,8 @@ export class LogsTable {
103134
this.tableBody.map((item: any) => (
104135
<tr class="hover:bg-gray-100 transition">
105136
{this.tableHeader.map((id: any) => (
106-
// <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{item[id.alias]}</td>
107137
<td text-overflow:ellipsis title={item[id.alias]} max-width="50px" class="px-6 py-3 whitespace-nowrap text-sm text-gray-900">
108-
{!id.click.clickable ? (
109-
item[id.alias].length > 25 ? (
110-
item[id.alias].slice(0, 25) + '...'
111-
) : /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z/.test(item[id.alias]) ? (
112-
item[id.alias].slice(0, 16).split('T')[0] + ' at ' + item[id.alias].slice(11, 19)
113-
) : (
114-
item[id.alias]
115-
)
116-
) : (
117-
<a target="_blank" href={id.click.url + item[id.alias]} class="flex items-center py-1 px-4 text-base font-normal text-gray-900 rounded-lg bg-gray-200">
118-
<img class="h-4" src={id.click.icon} alt="icon" />
119-
<span class="px-2 ">View</span>
120-
</a>
121-
)}
138+
{this.dataFormatter(id, item)}
122139
</td>
123140
))}
124141
</tr>
@@ -139,47 +156,41 @@ export class LogsTable {
139156
)}
140157
</table>
141158
</div>
142-
<div style={{maxWidth: '75rem'}} class="bg-gray-100 sticky bottom-0">
143-
<div class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
144-
<div class="flex justify-between items-center">
145-
{/* pagination description */}
146-
<p>
147-
Showing <strong>{this.from}</strong> to <strong>{this.to <= Number(this.dataLength) ? this.to : this.dataLength}</strong> of{' '}
148-
<strong>{this.dataLength}</strong> results
149-
</p>
159+
<div style={{ maxWidth: '75rem' }} class="bg-gray-100 sticky bottom-0">
160+
<div class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
161+
<div class="flex justify-between items-center">
162+
{/* pagination description */}
163+
<p>
164+
Showing <strong>{this.from}</strong> to <strong>{this.to <= Number(this.dataLength) ? this.to : this.dataLength}</strong> of <strong>{this.dataLength}</strong>{' '}
165+
results
166+
</p>
150167

151-
{/* rows per page */}
152-
<div class="space-x-3">
153-
<span>Rows per page</span>
154-
<select
155-
onChange={e => this.rowsHandler(e)}
156-
class="form-select px-3 py-1.5 border-none text-inherit font-inherit text-gray-700 bg-transparent bg-clip-padding bg-no-repeat rounded transition ease-in-out focus:text-gray-700 focus:bg-white focus:border-blue-600 focus:outline-none"
157-
>
158-
{this.rows.map(row => (
159-
<option value={`${row}`}>{row}</option>
160-
))}
161-
</select>
162-
</div>
168+
{/* rows per page */}
169+
<div class="space-x-3">
170+
<span>Rows per page</span>
171+
<select
172+
onChange={e => this.rowsHandler(e)}
173+
class="form-select px-3 py-1.5 border-none text-inherit font-inherit text-gray-700 bg-transparent bg-clip-padding bg-no-repeat rounded transition ease-in-out focus:text-gray-700 focus:bg-white focus:border-blue-600 focus:outline-none"
174+
>
175+
{this.rows.map(row => (
176+
<option value={`${row}`}>{row}</option>
177+
))}
178+
</select>
179+
</div>
163180

164-
{/* pagination navigation menu */}
165-
<nav class="flex gap-4 items-center">
166-
<plain-button color="gray-500" type="text" clickHandler={() => this.prev()} disabledHandler={this.currentPage === 1} addClass="disabled:opacity-50">
167-
prev
168-
</plain-button>
169-
<plain-button
170-
color="gray-500"
171-
type="text"
172-
clickHandler={() => this.next()}
173-
disabledHandler={parseInt(this.dataLength) <= this.to}
174-
addClass="disabled:opacity-50"
175-
>
176-
next
177-
</plain-button>
178-
</nav>
179-
</div>
180-
</div>
181-
{this.isLoading && <td class="text-gray-500">&nbsp;</td>}
181+
{/* pagination navigation menu */}
182+
<nav class="flex gap-4 items-center">
183+
<plain-button color="gray-500" type="text" clickHandler={() => this.prev()} disabledHandler={this.currentPage === 1} addClass="disabled:opacity-50">
184+
prev
185+
</plain-button>
186+
<plain-button color="gray-500" type="text" clickHandler={() => this.next()} disabledHandler={parseInt(this.dataLength) <= this.to} addClass="disabled:opacity-50">
187+
next
188+
</plain-button>
189+
</nav>
182190
</div>
191+
</div>
192+
{this.isLoading && <td class="text-gray-500">&nbsp;</td>}
193+
</div>
183194
</div>
184195
);
185196
}

src/components/logsPage/query-logs/query-logs.tsx

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,6 @@ import state from '../../editorPage/store';
88
})
99
export class QueryLogs {
1010
@State() headerList = [
11-
{
12-
title: 'id',
13-
filter: {
14-
searchable: false,
15-
sortable: false,
16-
},
17-
alias: 'id',
18-
click: {
19-
clickable: false,
20-
},
21-
},
2211
{
2312
title: 'query_text',
2413
filter: {
@@ -52,17 +41,6 @@ export class QueryLogs {
5241
clickable: false,
5342
},
5443
},
55-
{
56-
title: 'query_status',
57-
filter: {
58-
searchable: true,
59-
sortable: true,
60-
},
61-
alias: 'queryStatus',
62-
click: {
63-
clickable: false,
64-
},
65-
},
6644
{
6745
title: 'time_of_execution',
6846
filter: {
@@ -93,7 +71,8 @@ export class QueryLogs {
9371
},
9472
alias: 'email',
9573
click: {
96-
clickable: false,
74+
clickable: true,
75+
url: '/users/',
9776
},
9877
},
9978
{
@@ -141,7 +120,6 @@ export class QueryLogs {
141120
}
142121
}
143122
const result = await axios.get(`${state.url}/api/editor/query/logs?${filterPar}`);
144-
145123
return {
146124
total: result.data.total,
147125
data: result.data,

0 commit comments

Comments
 (0)