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

Made library-related header links update when library changes. #101

Merged
merged 1 commit into from
Jul 12, 2017
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
4 changes: 2 additions & 2 deletions src/components/CatalogHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ export interface CatalogHandlerProps extends React.Props<CatalogHandler> {
export default class CatalogHandler extends React.Component<CatalogHandlerProps, any> {
static childContextTypes: React.ValidationMap<any> = {
tab: React.PropTypes.string,
library: React.PropTypes.string
library: React.PropTypes.func
};

getChildContext() {
return {
tab: this.props.params.tab,
library: this.getLibrary(this.props.params.collectionUrl, this.props.params.bookUrl)
library: () => this.getLibrary(this.props.params.collectionUrl, this.props.params.bookUrl)
};
}

Expand Down
13 changes: 7 additions & 6 deletions src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ export interface HeaderProps extends React.Props<Header> {
}

export class Header extends React.Component<HeaderProps, any> {
context: { library: string, router: Router };
context: { library: () => string, router: Router };

static contextTypes = {
library: React.PropTypes.string,
library: React.PropTypes.func,
router: React.PropTypes.object.isRequired
};

Expand All @@ -40,7 +40,7 @@ export class Header extends React.Component<HeaderProps, any> {
<EditableInput
elementType="select"
ref="library"
value={this.context.library}
value={this.context.library && this.context.library()}
onChange={this.changeLibrary}
>
{ !this.context.library &&
Expand All @@ -60,21 +60,21 @@ export class Header extends React.Component<HeaderProps, any> {
<Nav>
<li>
<CatalogLink
collectionUrl={"/" + this.context.library + "/groups"}
collectionUrl={"/" + this.context.library() + "/groups"}
bookUrl={null}>
Catalog
</CatalogLink>
</li>
<li>
<CatalogLink
collectionUrl={"/" + this.context.library + "/admin/complaints"}
collectionUrl={"/" + this.context.library() + "/admin/complaints"}
bookUrl={null}>
Complaints
</CatalogLink>
</li>
<li>
<CatalogLink
collectionUrl={"/" + this.context.library + "/admin/suppressed"}
collectionUrl={"/" + this.context.library() + "/admin/suppressed"}
bookUrl={null}>
Hidden Books
</CatalogLink>
Expand Down Expand Up @@ -104,6 +104,7 @@ export class Header extends React.Component<HeaderProps, any> {
let library = (this.refs["library"] as any).getValue();
if (library) {
this.context.router.push("/admin/web/collection/" + library + "%2Fgroups");
this.forceUpdate();
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/__tests__/CatalogHandler-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ describe("CatalogHandler", () => {

it("includes library in child context", () => {
let context = wrapper.instance().getChildContext();
expect(context.library).to.equal("library");
expect(context.library()).to.equal("library");

let newParams = Object.assign({}, params, { collectionUrl: null, bookUrl: "library/bookurl" });
wrapper.setProps({ params: newParams });
context = wrapper.instance().getChildContext();
expect(context.library).to.equal("library");
expect(context.library()).to.equal("library");

newParams = Object.assign({}, params, { collectionUrl: null, bookUrl: null });
wrapper.setProps({ params: newParams });
context = wrapper.instance().getChildContext();
expect(context.library).to.equal(null);
expect(context.library()).to.equal(null);
});
});
4 changes: 2 additions & 2 deletions src/components/__tests__/Header-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe("Header", () => {

beforeEach(() => {
push = stub();
context = { library: "nypl" };
context = { library: () => "nypl" };

wrapper = shallow(
<Header />,
Expand Down Expand Up @@ -48,7 +48,7 @@ describe("Header", () => {
expect(options.at(1).text()).to.equal("bpl");
expect(options.at(1).props().value).to.equal("bpl");

wrapper.setContext({ library: "bpl" });
wrapper.setContext({ library: () => "bpl" });
select = wrapper.find(EditableInput);
expect(select.props().value).to.equal("bpl");

Expand Down