-
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.
IIIF #3 - Refactoring layout, list pages, and edit pages
- Loading branch information
1 parent
ff487a0
commit 95b3ba3
Showing
29 changed files
with
615 additions
and
236 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,27 @@ | ||
class Api::OrganizationsController < Api::BaseController | ||
search_attributes :name, :location | ||
|
||
protected | ||
|
||
def apply_filters(query) | ||
query = super | ||
|
||
query = filter_user(query) | ||
|
||
query | ||
end | ||
|
||
private | ||
|
||
def filter_user(query) | ||
return query unless params[:user_id].present? | ||
|
||
query.where( | ||
UserOrganization | ||
.where(UserOrganization.arel_table[:organization_id].eq(Organization.arel_table[:id])) | ||
.where(user_id: params[:user_id]) | ||
.arel | ||
.exists | ||
) | ||
end | ||
end |
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,3 +1,27 @@ | ||
class Api::UsersController < Api::BaseController | ||
search_attributes :name, :email | ||
|
||
protected | ||
|
||
def apply_filters(query) | ||
query = super | ||
|
||
query = filter_organization(query) | ||
|
||
query | ||
end | ||
|
||
private | ||
|
||
def filter_organization(query) | ||
return query unless params[:organization_id].present? | ||
|
||
query.where( | ||
UserOrganization | ||
.where(UserOrganization.arel_table[:user_id].eq(User.arel_table[:id])) | ||
.where(organization_id: params[:organization_id]) | ||
.arel | ||
.exists | ||
) | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// @flow | ||
|
||
import { BaseService } from '@performant-software/shared-components'; | ||
import React, { | ||
useEffect, | ||
useState, | ||
type Element, | ||
type Node | ||
} from 'react'; | ||
import { useParams } from 'react-router-dom'; | ||
|
||
type Props = { | ||
idParam: string, | ||
parameterName: string, | ||
renderItem: (item: any) => Element<any>, | ||
serviceClass: typeof BaseService, | ||
}; | ||
|
||
const Breadcrumb = (props: Props): Node => { | ||
const params = useParams(); | ||
const [item, setItem] = useState(); | ||
|
||
const id = params[props.idParam]; | ||
|
||
useEffect(() => { | ||
if (id) { | ||
props.serviceClass | ||
.fetchOne(id) | ||
.then(({ data }) => setItem(data[props.parameterName])); | ||
} | ||
}, [id]); | ||
|
||
if (!item) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<span>{ props.renderItem(item) }</span> | ||
); | ||
}; | ||
|
||
export default Breadcrumb; |
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,14 @@ | ||
// @flow | ||
|
||
import React, { type Node } from 'react'; | ||
import { Outlet } from 'react-router-dom'; | ||
import Breadcrumbs from './Breadcrumbs'; | ||
|
||
const DetailLayout = (): Node => ( | ||
<div> | ||
<Breadcrumbs /> | ||
<Outlet /> | ||
</div> | ||
); | ||
|
||
export default DetailLayout; |
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,43 @@ | ||
// @flow | ||
|
||
import { ListTable } from '@performant-software/semantic-components'; | ||
import React, { type Node } from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
import { Button } from 'semantic-ui-react'; | ||
import _ from 'underscore'; | ||
|
||
type Props = { | ||
actions?: Array<any>, | ||
buttons?: Array<any> | ||
}; | ||
|
||
const ItemList = (props: Props): Node => ( | ||
<ListTable | ||
actions={[{ | ||
name: 'edit', | ||
render: (item) => ( | ||
<Button | ||
as={Link} | ||
basic | ||
compact | ||
icon='edit' | ||
to={item.id.toString()} | ||
/> | ||
) | ||
}, { | ||
name: 'delete' | ||
}, ...(props.actions || [])]} | ||
addButton={{}} | ||
buttons={[{ | ||
as: Link, | ||
basic: true, | ||
content: 'Add', | ||
icon: 'plus', | ||
to: 'new' | ||
}, ...(props.buttons || [])]} | ||
perPageOptions={[10, 25, 50, 100]} | ||
{..._.omit(props, 'actions', 'buttons')} | ||
/> | ||
); | ||
|
||
export default ItemList; |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.