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

Add establishment search results page #43

Merged
merged 5 commits into from
Jan 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const {
} = pages;

const dashboard = require('../pages/dashboard');
const establishmentList = require('../pages/establishment-list');
const search = require('../pages/search');

const urls = require('./urls');
Expand Down Expand Up @@ -51,12 +50,6 @@ module.exports = settings => {

app.use(urls.account.menu, user());
app.use(urls.feedback, feedback(settings));
app.use(urls.establishment.list, establishmentList());

app.use(urls.establishment.list, (req, res, next) => {
req.breadcrumb('establishment.list');
next();
});

app.use(urls.establishment.dashboard, (req, res, next) => {
req.breadcrumb('establishment.dashboard');
Expand Down
1 change: 0 additions & 1 deletion lib/urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module.exports = {
edit: '/profile/edit'
},
establishment: {
list: '/establishments',
dashboard: '/establishments/:establishmentId',
read: '/establishments/:establishmentId/details'
},
Expand Down
2 changes: 1 addition & 1 deletion pages/components/search-panel/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
placeholder: 'Search by name',
viewAll: 'View all establishments'
},
people: {
profiles: {
label: 'People',
placeholder: 'Search by name or licence number',
viewAll: 'View all people'
Expand Down
29 changes: 5 additions & 24 deletions pages/components/search-panel/index.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component } from 'react';
import { Link, Search, Snippet } from '@asl/components';
import { Search, Snippet } from '@asl/components';

class SearchPanel extends Component {
render() {
Expand Down Expand Up @@ -27,24 +27,9 @@ class SearchPanel extends Component {

<div className="govuk-grid-column-one-third">
<div className="view-all-link">
{ searchType === 'establishments' &&
<Link
page="establishment.list"
label={<Snippet>searchPanel.establishments.viewAll</Snippet>}
/>
}
{ searchType === 'people' &&
<Link
page="profile.list"
label={<Snippet>searchPanel.people.viewAll</Snippet>}
/>
}
{ searchType === 'projects' &&
<Link
page="project.list"
label={<Snippet>searchPanel.projects.viewAll</Snippet>}
/>
}
<a href={`/search/${searchType}`}>
<Snippet>{`searchPanel.${searchType}.viewAll`}</Snippet>
</a>
</div>
</div>
</div>
Expand All @@ -54,11 +39,7 @@ class SearchPanel extends Component {
}

SearchPanel.defaultProps = {
searchableModels: [
'establishments',
'people',
'projects'
]
searchableModels: ['establishments', 'profiles', 'projects']
};

export default SearchPanel;
11 changes: 0 additions & 11 deletions pages/establishment-list/content/index.js

This file was deleted.

22 changes: 0 additions & 22 deletions pages/establishment-list/index.js

This file was deleted.

8 changes: 0 additions & 8 deletions pages/establishment-list/schema/index.js

This file was deleted.

34 changes: 0 additions & 34 deletions pages/establishment-list/views/index.jsx

This file was deleted.

8 changes: 8 additions & 0 deletions pages/search/content/establishments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
name: {
label: 'Name'
},
status: {
label: 'Status'
}
};
25 changes: 12 additions & 13 deletions pages/search/content/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
const searchPanel = require('../../components/search-panel/content');
const establishments = require('./establishments');
const profiles = require('./profiles');
const projects = require('./projects');

module.exports = {
const fields = {
establishments,
profiles,
projects
};

module.exports = (searchType) => ({
breadcrumbs: {
search: 'Search'
},
searchPanel,
fields: {
lastName: {
label: 'Name'
},
email: {
label: 'Email'
},
establishments: {
label: 'Establishments'
}
}
};
fields: fields[searchType]
});
11 changes: 11 additions & 0 deletions pages/search/content/profiles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
lastName: {
label: 'Name'
},
email: {
label: 'Email'
},
establishments: {
label: 'Establishments'
}
};
2 changes: 2 additions & 0 deletions pages/search/content/projects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module.exports = {
};
23 changes: 7 additions & 16 deletions pages/search/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const { merge } = require('lodash');
const { page } = require('@asl/service/ui');
const datatable = require('@asl/pages/pages/common/routers/datatable');
const schemas = require('./schema');
const NotFoundError = require('../../lib/errors/not-found');
const content = require('./content');

const searchableModels = ['establishments', 'people', 'projects'];
const searchableModels = ['establishments', 'profiles', 'projects'];

module.exports = settings => {
const app = page({
Expand All @@ -15,6 +17,7 @@ module.exports = settings => {
req.breadcrumb('search');
req.searchType = req.params.searchType || searchableModels[0];

merge(res.locals.static.content, content(req.searchType));
res.locals.static.profile = req.user.profile;
res.locals.static.searchType = req.searchType;
res.locals.static.searchableModels = req.query.searchableModels;
Expand All @@ -24,27 +27,15 @@ module.exports = settings => {
app.use('/', datatable({
configure: (req, res, next) => {
const searchType = req.searchType;
req.datatable.searchType = searchType;
req.datatable.schema = schemas[searchType];
req.datatable.disable = !req.query.filters;

if (searchType && !searchableModels.includes(searchType)) {
return next(new NotFoundError());
}

switch (searchType) {
case 'people':
req.datatable.apiPath = `/search/profiles`;
break;

case 'projects':
req.datatable.apiPath = `/search/projects`;
break;
req.datatable.searchType = searchType;
req.datatable.schema = schemas[searchType];
req.datatable.apiPath = `/search/${searchType}`;

default:
req.datatable.apiPath = `/search/establishments`;
break;
}
next();
}
})());
Expand Down
12 changes: 11 additions & 1 deletion pages/search/schema/establishments.js
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
module.exports = {};
module.exports = {
id: {
filter: false
},
name: {
show: true
},
status: {
show: true
}
};
2 changes: 1 addition & 1 deletion pages/search/schema/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
establishments: require('./establishments'),
people: require('./people'),
profiles: require('./profiles'),
projects: require('./projects')
};
File renamed without changes.
30 changes: 16 additions & 14 deletions pages/search/views/index.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import React, { Fragment } from 'react';
import { connect } from 'react-redux';
import { Datatable, FilterSummary, Header, Snippet } from '@asl/components';
import { Datatable, FilterSummary, Header, Link, Snippet } from '@asl/components';
import SearchPanel from '../../components/search-panel';

const formatters = {
lastName: {
format: (lastName, profile) => `${profile.firstName} ${lastName}`
},
establishments: {
format: establishments => establishments.map(establishment => establishment.name).join(', ')
}
name: {
format: (name, establishment) => <Link page="establishment.read" establishmentId={establishment.id} label={name} />
}
},
profiles: {
lastName: {
format: (lastName, profile) => `${profile.firstName} ${lastName}`
},
establishments: {
format: establishments => establishments.map(establishment => establishment.name).join(', ')
wheelsandcogs marked this conversation as resolved.
Show resolved Hide resolved
}
},
projects: {}
};

const Index = ({ profile, searchType, searchableModels, filters }) => {
Expand All @@ -20,14 +28,8 @@ const Index = ({ profile, searchType, searchableModels, filters }) => {
<div className="govuk-grid-row">
<div className="govuk-grid-column-full">
<SearchPanel searchType={searchType} searchableModels={searchableModels} />

{ filters.active['*'] &&
<Fragment>
<FilterSummary />
<Datatable formatters={formatters} />
</Fragment>
}

<FilterSummary />
<Datatable formatters={formatters[searchType]} />
</div>
</div>

Expand Down