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

View Store And Hierarchy Search #408

Merged
merged 4 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/beige-shoes-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'mexit-webapp': patch
---

Search in View hierarchy, move view store to core
15 changes: 0 additions & 15 deletions apps/webapp/src/Components/Filters/NewFilterMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,3 @@ const NewFilterMenu = ({ addFilter, filters, removeLastFilter }: NewFilterMenuPr
}

export default NewFilterMenu

//////// Testing things
//
// const valueOptions = (k: string): FilterValue[] =>
// duplicateTimes([`${k} Test 1`, `${k} Test 2`, `${k} Test 3`, `${k} Test 4`, `${k} Test 5`], 20).map((value, i) => ({
// id: `${value}_${i}`,
// label: `${value}_${i}`,
// value
// }))
//
// const TypeOptions = ['note', 'tag', 'mention', 'space'].map((type) => ({
// label: capitalize(type),
// value: type as FilterType,
// options: valueOptions(type)
// }))
22 changes: 11 additions & 11 deletions apps/webapp/src/Components/Mentions/InvitedUsersContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@ import repeatLine from '@iconify/icons-ri/repeat-line'

import { IconButton, PrimaryButton } from '@workduck-io/mex-components'

import { AccessLevel, DefaultPermissionValue, InvitedUser, mog, permissionOptions, useEditorStore, useMentionStore , userPreferenceStore as useUserPreferenceStore,useShareModalStore } from '@mexit/core'
import {
AccessLevel,
DefaultPermissionValue,
InvitedUser,
mog,
permissionOptions,
useEditorStore,
useMentionStore,
userPreferenceStore as useUserPreferenceStore,
useShareModalStore
} from '@mexit/core'
import { StyledCreatatbleSelect } from '@mexit/shared'

import { useNodeShareAPI } from '../../Hooks/API/useNodeShareAPI'
Expand Down Expand Up @@ -178,16 +188,6 @@ export const InvitedUsersContent = (/*{}: PermissionModalContentProps*/) => {
return acc
}, [])

// const applyPermissions = async () => {
// const userChangePerm = await changeUserPermission(node.nodeid, newPermissions)
// const userRevoke = await revokeUserAccess(node.nodeid, revokedUsers)
// mog('set new permissions', { userChangePerm, userRevoke })
// }

// await applyPermissions()

// closeModal()

mog('onSave', { changedIUsers, newPermissions, newAliases, revokedUsers })
}

Expand Down
12 changes: 8 additions & 4 deletions apps/webapp/src/Components/TaskViewModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Entities } from '@workduck-io/mex-search'
import { tinykeys } from '@workduck-io/tinykeys'

import {
createEntityPath,
Filter,
generateTaskViewId,
getPathNum,
Expand Down Expand Up @@ -39,6 +40,8 @@ interface ViewProperties {
groupBy?: string
}

export type ViewParentType = { id: string; path: string }

export type ViewCreateType = 'new' | 'update' | 'clone' | 'save-as'

interface TaskViewModalState {
Expand All @@ -47,15 +50,15 @@ interface TaskViewModalState {
updateViewId?: string
// If present, title, description will be cloned from the view with viewid
cloneViewId?: string
parent?: string
parent?: ViewParentType
filters: Filter[]
properties?: ViewProperties
type?: ViewCreateType

openModal: (args: {
filters: Filter[]
type?: ViewCreateType
parent?: string | undefined
parent?: ViewParentType | undefined
updateViewId?: string
cloneViewId?: string
properties: ViewProperties
Expand Down Expand Up @@ -167,11 +170,12 @@ const TaskViewModal = () => {
await updateView(newView)
goTo(ROUTE_PATHS.view, NavigationType.push, newView.id)
} else {
const parent = useTaskViewModalStore.getState().parent
const parentDetails = useTaskViewModalStore.getState().parent
const path = createEntityPath('view', parentDetails?.id, parentDetails?.path)

const view: View = {
title: data.title,
parent,
path,
description: data.description,
filters,
id: generateTaskViewId(),
Expand Down
19 changes: 9 additions & 10 deletions apps/webapp/src/Components/Tree/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ const updateNode = (
const parentId = node?.parentId ?? options.root
const parent = nodes[parentId] ?? findItem(allItems, parentId)

if (!nodes[id]) {
const updatedNode: TreeItem = {
id,
children: [],
properties: node.properties,
isStub: options.isStub,
collapsed: options.collapsed
}
const updatedNode: TreeItem = {
id,
children: [],
properties: node.properties,
isStub: options.isStub,
collapsed: options.collapsed
}

if (!nodes[id]) {
nodes[id] = updatedNode
parent?.children?.push(updatedNode)
}
Expand All @@ -123,7 +123,6 @@ const updateNode = (
export function buildPartialTree(items: FlattenedItem[], allItems: FlattenedItem[]) {
const root: TreeItem = { id: 'root', children: [], properties: {} }
const nodes: Record<string, TreeItem> = { [root.id]: root }

for (const item of items) {
const parents = getAllEntities(item.properties.path)

Expand All @@ -150,7 +149,7 @@ export function buildTree(flattenedItems: FlattenedItem[]): TreeItems {

if (!nodes[id]) {
nodes[id] = { id, children }
parent.children.push(item)
parent?.children?.push(item)
}
}

Expand Down
13 changes: 11 additions & 2 deletions apps/webapp/src/Hooks/API/useViewsAPI.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { API, generateFilterId, GET_REQUEST_MINIMUM_GAP_IN_MS, mog, useAuthStore, View } from '@mexit/core'
import {
API,
generateFilterId,
GET_REQUEST_MINIMUM_GAP_IN_MS,
getParentEntity,
mog,
useAuthStore,
View
} from '@mexit/core'

import { useViewStore } from '../../Stores/useViewStore'

Expand All @@ -7,7 +15,8 @@ export const useViewAPI = () => {
const setViews = useViewStore((store) => store.setViews)

const saveView = async (view: View) => {
const { id: entityId, parent, filters, ...properties } = view
const { id: entityId, filters, path, ...properties } = view
const parent = getParentEntity(path)?.parent

const reqData = {
workspaceId: getWorkspaceId(),
Expand Down
26 changes: 15 additions & 11 deletions apps/webapp/src/Hooks/useCreateNewMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export const useCreateNewMenu = () => {
const loadSnippet = useSnippetStore((store) => store.loadSnippet)
const toggleModal = useModalStore((store) => store.toggleOpen)
const { addDefaultNewNamespace, getDefaultNamespaceId } = useNamespaces()
const setCurrentView = useViewStore((store) => store.setCurrentView)
const changeSpace = useUserPreferenceStore((store) => store.setActiveNamespace)
const expandSidebar = useLayoutStore((store) => store.expandSidebar)
const openShareModal = useShareModalStore((store) => store.openModal)
Expand Down Expand Up @@ -213,16 +212,21 @@ export const useCreateNewMenu = () => {
const handleCreateChildView = () => {
const view = useLayoutStore.getState().contextMenu?.item?.data

openTaskViewModal({
filters: view.filters,
parent: view.id,
properties: {
viewType: view.viewType,
sortOrder: view.sortOrder,
sortType: view.sortType,
globalJoin: view.globalJoin
}
})
if (view) {
openTaskViewModal({
filters: [],
parent: {
id: view.id,
path: view.path
},
properties: {
viewType: view.viewType,
sortOrder: view.sortOrder,
sortType: view.sortType,
globalJoin: view.globalJoin
}
})
}
}

/**
Expand Down
4 changes: 0 additions & 4 deletions apps/webapp/src/Hooks/useLoad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,12 @@ const useLoad = () => {
const changeSpace = useUserPreferenceStore((store) => store.setActiveNamespace)

const setLoadingNodeid = useEditorStore((store) => store.setLoadingNodeid)
// const { push } = useNavigation()
// const clearLoadingNodeid = useEditorStore((store) => store.clearLoadingNodeid)
const expandNodes = useTreeStore((store) => store.expandNodes)

// const quitFullscreenGraph = useGraphStore((store) => store.quitFullscreen)

// const { saveNodeAPIandFs } = useDataSaverFromContent()
const { saveAndClearBuffer } = useEditorBuffer()
const { execRefactorAsync } = useRefactor()
// const { saveQ } = useSaveQ()

const saveNodeName = (nodeId: string, title?: string) => {
if (nodeId !== useAnalysisStore.getState().analysis?.nodeid) return
Expand Down
12 changes: 4 additions & 8 deletions apps/webapp/src/Hooks/useViews.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Entities } from '@workduck-io/mex-search'

import { createEntityPath, Filter, getAllEntities, useDataStore, View, ViewType } from '@mexit/core'
import { Filter, getAllEntities, useDataStore, View, ViewType } from '@mexit/core'

import { useViewStore } from '../Stores/useViewStore'

Expand Down Expand Up @@ -101,21 +101,17 @@ export const useViews = () => {

const addView = async (view: View, onSuccess: (id: string) => void) => {
await saveView(view)
const { parent, ...restView } = view
const path = createEntityPath('view', parent, view.path)
onSuccess(view.id)
addViewStore({ ...restView, path })
addViewStore(view)
}

const updateView = async (view: View) => {
const resp = await saveView(view)
// mog('After update via saving that view', { resp })
await saveView(view)
updateViewStore(view)
}

const deleteView = async (viewid: string) => {
const resp = await deleteViewApi(viewid)
// mog('After deleting that view', { resp })
await deleteViewApi(viewid)
removeViewStore(viewid)
}

Expand Down
11 changes: 1 addition & 10 deletions apps/webapp/src/Stores/useViewStore.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
import create from 'zustand'
import { persist } from 'zustand/middleware'

import { ViewStore, viewStoreConstructor } from '@mexit/core'

export const useViewStore = create<ViewStore>(
persist(viewStoreConstructor, {
name: 'mexit-view-store'
})
)
export { useViewStore } from '@mexit/core'
2 changes: 1 addition & 1 deletion apps/webapp/src/Utils/convertValueToTasks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ELEMENT_LI, ELEMENT_LIC, ELEMENT_OL, ELEMENT_PARAGRAPH, ELEMENT_UL } from '@udecode/plate'

import { ELEMENT_MEDIA_EMBED, ELEMENT_TODO_LI,generateTempId, NodeEditorContent } from '@mexit/core'
import { ELEMENT_MEDIA_EMBED, ELEMENT_TODO_LI, generateTempId, NodeEditorContent } from '@mexit/core'

/**
* Converts the content to a list of tasks
Expand Down
2 changes: 0 additions & 2 deletions apps/webapp/src/Views/Reminders/RemindersAll.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,6 @@ const useReminderFilters = () => {
})
}

// mog('Filters', { filters })

return filters
}

Expand Down
7 changes: 0 additions & 7 deletions apps/webapp/src/Views/ViewSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ const viewIcons = {
}

const ViewSelector = ({ onChangeView, availableViews = defaultEntries, currentView }: ViewSelectorProps) => {
// mog('ViewSelector', {
// currentView,
// entries: Object.entries(View),
// availableViews,
// entriesAvailable: Object.entries(availableViews)
// })

return (
<ViewSelectorWrapper>
{availableViews.map((view) => (
Expand Down
Loading