-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from dolthub/taylor/no-writes-wrapper
Add component/hook for roles/writes
- Loading branch information
Showing
28 changed files
with
518 additions
and
217 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
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
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
56 changes: 37 additions & 19 deletions
56
packages/web/components/DatabaseHeaderAndNav/AddItemDropdown/DocItem.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 |
---|---|---|
@@ -1,43 +1,61 @@ | ||
import SmallLoader from "@components/SmallLoader"; | ||
import { | ||
DocListForDocPageFragment, | ||
useDocsRowsForDocPageQuery, | ||
} from "@gen/graphql-types"; | ||
import { useDocsRowsForDocPageQuery } from "@gen/graphql-types"; | ||
import { RefParams } from "@lib/params"; | ||
import { newDoc } from "@lib/urls"; | ||
import { HiOutlineDocumentAdd } from "@react-icons/all-files/hi/HiOutlineDocumentAdd"; | ||
import DropdownItem from "./Item"; | ||
|
||
type Props = { | ||
type InnerProps = { | ||
params: RefParams; | ||
doltDisabled?: boolean; | ||
userHasWritePerms: boolean; | ||
}; | ||
|
||
type InnerProps = Props & { | ||
docs?: DocListForDocPageFragment; | ||
type Props = InnerProps & { | ||
doltDisabled?: boolean; | ||
}; | ||
|
||
function Inner(props: InnerProps) { | ||
const canCreateNewDoc = !props.docs || props.docs.list.length < 2; | ||
const res = useDocsRowsForDocPageQuery({ | ||
variables: props.params, | ||
}); | ||
|
||
if (res.loading) return <SmallLoader loaded={false} />; | ||
|
||
const canCreateNewDoc = | ||
props.userHasWritePerms && | ||
(!res.data?.docs || res.data.docs.list.length < 2); | ||
|
||
return <NewDocLink params={props.params} hide={!canCreateNewDoc} />; | ||
} | ||
|
||
export default function DocsDropdownItem(props: Props) { | ||
if (props.doltDisabled) { | ||
return ( | ||
<NewDocLink | ||
params={props.params} | ||
doltDisabled={props.doltDisabled} | ||
hide={!props.userHasWritePerms} | ||
/> | ||
); | ||
} | ||
|
||
return <Inner {...props} />; | ||
} | ||
|
||
function NewDocLink(props: { | ||
params: RefParams; | ||
doltDisabled?: boolean; | ||
hide?: boolean; | ||
}) { | ||
return ( | ||
<DropdownItem | ||
url={newDoc(props.params)} | ||
icon={<HiOutlineDocumentAdd />} | ||
hide={!canCreateNewDoc} | ||
data-cy="add-dropdown-new-docs-link" | ||
doltDisabled={props.doltDisabled} | ||
hide={props.hide} | ||
> | ||
New README/LICENSE | ||
</DropdownItem> | ||
); | ||
} | ||
|
||
export default function DocsDropdownItem(props: Props) { | ||
const res = useDocsRowsForDocPageQuery({ | ||
variables: props.params, | ||
}); | ||
|
||
if (res.loading) return <SmallLoader loaded={false} />; | ||
return <Inner {...props} docs={res.data?.docs} />; | ||
} |
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
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
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
Oops, something went wrong.