slick-table 1.2.0 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +117 -115
- package/dist/index.es.js +26774 -23417
- package/dist/styles/icons.scss +4 -0
- package/dist/types/entities/popup-query/index.d.ts +2 -0
- package/dist/types/entities/popup-query/index.d.ts.map +1 -0
- package/dist/types/entities/popup-query/lib/hooks/index.d.ts +2 -0
- package/dist/types/entities/popup-query/lib/hooks/index.d.ts.map +1 -0
- package/dist/types/entities/popup-query/lib/hooks/useSubscribeToEvent.d.ts +3 -0
- package/dist/types/entities/popup-query/lib/hooks/useSubscribeToEvent.d.ts.map +1 -0
- package/dist/types/entities/popup-query/lib/index.d.ts +3 -0
- package/dist/types/entities/popup-query/lib/index.d.ts.map +1 -0
- package/dist/types/entities/popup-query/lib/table/index.d.ts +2 -0
- package/dist/types/entities/popup-query/lib/table/index.d.ts.map +1 -0
- package/dist/types/entities/popup-query/lib/table/tableQuery.d.ts +3 -0
- package/dist/types/entities/popup-query/lib/table/tableQuery.d.ts.map +1 -0
- package/dist/types/entities/popup-query/model/consts/id.d.ts +2 -0
- package/dist/types/entities/popup-query/model/consts/id.d.ts.map +1 -0
- package/dist/types/entities/popup-query/model/consts/index.d.ts +2 -0
- package/dist/types/entities/popup-query/model/consts/index.d.ts.map +1 -0
- package/dist/types/entities/popup-query/model/index.d.ts +3 -0
- package/dist/types/entities/popup-query/model/index.d.ts.map +1 -0
- package/dist/types/entities/popup-query/model/types/ITotal.d.ts +10 -0
- package/dist/types/entities/popup-query/model/types/ITotal.d.ts.map +1 -0
- package/dist/types/entities/popup-query/model/types/index.d.ts +2 -0
- package/dist/types/entities/popup-query/model/types/index.d.ts.map +1 -0
- package/dist/types/entities/popup-query/ui/PopupQuery.d.ts +7 -0
- package/dist/types/entities/popup-query/ui/PopupQuery.d.ts.map +1 -0
- package/dist/types/entities/popup-query/ui/PopupQuery.style.d.ts +29 -0
- package/dist/types/entities/popup-query/ui/PopupQuery.style.d.ts.map +1 -0
- package/dist/types/entities/popup-query/ui/index.d.ts +2 -0
- package/dist/types/entities/popup-query/ui/index.d.ts.map +1 -0
- package/dist/types/entities/popup-summary/ui/PopupSummary.style.d.ts +1 -1
- package/dist/types/features/column-filters/ui/ButtonReset/ButtonReset.style.d.ts +1 -1
- package/dist/types/features/context-menu/ui/ButtonQuery/index.d.ts +2 -0
- package/dist/types/features/context-menu/ui/ButtonQuery/index.d.ts.map +1 -0
- package/dist/types/features/context-menu/ui/ButtonQuery/ui/ButtonQuery.d.ts +7 -0
- package/dist/types/features/context-menu/ui/ButtonQuery/ui/ButtonQuery.d.ts.map +1 -0
- package/dist/types/features/context-menu/ui/ButtonQuery/ui/index.d.ts +2 -0
- package/dist/types/features/context-menu/ui/ButtonQuery/ui/index.d.ts.map +1 -0
- package/dist/types/features/context-menu/ui/ContextMenu.d.ts.map +1 -1
- package/dist/types/features/header-context-menu/ui/Item/Item.style.d.ts +1 -1
- package/dist/types/shared/lib/dom/doNotForwardProps.d.ts +2 -0
- package/dist/types/shared/lib/dom/doNotForwardProps.d.ts.map +1 -0
- package/dist/types/shared/lib/dom/index.d.ts +1 -0
- package/dist/types/shared/lib/dom/index.d.ts.map +1 -1
- package/dist/types/shared/lib/slickgrid/index.d.ts +1 -1
- package/dist/types/shared/lib/slickgrid/index.d.ts.map +1 -1
- package/dist/types/shared/lib/slickgrid/model/events/eventQuery.d.ts +15 -0
- package/dist/types/shared/lib/slickgrid/model/events/eventQuery.d.ts.map +1 -0
- package/dist/types/shared/lib/slickgrid/model/events/index.d.ts +1 -0
- package/dist/types/shared/lib/slickgrid/model/events/index.d.ts.map +1 -1
- package/dist/types/shared/lib/slickgrid/model/index.d.ts +1 -1
- package/dist/types/shared/lib/slickgrid/model/index.d.ts.map +1 -1
- package/dist/types/shared/lib/slickgrid/ui/SlickgridTable/ui/SlickgridTable.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/app/styles/icons.scss +4 -0
- package/src/entities/popup-query/index.ts +1 -0
- package/src/entities/popup-query/lib/hooks/index.ts +1 -0
- package/src/entities/popup-query/lib/hooks/useSubscribeToEvent.ts +24 -0
- package/src/entities/popup-query/lib/index.ts +2 -0
- package/src/entities/popup-query/lib/table/index.ts +1 -0
- package/src/entities/popup-query/lib/table/tableQuery.ts +3 -0
- package/src/entities/popup-query/model/consts/id.ts +1 -0
- package/src/entities/popup-query/model/consts/index.ts +1 -0
- package/src/entities/popup-query/model/index.ts +2 -0
- package/src/entities/popup-query/model/types/ITotal.ts +23 -0
- package/src/entities/popup-query/model/types/index.ts +1 -0
- package/src/entities/popup-query/ui/PopupQuery.style.ts +95 -0
- package/src/entities/popup-query/ui/PopupQuery.tsx +160 -0
- package/src/entities/popup-query/ui/index.ts +1 -0
- package/src/features/context-menu/ui/ButtonQuery/index.ts +1 -0
- package/src/features/context-menu/ui/ButtonQuery/ui/ButtonQuery.tsx +28 -0
- package/src/features/context-menu/ui/ButtonQuery/ui/index.ts +1 -0
- package/src/features/context-menu/ui/ContextMenu.tsx +2 -0
- package/src/shared/lib/dom/doNotForwardProps.ts +5 -0
- package/src/shared/lib/dom/index.ts +1 -0
- package/src/shared/lib/slickgrid/index.ts +1 -0
- package/src/shared/lib/slickgrid/model/events/eventQuery.ts +26 -0
- package/src/shared/lib/slickgrid/model/events/index.ts +1 -0
- package/src/shared/lib/slickgrid/model/index.ts +1 -0
- package/src/shared/lib/slickgrid/ui/SlickgridTable/lib/callbacks/onActiveCellChanged.ts +18 -18
- package/src/shared/lib/slickgrid/ui/SlickgridTable/ui/SlickgridTable.tsx +2 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { Box, IconButton } from "@mui/material";
|
|
2
|
+
import { GvizTable } from "myworkql";
|
|
3
|
+
import { ChangeEvent, FC, MouseEvent, useRef, useState } from "react";
|
|
4
|
+
import { SlickDataView } from "slickgrid";
|
|
5
|
+
|
|
6
|
+
import { SlickgridTable, eventQuery } from "shared/lib/slickgrid";
|
|
7
|
+
import { CHECKBOX_SELECTOR } from "shared/model/consts";
|
|
8
|
+
import { IColumn } from "shared/model/types";
|
|
9
|
+
|
|
10
|
+
import { tableQuery, useSubscribeToEvent } from "../lib";
|
|
11
|
+
|
|
12
|
+
import Styled from "./PopupQuery.style";
|
|
13
|
+
|
|
14
|
+
export const PopupQuery: FC<Props> = ({ tableId }) => {
|
|
15
|
+
const [query, setQuery] = useState(`select * where hours > 7`);
|
|
16
|
+
const [isOpened, setIsOpened] = useState(false);
|
|
17
|
+
const [isExpanded, setIsExpanded] = useState(false);
|
|
18
|
+
const [items, setItems] = useState<Record<string, any>[]>([]);
|
|
19
|
+
const [columns, setColumns] = useState<IColumn[]>([]);
|
|
20
|
+
const queryInputRef = useRef<HTMLTextAreaElement>(null);
|
|
21
|
+
|
|
22
|
+
function getColumNames(): IColumn[] {
|
|
23
|
+
const table = eventQuery.table;
|
|
24
|
+
if (!table) return [];
|
|
25
|
+
const grid = table.grid;
|
|
26
|
+
if (!grid) return [];
|
|
27
|
+
return grid
|
|
28
|
+
.getColumns()
|
|
29
|
+
.filter(
|
|
30
|
+
({ id, name }) =>
|
|
31
|
+
typeof name === "string" &&
|
|
32
|
+
id !== CHECKBOX_SELECTOR &&
|
|
33
|
+
id !== "isEdited",
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function onClose() {
|
|
38
|
+
eventQuery.open = false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function updateQuery(event: ChangeEvent<HTMLTextAreaElement>) {
|
|
42
|
+
setQuery(event.target.value);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function pasteColumnId(event: MouseEvent<HTMLSpanElement>) {
|
|
46
|
+
const columnId = event.currentTarget.id;
|
|
47
|
+
if (!columnId) return;
|
|
48
|
+
const input = queryInputRef.current;
|
|
49
|
+
if (!input) return;
|
|
50
|
+
const start = input.selectionStart ?? query.length;
|
|
51
|
+
const end = input.selectionEnd ?? query.length;
|
|
52
|
+
setQuery(query.slice(0, start) + columnId + query.slice(end));
|
|
53
|
+
const caret = start + columnId.length;
|
|
54
|
+
requestAnimationFrame(() => {
|
|
55
|
+
input.focus();
|
|
56
|
+
input.setSelectionRange(caret, caret);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function executeQuery() {
|
|
61
|
+
const table = eventQuery.table;
|
|
62
|
+
if (!table) return;
|
|
63
|
+
const grid = table.grid;
|
|
64
|
+
if (!grid) return;
|
|
65
|
+
const dataView: SlickDataView = grid.getData();
|
|
66
|
+
const items = dataView.getItems();
|
|
67
|
+
const idPropertyName = dataView.getIdPropertyName();
|
|
68
|
+
const itemsCopy = [...items];
|
|
69
|
+
for (const item of itemsCopy) {
|
|
70
|
+
delete item[idPropertyName];
|
|
71
|
+
}
|
|
72
|
+
const gvizTable = new GvizTable(itemsCopy);
|
|
73
|
+
const run = gvizTable.query(query);
|
|
74
|
+
const newItems = run.toObjects();
|
|
75
|
+
setItems(newItems);
|
|
76
|
+
setColumns(
|
|
77
|
+
Object.keys(newItems[0]).map(
|
|
78
|
+
(key): IColumn => ({
|
|
79
|
+
id: key,
|
|
80
|
+
field: key,
|
|
81
|
+
name: key
|
|
82
|
+
.split(" ")
|
|
83
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
84
|
+
.join(" "),
|
|
85
|
+
}),
|
|
86
|
+
),
|
|
87
|
+
);
|
|
88
|
+
setIsExpanded(true);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
useSubscribeToEvent(setIsOpened, tableId);
|
|
92
|
+
|
|
93
|
+
if (!isOpened) return null;
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<Styled.Drawer anchor={"bottom"} open={isOpened} onClose={onClose}>
|
|
97
|
+
<Box>
|
|
98
|
+
<Styled.Header>
|
|
99
|
+
<Styled.Title variant={"h6"}>
|
|
100
|
+
Run query across table data
|
|
101
|
+
</Styled.Title>
|
|
102
|
+
<Box>
|
|
103
|
+
{isExpanded && (
|
|
104
|
+
<IconButton onClick={() => setIsExpanded(false)}>
|
|
105
|
+
<span className={"sgi sgi-minus"}></span>
|
|
106
|
+
</IconButton>
|
|
107
|
+
)}
|
|
108
|
+
{!isExpanded && (
|
|
109
|
+
<IconButton onClick={() => setIsExpanded(true)}>
|
|
110
|
+
<span className={"sgi sgi-arrow-expand"}></span>
|
|
111
|
+
</IconButton>
|
|
112
|
+
)}
|
|
113
|
+
<IconButton onClick={onClose}>
|
|
114
|
+
<span className={"sgi sgi-close"}></span>
|
|
115
|
+
</IconButton>
|
|
116
|
+
</Box>
|
|
117
|
+
</Styled.Header>
|
|
118
|
+
<Styled.ContainerInput>
|
|
119
|
+
<Styled.TextField
|
|
120
|
+
id="query-input"
|
|
121
|
+
label="Query"
|
|
122
|
+
maxRows={10}
|
|
123
|
+
multiline
|
|
124
|
+
onChange={updateQuery}
|
|
125
|
+
inputRef={queryInputRef}
|
|
126
|
+
value={query}
|
|
127
|
+
/>
|
|
128
|
+
<Styled.Button variant={"contained"} onClick={executeQuery}>
|
|
129
|
+
Execute
|
|
130
|
+
</Styled.Button>
|
|
131
|
+
</Styled.ContainerInput>
|
|
132
|
+
<Box sx={{ display: "flex", columnGap: "1em", marginBottom: "1em" }}>
|
|
133
|
+
{getColumNames().map(({ id, name }) => (
|
|
134
|
+
<Styled.ColumnName
|
|
135
|
+
key={id}
|
|
136
|
+
id={id as string}
|
|
137
|
+
onClick={pasteColumnId}
|
|
138
|
+
>
|
|
139
|
+
{`#${name}`}
|
|
140
|
+
</Styled.ColumnName>
|
|
141
|
+
))}
|
|
142
|
+
</Box>
|
|
143
|
+
</Box>
|
|
144
|
+
<Styled.ContainerTable isExpanded={isExpanded}>
|
|
145
|
+
{!!columns.length && (
|
|
146
|
+
<SlickgridTable
|
|
147
|
+
assignIds={true}
|
|
148
|
+
columns={columns}
|
|
149
|
+
items={items}
|
|
150
|
+
table={tableQuery}
|
|
151
|
+
/>
|
|
152
|
+
)}
|
|
153
|
+
</Styled.ContainerTable>
|
|
154
|
+
</Styled.Drawer>
|
|
155
|
+
);
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
interface Props {
|
|
159
|
+
tableId: string;
|
|
160
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PopupQuery } from "./PopupQuery";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ButtonQuery } from "./ui";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Dispatch, FC, SetStateAction } from "react";
|
|
2
|
+
|
|
3
|
+
import { eventContextMenu, eventQuery } from "shared/lib/slickgrid";
|
|
4
|
+
|
|
5
|
+
import Styled from "../../ContextMenu.style";
|
|
6
|
+
|
|
7
|
+
export const ButtonQuery: FC<Props> = ({ setIsOpened }) => {
|
|
8
|
+
const table = eventContextMenu.table;
|
|
9
|
+
|
|
10
|
+
function openModalWindow() {
|
|
11
|
+
setIsOpened(false);
|
|
12
|
+
eventQuery.table = table;
|
|
13
|
+
eventQuery.open = true;
|
|
14
|
+
eventQuery.x = eventContextMenu.x;
|
|
15
|
+
eventQuery.y = eventContextMenu.y;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<Styled.Li onClick={openModalWindow}>
|
|
20
|
+
<Styled.Icon className={"sgi sgi-table-large"}></Styled.Icon>
|
|
21
|
+
Run query
|
|
22
|
+
</Styled.Li>
|
|
23
|
+
);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
interface Props {
|
|
27
|
+
setIsOpened: Dispatch<SetStateAction<boolean>>;
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ButtonQuery } from "./ButtonQuery";
|
|
@@ -7,6 +7,7 @@ import { useSubscribeToEvent } from "../lib";
|
|
|
7
7
|
import { CONTEXT_MENU } from "../model";
|
|
8
8
|
import { ButtonDownloadCSV } from "./ButtonDownloadCSV";
|
|
9
9
|
import { ButtonGroup } from "./ButtonGroup";
|
|
10
|
+
import { ButtonQuery } from "./ButtonQuery";
|
|
10
11
|
import { ButtonResetFilters } from "./ButtonResetFilters";
|
|
11
12
|
import { ButtonSummary } from "./ButtonSummary";
|
|
12
13
|
import { ButtonUngroup } from "./ButtonUngroup";
|
|
@@ -43,6 +44,7 @@ export const ContextMenu: FC<Props> = ({ tableId }) => {
|
|
|
43
44
|
<ButtonSummary setIsOpened={setIsOpened} />
|
|
44
45
|
<CopyRows setIsOpened={setIsOpened} />
|
|
45
46
|
<PasteRows setIsOpened={setIsOpened} />
|
|
47
|
+
<ButtonQuery setIsOpened={setIsOpened} />
|
|
46
48
|
</Styled.Ul>
|
|
47
49
|
</Popup>
|
|
48
50
|
</Fragment>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { AnEvent } from "shared/lib/an-event";
|
|
2
|
+
import { ISlickTable } from "shared/model/types";
|
|
3
|
+
|
|
4
|
+
class EventQuery extends AnEvent {
|
|
5
|
+
private _open = false;
|
|
6
|
+
private _table: ISlickTable | undefined;
|
|
7
|
+
x = 0;
|
|
8
|
+
y = 0;
|
|
9
|
+
|
|
10
|
+
get open() {
|
|
11
|
+
return this._open;
|
|
12
|
+
}
|
|
13
|
+
set open(open) {
|
|
14
|
+
this._open = open;
|
|
15
|
+
this.notify();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
get table() {
|
|
19
|
+
return this._table;
|
|
20
|
+
}
|
|
21
|
+
set table(table) {
|
|
22
|
+
this._table = table;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const eventQuery = new EventQuery();
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Handler,
|
|
3
|
-
OnActiveCellChangedEventArgs,
|
|
4
|
-
SlickEventData,
|
|
5
|
-
} from "slickgrid";
|
|
6
|
-
|
|
7
|
-
import { ISlickTable } from "shared/model/types";
|
|
8
|
-
|
|
9
|
-
export function getOnActiveCellChanged(
|
|
10
|
-
table: ISlickTable,
|
|
11
|
-
): Handler<OnActiveCellChangedEventArgs> {
|
|
12
|
-
return function onActiveCellChanged({
|
|
13
|
-
//@ts-expect-error. Property 'args' is protected and only accessible within class 'SlickEventData<ArgType>' and its subclasses
|
|
14
|
-
args,
|
|
15
|
-
}: SlickEventData<OnActiveCellChangedEventArgs>): void {
|
|
16
|
-
table.lastActiveSell = { cell: args?.cell || 0, row: args?.row || 0 };
|
|
17
|
-
};
|
|
18
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
Handler,
|
|
3
|
+
OnActiveCellChangedEventArgs,
|
|
4
|
+
SlickEventData,
|
|
5
|
+
} from "slickgrid";
|
|
6
|
+
|
|
7
|
+
import { ISlickTable } from "shared/model/types";
|
|
8
|
+
|
|
9
|
+
export function getOnActiveCellChanged(
|
|
10
|
+
table: ISlickTable,
|
|
11
|
+
): Handler<OnActiveCellChangedEventArgs> {
|
|
12
|
+
return function onActiveCellChanged({
|
|
13
|
+
//@ts-expect-error. Property 'args' is protected and only accessible within class 'SlickEventData<ArgType>' and its subclasses
|
|
14
|
+
args,
|
|
15
|
+
}: SlickEventData<OnActiveCellChangedEventArgs>): void {
|
|
16
|
+
table.lastActiveSell = { cell: args?.cell || 0, row: args?.row || 0 };
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { FC } from "react";
|
|
2
2
|
|
|
3
|
+
import { PopupQuery } from "entities/popup-query";
|
|
3
4
|
import { PopupSummary } from "entities/popup-summary";
|
|
4
5
|
|
|
5
6
|
import { ColumnFilters } from "features/column-filters";
|
|
@@ -67,6 +68,7 @@ export const SlickgridTable: FC<Props> = ({
|
|
|
67
68
|
<ColumnFilters tableId={table.id} />
|
|
68
69
|
<ContextMenu tableId={table.id} />
|
|
69
70
|
<PopupSummary tableId={table.id} />
|
|
71
|
+
<PopupQuery tableId={table.id} />
|
|
70
72
|
</Styled.Wrapper>
|
|
71
73
|
);
|
|
72
74
|
};
|