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

feat(core): add studioActiveToolLayout and navbar rightSectionNode prop #5749

Merged
merged 2 commits into from
Feb 15, 2024

Conversation

pedrobonamin
Copy link
Contributor

Description

This PR adds two necessary core changes for the tasks feature.

Studio Active Tool Layout.

It's intention is to wrap the ActiveTool and allow plugins to modify the layout around it.

The red border shows how it wraps the active tool.
Screenshot 2024-02-15 at 11 11 07

// Plugin implementation
export const tasks = definePlugin({
  name: 'sanity/tasks',
  studio: {
    components: {
			...
      activeToolLayout: TasksStudioActiveToolLayout,
    },
  },
})

// Usage
export function TasksStudioActiveToolLayout(props: ActiveToolLayoutProps) {
  const {isOpen} = useTasks()
  const {enabled} = useTasksEnabled()
  if (!enabled) return props.renderDefault(props)

  return (
    <Flex height="fill">
      <div style={{minHeight: '100%', width: '100%'}}>{props.renderDefault(props)}</div>
      {isOpen && <TasksStudioSidebar />}
    </Flex>
  )
}

Navbar rightSectionNode

Adds a prop to the studio navbar prop which will be used to insert the TasksNabarButton in the correct position.

The red border shows where the rightSectionNode will be rendered.
Screenshot 2024-02-15 at 11 13 07

// Plugin 
export const tasks = definePlugin({
  name: 'sanity/tasks',
  studio: {
    components: {
			...
      navbar: TasksStudioNavbar,
    },
  },
})

// Usage
export function TasksStudioNavbar(props: NavbarProps) {
  const {enabled} = useTasksEnabled()

  if (!enabled) return props.renderDefault(props)
  return props.renderDefault({
    ...props,
    __internal_rightSectionNode: <TasksNavbarButton />,
  })
}

What to review

Implementation follows the expected guidelines.

Testing

Create a plugin which uses this new api and the navbar api.

Notes for release

Implements new studio API, ActiveToolLayout which allows plugin authors to have more flexibility by wrapping the active tool.
Adds __internal_rightSectionNode navbar prop.

@pedrobonamin pedrobonamin requested a review from a team February 15, 2024 10:15
@pedrobonamin pedrobonamin requested a review from a team as a code owner February 15, 2024 10:15
@pedrobonamin pedrobonamin requested review from ninaandal and bjoerge and removed request for a team February 15, 2024 10:15
Copy link

vercel bot commented Feb 15, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
performance-studio ✅ Ready (Inspect) Visit Preview Feb 15, 2024 10:15am
test-studio ✅ Ready (Inspect) Visit Preview Feb 15, 2024 10:15am
1 Ignored Deployment
Name Status Preview Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Feb 15, 2024 10:15am

Copy link
Contributor

No changes to documentation

Copy link
Contributor

Component Testing Report Updated Feb 15, 2024 10:23 AM (UTC)

File Status Duration Passed Skipped Failed
comments/CommentInput.spec.tsx ✅ Passed (Inspect) 32s 15 0 0
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 6s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ✅ Passed (Inspect) 12s 3 0 0
formBuilder/inputs/PortableText/copyPaste/CopyPaste.spec.tsx ✅ Passed (Inspect) 13s 4 2 0
formBuilder/inputs/PortableText/Decorators.spec.tsx ✅ Passed (Inspect) 13s 6 0 0
formBuilder/inputs/PortableText/FocusTracking.spec.tsx ✅ Passed (Inspect) 33s 15 0 0
formBuilder/inputs/PortableText/Input.spec.tsx ✅ Passed (Inspect) 18s 9 0 0
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ✅ Passed (Inspect) 1m 1s 18 0 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 15s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ✅ Passed (Inspect) 20s 9 0 0

Copy link
Member

@bjoerge bjoerge left a comment

Choose a reason for hiding this comment

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

LGTM, just a small reflection, but not a blocker for merge.

/**
* @internal
* @beta */
__internal_rightSectionNode?: ReactNode
Copy link
Member

Choose a reason for hiding this comment

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

We should probably think about how we could offer an API with more granularity, so we could use a render/renderDefault pattern for these things as well, but I understand why navbar.render + renderDefault didn't work for you here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it was an interesting discussion with the ex team, but we couldn't find any other solution given this navbar component adds multiple internal components and we would have need to recreate the same through the plugin.
Will be a nice discussion to bring to next studio meeting. Will propose it.

Thanks @bjoerge !

@pedrobonamin pedrobonamin added this pull request to the merge queue Feb 15, 2024
Merged via the queue into next with commit c708671 Feb 15, 2024
40 checks passed
@pedrobonamin pedrobonamin deleted the edx-986-core branch February 15, 2024 11:20
@hermanwikner
Copy link
Member

Looks great! I have two thoughts/suggestions:

  • I suggest renaming activeToolLayout to toolLayout. My reasoning is that this API renders the layout for all tools, unless specifically conditioned otherwise, and given that only one tool can be active at a time, I think it's implicitly understood that the API will render the "active tool".
  • It would be great if we could add a e2e test for this new API in the Studio Components API test

juice49 pushed a commit that referenced this pull request Feb 16, 2024
…op (#5749)

* feat(core): add StudioActiveToolLayout api

* feat(core): add studioNavbar __internal_rightSectionNode prop
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.

3 participants