Skip to content

Dashboard/pre-v2 fixes#1305

Merged
Davy-c merged 22 commits intodashboard/newfrom
dashboard/v2-fixes
Nov 8, 2021
Merged

Dashboard/pre-v2 fixes#1305
Davy-c merged 22 commits intodashboard/newfrom
dashboard/v2-fixes

Conversation

@Davy-c
Copy link
Copy Markdown
Contributor

@Davy-c Davy-c commented Nov 8, 2021

No description provided.

@Davy-c Davy-c changed the title Dashboard/v2 fixes Dashboard/pre-v2 fixes Nov 8, 2021
const { openModal } = useModal()

useEffect(() => {
if (parent.target.id === targetIdRef.current) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is parent? and what is parent.target?

Copy link
Copy Markdown
Contributor Author

@Davy-c Davy-c Nov 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

views can belong to either a folder, or a dashboard/smart view

so the parent is just a way to call the correct apis

export type ViewParent =
  | { type: 'folder'; target: SerializedFolderWithBookmark }
  | { type: 'smartView'; target: SerializedSmartView }

the useeffect here is used when you switch the selected dashboard/smart view so that it selects one of the new views so for example

select dashboard 1 >  select dashboard1[views][0]
select dashboard 2 > useEffect select dashboard2[views][0]


if (!res.err) {
const { data: dashboard } = res.data as CreateDashboardResponseBody
await createViewApi({ dashboard: dashboard.id, type: 'table' })
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should handle error

Copy link
Copy Markdown
Contributor Author

@Davy-c Davy-c Nov 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all the current api calls already handle errors by default
if it errors, a toast message with the error message will be shown.
if it does not, then we can continue via callbacks or via the (!res.err)

in this instance the view creation is not the primary focus, the dashboard/smart view creation is.
So if the dashboard is still created normally then it will continue by closing the createDashboardModal

 const createViewApi = useCallback(
    async (target: CreateViewRequestBody) => {
      return send(shortid.generate(), 'create', {
        api: () => createView(target),
        cb: ({ data }: CreateViewResponseBody) => {
          updateViewsMap([data.id, data])
        },
      })
    },
    [updateViewsMap, send]
  )


const send = useCallback(
    async (id: string, act: string, { api, cb }) => {
      const res = { err: false, error: undefined, data: undefined }
      if (sendingMap.get(id)) {
        return
      }

      setSendingMap((prev) => {
        const newMap = new Map(prev)
        newMap.delete(id)
        newMap.set(id, act)
        return newMap
      })
      try {
        const data = await api()
        res.data = data
        if (cb != null) {
          cb(data)
        }
      } catch (error) {
        res.err = true
        res.error = error
        console.error(error)
        pushApiErrorMessage(error)
      }

      setSendingMap((prev) => {
        const newMap = new Map(prev)
        newMap.delete(id)
        return newMap
      })

      return res
    },
    [sendingMap, pushApiErrorMessage]
  )

@Davy-c Davy-c merged commit a43fa8f into dashboard/new Nov 8, 2021
@Davy-c Davy-c deleted the dashboard/v2-fixes branch November 8, 2021 05:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants