-
Notifications
You must be signed in to change notification settings - Fork 430
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(tasks): decouple from structure via IsLastPaneContext
- Loading branch information
1 parent
707928c
commit a74f32d
Showing
8 changed files
with
86 additions
and
41 deletions.
There are no files selected for viewing
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
15 changes: 15 additions & 0 deletions
15
packages/sanity/src/core/tasks/context/isLastPane/IsLastPaneContext.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,15 @@ | ||
import {createContext} from 'react' | ||
|
||
/** | ||
* TODO: remove this context when alternate document-specific context are | ||
* introduced. | ||
* | ||
* The following context is used in the structure tool to set the active | ||
* document if it's the last pane open in the structure tool. This is a | ||
* temporary context provider that was introduced when the comments and tasks | ||
* plugins were refactor and decoupled from the structure tool. ideally this | ||
* should be removed and replaced with a document-specific context that gives | ||
* plugin authors access to what the `usePane`, `usePaneRouter`, and | ||
* `useDocumentPane` provides without exposing specifics from the structure tool | ||
*/ | ||
export const IsLastPaneContext = createContext<boolean>(false) |
14 changes: 14 additions & 0 deletions
14
packages/sanity/src/core/tasks/context/isLastPane/IsLastPaneProvider.tsx
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,14 @@ | ||
import {IsLastPaneContext} from './IsLastPaneContext' | ||
|
||
interface IsLastPaneProviderProps { | ||
isLastPane: boolean | ||
children: React.ReactNode | ||
} | ||
|
||
/** | ||
* @internal | ||
* @hidden | ||
*/ | ||
export function IsLastPaneProvider({children, isLastPane}: IsLastPaneProviderProps): JSX.Element { | ||
return <IsLastPaneContext.Provider value={isLastPane}>{children}</IsLastPaneContext.Provider> | ||
} |
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,2 @@ | ||
export * from './IsLastPaneProvider' | ||
export * from './useIsLastPane' |
11 changes: 11 additions & 0 deletions
11
packages/sanity/src/core/tasks/context/isLastPane/useIsLastPane.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,11 @@ | ||
import {useContext} from 'react' | ||
|
||
import {IsLastPaneContext} from './IsLastPaneContext' | ||
|
||
/** | ||
* @internal | ||
* @hidden | ||
*/ | ||
export function useIsLastPane(): boolean { | ||
return useContext(IsLastPaneContext) | ||
} |
5 changes: 2 additions & 3 deletions
5
packages/sanity/src/core/tasks/plugin/structure/SetActiveDocument.tsx
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