Farmbot-Web-App/frontend/farm_designer/plants/openfarm_search_results.tsx

65 lines
1.8 KiB
TypeScript
Raw Normal View History

2017-06-29 12:54:02 -06:00
import * as React from "react";
import { Link } from "../../link";
2018-11-28 15:29:46 -07:00
import {
EmptyStateWrapper, EmptyStateGraphic
} from "../../ui/empty_state_wrapper";
import { Content } from "../../constants";
2019-04-02 13:59:37 -06:00
import { t } from "../../i18next_wrapper";
2020-02-15 11:30:23 -07:00
import { ExternalUrl } from "../../external_urls";
2019-04-02 13:59:37 -06:00
2017-08-23 14:49:30 -06:00
/** A stripped down version of OFSearchResult */
interface Result {
crop: {
slug: string;
name: string;
};
image: string;
}
export interface SearchResultProps {
cropSearchResults: Result[];
2018-11-28 15:29:46 -07:00
cropSearchInProgress: boolean;
2017-08-23 14:49:30 -06:00
}
export class OpenFarmResults extends React.Component<SearchResultProps, {}> {
2018-11-28 15:29:46 -07:00
get text(): JSX.Element {
return <p>{`${t(Content.CROP_NOT_FOUND_INTRO)} `}
2020-02-15 11:30:23 -07:00
<a href={ExternalUrl.OpenFarm.newCrop} target="_blank">
2018-11-28 15:29:46 -07:00
{t(Content.CROP_NOT_FOUND_LINK)}
</a>
</p>;
}
2017-06-29 12:54:02 -06:00
render() {
return <div>
2018-11-28 15:29:46 -07:00
<EmptyStateWrapper
notEmpty={this.props.cropSearchResults.length > 0}
graphic={EmptyStateGraphic.no_crop_results}
title={this.props.cropSearchInProgress
? t("Searching...")
: t("No search results")}
textElement={this.props.cropSearchInProgress ? <div /> : this.text}
colorScheme={"plants"}>
{this.props.cropSearchResults.map(resp => {
const { crop, image } = resp;
return <Link
key={resp.crop.slug}
draggable={false}
to={`/app/designer/plants/crop_search/` + crop.slug.toString()}>
<div className="plant-catalog-tile col-xs-6">
<label>
{crop.name}
</label>
<div
className="plant-catalog-image"
style={{ background: `url(${image}) top center no-repeat` }}
draggable={false} />
</div>
</Link>;
})}
</EmptyStateWrapper>
2017-06-29 12:54:02 -06:00
</div>;
}
}