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

[base] Create part of referring documents hoc/util-component #1188

Merged
merged 2 commits into from
Jan 30, 2019

Conversation

bjoerge
Copy link
Member

@bjoerge bjoerge commented Jan 30, 2019

This is a tiny refactor of the enhanceWithReferringDocuments utility used in desk tool for fetching a list of document that refers to the one you are attempting to unpublish/delete. Since it is useful for other packages as well, i moved it into base and made a sanity-part of it.

Additionally it is usable not only a higher order component, but also as a component that takes a render func as child, so it can be used like this:

import {WithReferringDocuments} from 'part:@sanity/base/with-referring-documents'
function MyComponent(props) {
  return (
    <WithReferringDocuments id={props.documentId}>
      {({isLoading, referringDocuments}) =>
        isLoading
          ? 'Loading referring documents…'
          : `Found ${referringDocuments.length} documents referring to ${props.documentId}`
      }
    </WithReferringDocuments>
  )
}

This is a tiny refactor of the `enhanceWithReferringDocuments` utility used in desk tool for fetching a list of document that refers to the one you are attempting to unpublish/delete. Since it is useful for other packages as well, i moved it into base and made a sanity-part of it.

Additionally it is usable not only a higher order component, but also as a component that takes a render func as child, so it can be used like this:

```jsx
import {WithReferringDocuments} from 'part:@sanity/base/with-referring-documents'
function MyComponent(props) {
  return (
    <WithReferringDocuments id={props.documentId}>
      {({isLoading, referringDocuments}) =>
        isLoading
          ? 'Loading referring documents…'
          : `Found ${referringDocuments.length} documents referring to ${props.documentId}`
      }
    </WithReferringDocuments>
  )
}
```
Copy link
Contributor

@kristofferjs kristofferjs left a comment

Choose a reason for hiding this comment

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

👍

@bjoerge bjoerge merged commit 9a56507 into next Jan 30, 2019
@bjoerge bjoerge deleted the with-referring-documents-part branch January 30, 2019 12:29
kristofferjs pushed a commit that referenced this pull request Jan 31, 2019
This is a tiny refactor of the `enhanceWithReferringDocuments` utility used in desk tool for fetching a list of document that refers to the one you are attempting to unpublish/delete. Since it is useful for other packages as well, i moved it into base and made a sanity-part of it.

It has been rewritten to be a component that takes a render func as child, so it can be used like this:

```jsx
import {WithReferringDocuments} from 'part:@sanity/base/with-referring-documents'
function MyComponent(props) {
  return (
    <WithReferringDocuments id={props.documentId}>
      {({isLoading, referringDocuments}) =>
        isLoading
          ? 'Loading referring documents…'
          : `Found ${referringDocuments.length} documents referring to ${props.documentId}`
      }
    </WithReferringDocuments>
  )
}
```

The old higher order component behavior is kept in desk tool for now, but should probably be replaced by using `WithReferringDocuments` directly
skogsmaskin pushed a commit that referenced this pull request Jan 31, 2019
This is a tiny refactor of the `enhanceWithReferringDocuments` utility used in desk tool for fetching a list of document that refers to the one you are attempting to unpublish/delete. Since it is useful for other packages as well, i moved it into base and made a sanity-part of it.

It has been rewritten to be a component that takes a render func as child, so it can be used like this:

```jsx
import {WithReferringDocuments} from 'part:@sanity/base/with-referring-documents'
function MyComponent(props) {
  return (
    <WithReferringDocuments id={props.documentId}>
      {({isLoading, referringDocuments}) =>
        isLoading
          ? 'Loading referring documents…'
          : `Found ${referringDocuments.length} documents referring to ${props.documentId}`
      }
    </WithReferringDocuments>
  )
}
```

The old higher order component behavior is kept in desk tool for now, but should probably be replaced by using `WithReferringDocuments` directly
bjoerge added a commit that referenced this pull request Feb 1, 2019
This is a tiny refactor of the `enhanceWithReferringDocuments` utility used in desk tool for fetching a list of document that refers to the one you are attempting to unpublish/delete. Since it is useful for other packages as well, i moved it into base and made a sanity-part of it.

Additionally it is usable not only a higher order component, but also as a component that takes a render func as child, so it can be used like this:

```jsx
import {WithReferringDocuments} from 'part:@sanity/base/with-referring-documents'
function MyComponent(props) {
  return (
    <WithReferringDocuments id={props.documentId}>
      {({isLoading, referringDocuments}) =>
        isLoading
          ? 'Loading referring documents…'
          : `Found ${referringDocuments.length} documents referring to ${props.documentId}`
      }
    </WithReferringDocuments>
  )
}
```
bjoerge added a commit that referenced this pull request Feb 1, 2019
This is a tiny refactor of the `enhanceWithReferringDocuments` utility used in desk tool for fetching a list of document that refers to the one you are attempting to unpublish/delete. Since it is useful for other packages as well, i moved it into base and made a sanity-part of it.

Additionally it is usable not only a higher order component, but also as a component that takes a render func as child, so it can be used like this:

```jsx
import {WithReferringDocuments} from 'part:@sanity/base/with-referring-documents'
function MyComponent(props) {
  return (
    <WithReferringDocuments id={props.documentId}>
      {({isLoading, referringDocuments}) =>
        isLoading
          ? 'Loading referring documents…'
          : `Found ${referringDocuments.length} documents referring to ${props.documentId}`
      }
    </WithReferringDocuments>
  )
}
```
@skogsmaskin skogsmaskin mentioned this pull request Feb 1, 2019
skogsmaskin pushed a commit that referenced this pull request Feb 1, 2019
This is a tiny refactor of the `enhanceWithReferringDocuments` utility used in desk tool for fetching a list of document that refers to the one you are attempting to unpublish/delete. Since it is useful for other packages as well, i moved it into base and made a sanity-part of it.

Additionally it is usable not only a higher order component, but also as a component that takes a render func as child, so it can be used like this:

```jsx
import {WithReferringDocuments} from 'part:@sanity/base/with-referring-documents'
function MyComponent(props) {
  return (
    <WithReferringDocuments id={props.documentId}>
      {({isLoading, referringDocuments}) =>
        isLoading
          ? 'Loading referring documents…'
          : `Found ${referringDocuments.length} documents referring to ${props.documentId}`
      }
    </WithReferringDocuments>
  )
}
```
bjoerge added a commit that referenced this pull request Aug 13, 2019
This is a tiny refactor of the `enhanceWithReferringDocuments` utility used in desk tool for fetching a list of document that refers to the one you are attempting to unpublish/delete. Since it is useful for other packages as well, i moved it into base and made a sanity-part of it.

Additionally it is usable not only a higher order component, but also as a component that takes a render func as child, so it can be used like this:

```jsx
import {WithReferringDocuments} from 'part:@sanity/base/with-referring-documents'
function MyComponent(props) {
  return (
    <WithReferringDocuments id={props.documentId}>
      {({isLoading, referringDocuments}) =>
        isLoading
          ? 'Loading referring documents…'
          : `Found ${referringDocuments.length} documents referring to ${props.documentId}`
      }
    </WithReferringDocuments>
  )
}
```
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