chore: fixes broken tests and ts

This commit is contained in:
James
2022-11-22 20:05:40 -05:00
parent 56682c7fd4
commit fbb4944e83
5 changed files with 17 additions and 15 deletions

View File

@@ -1,11 +1,11 @@
import React, { useReducer, useState, useCallback, useEffect } from 'react';
import { useTranslation } from 'react-i18next';
import { useConfig } from '../../../../utilities/Config';
import { Props, Option, ValueWithRelation, GetResults } from './types';
import { Props, ValueWithRelation, GetResults } from './types';
import optionsReducer from './optionsReducer';
import useDebounce from '../../../../../hooks/useDebounce';
import ReactSelect from '../../../ReactSelect';
import { Value } from '../../../ReactSelect/types';
import { Option } from '../../../ReactSelect/types';
import { PaginatedDocs } from '../../../../../../mongoose/types';
import './index.scss';
@@ -201,7 +201,7 @@ const RelationshipField: React.FC<Props> = (props) => {
if (hasMany) {
const matchedOptions = findOptionsByValue();
(matchedOptions as Value[] || []).forEach((option, i) => {
(matchedOptions as Option[] || []).forEach((option, i) => {
if (!option) {
if (hasMultipleRelations) {
addOptionByID(value[i].value, value[i].relationTo);
@@ -231,7 +231,7 @@ const RelationshipField: React.FC<Props> = (props) => {
errorLoading && 'error-loading',
].filter(Boolean).join(' ');
const valueToRender = (findOptionsByValue() || value) as Value;
const valueToRender = (findOptionsByValue() || value) as Option;
return (
<div className={classes}>

View File

@@ -41,7 +41,6 @@ export const AddNewRelation: React.FC<Props> = ({ path, hasMany, relationTo, val
dispatchOptions({
type: 'ADD',
hasMultipleRelations: Array.isArray(relationTo),
collection: modalCollection,
docs: [
json.doc,

View File

@@ -279,7 +279,7 @@ const Relationship: React.FC<Props> = (props) => {
setEnableWordBoundarySearch(!isIdOnly);
}, [relationTo, collections]);
// When relationTo changes, reset relationship options
// When relationTo or filterOptionsResult changes, reset component
// Note - effect should not run on first run
useEffect(() => {
if (firstRun.current) {
@@ -288,7 +288,10 @@ const Relationship: React.FC<Props> = (props) => {
}
dispatchOptions({ type: 'CLEAR' });
}, [relationTo]);
setLastFullyLoadedRelation(-1);
setLastLoadedPage(1);
setHasLoadedFirstPage(false);
}, [relationTo, filterOptionsResult]);
const classes = [
'field-type',

View File

@@ -6,7 +6,7 @@ import FieldDescription from '../../FieldDescription';
import { OptionObject, SelectField } from '../../../../../fields/config/types';
import { Description } from '../../FieldDescription/types';
import ReactSelect from '../../../elements/ReactSelect';
import { Value as ReactSelectValue } from '../../../elements/ReactSelect/types';
import { Option } from '../../../elements/ReactSelect/types';
import { getTranslation } from '../../../../../utilities/getTranslation';
import './index.scss';
@@ -19,7 +19,7 @@ export type SelectInputProps = Omit<SelectField, 'type' | 'value' | 'options'> &
required?: boolean
value?: string | string[]
description?: Description
onChange?: (value: ReactSelectValue) => void
onChange?: (value: Option) => void
style?: React.CSSProperties
className?: string
width?: string
@@ -87,7 +87,7 @@ const SelectInput: React.FC<SelectInputProps> = (props) => {
/>
<ReactSelect
onChange={onChange}
value={valueToRender as ReactSelectValue}
value={valueToRender as Option}
showError={showError}
isDisabled={readOnly}
options={options.map((option) => ({ ...option, label: getTranslation(option.label, i18n) }))}

View File

@@ -110,10 +110,10 @@ describe('fields - relationship', () => {
const options = page.locator('.rs__option');
await expect(options).toHaveCount(3); // None + two docs
await expect(options).toHaveCount(2); // two docs
// Select a relationship
await options.nth(1).click();
await options.nth(0).click();
await expect(field).toContainText(relationOneDoc.id);
await saveDocAndAssert(page);
@@ -155,7 +155,7 @@ describe('fields - relationship', () => {
const options = page.locator('.rs__option');
await expect(options).toHaveCount(4); // None + 3 docs
await expect(options).toHaveCount(3); // 3 docs
// Add one relationship
await options.locator(`text=${relationOneDoc.id}`).click();
@@ -204,7 +204,7 @@ describe('fields - relationship', () => {
await field.click({ delay: 100 });
const options = page.locator('.rs__option');
await expect(options).toHaveCount(2); // None + 1 Unitled ID
await expect(options).toHaveCount(1); // None + 1 Unitled ID
});
// test.todo('should paginate within the dropdown');
@@ -239,7 +239,7 @@ describe('fields - relationship', () => {
await field.click({ delay: 100 });
const options = page.locator('.rs__option');
await expect(options).toHaveCount(3); // None + 2 Doc
await expect(options).toHaveCount(2);
});
test('should show id on relation in list view', async () => {