Skip to content

Commit

Permalink
allow share links with collapsible sidebar param
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfcosta committed Jan 4, 2025
1 parent 515ccf4 commit dc24fea
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { broadcastDocument } from '../../../../../websocket/workspace/documents.
const DocumentSettings = z.object({
runUnexecutedBlocks: z.boolean().optional(),
runSQLSelection: z.boolean().optional(),
shareLinksWithoutSidebar: z.boolean().optional(),
})

export default function settingsRouter(socketServer: IOServer) {
Expand All @@ -22,13 +23,18 @@ export default function settingsRouter(socketServer: IOServer) {
return
}

const { runUnexecutedBlocks, runSQLSelection } = body.data
const { runUnexecutedBlocks, runSQLSelection, shareLinksWithoutSidebar } =
body.data

try {
const doc = await recoverFromNotFound(
prisma().document.update({
where: { id: documentId },
data: { runUnexecutedBlocks, runSQLSelection },
data: {
runUnexecutedBlocks,
runSQLSelection,
shareLinksWithoutSidebar,
},
})
)
if (!doc) {
Expand Down
12 changes: 10 additions & 2 deletions apps/web/src/components/Dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,20 @@ export default function Dashboard(props: Props) {
)
}, [props.publish, props.publishing])

const shareLinkWithoutSidebar = props.document.shareLinksWithoutSidebar
const copyLink = useMemo(
() =>
`${NEXT_PUBLIC_PUBLIC_URL()}/workspaces/${
props.document.workspaceId
}/documents/${props.document.id}`,
[router]
}/documents/${props.document.id}/dashboard${
props.isEditing ? '/edit' : ''
}${shareLinkWithoutSidebar ? '?sidebarCollapsed=true' : ''}`,
[
props.document.workspaceId,
props.document.id,
props.isEditing,
shareLinkWithoutSidebar,
]
)

const documentTitle = useMemo(
Expand Down
6 changes: 6 additions & 0 deletions apps/web/src/components/PageSettingsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ export default function PageSettingsPanel(props: Props) {
enabled={document?.runSQLSelection ?? false}
onToggle={api.toggleRunSQLSelection}
/>
<PageSettingToggle
name="Share links without sidebar"
description="Whether the 'copy link' button should include a query parameter to hide the sidebar (open dashboards with the sidebar collapsed)."
enabled={document?.shareLinksWithoutSidebar ?? false}
onToggle={api.toggleShareLinksWithoutSidebar}
/>
</div>
</div>
</Transition>
Expand Down
11 changes: 10 additions & 1 deletion apps/web/src/components/PrivateDocumentPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,21 @@ function PrivateDocumentPageInner(
}, [setSelectedSidebar])

const router = useRouter()
const shareLinkWithoutSidebar = props.document.shareLinksWithoutSidebar
const copyLink = useMemo(
() =>
`${NEXT_PUBLIC_PUBLIC_URL()}/workspaces/${props.workspaceId}/documents/${
props.documentId
}/notebook${props.isApp ? '' : '/edit'}${
shareLinkWithoutSidebar ? `?sidebarCollapsed=true` : ''
}`,
[router]
[
router,
props.workspaceId,
props.documentId,
props.isApp,
shareLinkWithoutSidebar,
]
)

const isViewer = props.user.roles[props.workspaceId] === 'viewer'
Expand Down
26 changes: 25 additions & 1 deletion apps/web/src/hooks/useDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type API = {
publish: () => Promise<void>
toggleRunUnexecutedBlocks: () => Promise<void>
toggleRunSQLSelection: () => Promise<void>
toggleShareLinksWithoutSidebar: () => Promise<void>
}

type UseDocument = [
Expand Down Expand Up @@ -76,17 +77,40 @@ function useDocument(workspaceId: string, documentId: string): UseDocument {
api.updateDocumentSettings,
])

const toggleShareLinksWithoutSidebar = useCallback(async () => {
const newShareLinksWithoutSidebar = !document?.shareLinksWithoutSidebar
try {
await api.updateDocumentSettings(documentId, {
shareLinksWithoutSidebar: newShareLinksWithoutSidebar,
})
} catch (err) {
alert('Failed to update document settings')
}
}, [
workspaceId,
documentId,
document?.shareLinksWithoutSidebar,
api.updateDocumentSettings,
])

return useMemo(
() => [
{ document, loading, publishing },
{ setIcon, publish, toggleRunUnexecutedBlocks, toggleRunSQLSelection },
{
setIcon,
publish,
toggleRunUnexecutedBlocks,
toggleRunSQLSelection,
toggleShareLinksWithoutSidebar,
},
],
[
loading,
setIcon,
publish,
toggleRunUnexecutedBlocks,
toggleRunSQLSelection,
toggleShareLinksWithoutSidebar,
]
)
}
Expand Down
7 changes: 6 additions & 1 deletion apps/web/src/hooks/useDocuments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ function upsertDocumentInMemory(
userAppClock: {},
runUnexecutedBlocks: false,
runSQLSelection: false,
shareLinksWithoutSidebar: true,
hasDashboard: false,
})
}
Expand Down Expand Up @@ -207,7 +208,11 @@ type API = {
) => Promise<void>
updateDocumentSettings: (
id: string,
settings: { runUnexecutedBlocks?: boolean; runSQLSelection?: boolean }
settings: {
runUnexecutedBlocks?: boolean
runSQLSelection?: boolean
shareLinksWithoutSidebar?: boolean
}
) => Promise<void>
publish: (id: string) => Promise<void>
}
Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/hooks/useSideBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
useContext,
useState,
} from 'react'
import { useStringQuery } from './useQueryArgs'

type Context = [boolean, Dispatch<SetStateAction<boolean>>]
const Context = createContext<Context>([true, () => {}] as unknown as Context)
Expand All @@ -14,7 +15,8 @@ export default function useSideBar(): Context {
}

export function SideBarProvider({ children }: { children: React.ReactNode }) {
const value = useState(true)
const noSidebarQs = useStringQuery('sidebarCollapsed')
const value = useState(noSidebarQs === 'true')

return <Context.Provider value={value}>{children}</Context.Provider>
}
10 changes: 10 additions & 0 deletions docs/settings/page-settings.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,13 @@ When you run a SQL block, Briefer will run its entire content by default.
If you only want to run a specific part of the SQL block, you need to enable the "Run selected SQL only" switch.

After enabling this setting, Briefer will only run the SQL code you've selected. If you haven't selected any code, Briefer will run the entire block.

## Share links without sidebar

By default, clicking the "copy link" element within the "Share" menu will copy a link that opens the page with the sidebar _collapsed_.

If you want to share a link that opens the page with the sidebar _expanded_, you can disable the "Share links without sidebar" switch.

<Note>
The query parameter which controls the sidebar state is `sidebarCollapsed`. You can also manually set it to `true` or `false` to control the sidebar state.
</Note>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Document" ADD COLUMN "shareLinksWithoutSidebar" BOOLEAN NOT NULL DEFAULT true;
17 changes: 9 additions & 8 deletions packages/database/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@ model Document {
parent Document? @relation("DocumentParent", fields: [parentId], references: [id], onDelete: Cascade)
children Document[] @relation("DocumentParent")
yjsDocument YjsDocument?
yjsAppDocuments YjsAppDocument[]
comments Comment[]
Favorite Favorite[]
executionSchedules ExecutionSchedule[]
reusableComponents ReusableComponent[]
yjsDocument YjsDocument?
yjsAppDocuments YjsAppDocument[]
comments Comment[]
Favorite Favorite[]
executionSchedules ExecutionSchedule[]
reusableComponents ReusableComponent[]
reusableComponentInstances ReusableComponentInstance[]
runUnexecutedBlocks Boolean @default(false)
runSQLSelection Boolean @default(false)
runUnexecutedBlocks Boolean @default(false)
runSQLSelection Boolean @default(false)
shareLinksWithoutSidebar Boolean @default(false)
}

model YjsDocument {
Expand Down

0 comments on commit dc24fea

Please sign in to comment.