-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(3000): Add sites sidebar for Toolbar launching (#16389)
* feat(3000): Add sites sidebar for Toolbar launching * Fix project settings button * Update UI snapshots for `chromium` (1) * Rework scene config `plain` to `layout` * Clarify "Open in new tab" --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
8adac54
commit 72dcf73
Showing
29 changed files
with
282 additions
and
26 deletions.
There are no files selected for viewing
Binary file modified
BIN
+351 Bytes
(100%)
frontend/__snapshots__/posthog-3000-navigation--dark-mode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+353 Bytes
(100%)
frontend/__snapshots__/posthog-3000-navigation--light-mode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
frontend/src/layout/navigation-3000/sidebars/toolbar.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import { connect, kea, path, selectors } from 'kea' | ||
import { sceneLogic } from 'scenes/sceneLogic' | ||
import { Scene } from 'scenes/sceneTypes' | ||
import { urls } from 'scenes/urls' | ||
import { SidebarCategory, BasicListItem } from '../types' | ||
import Fuse from 'fuse.js' | ||
import { subscriptions } from 'kea-subscriptions' | ||
import { navigation3000Logic } from '~/layout/navigation-3000/navigationLogic' | ||
import { FuseSearchMatch } from './utils' | ||
import { | ||
AuthorizedUrlListType, | ||
KeyedAppUrl, | ||
authorizedUrlListLogic, | ||
} from 'lib/components/AuthorizedUrlList/authorizedUrlListLogic' | ||
|
||
import type { toolbarSidebarLogicType } from './toolbarType' | ||
|
||
const fuse = new Fuse<KeyedAppUrl>([], { | ||
keys: ['url'], | ||
threshold: 0.3, | ||
ignoreLocation: true, | ||
includeMatches: true, | ||
}) | ||
|
||
export const toolbarSidebarLogic = kea<toolbarSidebarLogicType>([ | ||
path(['layout', 'navigation-3000', 'sidebars', 'toolbarSidebarLogic']), | ||
connect(() => ({ | ||
values: [ | ||
authorizedUrlListLogic({ actionId: null, type: AuthorizedUrlListType.TOOLBAR_URLS }), | ||
['urlsKeyed', 'suggestionsLoading'], | ||
sceneLogic, | ||
['activeScene', 'sceneParams'], | ||
], | ||
actions: [ | ||
authorizedUrlListLogic({ actionId: null, type: AuthorizedUrlListType.TOOLBAR_URLS }), | ||
['addUrl', 'removeUrl', 'updateUrl'], | ||
], | ||
})), | ||
selectors(({ actions }) => ({ | ||
contents: [ | ||
(s) => [s.relevantUrls, s.suggestionsLoading], | ||
(relevantUrls, suggestionsLoading) => [ | ||
{ | ||
key: 'sites', | ||
title: 'Sites', | ||
loading: suggestionsLoading, | ||
items: relevantUrls.map( | ||
([url, matches]) => | ||
({ | ||
key: url.url, | ||
name: url.url, | ||
url: url.type !== 'suggestion' ? urls.site(url.url) : null, | ||
tag: url.type === 'suggestion' ? { status: 'warning', text: 'SUGGESTION' } : undefined, | ||
searchMatch: matches | ||
? { | ||
matchingFields: matches.map((match) => match.key), | ||
nameHighlightRanges: matches.find((match) => match.key === 'url')?.indices, | ||
} | ||
: null, | ||
onRename: | ||
url.type !== 'suggestion' | ||
? (newUrl) => actions.updateUrl(url.originalIndex, newUrl) | ||
: undefined, | ||
menuItems: | ||
url.type !== 'suggestion' | ||
? (initiateRename) => [ | ||
{ | ||
items: [ | ||
{ | ||
to: urls.site(url.url), | ||
targetBlank: true, | ||
label: 'Open with Toolbar in new tab', | ||
}, | ||
], | ||
}, | ||
{ | ||
items: [ | ||
{ | ||
onClick: initiateRename, | ||
label: 'Edit', | ||
keyboardShortcut: ['enter'], | ||
}, | ||
{ | ||
onClick: () => actions.removeUrl(url.originalIndex), | ||
status: 'danger', | ||
label: 'Delete site', | ||
}, | ||
], | ||
}, | ||
] | ||
: [{ onClick: () => actions.addUrl(url.url), label: 'Apply suggestion' }], | ||
} as BasicListItem) | ||
), | ||
} as SidebarCategory, | ||
], | ||
], | ||
activeListItemKey: [ | ||
(s) => [s.activeScene, s.sceneParams], | ||
(activeScene, sceneParams) => { | ||
return activeScene === Scene.Site ? decodeURIComponent(sceneParams.params.url) : null | ||
}, | ||
], | ||
relevantUrls: [ | ||
(s) => [s.urlsKeyed, navigation3000Logic.selectors.searchTerm], | ||
(urlsKeyed, searchTerm): [KeyedAppUrl, FuseSearchMatch[] | null][] => { | ||
if (searchTerm) { | ||
return fuse.search(searchTerm).map((result) => [result.item, result.matches as FuseSearchMatch[]]) | ||
} | ||
return urlsKeyed.map((url) => [url, null]) | ||
}, | ||
], | ||
})), | ||
subscriptions({ | ||
urlsKeyed: (urlsKeyed) => { | ||
fuse.setCollection(urlsKeyed) | ||
}, | ||
}), | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.