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

Session List #3132

Merged
merged 28 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d14fd4d
Renamed session to session-location
jameskerr Jul 15, 2024
7f60573
Session Models Snapshot Models
jameskerr Jul 15, 2024
212cc03
No Typescript Errors
jameskerr Jul 18, 2024
c295ce4
Revert "Renamed session to session-location"
jameskerr Jul 18, 2024
59d6d36
Revert
jameskerr Jul 18, 2024
a8dec34
Create a QuerySession entity
jameskerr Jul 19, 2024
336799c
Merge remote-tracking branch 'origin/main' into session-list
jameskerr Jul 19, 2024
364221e
Start creating query session objects in the store
jameskerr Jul 19, 2024
895ce3f
Persist the query sessions'
jameskerr Jul 19, 2024
e166b1b
Allow a tab to be activated from the sessions pane
jameskerr Jul 19, 2024
a2b21c2
Back up History changes
jameskerr Jul 19, 2024
7b10553
Session List MVP
jameskerr Jul 22, 2024
0ac8765
Use bullet from github
jameskerr Jul 22, 2024
15eed29
Fix Tests
jameskerr Jul 22, 2024
35106f3
Back out snapshot for now
jameskerr Jul 22, 2024
01376ae
Prevent a dependency loop
jameskerr Jul 22, 2024
d8800df
Add the migration
jameskerr Jul 22, 2024
08d7b07
Make these global
jameskerr Jul 22, 2024
ffdbe77
Create query here too
jameskerr Jul 22, 2024
ece6617
Write the migration for the query_sessions
jameskerr Jul 23, 2024
787f9c5
Fix lint and migration
jameskerr Jul 23, 2024
1c73048
Dont create a new reference here
jameskerr Jul 23, 2024
0babafa
Use Bullet 0.0.2
jameskerr Jul 25, 2024
7ae1542
Fix tab removal logic
jameskerr Aug 9, 2024
41388c4
Update migration
jameskerr Aug 15, 2024
bb22432
Merge remote-tracking branch 'origin/main' into session-list
jameskerr Aug 15, 2024
3e1ea2e
Merge remote-tracking branch 'origin/main' into session-list
jameskerr Aug 15, 2024
8533eba
Update state values
jameskerr Aug 15, 2024
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
10 changes: 10 additions & 0 deletions apps/zui/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,21 @@ const moduleNameMapper = pathsToModuleNameMapper(config.compilerOptions.paths, {
prefix: "<rootDir>/../../",
})

const esModules = [
"bullet",
"@reduxjs/toolkit",
"immer",
"redux",
"lodash-es",
].join("|")
// https://github.com/gravitational/teleport/issues/33810

module.exports = {
transform: {
"^.+\\.(t|j)sx?$": ["@swc/jest"],
".+\\.(css|styl|less|sass|scss)$": "jest-css-modules-transform",
},
transformIgnorePatterns: [`/node_modules/(?!${esModules})`],
setupFiles: ["./src/test/unit/setup/before-env.ts"],
setupFilesAfterEnv: ["./src/test/unit/setup/after-env.ts"],
testEnvironmentOptions: {
Expand Down
1 change: 1 addition & 0 deletions apps/zui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"ajv": "^6.9.1",
"animejs": "^3.2.0",
"brimcap": "brimdata/brimcap#0c3a564771dd204e9ce93e4600de2dbcf97bd446",
"bullet": "^0.0.2",
"chalk": "^4.1.0",
"chevrotain": "^10.5.0",
"chrono-node": "^2.5.0",
Expand Down
1 change: 0 additions & 1 deletion apps/zui/src/components/drag-anchor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ export default class DragAnchor extends React.Component<Props> {
className={classNames(
`align-${this.props.position}`,
this.props.className,

{
debug: this.props.debug,
showOnHover: this.props.showOnHover,
Expand Down
2 changes: 1 addition & 1 deletion apps/zui/src/components/icon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function Icon(props: Props) {

return (
<svg
className={classNames("icon", styles.icon)}
className={classNames("icon", styles.icon, props.className)}
fill={props.fill || "currentColor"}
style={style}
>
Expand Down
4 changes: 4 additions & 0 deletions apps/zui/src/css/_utilities.scss
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,7 @@
overflow: hidden;
text-overflow: ellipsis;
}

.list-none {
list-style-type: none;
}
12 changes: 6 additions & 6 deletions apps/zui/src/css/blocks/_sidebar-item.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.sidebar-item {
list-style-type: none;
border-radius: 6px;
width: 100%;
cursor: default;
Expand All @@ -15,14 +16,13 @@
--selected-border: var(--primary-color-dark);
}

.sidebar-item:hover {
background-color: inherit;
filter: var(--hover-filter);
.sidebar-item:hover,
.sidebar-item:active {
background-color: var(--emphasis-bg-less);
}

.sidebar-item:active {
background-color: inherit;
filter: var(--active-filter);
transform: scale(0.995);
}

.sidebar-item[aria-selected="true"] {
Expand All @@ -35,5 +35,5 @@
.white-selection {
--selected-bg: white;
--selected-color: var(--fg-color);
--selected-border: var(--border-color);
--selected-border: transparent;
}
4 changes: 4 additions & 0 deletions apps/zui/src/css/compositions/_gutter.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@
.gutter-inline-end {
padding-inline-end: var(--gutter);
}

.gutter-inline-start {
padding-inline-start: var(--gutter);
}
2 changes: 1 addition & 1 deletion apps/zui/src/css/utilities/_flex.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
align-items: center;
}

.flex-shrink-0 {
.shrink-0 {
flex-shrink: 0;
}

Expand Down
2 changes: 2 additions & 0 deletions apps/zui/src/js/initializers/init-domain-models.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {DomainModel} from "src/core/domain-model"
import {Store} from "../state/types"
import {Entity} from "bullet"

export function initDomainModels(args: {store: Store}) {
DomainModel.store = args.store
Entity.store = args.store
}
2 changes: 1 addition & 1 deletion apps/zui/src/js/state/Appearance/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export type HistoryView = "tree" | "linear"
export type SectionName = "pools" | "queries" | "history"
export type SectionName = "pools" | "queries" | "sessions"
export type OpenMap = {[id: string]: boolean}
14 changes: 4 additions & 10 deletions apps/zui/src/js/state/QueryVersions/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import {
createNestedEntitySlice,
initialState,
} from "../entity-slice/create-entity-slice"
import {actions as tabs} from "../Tabs/reducer"
import {State} from "../types"
import {QueryVersion} from "./types"

type VersionMeta = {queryId: string}

const initial = initialState()

export const versionSlice = createNestedEntitySlice<
QueryVersion,
{queryId: string},
Expand All @@ -19,8 +20,8 @@ export const versionSlice = createNestedEntitySlice<
sort: (a, b) => (a.ts > b.ts ? 1 : -1),
meta: (queryId) => ({queryId}),
select: (state: State, meta) => {
if (!state.queryVersions) return initialState()
return state.queryVersions[meta.queryId] ?? initialState()
if (!state.queryVersions) return initial
return state.queryVersions[meta.queryId] ?? initial
},
})

Expand All @@ -33,11 +34,4 @@ export const reducer = createReducer({}, (builder) => {
if (!state[id].ids.length) delete state[id]
}
)

builder.addMatcher(
({type}) => type == tabs.remove.toString(),
(s, a: PayloadAction<string>) => {
delete s[a.payload]
}
)
})
8 changes: 1 addition & 7 deletions apps/zui/src/js/state/SessionHistories/reducer.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {createSlice, PayloadAction} from "@reduxjs/toolkit"
import {SessionHistoriesState, SessionHistoryEntry} from "./types"
import {actions as tabs} from "../Tabs/reducer"

const slice = createSlice({
name: "sessionHistories",
name: "$sessionHistories",
initialState: {} as SessionHistoriesState,
reducers: {
replaceById(
Expand Down Expand Up @@ -33,11 +32,6 @@ const slice = createSlice({
}
},
},
extraReducers: (builder) => {
builder.addCase(tabs.remove, (s, a: ReturnType<typeof tabs.remove>) => {
delete s[a.payload]
})
},
})

export const reducer = slice.reducer
Expand Down
6 changes: 0 additions & 6 deletions apps/zui/src/js/state/SessionQueries/reducer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {createSlice} from "@reduxjs/toolkit"
import {actions as tabs} from "../Tabs/reducer"

const slice = createSlice({
name: "$sessionQueries",
Expand All @@ -9,11 +8,6 @@ const slice = createSlice({
s[a.payload.id] = a.payload
},
},
extraReducers: (builder) => {
builder.addCase(tabs.remove, (s, a: ReturnType<typeof tabs.remove>) => {
delete s[a.payload]
})
},
})

export const reducer = slice.reducer
Expand Down
10 changes: 0 additions & 10 deletions apps/zui/src/js/state/TabHistories/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {createEntityAdapter, createSlice} from "@reduxjs/toolkit"
import {actions as tabs} from "../Tabs/reducer"
import {State} from "../types"
import {SerializedHistory} from "./types"

Expand All @@ -11,15 +10,6 @@ const slice = createSlice({
reducers: {
save: adapter.setAll,
},
extraReducers: (builder) => {
builder.addCase(
tabs.remove,
(state, action: ReturnType<typeof tabs.remove>) => {
global.tabHistories.delete(action.payload)
return state
}
)
},
})

export default {
Expand Down
14 changes: 12 additions & 2 deletions apps/zui/src/js/state/Tabs/flows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,34 @@ import {Thunk} from "../types"
import Tabs from "./"
import {findTabById, findTabByUrl} from "./find"
import {invoke} from "src/core/invoke"
import {QuerySession} from "src/models/query-session"

export const create =
(url = "/", id = nanoid()): Thunk<string> =>
(dispatch) => {
dispatch(SessionQueries.init(id))
dispatch(Tabs.add(id))
global.tabHistories.create(id, [{pathname: url}], 0)
// move to tabHistories.restore(id, url)
const history = global.tabHistories.get(id)
if (history) {
if (history.location.pathname !== url) history.push(url)
} else {
global.tabHistories.create(id, [{pathname: url}], 0)
}
// end
dispatch(Tabs.activate(id))
return id
}

export const createQuerySession =
(): Thunk<string> =>
(dispatch, getState, {api}) => {
const sessionId = nanoid()
const session = QuerySession.create()
const sessionId = session.id
const version = "0"
api.queries.createEditorSnapshot(sessionId, {version, value: "", pins: []})
const url = queryPath(sessionId, version)

return dispatch(create(url, sessionId))
}

Expand Down
24 changes: 14 additions & 10 deletions apps/zui/src/js/state/Tabs/history.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,46 @@ import tabHistory from "src/app/router/tab-history"
import initTestStore from "src/test/unit/helpers/initTestStore"
import Current from "../Current"
import Tabs from "./"
import Histories from "src/modules/histories"

let store
beforeEach(async () => {
global.tabHistories = new Histories()
store = await initTestStore()
store.dispatch(Tabs.closeActive())
})

const currentPathnames = () =>
Current.getHistory(store.getState(), "search").entries.map((e) => e.pathname)

test("creating a tab creates a history entry", () => {
expect(global.tabHistories.count()).toBe(0)
store.dispatch(Tabs.create("/url"))
expect(global.tabHistories.count()).toBe(1)
store.dispatch(Tabs.create("/url"))
expect(global.tabHistories.count()).toBe(2)
})

test("activate sets the global.tabHistory", () => {
expect(global.tabHistories.count()).toBe(0)
expect(global.tabHistories.count()).toBe(1)
store.dispatch(tabHistory.push("/url-for-tab-1"))
expect(currentPathnames()).toEqual(["/", "/url-for-tab-1"])
expect(currentPathnames()).toEqual(["/welcome", "/url-for-tab-1"])

store.dispatch(Tabs.add("2"))
expect(currentPathnames()).toEqual(["/", "/url-for-tab-1"])
expect(currentPathnames()).toEqual(["/welcome", "/url-for-tab-1"])

store.dispatch(Tabs.activate("2"))
store.dispatch(tabHistory.push("/url-for-tab-2"))
expect(currentPathnames()).toEqual(["/", "/url-for-tab-2"])
expect(global.tabHistories.count()).toBe(2)
})

test("removing a tab removes the history too", () => {
test("removing the tab does not removes the history too", () => {
expect(global.tabHistories.count()).toBe(1)
store.dispatch(tabHistory.push("/url-for-tab-1"))
store.dispatch(Tabs.add("2"))
store.dispatch(Tabs.activate("2"))
store.dispatch(Tabs.remove("2"))
store.dispatch(tabHistory.push("/url-for-tab-2"))
expect(global.tabHistories.count()).toBe(2)

expect(global.tabHistories.count()).toBe(1)
expect(currentPathnames()).toEqual(["/", "/url-for-tab-1"])
store.dispatch(Tabs.remove("2"))
expect(global.tabHistories.count()).toBe(2)
expect(currentPathnames()).toEqual(["/welcome", "/url-for-tab-1"])
})
1 change: 1 addition & 0 deletions apps/zui/src/js/state/Tabs/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const slice = createSlice({
remove(s, a: PayloadAction<string>) {
const id = a.payload
const index = findTabIndex(s, id)
if (index === -1) return
const isLast = index === s.data.length - 1
s.data.splice(index, 1)
if (id === s.active) {
Expand Down
5 changes: 5 additions & 0 deletions apps/zui/src/js/state/Tabs/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ test("remove tab", () => {
expect(Tabs.getCount(state)).toBe(0)
})

test("remove the id of a tab that doesn't exist", () => {
const state = dispatchAll(store, [Tabs.add("1"), Tabs.remove("999999")])
expect(Tabs.getCount(state)).toBe(1)
})

test("remove last, active tab", () => {
const state = dispatchAll(store, [
Tabs.add("1"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import {migrate} from "src/test/unit/helpers/migrate"
import {getAllStates} from "./utils/getTestState"

test("migrating 202407221450_populateSessions", async () => {
const next = await migrate({state: "v1.17.0", to: "202407221450"})

const sessions = {
entities: {
KbZNe9FuSHnKKfB398B0Z: {
id: "KbZNe9FuSHnKKfB398B0Z",
name: null,
createdAt: expect.any(String),
updatedAt: expect.any(String),
},
Zf8vsxTZ4mqT7IK1OtvRf: {
id: "Zf8vsxTZ4mqT7IK1OtvRf",
name: null,
createdAt: expect.any(String),
updatedAt: expect.any(String),
},
sIpManYfhNgo6gWdu10bA: {
id: "sIpManYfhNgo6gWdu10bA",
name: null,
createdAt: expect.any(String),
updatedAt: expect.any(String),
},
},
ids: [
"KbZNe9FuSHnKKfB398B0Z",
"sIpManYfhNgo6gWdu10bA",
"Zf8vsxTZ4mqT7IK1OtvRf",
],
}

const histories = {
KbZNe9FuSHnKKfB398B0Z: [
{
queryId: "KbZNe9FuSHnKKfB398B0Z",
version: "mDbO6knM4vakcKQ0u4CLv",
},
],
Zf8vsxTZ4mqT7IK1OtvRf: [
{
queryId: "Zf8vsxTZ4mqT7IK1OtvRf",
version: "88LzM379511XaOMGPKkHB",
},
{
queryId: "Zf8vsxTZ4mqT7IK1OtvRf",
version: "YXX7LtHVgCJRgJPNR-USP",
},
],
sIpManYfhNgo6gWdu10bA: [
{
queryId: "sIpManYfhNgo6gWdu10bA",
version: "BQS4GdEC5JcgV1fankooP",
},
],
}

for (const state of getAllStates(next)) {
expect(state.querySessions).toEqual(sessions)
expect(state.sessionHistories).toEqual(histories)
}
})
Loading
Loading