diff --git a/eslint.config.mjs b/eslint.config.mjs index 2afbbbfea0..0d47c8009b 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -30,7 +30,7 @@ const config = tseslint.config( "no-console": ["error", { allow: ["warn", "error"] }], "no-unused-vars": "off", "@typescript-eslint/no-unused-vars": [ - "off", + "error", { "argsIgnorePattern": "^_[^_].*$|^_$", "varsIgnorePattern": "^_[^_].*$|^_$", diff --git a/package.json b/package.json index 939a0c904d..0420b7baff 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ }, "lint-staged": { "*.{ts,tsx,js,jsx}": [ - "eslint --fix --max-warnings=0 " + "eslint --fix " ], "*.{js,jsx,ts,tsx,css,json,md}": [ "prettier --write " diff --git a/packages/common-ui/lib/account/DevUserProvider.tsx b/packages/common-ui/lib/account/DevUserProvider.tsx index 9e2cc1c250..755696b768 100644 --- a/packages/common-ui/lib/account/DevUserProvider.tsx +++ b/packages/common-ui/lib/account/DevUserProvider.tsx @@ -26,7 +26,7 @@ export function DevUserAccountProvider({ setDevModeEnabled(response.data["devUserEnabled"]); setKeycloakEnabled(response.data["keycloakEnabled"]); setGroupRole(response.data["groupRole"]); - } catch (error) { + } catch { setDevModeEnabled(false); setKeycloakEnabled(true); } diff --git a/packages/common-ui/lib/api-client/ApiClientContext.tsx b/packages/common-ui/lib/api-client/ApiClientContext.tsx index e5632e15f5..032f05fd09 100644 --- a/packages/common-ui/lib/api-client/ApiClientContext.tsx +++ b/packages/common-ui/lib/api-client/ApiClientContext.tsx @@ -8,8 +8,8 @@ import Kitsu, { KitsuResourceLink, PersistedResource } from "kitsu"; -import { deserialise, error as kitsuError, query } from "kitsu-core"; -import { compact, flatMap, fromPairs, isEmpty, keys, omit } from "lodash"; +import { deserialise, error as kitsuError } from "kitsu-core"; +import { compact, fromPairs, isEmpty, keys, omit } from "lodash"; import LRUCache from "lru-cache"; import React, { PropsWithChildren, useContext, useMemo } from "react"; import { v4 as uuidv4 } from "uuid"; @@ -22,7 +22,6 @@ import { SuccessfulOperation } from "./operations-types"; import DataLoader from "dataloader"; -import { ResponseType } from "axios"; export interface BulkGetOptions { apiBaseUrl?: string; diff --git a/packages/common-ui/lib/api-client/useElasticSearchQuery.tsx b/packages/common-ui/lib/api-client/useElasticSearchQuery.tsx index aefa254f49..dc442a0a41 100644 --- a/packages/common-ui/lib/api-client/useElasticSearchQuery.tsx +++ b/packages/common-ui/lib/api-client/useElasticSearchQuery.tsx @@ -1,4 +1,4 @@ -import { useContext, useMemo } from "react"; +import { useMemo } from "react"; import useSWR from "swr"; import { useApiClient } from "./ApiClientContext"; import { v4 as uuidv4 } from "uuid"; diff --git a/packages/common-ui/lib/api-client/useQuery.tsx b/packages/common-ui/lib/api-client/useQuery.tsx index f0ae23dc9d..58c4020cab 100644 --- a/packages/common-ui/lib/api-client/useQuery.tsx +++ b/packages/common-ui/lib/api-client/useQuery.tsx @@ -7,7 +7,6 @@ import { v4 as uuidv4 } from "uuid"; import { LoadingSpinner } from "../loading-spinner/LoadingSpinner"; import { ApiClientContext } from "./ApiClientContext"; import { ClientSideJoiner, ClientSideJoinSpec } from "./client-side-join"; -import { ResponseType } from "axios"; import Link from "next/link"; /** Attributes that compose a JsonApi query. */ diff --git a/packages/common-ui/lib/filter-builder/__tests__/rsql.test.ts b/packages/common-ui/lib/filter-builder/__tests__/rsql.test.ts index da8399d812..dc0a1382c3 100644 --- a/packages/common-ui/lib/filter-builder/__tests__/rsql.test.ts +++ b/packages/common-ui/lib/filter-builder/__tests__/rsql.test.ts @@ -1,4 +1,3 @@ -import { KitsuResource } from "kitsu"; import { FilterGroupModel } from "../FilterGroup"; import { rsql } from "../rsql"; diff --git a/packages/common-ui/lib/formik-connected/CheckBoxField.tsx b/packages/common-ui/lib/formik-connected/CheckBoxField.tsx index 60da258aa0..beb01dcb5d 100644 --- a/packages/common-ui/lib/formik-connected/CheckBoxField.tsx +++ b/packages/common-ui/lib/formik-connected/CheckBoxField.tsx @@ -20,7 +20,7 @@ const checkboxProps = { }; export function CheckBoxField(props: CheckBoxProps) { - const { onCheckBoxClick, disabled, type } = props; + const { onCheckBoxClick, disabled } = props; return ( String(!!value)}> {({ setValue, value, formik }) => { diff --git a/packages/common-ui/lib/formik-connected/CreatableSelectField.tsx b/packages/common-ui/lib/formik-connected/CreatableSelectField.tsx index 46f703702a..6d58548880 100644 --- a/packages/common-ui/lib/formik-connected/CreatableSelectField.tsx +++ b/packages/common-ui/lib/formik-connected/CreatableSelectField.tsx @@ -1,6 +1,6 @@ import { FormikContextType } from "formik"; import { find, isArray, castArray, compact } from "lodash"; -import { RefObject, useState } from "react"; +import { RefObject } from "react"; import { StylesConfig } from "react-select"; import { ReadOnlyValue } from "./FieldView"; import { FieldWrapper, FieldWrapperProps } from "./FieldWrapper"; diff --git a/packages/common-ui/lib/formik-connected/FieldSet.tsx b/packages/common-ui/lib/formik-connected/FieldSet.tsx index d5d15aeab3..69ba7118d7 100644 --- a/packages/common-ui/lib/formik-connected/FieldSet.tsx +++ b/packages/common-ui/lib/formik-connected/FieldSet.tsx @@ -36,7 +36,7 @@ export function FieldSet({ ...formSectionProps }: FieldSetProps) { const context = useContext(DinaFormContext); - const { componentName, sectionName, isTemplate } = formSectionProps; + const { componentName, sectionName } = formSectionProps; // Check the section to see if it should be visible or not. const disableSection = useMemo(() => { diff --git a/packages/common-ui/lib/formik-connected/FormattedTextField.tsx b/packages/common-ui/lib/formik-connected/FormattedTextField.tsx index 5d41f1a6b2..a6aa5a678f 100644 --- a/packages/common-ui/lib/formik-connected/FormattedTextField.tsx +++ b/packages/common-ui/lib/formik-connected/FormattedTextField.tsx @@ -16,9 +16,7 @@ export interface FormattedTextFieldProps extends FieldWrapperProps { */ export function FormattedTextField(props: FormattedTextFieldProps) { const { - initialValue, readOnly, - multiLines, inputProps: inputPropsExternal, placeholder, ...labelWrapperProps diff --git a/packages/common-ui/lib/formik-connected/GeoSuggestSearchBox.tsx b/packages/common-ui/lib/formik-connected/GeoSuggestSearchBox.tsx index 5898e146d7..0030f8748e 100644 --- a/packages/common-ui/lib/formik-connected/GeoSuggestSearchBox.tsx +++ b/packages/common-ui/lib/formik-connected/GeoSuggestSearchBox.tsx @@ -72,7 +72,7 @@ export function GeoSuggestSearchBox({ try { const results = await fetchJson(url.toString()); return results as NominatumApiSearchResult[]; - } catch (error) { + } catch { return []; } } diff --git a/packages/common-ui/lib/formik-connected/MetersField.tsx b/packages/common-ui/lib/formik-connected/MetersField.tsx index 2741ada48e..0bdbee1450 100644 --- a/packages/common-ui/lib/formik-connected/MetersField.tsx +++ b/packages/common-ui/lib/formik-connected/MetersField.tsx @@ -163,6 +163,7 @@ export function toMeters( // Special case matcher for "x feet x inches" -formatted text: const feetInchMatch = FEET_INCH_REGEX.exec(text); if (feetInchMatch) { + // eslint-disable-next-line @typescript-eslint/no-unused-vars const [_, feet, __, inches] = feetInchMatch; return toMeters(`${feet} feet + ${inches} inches`, maxDecimalPlaces); } @@ -174,7 +175,7 @@ export function toMeters( return maxDecimalPlaces !== undefined ? inMeters.toFixed(clamp(decimalPlaces, maxDecimalPlaces)) : String(inMeters); - } catch (error) { + } catch { // If the input contains a number: const containsNumbersMatch = CONTAINS_NUMBERS_REGEX.exec(text); if (containsNumbersMatch) { diff --git a/packages/common-ui/lib/formik-connected/NumberField.tsx b/packages/common-ui/lib/formik-connected/NumberField.tsx index fd4432c345..7f505c8b92 100644 --- a/packages/common-ui/lib/formik-connected/NumberField.tsx +++ b/packages/common-ui/lib/formik-connected/NumberField.tsx @@ -1,7 +1,7 @@ import { ChangeEvent, FocusEvent } from "react"; import { useIntl } from "react-intl"; import * as yup from "yup"; -import { TextField, TextFieldProps, useFieldLabels } from ".."; +import { TextField, TextFieldProps } from ".."; export interface NumberFieldProps extends TextFieldProps { placeholder?: string; diff --git a/packages/common-ui/lib/formik-connected/ResourceSelectField.tsx b/packages/common-ui/lib/formik-connected/ResourceSelectField.tsx index 875a7a1547..0b0cf2fa28 100644 --- a/packages/common-ui/lib/formik-connected/ResourceSelectField.tsx +++ b/packages/common-ui/lib/formik-connected/ResourceSelectField.tsx @@ -40,7 +40,6 @@ export function ResourceSelectField( resourceSelectFieldProps: ResourceSelectFieldProps ) { const { - name, onChange, readOnlyRender, showGroupCategary = false, diff --git a/packages/common-ui/lib/formik-connected/SelectFieldWithNav.tsx b/packages/common-ui/lib/formik-connected/SelectFieldWithNav.tsx index f60170ed5d..3b01521684 100644 --- a/packages/common-ui/lib/formik-connected/SelectFieldWithNav.tsx +++ b/packages/common-ui/lib/formik-connected/SelectFieldWithNav.tsx @@ -1,7 +1,6 @@ import { FormikProps } from "formik"; import React, { useRef, useState } from "react"; import { FaCaretLeft, FaCaretRight } from "react-icons/fa"; -import { GoCircleSlash } from "react-icons/go"; import { SelectField, SelectOption } from "./SelectField"; interface SelectFieldWithNavProps { diff --git a/packages/common-ui/lib/formik-connected/__tests__/FieldExtensionSelectField.test.tsx b/packages/common-ui/lib/formik-connected/__tests__/FieldExtensionSelectField.test.tsx index 9ef8429c47..18274f36b2 100644 --- a/packages/common-ui/lib/formik-connected/__tests__/FieldExtensionSelectField.test.tsx +++ b/packages/common-ui/lib/formik-connected/__tests__/FieldExtensionSelectField.test.tsx @@ -2,7 +2,6 @@ import React from "react"; import { mountWithAppContext } from "common-ui"; import { DinaForm } from "../DinaForm"; import { FieldExtensionSelectField } from "../FieldExtensionSelectField"; -import Select from "react-select/base"; import "@testing-library/jest-dom"; import { waitFor, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; @@ -43,7 +42,7 @@ const apiContext: any = { describe("FieldExtensionSelectField component", () => { it("Renders the FieldExtensionSelectField's options correctly.", async () => { // Render the component using the provided RTL wrapper function - const wrapper = mountWithAppContext( + mountWithAppContext( {({ values: { cfia_ppc } }) => ( <> diff --git a/packages/common-ui/lib/formik-connected/__tests__/GroupedCheckBoxFields.test.tsx b/packages/common-ui/lib/formik-connected/__tests__/GroupedCheckBoxFields.test.tsx index 731f30d537..26a46022ee 100644 --- a/packages/common-ui/lib/formik-connected/__tests__/GroupedCheckBoxFields.test.tsx +++ b/packages/common-ui/lib/formik-connected/__tests__/GroupedCheckBoxFields.test.tsx @@ -50,7 +50,7 @@ describe("Grouped check boxes hook", () => { }); it("Renders checkboxes.", () => { - const wrapper = mountWithAppContext(); + mountWithAppContext(); // Find all checkbox inputs const checkboxes = screen.getAllByRole("checkbox", { name: /select/i }); // Assert that 5 checkboxes are rendered diff --git a/packages/common-ui/lib/formik-connected/__tests__/MetersField.test.tsx b/packages/common-ui/lib/formik-connected/__tests__/MetersField.test.tsx index 428467eeb0..6f28370dee 100644 --- a/packages/common-ui/lib/formik-connected/__tests__/MetersField.test.tsx +++ b/packages/common-ui/lib/formik-connected/__tests__/MetersField.test.tsx @@ -92,7 +92,7 @@ describe("MetersField component", () => { }); it("Does the unit conversion onBlur.", async () => { - const wrapper = mountWithAppContext( + mountWithAppContext( @@ -189,7 +189,7 @@ describe("MetersField component", () => { }); it("Renders the initial value.", () => { - const wrapper = mountWithAppContext( + mountWithAppContext( mockSubmit(submittedValues)} @@ -202,7 +202,7 @@ describe("MetersField component", () => { }); it("Updates the input value when the form state changes.", () => { - const wrapper = mountWithAppContext( + mountWithAppContext( mockSubmit(submittedValues)} diff --git a/packages/common-ui/lib/formik-connected/__tests__/NumberField.test.tsx b/packages/common-ui/lib/formik-connected/__tests__/NumberField.test.tsx index 3d7e4f9489..f64492f1d4 100644 --- a/packages/common-ui/lib/formik-connected/__tests__/NumberField.test.tsx +++ b/packages/common-ui/lib/formik-connected/__tests__/NumberField.test.tsx @@ -23,7 +23,7 @@ describe("NumberField component", () => { }); it("Displays the field's label and value.", async () => { - const wrapper = getWrapper({ initialValues: { testField: 123.23 } }); + getWrapper({ initialValues: { testField: 123.23 } }); // Assert the label text expect(screen.getByLabelText("Test Field")).toBeInTheDocument(); @@ -70,7 +70,7 @@ describe("NumberField component", () => { }); it("Shows a blank input when the formik value is undefined.", async () => { - const wrapper = getWrapper({ initialValues: {} }); + getWrapper({ initialValues: {} }); // Assert the input value const input = screen.getByRole("textbox"); expect(input).toHaveValue(""); diff --git a/packages/common-ui/lib/formik-connected/__tests__/PlaceSectionsSelectionField.test.tsx b/packages/common-ui/lib/formik-connected/__tests__/PlaceSectionsSelectionField.test.tsx index ad7e5399cd..f1c2526ff5 100644 --- a/packages/common-ui/lib/formik-connected/__tests__/PlaceSectionsSelectionField.test.tsx +++ b/packages/common-ui/lib/formik-connected/__tests__/PlaceSectionsSelectionField.test.tsx @@ -36,7 +36,7 @@ describe("PlaceSectionSelectionField component", () => { beforeEach(jest.clearAllMocks); it("Display Src Admin Levels to table.", async () => { - const wrapper = mountWithAppContext( + mountWithAppContext( { it("Displays the field's label value.", () => { - const wrapper = mountWithAppContext( + mountWithAppContext( @@ -19,7 +19,7 @@ describe("QueryLogicSwitchField component", () => { }); it("Changes the selected query logic will update the submitted value.", async () => { - const wrapper = mountWithAppContext( + mountWithAppContext( diff --git a/packages/common-ui/lib/formik-connected/__tests__/ResourceSelectField.test.tsx b/packages/common-ui/lib/formik-connected/__tests__/ResourceSelectField.test.tsx index 101e02ed9c..676256cfbe 100644 --- a/packages/common-ui/lib/formik-connected/__tests__/ResourceSelectField.test.tsx +++ b/packages/common-ui/lib/formik-connected/__tests__/ResourceSelectField.test.tsx @@ -1,11 +1,9 @@ import { KitsuResource } from "kitsu"; -import lodash from "lodash"; -import Select from "react-select/base"; import { ResourceSelectField } from "../../"; import { mountWithAppContext } from "common-ui"; import { DinaForm } from "../DinaForm"; import "@testing-library/jest-dom"; -import { fireEvent, screen, waitFor, within } from "@testing-library/react"; +import { screen, waitFor } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; interface TestGroup extends KitsuResource { @@ -59,7 +57,7 @@ jest.mock("use-debounce", () => ({ describe("ResourceSelectField component", () => { it("Displays the Formik field's value.", () => { - const wrapper = mountWithAppContext( + mountWithAppContext( @@ -133,7 +131,7 @@ describe("ResourceSelectField component", () => { it("Provides an onChange callback prop.", async () => { const mockOnChange = jest.fn(); - const wrapper = mountWithAppContext( + mountWithAppContext( name="group" diff --git a/packages/common-ui/lib/formik-connected/__tests__/safeSubmit.test.tsx b/packages/common-ui/lib/formik-connected/__tests__/safeSubmit.test.tsx index 2480bdf34b..68a6adc5b2 100644 --- a/packages/common-ui/lib/formik-connected/__tests__/safeSubmit.test.tsx +++ b/packages/common-ui/lib/formik-connected/__tests__/safeSubmit.test.tsx @@ -4,8 +4,7 @@ import { mountWithAppContext } from "common-ui"; import { ErrorViewer } from "../ErrorViewer"; import { OnFormikSubmit, safeSubmit } from "../safeSubmit"; import "@testing-library/jest-dom"; -import { fireEvent, screen, waitFor } from "@testing-library/react"; -import userEvent from "@testing-library/user-event"; +import { fireEvent } from "@testing-library/react"; function getWrapper(customOnSubmit: OnFormikSubmit) { const onSubmit = safeSubmit(customOnSubmit); diff --git a/packages/common-ui/lib/formik-connected/data-entry/DataBlock.tsx b/packages/common-ui/lib/formik-connected/data-entry/DataBlock.tsx index c25c32941b..e3358938b4 100644 --- a/packages/common-ui/lib/formik-connected/data-entry/DataBlock.tsx +++ b/packages/common-ui/lib/formik-connected/data-entry/DataBlock.tsx @@ -1,6 +1,6 @@ import { useFormikContext } from "formik"; import { find } from "lodash"; -import { useEffect, useState } from "react"; +import { useState } from "react"; import Button from "react-bootstrap/Button"; import { CheckBoxField, diff --git a/packages/common-ui/lib/formik-connected/data-entry/DataEntryField.tsx b/packages/common-ui/lib/formik-connected/data-entry/DataEntryField.tsx index 332ff2896e..9e0136a45f 100644 --- a/packages/common-ui/lib/formik-connected/data-entry/DataEntryField.tsx +++ b/packages/common-ui/lib/formik-connected/data-entry/DataEntryField.tsx @@ -1,5 +1,3 @@ -import { Dispatch } from "react"; -import { FieldWrapper } from "../.."; import { DataEntry } from "./DataEntry"; export interface DataEntryFieldProps { diff --git a/packages/common-ui/lib/instance/__tests__/useInstanceContext.test.tsx b/packages/common-ui/lib/instance/__tests__/useInstanceContext.test.tsx index 0ec834f6fa..aef206b173 100644 --- a/packages/common-ui/lib/instance/__tests__/useInstanceContext.test.tsx +++ b/packages/common-ui/lib/instance/__tests__/useInstanceContext.test.tsx @@ -1,8 +1,6 @@ import { InstanceContext, InstanceContextI } from "../InstanceContextProvider"; import { render } from "@testing-library/react"; -import { ApiClientProvider } from "../../api-client/ApiClientContext"; -import { InstanceContextProvider } from "../InstanceContextProvider"; import { useInstanceContext } from "../useInstanceContext"; import "@testing-library/jest-dom"; import { ReactNode } from "react"; diff --git a/packages/common-ui/lib/intl/IntlSupport.tsx b/packages/common-ui/lib/intl/IntlSupport.tsx index 79256a49ba..83f7085031 100644 --- a/packages/common-ui/lib/intl/IntlSupport.tsx +++ b/packages/common-ui/lib/intl/IntlSupport.tsx @@ -3,8 +3,7 @@ import { createContext, useContext, useEffect, useMemo } from "react"; import { FormattedMessage as ReactFormattedMessage, IntlProvider as ReactIntlProvider, - useIntl as useReactIntl, - ReactIntlErrorCode + useIntl as useReactIntl } from "react-intl"; interface MessageDictionary { diff --git a/packages/common-ui/lib/intl/common-ui-intl.ts b/packages/common-ui/lib/intl/common-ui-intl.ts index 58d34a0267..79a8d507c6 100644 --- a/packages/common-ui/lib/intl/common-ui-intl.ts +++ b/packages/common-ui/lib/intl/common-ui-intl.ts @@ -7,7 +7,7 @@ const en = COMMON_UI_MESSAGES_ENGLISH; const fr = COMMON_UI_MESSAGES_FR; const de = COMMON_UI_MESSAGES_GERMAN; -const { FormattedMessage, IntlProvider, useIntl } = getIntlSupport({ +const { FormattedMessage, IntlProvider } = getIntlSupport({ defaultMessages: en, translations: { en, fr, de } }); diff --git a/packages/common-ui/lib/list-page-layout/bulk-buttons.tsx b/packages/common-ui/lib/list-page-layout/bulk-buttons.tsx index dea288060d..7eb847bc1d 100644 --- a/packages/common-ui/lib/list-page-layout/bulk-buttons.tsx +++ b/packages/common-ui/lib/list-page-layout/bulk-buttons.tsx @@ -186,7 +186,7 @@ export function DataExportButton({ entityLink }: DataExportButtonProps) { const router = useRouter(); - const [exportObjectIds, setExportObjectIds] = useSessionStorage( + const [_exportObjectIds, setExportObjectIds] = useSessionStorage( OBJECT_EXPORT_IDS_KEY, [] ); diff --git a/packages/common-ui/lib/list-page/QueryPage.tsx b/packages/common-ui/lib/list-page/QueryPage.tsx index 381fda92bc..b110862afb 100644 --- a/packages/common-ui/lib/list-page/QueryPage.tsx +++ b/packages/common-ui/lib/list-page/QueryPage.tsx @@ -425,7 +425,7 @@ export function QueryPage({ const sessionStorageLastUsedKeyTreeKey = uniqueName + "-last-used-tree"; const localStorageLastUsedSavedSearchChangedKey = uniqueName + "-saved-search-changed"; - const [sessionStorageQueryTree, setSessionStorageQueryTree] = + const [_sessionStorageQueryTree, setSessionStorageQueryTree] = useSessionStorage( sessionStorageLastUsedKeyTreeKey, defaultJsonTree diff --git a/packages/common-ui/lib/list-page/query-builder/query-builder-core-components/useQueryBetweenSupport.tsx b/packages/common-ui/lib/list-page/query-builder/query-builder-core-components/useQueryBetweenSupport.tsx index 2ea8a7ef69..9d061c5c94 100644 --- a/packages/common-ui/lib/list-page/query-builder/query-builder-core-components/useQueryBetweenSupport.tsx +++ b/packages/common-ui/lib/list-page/query-builder/query-builder-core-components/useQueryBetweenSupport.tsx @@ -59,7 +59,7 @@ export const isBetweenStateString = (val: string): val is string => { // Check if the parsed object has the required properties // and is a valid BetweenStates object return isBetweenStateObject(parsedState); - } catch (error) { + } catch { // Not a valid BetweenStates string return false; } @@ -83,7 +83,7 @@ export const convertStringToBetweenState = (val: string): BetweenStates => { } else { return DEFAULT_TYPE; } - } catch (error) { + } catch { return DEFAULT_TYPE; // Return default values on parsing error } }; diff --git a/packages/common-ui/lib/list-page/query-builder/query-builder-elastic-search/QueryBuilderElasticSearchValidator.tsx b/packages/common-ui/lib/list-page/query-builder/query-builder-elastic-search/QueryBuilderElasticSearchValidator.tsx index 740e584a67..b9751b1d7e 100644 --- a/packages/common-ui/lib/list-page/query-builder/query-builder-elastic-search/QueryBuilderElasticSearchValidator.tsx +++ b/packages/common-ui/lib/list-page/query-builder/query-builder-elastic-search/QueryBuilderElasticSearchValidator.tsx @@ -116,20 +116,9 @@ export function validateEsRule( formattedValue = formattedValue.trim(); } - // Edge case if nothing is provided for a date (unless operator is empty/not empty) - let operatorValue = operator; - if ( - widgetName === "date" && - formattedValue === "" && - operator !== "empty" && - operator !== "notEmpty" - ) { - operatorValue = "empty"; - } - // Retrieve the field name label const fieldLabel = formatMessage({ - id: "field_" + config.fields?.[fieldName]?.label ?? fieldName + id: "field_" + (config.fields?.[fieldName]?.label ?? fieldName) }); // For all the different widgets, a validate date function can be setup to do custom validation. diff --git a/packages/common-ui/lib/list-page/query-builder/query-builder-elastic-search/__tests__/QueryBuilderElasticSearchValidator.test.tsx b/packages/common-ui/lib/list-page/query-builder/query-builder-elastic-search/__tests__/QueryBuilderElasticSearchValidator.test.tsx index 456ec1270f..aa93ea796e 100644 --- a/packages/common-ui/lib/list-page/query-builder/query-builder-elastic-search/__tests__/QueryBuilderElasticSearchValidator.test.tsx +++ b/packages/common-ui/lib/list-page/query-builder/query-builder-elastic-search/__tests__/QueryBuilderElasticSearchValidator.test.tsx @@ -1,4 +1,4 @@ -import { ImmutableTree, JsonTree, Utils } from "react-awesome-query-builder"; +import { JsonTree, Utils } from "react-awesome-query-builder"; import { ESIndexMapping } from "../../../types"; import { generateBuilderConfig } from "../../useQueryBuilderConfig"; import { getElasticSearchValidationResults } from "../QueryBuilderElasticSearchValidator"; diff --git a/packages/common-ui/lib/list-page/query-builder/query-builder-value-types/QueryBuilderDateSearch.tsx b/packages/common-ui/lib/list-page/query-builder/query-builder-value-types/QueryBuilderDateSearch.tsx index 15c5051caf..53ffa8929f 100644 --- a/packages/common-ui/lib/list-page/query-builder/query-builder-value-types/QueryBuilderDateSearch.tsx +++ b/packages/common-ui/lib/list-page/query-builder/query-builder-value-types/QueryBuilderDateSearch.tsx @@ -5,7 +5,6 @@ import { rangeQuery, existsQuery, betweenQuery, - inQuery, inDateQuery } from "../query-builder-elastic-search/QueryBuilderElasticSearchExport"; import { TransformToDSLProps } from "../../types"; diff --git a/packages/common-ui/lib/list-page/query-builder/query-builder-value-types/QueryBuilderManagedAttributeSearch.tsx b/packages/common-ui/lib/list-page/query-builder/query-builder-value-types/QueryBuilderManagedAttributeSearch.tsx index b78f62a2b1..36f17902da 100644 --- a/packages/common-ui/lib/list-page/query-builder/query-builder-value-types/QueryBuilderManagedAttributeSearch.tsx +++ b/packages/common-ui/lib/list-page/query-builder/query-builder-value-types/QueryBuilderManagedAttributeSearch.tsx @@ -3,7 +3,7 @@ import { TransformToDSLProps, ESIndexMapping } from "../../types"; import { useIntl } from "react-intl"; import Select from "react-select"; import { useEffect } from "react"; -import { filterBy, ResourceSelect, SelectOption, useQuery } from "common-ui"; +import { filterBy, ResourceSelect, SelectOption } from "common-ui"; import { ManagedAttribute } from "../../../../../dina-ui/types/collection-api"; import QueryBuilderNumberSearch, { transformNumberSearchToDSL, diff --git a/packages/common-ui/lib/list-page/saved-searches/SavedSearch.tsx b/packages/common-ui/lib/list-page/saved-searches/SavedSearch.tsx index ddf59af6e9..b890b2cf9b 100644 --- a/packages/common-ui/lib/list-page/saved-searches/SavedSearch.tsx +++ b/packages/common-ui/lib/list-page/saved-searches/SavedSearch.tsx @@ -155,8 +155,7 @@ export function SavedSearch({ const [changesMade, setChangesMade] = useState(false); - const [selectedSavedSearchName, setSelectedSavedSearchName] = - useState(); + const [selectedSavedSearchName] = useState(); // Local storage of the displayed columns that are saved. const [localStorageDisplayedColumns, setLocalStorageDisplayedColumns] = diff --git a/packages/common-ui/lib/list-page/useElasticSearchDistinctTerm.tsx b/packages/common-ui/lib/list-page/useElasticSearchDistinctTerm.tsx index d88e69c37a..dc8a3d36b3 100644 --- a/packages/common-ui/lib/list-page/useElasticSearchDistinctTerm.tsx +++ b/packages/common-ui/lib/list-page/useElasticSearchDistinctTerm.tsx @@ -1,5 +1,5 @@ import Bodybuilder from "bodybuilder"; -import { castArray, pick } from "lodash"; +import { castArray } from "lodash"; import { useEffect, useState } from "react"; import { useApiClient, useQueryBuilderContext } from ".."; const TOTAL_SUGGESTIONS: number = 100; diff --git a/packages/common-ui/lib/list-page/useIndexMapping.tsx b/packages/common-ui/lib/list-page/useIndexMapping.tsx index 4bbd71c58e..312c0e7920 100644 --- a/packages/common-ui/lib/list-page/useIndexMapping.tsx +++ b/packages/common-ui/lib/list-page/useIndexMapping.tsx @@ -237,7 +237,7 @@ export function useIndexMapping({ } return result; - } catch (error) { + } catch { return undefined; } } diff --git a/packages/common-ui/lib/table/QueryTable.tsx b/packages/common-ui/lib/table/QueryTable.tsx index 8b225231f8..9f1e730771 100644 --- a/packages/common-ui/lib/table/QueryTable.tsx +++ b/packages/common-ui/lib/table/QueryTable.tsx @@ -10,7 +10,7 @@ import { KitsuResponse, PersistedResource } from "kitsu"; -import { ReactNode, useEffect, useReducer, useRef, useState } from "react"; +import { ReactNode, useEffect, useRef, useState } from "react"; import { useIntl } from "react-intl"; import { ClientSideJoinSpec, diff --git a/packages/common-ui/lib/table/RowComponents.tsx b/packages/common-ui/lib/table/RowComponents.tsx index aab55702a2..60a97578c9 100644 --- a/packages/common-ui/lib/table/RowComponents.tsx +++ b/packages/common-ui/lib/table/RowComponents.tsx @@ -1,4 +1,4 @@ -import { Row, Table, flexRender } from "@tanstack/react-table"; +import { Row, flexRender } from "@tanstack/react-table"; import { CSSProperties } from "react"; import { useDrag, useDrop } from "react-dnd"; diff --git a/packages/common-ui/lib/table/__tests__/QueryTable.test.tsx b/packages/common-ui/lib/table/__tests__/QueryTable.test.tsx index a0419982ec..7f20bcb8eb 100644 --- a/packages/common-ui/lib/table/__tests__/QueryTable.test.tsx +++ b/packages/common-ui/lib/table/__tests__/QueryTable.test.tsx @@ -16,7 +16,6 @@ import { import { mountWithAppContext } from "common-ui"; import { fireEvent, - screen, waitForElementToBeRemoved, within } from "@testing-library/react"; diff --git a/packages/common-ui/lib/util/isBlankResourceAttribute.ts b/packages/common-ui/lib/util/isBlankResourceAttribute.ts index d8b95866e5..9f5d464c4c 100644 --- a/packages/common-ui/lib/util/isBlankResourceAttribute.ts +++ b/packages/common-ui/lib/util/isBlankResourceAttribute.ts @@ -1,4 +1,4 @@ -import { isArray, omitBy, isEmpty } from "lodash"; +import { omitBy, isEmpty } from "lodash"; /** * Checks whether an API resource's attribute is blank. diff --git a/packages/common-ui/types/react-table.d.ts b/packages/common-ui/types/react-table.d.ts index 66971ed3c1..3e34dac714 100644 --- a/packages/common-ui/types/react-table.d.ts +++ b/packages/common-ui/types/react-table.d.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ import "@tanstack/react-table"; declare module "@tanstack/table-core" { diff --git a/packages/dina-ui/components/add-person/PersonForm.tsx b/packages/dina-ui/components/add-person/PersonForm.tsx index 20cf4e5a42..5f97ff1ecc 100644 --- a/packages/dina-ui/components/add-person/PersonForm.tsx +++ b/packages/dina-ui/components/add-person/PersonForm.tsx @@ -1,5 +1,4 @@ import { - DeleteButton, DinaForm, DinaFormOnSubmit, filterBy, @@ -12,7 +11,6 @@ import { OperationError, SaveArgs, useApiClient, - DeleteArgs, BackButton, ButtonBar } from "common-ui"; diff --git a/packages/dina-ui/components/add-person/PersonFormFields.tsx b/packages/dina-ui/components/add-person/PersonFormFields.tsx index fc07d85392..7074cf1dbf 100644 --- a/packages/dina-ui/components/add-person/PersonFormFields.tsx +++ b/packages/dina-ui/components/add-person/PersonFormFields.tsx @@ -1,9 +1,4 @@ -import { - FieldSet, - FormikButton, - useDinaFormContext, - SelectOption -} from "common-ui"; +import { FieldSet, FormikButton, useDinaFormContext } from "common-ui"; import { Person } from "../../../dina-ui/types/objectstore-api"; import React, { useState } from "react"; import { FieldArray } from "formik"; diff --git a/packages/dina-ui/components/bulk-edit/__tests__/useBulkEditTab.test.tsx b/packages/dina-ui/components/bulk-edit/__tests__/useBulkEditTab.test.tsx index c75ba7b968..6bdeca7841 100644 --- a/packages/dina-ui/components/bulk-edit/__tests__/useBulkEditTab.test.tsx +++ b/packages/dina-ui/components/bulk-edit/__tests__/useBulkEditTab.test.tsx @@ -11,11 +11,7 @@ import { useMaterialSampleFormTemplateSelectState } from "../../collection/form- import { MaterialSampleFormProps } from "../../collection/material-sample/MaterialSampleForm"; import { BulkNavigatorTab } from "../BulkEditNavigator"; import { useBulkEditTab } from "../useBulkEditTab"; -import { - fireEvent, - waitForElementToBeRemoved, - screen -} from "@testing-library/react"; +import { fireEvent, waitForElementToBeRemoved } from "@testing-library/react"; const mockSubmitOverride = jest.fn(); @@ -33,9 +29,7 @@ function BulkEditTab({ baseSample }: BulkEditTabProps) { collectingEventInitialValues } = useMaterialSampleFormTemplateSelectState({}); - const [selectedTab, setSelectedTab] = useState< - BulkNavigatorTab | ResourceWithHooks - >(); + const [selectedTab] = useState(); const { bulkEditFormRef, diff --git a/packages/dina-ui/components/bulk-material-sample/MaterialSampleGenerationForm.tsx b/packages/dina-ui/components/bulk-material-sample/MaterialSampleGenerationForm.tsx index a591b0fb39..eba4f570cb 100644 --- a/packages/dina-ui/components/bulk-material-sample/MaterialSampleGenerationForm.tsx +++ b/packages/dina-ui/components/bulk-material-sample/MaterialSampleGenerationForm.tsx @@ -369,7 +369,7 @@ interface GenerateNameParams { } function generateName(params: GenerateNameParams) { - const { formState, generationMode } = params; + const { formState } = params; const generatedName = `${formState.baseName || ""}${ formState.separator || "" @@ -396,7 +396,7 @@ function generateSeriesSuffix({ index, formState }: GenerateNameParams) { try { const sc = new SpreadSheetColumn(); return sc.fromInt(index + sc.fromStr(start)) as string; - } catch (error) { + } catch { return ""; } } diff --git a/packages/dina-ui/components/bulk-metadata/ExistingMetadataBulkEditor.tsx b/packages/dina-ui/components/bulk-metadata/ExistingMetadataBulkEditor.tsx index 3ba35bbd83..b16cdcfde3 100644 --- a/packages/dina-ui/components/bulk-metadata/ExistingMetadataBulkEditor.tsx +++ b/packages/dina-ui/components/bulk-metadata/ExistingMetadataBulkEditor.tsx @@ -1,8 +1,7 @@ import { LoadingSpinner } from "common-ui"; -import { InputResource, PersistedResource } from "kitsu"; +import { InputResource } from "kitsu"; import { compact } from "lodash"; -import { Promisable } from "type-fest"; -import { License, Metadata } from "../../types/objectstore-api"; +import { Metadata } from "../../types/objectstore-api"; import { useMetadataEditQuery } from "../object-store/metadata/useMetadata"; import { MetadataBulkEditor } from "./MetadataBulkEditor"; diff --git a/packages/dina-ui/components/bulk-metadata/MetadataBulkEditor.tsx b/packages/dina-ui/components/bulk-metadata/MetadataBulkEditor.tsx index abbcfbfac2..bdff57dd90 100644 --- a/packages/dina-ui/components/bulk-metadata/MetadataBulkEditor.tsx +++ b/packages/dina-ui/components/bulk-metadata/MetadataBulkEditor.tsx @@ -1,7 +1,6 @@ import React from "react"; -import { License, Metadata } from "../../types/objectstore-api"; -import { InputResource, PersistedResource, KitsuResource } from "kitsu"; -import { Promisable } from "type-fest"; +import { Metadata } from "../../types/objectstore-api"; +import { InputResource } from "kitsu"; import { BulkEditTabContextI, ButtonBar, @@ -225,7 +224,7 @@ function useBulkMetadataSave({ }: BulkMetadataSaveParams) { // Force re-render when there is a bulk submission error: const [_error, setError] = useState(null); - const { save, apiClient } = useApiClient(); + const { save } = useApiClient(); const { formatMessage } = useDinaIntl(); const { bulkEditFormRef, resourceHooks: metadataHooks } = bulkEditCtx; @@ -258,11 +257,9 @@ function useBulkMetadataSave({ try { const submittedValues = formik.values; - const { - // Don't include derivatives in the form submission: - derivatives, - ...metadataValues - } = submittedValues; + // Don't include derivatives in the form submission: + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const { derivatives, ...metadataValues } = submittedValues; const saveOp = await saveHook.prepareMetadataSaveOperation({ submittedValues: metadataValues, diff --git a/packages/dina-ui/components/button-bar/nav/nav.tsx b/packages/dina-ui/components/button-bar/nav/nav.tsx index 46f08b76eb..58f4a54ba5 100644 --- a/packages/dina-ui/components/button-bar/nav/nav.tsx +++ b/packages/dina-ui/components/button-bar/nav/nav.tsx @@ -483,6 +483,11 @@ function NavControlledVocabularyDropdown({ formatMessage }) { + + + + + @@ -537,6 +542,11 @@ function NavDinaManagementDropdown({ formatMessage }) { menuRole="menu" style={{ marginLeft: "auto" }} > + + + + + {/* Admins only can view users. */} {isAdmin && ( <> diff --git a/packages/dina-ui/components/collection/MaterialSampleAssociationsField.tsx b/packages/dina-ui/components/collection/MaterialSampleAssociationsField.tsx index c2f8eb0932..ea8e7fbf54 100644 --- a/packages/dina-ui/components/collection/MaterialSampleAssociationsField.tsx +++ b/packages/dina-ui/components/collection/MaterialSampleAssociationsField.tsx @@ -9,7 +9,7 @@ import { } from "common-ui"; import { PersistedResource } from "kitsu"; import Link from "next/link"; -import React, { useRef, useState } from "react"; +import React, { useState } from "react"; import { BulkEditTabWarning, VocabularyReadOnlyView, diff --git a/packages/dina-ui/components/collection/TabbedResourceLinker.tsx b/packages/dina-ui/components/collection/TabbedResourceLinker.tsx index a53a32ff36..09bf99189e 100644 --- a/packages/dina-ui/components/collection/TabbedResourceLinker.tsx +++ b/packages/dina-ui/components/collection/TabbedResourceLinker.tsx @@ -4,7 +4,6 @@ import { QueryState, useBulkEditTabFieldIndicators, useDinaFormContext, - useFieldLabels, withResponse } from "common-ui"; import { KitsuResource, PersistedResource } from "kitsu"; @@ -52,8 +51,6 @@ export function TabbedResourceLinker({ fieldName, currentValue: resourceIdProp ? { id: resourceIdProp } : undefined }); - const isInBulkEditTab = !!bulkCtx; - const { getFieldLabel } = useFieldLabels(); // In bulk edit mode, show the common value if there is one instead of a new linked resource: const defaultValue = bulkCtx?.defaultValue; diff --git a/packages/dina-ui/components/collection/VocabularySelectField.tsx b/packages/dina-ui/components/collection/VocabularySelectField.tsx index 853c3d349b..48ffe81806 100644 --- a/packages/dina-ui/components/collection/VocabularySelectField.tsx +++ b/packages/dina-ui/components/collection/VocabularySelectField.tsx @@ -6,7 +6,6 @@ import { useDinaIntl } from "../../intl/dina-ui-intl"; import useVocabularyOptions from "./useVocabularyOptions"; import { IdentifierType } from "packages/dina-ui/types/collection-api/resources/IdentifierType"; import { startCase } from "lodash"; -import { boolean } from "zod"; export interface VocabularySelectFieldProps extends FieldWrapperProps { path: string; diff --git a/packages/dina-ui/components/collection/catalogue-of-life/CatalogueOfLifeSearchBox.tsx b/packages/dina-ui/components/collection/catalogue-of-life/CatalogueOfLifeSearchBox.tsx index dba5a33e64..6d376e17dc 100644 --- a/packages/dina-ui/components/collection/catalogue-of-life/CatalogueOfLifeSearchBox.tsx +++ b/packages/dina-ui/components/collection/catalogue-of-life/CatalogueOfLifeSearchBox.tsx @@ -52,7 +52,7 @@ export function CatalogueOfLifeSearchBox({ }: CatalogueOfLifeSearchBoxProps) { const { formatMessage } = useDinaIntl(); - const [dataSet, setDataSet] = useState({ + const [dataSet] = useState({ title: "Catalogue of Life Checklist", key: 2328 }); diff --git a/packages/dina-ui/components/collection/collecting-event/DeterminationField.tsx b/packages/dina-ui/components/collection/collecting-event/DeterminationField.tsx index 27783546db..13a204aae5 100644 --- a/packages/dina-ui/components/collection/collecting-event/DeterminationField.tsx +++ b/packages/dina-ui/components/collection/collecting-event/DeterminationField.tsx @@ -68,7 +68,8 @@ export function DeterminationField({ const { readOnly, isTemplate, initialValues } = useDinaFormContext(); const form = useFormikContext(); - const [hideScientificNameInput, setHideScientificNameInput] = useState(false); + const [_hideScientificNameInput, setHideScientificNameInput] = + useState(false); const determinationsPath = name || "determination"; diff --git a/packages/dina-ui/components/collection/collecting-event/GeographySearchDialog.tsx b/packages/dina-ui/components/collection/collecting-event/GeographySearchDialog.tsx index d4d914a465..d3c03f8939 100644 --- a/packages/dina-ui/components/collection/collecting-event/GeographySearchDialog.tsx +++ b/packages/dina-ui/components/collection/collecting-event/GeographySearchDialog.tsx @@ -27,7 +27,7 @@ async function nominatimSearch( try { const results = await fetchJson(url.toString()); return results as NominatumApiSearchResult[]; - } catch (error) { + } catch { return []; } } diff --git a/packages/dina-ui/components/collection/collecting-event/SetCoordinatesFromVerbatimButton.tsx b/packages/dina-ui/components/collection/collecting-event/SetCoordinatesFromVerbatimButton.tsx index 8f2ac1aabe..ca41d1797b 100644 --- a/packages/dina-ui/components/collection/collecting-event/SetCoordinatesFromVerbatimButton.tsx +++ b/packages/dina-ui/components/collection/collecting-event/SetCoordinatesFromVerbatimButton.tsx @@ -3,7 +3,7 @@ import Coordinates from "coordinate-parser"; import { FormikContextType } from "formik"; import { get } from "lodash"; import { useDinaIntl } from "../../../intl/dina-ui-intl"; -import { ReactNode, useState } from "react"; +import { useState } from "react"; import { SiConvertio } from "react-icons/si"; export interface SetCoordinatesFromVerbatimButtonProps { diff --git a/packages/dina-ui/components/collection/collecting-event/__tests__/SetCoordinatesFromVerbatimButton.test.tsx b/packages/dina-ui/components/collection/collecting-event/__tests__/SetCoordinatesFromVerbatimButton.test.tsx index 30667f477d..0901c9ab79 100644 --- a/packages/dina-ui/components/collection/collecting-event/__tests__/SetCoordinatesFromVerbatimButton.test.tsx +++ b/packages/dina-ui/components/collection/collecting-event/__tests__/SetCoordinatesFromVerbatimButton.test.tsx @@ -1,7 +1,7 @@ import { DinaForm, NumberField } from "common-ui"; import { mountWithAppContext } from "common-ui"; import { SetCoordinatesFromVerbatimButton } from "../SetCoordinatesFromVerbatimButton"; -import { screen, waitFor, fireEvent } from "@testing-library/react"; +import { screen, fireEvent } from "@testing-library/react"; import "@testing-library/jest-dom"; describe("SetCoordinatesFromVerbatimButton component", () => { diff --git a/packages/dina-ui/components/collection/collecting-event/__tests__/ViewInMapButton.test.tsx b/packages/dina-ui/components/collection/collecting-event/__tests__/ViewInMapButton.test.tsx index 8eb5901cf0..9cb64fac82 100644 --- a/packages/dina-ui/components/collection/collecting-event/__tests__/ViewInMapButton.test.tsx +++ b/packages/dina-ui/components/collection/collecting-event/__tests__/ViewInMapButton.test.tsx @@ -1,7 +1,7 @@ import { DinaForm } from "common-ui"; import { mountWithAppContext } from "common-ui"; import { ViewInMapButton } from "../GeoReferenceAssertionRow"; -import { screen, waitFor, fireEvent } from "@testing-library/react"; +import { screen } from "@testing-library/react"; import "@testing-library/jest-dom"; describe("ViewInMapButton component", () => { diff --git a/packages/dina-ui/components/collection/material-sample/MaterialSampleIdentifiersSection.tsx b/packages/dina-ui/components/collection/material-sample/MaterialSampleIdentifiersSection.tsx index c929bab6ae..ecab531eb0 100644 --- a/packages/dina-ui/components/collection/material-sample/MaterialSampleIdentifiersSection.tsx +++ b/packages/dina-ui/components/collection/material-sample/MaterialSampleIdentifiersSection.tsx @@ -1,7 +1,6 @@ import { CheckBoxField, FieldSet, - StringArrayField, TextField, useDinaFormContext } from "common-ui"; diff --git a/packages/dina-ui/components/collection/material-sample/OrganismsField.tsx b/packages/dina-ui/components/collection/material-sample/OrganismsField.tsx index 96c036bd86..90e6f0c562 100644 --- a/packages/dina-ui/components/collection/material-sample/OrganismsField.tsx +++ b/packages/dina-ui/components/collection/material-sample/OrganismsField.tsx @@ -6,14 +6,13 @@ import { FormikButton, NumberField, ReactTable, - TextField, ToggleField, useDinaFormContext, useFieldLabels } from "common-ui"; import { FieldArray, useFormikContext } from "formik"; import { get, isEmpty, keys } from "lodash"; -import { useEffect, useState } from "react"; +import { useEffect } from "react"; import { BulkEditTabWarning, OrganismStateField } from "../.."; import { DinaMessage } from "../../../intl/dina-ui-intl"; import { ORGANISMS_COMPONENT_NAME } from "../../../types/collection-api"; @@ -230,7 +229,7 @@ function OrganismsTable({ useTargetOrganism }: OrganismsTableProps) { const { getFieldLabel } = useFieldLabels(); - const { isTemplate, readOnly, initialValues } = useDinaFormContext(); + const { isTemplate, readOnly } = useDinaFormContext(); function handleRemoveClick(index: number) { onRemoveClick(index); diff --git a/packages/dina-ui/components/collection/material-sample/ScheduledActionsField.tsx b/packages/dina-ui/components/collection/material-sample/ScheduledActionsField.tsx index e136c0c198..58a92ec3d0 100644 --- a/packages/dina-ui/components/collection/material-sample/ScheduledActionsField.tsx +++ b/packages/dina-ui/components/collection/material-sample/ScheduledActionsField.tsx @@ -260,15 +260,11 @@ export function ScheduledActionSubForm({ actionToEdit, defaultDate }: ScheduledActionSubFormProps) { - const { formTemplate, initialValues, isTemplate } = useDinaFormContext(); + const { initialValues, isTemplate } = useDinaFormContext(); // TODO: This needs to be fixed. const enabledFields: string[] = []; - const actionsEnabledFields = enabledFields?.filter((it) => - it.startsWith("scheduledAction.") - ); - const actionTemplateInitialValues = enabledFields ? initialValues.scheduledAction : undefined; diff --git a/packages/dina-ui/components/collection/material-sample/__tests__/MaterialSampleBreadCrumb.test.tsx b/packages/dina-ui/components/collection/material-sample/__tests__/MaterialSampleBreadCrumb.test.tsx index e4caafe8bc..c88f3ca1c6 100644 --- a/packages/dina-ui/components/collection/material-sample/__tests__/MaterialSampleBreadCrumb.test.tsx +++ b/packages/dina-ui/components/collection/material-sample/__tests__/MaterialSampleBreadCrumb.test.tsx @@ -3,7 +3,6 @@ import { DinaForm } from "../../../../../common-ui/lib"; import { mountWithAppContext } from "common-ui"; import { MaterialSample } from "../../../../types/collection-api"; import { MaterialSampleBreadCrumb } from "../MaterialSampleBreadCrumb"; -import { screen, waitFor, fireEvent } from "@testing-library/react"; import "@testing-library/jest-dom"; const materialSampleWithHierarchy: PersistedResource = { diff --git a/packages/dina-ui/components/collection/material-sample/__tests__/ScheduledActionsField.test.tsx b/packages/dina-ui/components/collection/material-sample/__tests__/ScheduledActionsField.test.tsx index fccc77c763..0078e3d01c 100644 --- a/packages/dina-ui/components/collection/material-sample/__tests__/ScheduledActionsField.test.tsx +++ b/packages/dina-ui/components/collection/material-sample/__tests__/ScheduledActionsField.test.tsx @@ -1,7 +1,7 @@ import { DinaForm } from "common-ui"; import { mountWithAppContext } from "common-ui"; import { ScheduledActionsField } from "../ScheduledActionsField"; -import { screen, waitFor, fireEvent } from "@testing-library/react"; +import { screen, fireEvent } from "@testing-library/react"; import "@testing-library/jest-dom"; const mockOnSubmit = jest.fn(); @@ -29,16 +29,15 @@ const testCtx = { describe("ScheduledActionsField", () => { it("Edits the scheduled actions.", async () => { - const { container, getByRole, getByText, waitForRequests } = - mountWithAppContext( - mockOnSubmit(submittedValues)} - > - - , - testCtx - ); + const { container, getByText, waitForRequests } = mountWithAppContext( + mockOnSubmit(submittedValues)} + > + + , + testCtx + ); // No actions initially: expect(container.querySelector(".ReactTable")).toBeNull(); diff --git a/packages/dina-ui/components/collection/material-sample/next-sample-functions.ts b/packages/dina-ui/components/collection/material-sample/next-sample-functions.ts index 67b21bda54..ef834cd9c5 100644 --- a/packages/dina-ui/components/collection/material-sample/next-sample-functions.ts +++ b/packages/dina-ui/components/collection/material-sample/next-sample-functions.ts @@ -35,11 +35,11 @@ export function nextSampleInitialValues( ) { // Use the copied sample as a base, omitting some fields that shouldn't be copied: const { - id, - createdOn, - createdBy, + id: _id, + createdOn: _createdOn, + createdBy: _createdBy, materialSampleName, - allowDuplicateName, + allowDuplicateName: _allowDuplicateName, organism, ...copiedValues } = originalSample; diff --git a/packages/dina-ui/components/collection/material-sample/useMaterialSample.tsx b/packages/dina-ui/components/collection/material-sample/useMaterialSample.tsx index bd19967855..c6c5032907 100644 --- a/packages/dina-ui/components/collection/material-sample/useMaterialSample.tsx +++ b/packages/dina-ui/components/collection/material-sample/useMaterialSample.tsx @@ -886,7 +886,7 @@ export function useMaterialSampleSave({ type: "organism" as const }; - const { id: firstOrganismId, ...firstOrganismValues } = + const { id: _firstOrganismId, ...firstOrganismValues } = sample.organism?.[0] ?? {}; return { diff --git a/packages/dina-ui/components/group-select/__tests__/CollectionSelectField.test.tsx b/packages/dina-ui/components/group-select/__tests__/CollectionSelectField.test.tsx index 2e89e83221..075006bb4b 100644 --- a/packages/dina-ui/components/group-select/__tests__/CollectionSelectField.test.tsx +++ b/packages/dina-ui/components/group-select/__tests__/CollectionSelectField.test.tsx @@ -1,8 +1,7 @@ import { DinaForm } from "common-ui"; import { mountWithAppContext } from "common-ui"; import { CollectionSelectField } from "../../resource-select-fields/resource-select-fields"; -import Select from "react-select/base"; -import { screen, waitFor, fireEvent } from "@testing-library/react"; +import { screen, waitFor } from "@testing-library/react"; import "@testing-library/jest-dom"; const COLL1 = { diff --git a/packages/dina-ui/components/group-select/__tests__/GroupFieldView.test.tsx b/packages/dina-ui/components/group-select/__tests__/GroupFieldView.test.tsx index 5191828ed1..e738b55eb4 100644 --- a/packages/dina-ui/components/group-select/__tests__/GroupFieldView.test.tsx +++ b/packages/dina-ui/components/group-select/__tests__/GroupFieldView.test.tsx @@ -1,7 +1,7 @@ import { DinaForm } from "common-ui"; import { mountWithAppContext } from "common-ui"; import { GroupFieldView } from "../GroupFieldView"; -import { screen, waitFor, fireEvent } from "@testing-library/react"; +import { waitFor } from "@testing-library/react"; import "@testing-library/jest-dom"; describe("GroupFieldView component.", () => { diff --git a/packages/dina-ui/components/group/GroupForm.tsx b/packages/dina-ui/components/group/GroupForm.tsx new file mode 100644 index 0000000000..c56c7cfcbf --- /dev/null +++ b/packages/dina-ui/components/group/GroupForm.tsx @@ -0,0 +1,78 @@ +import { NextRouter } from "next/router"; +import { + BackButton, + ButtonBar, + DinaForm, + DinaFormOnSubmit, + DinaFormSubmitParams, + SubmitButton, + TextField +} from "../../../common-ui/lib"; +import { Group } from "../../../dina-ui/types/user-api"; +import { GroupLabelsEditor } from "./GroupLabelsEditor"; + +export interface GroupFormProps { + group?: Group; + router: NextRouter; +} + +export function GroupForm({ group, router }: GroupFormProps) { + const { id } = router.query; + const initialValues: Group = + group || + ({ + type: "group" + } as Group); + + const onSubmit: DinaFormOnSubmit = async ({ + api: { apiClient }, + submittedValues + }: DinaFormSubmitParams) => { + const response = await apiClient.axios.post( + "/user-api/group", + { + data: { + id: submittedValues.id, + type: "group", + attributes: { + name: submittedValues.name, + labels: submittedValues.labels + } + } + }, + { + headers: { + "Content-Type": "application/vnd.api+json" + } + } + ); + + const newId = response?.data?.data?.id; + await router.push(`/group/view?id=${newId}`); + }; + + return ( + initialValues={initialValues} onSubmit={onSubmit}> + +
+ +
+
+ +
+
+ +
+ ); +} + +export function GroupFormFields({ group }: { group: Group }) { + return ( +
+
+ +
+ +
+ ); +} diff --git a/packages/dina-ui/components/group/GroupLabelsEditor.tsx b/packages/dina-ui/components/group/GroupLabelsEditor.tsx new file mode 100644 index 0000000000..fd03618bdb --- /dev/null +++ b/packages/dina-ui/components/group/GroupLabelsEditor.tsx @@ -0,0 +1,129 @@ +import { concat, difference, keys } from "lodash"; +import { useState } from "react"; +import { RiDeleteBinLine } from "react-icons/ri"; +import Select from "react-select"; +import { + FieldSet, + FieldSpy, + FieldWrapper, + FormikButton, + useInstanceContext +} from "../../../common-ui/lib"; +import { DinaMessage } from "../../../dina-ui/intl/dina-ui-intl"; + +export interface GroupLabelsEditorProps { + valuesPath: string; + labels: Record; +} + +type Option = { + label: string; + value?: string; +}; + +export function GroupLabelsEditor({ valuesPath }: GroupLabelsEditorProps) { + const instanceContext = useInstanceContext(); + const [languageToAdd] = useState