You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.tsx 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import TopNItem from '@/components/top-n-item';
  2. import { useTranslate } from '@/hooks/common-hooks';
  3. import { DatePicker, DatePickerProps, Form, Select, Switch } from 'antd';
  4. import dayjs from 'dayjs';
  5. import { useCallback, useMemo } from 'react';
  6. import { useBuildSortOptions } from '../../form-hooks';
  7. import { IOperatorForm } from '../../interface';
  8. const YearPicker = ({
  9. onChange,
  10. value,
  11. }: {
  12. onChange?: (val: number | undefined) => void;
  13. value?: number | undefined;
  14. }) => {
  15. const handleChange: DatePickerProps['onChange'] = useCallback(
  16. (val: any) => {
  17. const nextVal = val?.format('YYYY');
  18. onChange?.(nextVal ? Number(nextVal) : undefined);
  19. },
  20. [onChange],
  21. );
  22. // The year needs to be converted into a number and saved to the backend
  23. const nextValue = useMemo(() => {
  24. if (value) {
  25. return dayjs(value.toString());
  26. }
  27. return undefined;
  28. }, [value]);
  29. return <DatePicker picker="year" onChange={handleChange} value={nextValue} />;
  30. };
  31. const GoogleScholarForm = ({ onValuesChange, form }: IOperatorForm) => {
  32. const { t } = useTranslate('flow');
  33. const options = useBuildSortOptions();
  34. return (
  35. <Form
  36. name="basic"
  37. labelCol={{ span: 6 }}
  38. wrapperCol={{ span: 18 }}
  39. autoComplete="off"
  40. form={form}
  41. onValuesChange={onValuesChange}
  42. >
  43. <TopNItem initialValue={5}></TopNItem>
  44. <Form.Item
  45. label={t('sortBy')}
  46. name={'sort_by'}
  47. initialValue={'relevance'}
  48. >
  49. <Select options={options}></Select>
  50. </Form.Item>
  51. <Form.Item label={t('yearLow')} name={'year_low'}>
  52. <YearPicker />
  53. </Form.Item>
  54. <Form.Item label={t('yearHigh')} name={'year_high'}>
  55. <YearPicker />
  56. </Form.Item>
  57. <Form.Item
  58. label={t('patents')}
  59. name={'patents'}
  60. valuePropName="checked"
  61. initialValue={true}
  62. >
  63. <Switch></Switch>
  64. </Form.Item>
  65. </Form>
  66. );
  67. };
  68. export default GoogleScholarForm;