Skip to content

Commit

Permalink
Renamed 'autocomplete' to 'select'
Browse files Browse the repository at this point in the history
  • Loading branch information
pkirilin committed Jan 31, 2024
1 parent 644b6e5 commit c2941bc
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 25 deletions.
12 changes: 6 additions & 6 deletions src/frontend/src/features/notes/components/NotesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { type FC, useEffect, useState, useMemo } from 'react';
import { useRouterId } from 'src/hooks';
import { notesApi } from '../api';
import { toCreateNoteRequest } from '../mapping';
import { useProductAutocomplete } from '../model';
import { useProductSelect } from '../model';
import { type NoteItem, type MealType, type NoteCreateEdit } from '../models';
import NoteInputDialog from './NoteInputDialog';
import NotesTableRow from './NotesTableRow';
Expand All @@ -25,7 +25,7 @@ interface NotesTableProps {

const NotesTable: FC<NotesTableProps> = ({ mealType, notes }: NotesTableProps) => {
const pageId = useRouterId('id');
const productAutocomplete = useProductAutocomplete();
const productSelect = useProductSelect();
const [createNote, createNoteResponse] = notesApi.useCreateNoteMutation();
const [isDialogOpened, setIsDialogOpened] = useState(false);

Expand Down Expand Up @@ -65,8 +65,8 @@ const NotesTable: FC<NotesTableProps> = ({ mealType, notes }: NotesTableProps) =
isOpened={isDialogOpened}
mealType={mealType}
product={null}
products={productAutocomplete.data}
productsLoading={productAutocomplete.isLoading}
products={productSelect.data}
productsLoading={productSelect.isLoading}
quantity={100}
pageId={pageId}
displayOrder={maxDisplayOrderForNotesGroup + 1}
Expand All @@ -87,8 +87,8 @@ const NotesTable: FC<NotesTableProps> = ({ mealType, notes }: NotesTableProps) =
<NotesTableRow
key={note.id}
note={note}
products={productAutocomplete.data}
productsLoading={productAutocomplete.isLoading}
products={productSelect.data}
productsLoading={productSelect.isLoading}
/>
))}
</TableBody>
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/features/notes/model/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './useProductAutocomplete';
export * from './useProductSelect';
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { productsApi, type ProductSelectOption } from 'src/features/products';

interface UseProductAutocompleteResult {
interface UseProductSelectResult {
data: ProductSelectOption[];
isLoading: boolean;
}

const QUERY_ARG = {};

export const useProductAutocomplete = (): UseProductAutocompleteResult => {
export const useProductSelect = (): UseProductSelectResult => {
const query = productsApi.useGetProductSelectOptionsQuery(QUERY_ARG, { refetchOnFocus: true });

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { type FC, useEffect, useState } from 'react';
import { useAppSelector } from 'src/store';
import { productsApi } from '../api';
import { toCreateProductRequest } from '../mapping';
import { useCategoryAutocomplete } from '../model';
import { useCategorySelect } from '../model';
import { selectProductsQueryArg } from '../selectors';
import { type ProductFormData } from '../types';
import ProductInputDialog from './ProductInputDialog';
Expand All @@ -13,7 +13,7 @@ const CreateProduct: FC = () => {
const [isDialogOpened, setIsDialogOpened] = useState(false);
const getProductsQueryArg = useAppSelector(selectProductsQueryArg);
const getProductsQuery = productsApi.useGetProductsQuery(getProductsQueryArg);
const categoryAutocomplete = useCategoryAutocomplete();
const categorySelect = useCategorySelect();
const [createProduct, createProductRequest] = productsApi.useCreateProductMutation();

useEffect(() => {
Expand Down Expand Up @@ -52,8 +52,8 @@ const CreateProduct: FC = () => {
submitText="Create"
onSubmit={handleDialogSubmit}
isLoading={createProductRequest.isLoading}
categories={categoryAutocomplete.data}
categoriesLoading={categoryAutocomplete.isLoading}
categories={categorySelect.data}
categoriesLoading={categorySelect.isLoading}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { type FC, useEffect, useState } from 'react';
import { useAppDispatch, useAppSelector } from '../../__shared__/hooks';
import { productsApi } from '../api';
import { toEditProductRequest, toProductFormData } from '../mapping';
import { useCategoryAutocomplete } from '../model';
import { useCategorySelect } from '../model';
import { selectCheckedProductIds } from '../selectors';
import { productChecked, productUnchecked } from '../store';
import { type Product, type ProductFormData } from '../types';
Expand All @@ -17,7 +17,7 @@ interface ProductsTableRowProps {
const ProductsTableRow: FC<ProductsTableRowProps> = ({ product }: ProductsTableRowProps) => {
const [isEditDialogOpened, setIsEditDialogOpened] = useState(false);
const [editProduct, editProductRequest] = productsApi.useEditProductMutation();
const categoryAutocomplete = useCategoryAutocomplete();
const categorySelect = useCategorySelect();
const dispatch = useAppDispatch();
const checkedProductIds = useAppSelector(selectCheckedProductIds);
const isChecked = checkedProductIds.some(id => id === product.id);
Expand Down Expand Up @@ -97,8 +97,8 @@ const ProductsTableRow: FC<ProductsTableRowProps> = ({ product }: ProductsTableR
onSubmit={handleEditDialogSubmit}
isLoading={editProductRequest.isLoading}
product={toProductFormData(product)}
categories={categoryAutocomplete.data}
categoriesLoading={categoryAutocomplete.isLoading}
categories={categorySelect.data}
categoriesLoading={categorySelect.isLoading}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ import { Divider, MenuItem, TextField, Typography } from '@mui/material';
import { type FC, type ChangeEventHandler } from 'react';
import { useAppDispatch, useAppSelector } from 'src/store';
import { type SelectOption } from 'src/types';
import { useCategoryAutocomplete } from '../model';
import { useCategorySelect } from '../model';
import { filterByCategoryChanged } from '../store';
import * as styles from '../styles';

const ANY_CATEGORY_VALUE = ' ';

export const SearchByCategory: FC = () => {
const category = useAppSelector(state => state.products.filter.category);
const categoryAutocomplete = useCategoryAutocomplete();
const categorySelect = useCategorySelect();
const dispatch = useAppDispatch();

const findSelectedCategory = (selectedValue: string): SelectOption | null => {
if (selectedValue === ANY_CATEGORY_VALUE) {
return null;
}
return categoryAutocomplete.data.find(c => c.id === Number(selectedValue)) ?? null;
return categorySelect.data.find(c => c.id === Number(selectedValue)) ?? null;
};

const handleChange: ChangeEventHandler<HTMLInputElement> = event => {
Expand All @@ -35,8 +35,8 @@ export const SearchByCategory: FC = () => {
onChange={handleChange}
>
<MenuItem value={ANY_CATEGORY_VALUE}>Any</MenuItem>
{categoryAutocomplete.data.length > 0 && <Divider />}
{categoryAutocomplete.data.map(({ id, name }) => (
{categorySelect.data.length > 0 && <Divider />}
{categorySelect.data.map(({ id, name }) => (
<MenuItem key={id} value={id}>
<Typography noWrap>{name}</Typography>
</MenuItem>
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/features/products/model/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './useCategoryAutocomplete';
export * from './useCategorySelect';
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { categoriesApi } from 'src/features/categories';
import { type SelectOption } from 'src/types';

interface UseCategoryAutocompleteResult {
interface UseCategorySelectResult {
data: SelectOption[];
isLoading: boolean;
}

const QUERY_ARG = {};

export const useCategoryAutocomplete = (): UseCategoryAutocompleteResult => {
export const useCategorySelect = (): UseCategorySelectResult => {
const query = categoriesApi.useGetCategorySelectOptionsQuery(QUERY_ARG, { refetchOnFocus: true });

return {
Expand Down

0 comments on commit c2941bc

Please sign in to comment.