-
Notifications
You must be signed in to change notification settings - Fork 1
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 #199 from performant-software/feature/cdc1_projects
CDC #2 - Projects
- Loading branch information
Showing
19 changed files
with
633 additions
and
29 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
Empty file.
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,69 @@ | ||
// @flow | ||
|
||
import React, { useEffect, useState, type ComponentType } from 'react'; | ||
import { Breadcrumb, Loader } from 'semantic-ui-react'; | ||
|
||
type Props = { | ||
active: boolean, | ||
as?: ComponentType<any>, | ||
id?: number, | ||
label?: string, | ||
name: string, | ||
onLoad: (id: number, name: string) => Promise<any>, | ||
url: string | ||
}; | ||
|
||
const BreadcrumbItem: ComponentType<any> = (props: Props) => { | ||
const [loading, setLoading] = useState(false); | ||
const [name, setName] = useState(null); | ||
|
||
/** | ||
* Sets or clears the name attribute on the state. | ||
*/ | ||
useEffect(() => { | ||
if (props.id) { | ||
props | ||
.onLoad(props.id, props.name) | ||
.then((n) => setName(n)) | ||
.finally(() => setLoading(false)); | ||
|
||
setLoading(true); | ||
} else { | ||
setName(null); | ||
} | ||
}, [props.id, props.name]); | ||
|
||
return ( | ||
<> | ||
<Breadcrumb.Section | ||
active={props.active && !props.id} | ||
as={props.as} | ||
to={`/${props.url}`} | ||
> | ||
{ props.label } | ||
</Breadcrumb.Section> | ||
{ props.id && ( | ||
<Breadcrumb.Divider | ||
icon='right chevron' | ||
/> | ||
)} | ||
{ loading && ( | ||
<Loader | ||
active | ||
inline | ||
/> | ||
)} | ||
{ name && props.id && ( | ||
<Breadcrumb.Section | ||
active={props.active} | ||
as={props.as} | ||
to={`/${props.url}/${props.id}`} | ||
> | ||
{ name } | ||
</Breadcrumb.Section> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default BreadcrumbItem; |
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,4 @@ | ||
.ui.breadcrumb:first-child { | ||
margin-bottom: 1em; | ||
margin-top: 0.5em; | ||
} |
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,111 @@ | ||
// @flow | ||
|
||
import React, { useCallback, useMemo, type ComponentType } from 'react'; | ||
import { Breadcrumb } from 'semantic-ui-react'; | ||
import _ from 'underscore'; | ||
import BreadcrumbItem from './BreadcrumbItem'; | ||
import './Breadcrumbs.css'; | ||
|
||
const URL_DELIMITER = '/'; | ||
|
||
type Props = { | ||
/** | ||
* Alternate component to use to render the breadcrumb. | ||
*/ | ||
as?: ComponentType<any>, | ||
|
||
/** | ||
* A key-value pair of types to labels to match the `pathname`. | ||
*/ | ||
labels: { key: string, value: string }, | ||
|
||
/** | ||
* Callback fired to lookup the name of the passed breadcrumb item. | ||
*/ | ||
onLoad: (id: number, name: string) => Promise<any>, | ||
|
||
/** | ||
* The URL for which to generate the breadcrumb. | ||
*/ | ||
pathname: string | ||
}; | ||
|
||
/** | ||
* This component can be used to render a breadcrumb for the passed URL. | ||
*/ | ||
const Breadcrumbs: ComponentType<any> = (props: Props) => { | ||
/** | ||
* Returns true if the passed string contains only digits. | ||
* | ||
* @type {function(*): boolean} | ||
*/ | ||
const isNumeric = useCallback((str: string) => /^\d+$/.test(str), []); | ||
|
||
/** | ||
* Sets the items to display based on the URL path. | ||
* | ||
* @type {[]} | ||
*/ | ||
const items = useMemo(() => { | ||
const value = []; | ||
|
||
const path = props.pathname.split(URL_DELIMITER).splice(1); | ||
|
||
for (let i = 0; i < path.length; i += 1) { | ||
const key = path[i]; | ||
const id = path[i + 1]; | ||
const url = path.slice(0, i + 1).join(URL_DELIMITER); | ||
|
||
/* | ||
* If the item in the path is non-numeric, we'll add it as the item label. | ||
* If the next item is numeric, we'll add it as the ID. | ||
* If the next item is non-numeric, it'll be added as a separate label on the next iteration. | ||
*/ | ||
if (!isNumeric(key)) { | ||
const item = { key, url, id: undefined }; | ||
|
||
if (isNumeric(id)) { | ||
item.id = id; | ||
} | ||
|
||
value.push(item); | ||
} | ||
} | ||
|
||
return value; | ||
}, [props.pathname]); | ||
|
||
/** | ||
* Returns true if there are more items to display. | ||
* | ||
* @type {function(*): boolean} | ||
*/ | ||
const hasMore = useCallback((index: number) => index < (items.length - 1), [items]); | ||
|
||
return ( | ||
<Breadcrumb | ||
size='large' | ||
> | ||
{ _.map(items, (item, index) => ( | ||
<> | ||
<BreadcrumbItem | ||
active={!hasMore(index)} | ||
as={props.as} | ||
id={item.id} | ||
label={props.labels[item.key]} | ||
name={item.key} | ||
onLoad={props.onLoad} | ||
url={item.url} | ||
/> | ||
{ hasMore(index) && ( | ||
<Breadcrumb.Divider | ||
icon='right chevron' | ||
/> | ||
)} | ||
</> | ||
))} | ||
</Breadcrumb> | ||
); | ||
}; | ||
|
||
export default Breadcrumbs; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.simple-edit-page.ui.grid { | ||
padding-bottom: 2.5em; | ||
} | ||
|
||
.simple-edit-page .menu .item.button-container > .button { | ||
margin-right: 0.25em; | ||
} |
Oops, something went wrong.