-
Notifications
You must be signed in to change notification settings - Fork 3
Product fix #273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Product fix #273
Changes from all commits
d59d5dc
0dd4b76
8b81027
7ad9d3c
b14cfc0
2e5fd2a
478173d
16ffd7a
5958f1a
76cd8c5
191b0e3
6526b4b
daa1b4e
0ea3d73
5678117
7cb64ee
1620153
6d86584
f2fef86
1cf5e91
35a9f77
efd2267
1a309db
08054bd
ff8b238
a708f0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,6 +64,7 @@ export const GET_COMPANIES = gql` | |
| ownerId | ||
| tagIds | ||
| score | ||
| cursor | ||
| } | ||
| ${GQL_PAGE_INFO} | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,3 +1,6 @@ | ||||||||||||||||||||||||||||||||||
| import { useProductsEdit } from '@/products/hooks/useProductsEdit'; | ||||||||||||||||||||||||||||||||||
| import { renderingProductDetailAtom } from '@/products/states/productDetailStates'; | ||||||||||||||||||||||||||||||||||
| import { ProductHotKeyScope } from '@/products/types/ProductsHotKeyScope'; | ||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||
| IconCategory, | ||||||||||||||||||||||||||||||||||
| IconCurrencyDollar, | ||||||||||||||||||||||||||||||||||
|
|
@@ -12,21 +15,64 @@ import { | |||||||||||||||||||||||||||||||||
| RecordTableCellDisplay, | ||||||||||||||||||||||||||||||||||
| CurrencyFormatedDisplay, | ||||||||||||||||||||||||||||||||||
| CurrencyCode, | ||||||||||||||||||||||||||||||||||
| useQueryState, | ||||||||||||||||||||||||||||||||||
| RecordTablePopover, | ||||||||||||||||||||||||||||||||||
| RecordTableCellTrigger, | ||||||||||||||||||||||||||||||||||
| Badge, | ||||||||||||||||||||||||||||||||||
| RecordTableCellContent, | ||||||||||||||||||||||||||||||||||
| Input, | ||||||||||||||||||||||||||||||||||
| } from 'erxes-ui'; | ||||||||||||||||||||||||||||||||||
| import { IProduct } from 'ui-modules'; | ||||||||||||||||||||||||||||||||||
| import { productMoreColumn } from './ProductMoreColumn'; | ||||||||||||||||||||||||||||||||||
| import { useSetAtom } from 'jotai'; | ||||||||||||||||||||||||||||||||||
| import { useState } from 'react'; | ||||||||||||||||||||||||||||||||||
| import { IProduct, SelectCategory } from 'ui-modules'; | ||||||||||||||||||||||||||||||||||
| export const productColumns: ColumnDef<IProduct>[] = [ | ||||||||||||||||||||||||||||||||||
| productMoreColumn, | ||||||||||||||||||||||||||||||||||
| RecordTable.checkboxColumn as ColumnDef<IProduct>, | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| id: 'name', | ||||||||||||||||||||||||||||||||||
| accessorKey: 'name', | ||||||||||||||||||||||||||||||||||
| header: () => <RecordTable.InlineHead icon={IconLabel} label="Name" />, | ||||||||||||||||||||||||||||||||||
| cell: ({ cell }) => { | ||||||||||||||||||||||||||||||||||
| const name = cell.getValue() as string; | ||||||||||||||||||||||||||||||||||
| const [value, setValue] = useState(name); | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+35
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Sync local state with prop changes The local state should update when the product name changes externally. Add a useEffect to sync the state: const name = cell.getValue() as string;
const [value, setValue] = useState(name);
+ useEffect(() => {
+ setValue(name);
+ }, [name]);Don't forget to import -import { useState } from 'react';
+import { useState, useEffect } from 'react';📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
| const [, setProductId] = useQueryState('productId'); | ||||||||||||||||||||||||||||||||||
| const setRenderingProductDetail = useSetAtom(renderingProductDetailAtom); | ||||||||||||||||||||||||||||||||||
| const { productsEdit } = useProductsEdit(); | ||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||
| <RecordTableCellDisplay> | ||||||||||||||||||||||||||||||||||
| <TextOverflowTooltip value={cell.getValue() as string} /> | ||||||||||||||||||||||||||||||||||
| </RecordTableCellDisplay> | ||||||||||||||||||||||||||||||||||
| <RecordTablePopover | ||||||||||||||||||||||||||||||||||
| scope={`${ProductHotKeyScope.ProductsPage}-name-${cell.row.original._id}`} | ||||||||||||||||||||||||||||||||||
| onOpenChange={(open) => { | ||||||||||||||||||||||||||||||||||
| if (!open) { | ||||||||||||||||||||||||||||||||||
| productsEdit({ | ||||||||||||||||||||||||||||||||||
| variables: { | ||||||||||||||||||||||||||||||||||
| _id: cell.row.original._id, | ||||||||||||||||||||||||||||||||||
| name: value, | ||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| }} | ||||||||||||||||||||||||||||||||||
| closeOnEnter | ||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||
| <RecordTableCellTrigger> | ||||||||||||||||||||||||||||||||||
| <Badge | ||||||||||||||||||||||||||||||||||
| variant="secondary" | ||||||||||||||||||||||||||||||||||
| onClick={(e) => { | ||||||||||||||||||||||||||||||||||
| e.stopPropagation(); | ||||||||||||||||||||||||||||||||||
| setRenderingProductDetail(true); | ||||||||||||||||||||||||||||||||||
| setProductId(cell.row.original._id); | ||||||||||||||||||||||||||||||||||
| }} | ||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||
| {name} | ||||||||||||||||||||||||||||||||||
| </Badge> | ||||||||||||||||||||||||||||||||||
| </RecordTableCellTrigger> | ||||||||||||||||||||||||||||||||||
| <RecordTableCellContent className="min-w-72"> | ||||||||||||||||||||||||||||||||||
| <Input | ||||||||||||||||||||||||||||||||||
| value={value || ''} | ||||||||||||||||||||||||||||||||||
| onChange={(e) => { | ||||||||||||||||||||||||||||||||||
| setValue(e.target.value); | ||||||||||||||||||||||||||||||||||
| }} | ||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||
| </RecordTableCellContent> | ||||||||||||||||||||||||||||||||||
| </RecordTablePopover> | ||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||
|
|
@@ -53,7 +99,7 @@ export const productColumns: ColumnDef<IProduct>[] = [ | |||||||||||||||||||||||||||||||||
| <RecordTableCellDisplay> | ||||||||||||||||||||||||||||||||||
| <CurrencyFormatedDisplay | ||||||||||||||||||||||||||||||||||
| currencyValue={{ | ||||||||||||||||||||||||||||||||||
| amountMicros: (cell.getValue() as number), | ||||||||||||||||||||||||||||||||||
| amountMicros: cell.getValue() as number, | ||||||||||||||||||||||||||||||||||
| currencyCode: CurrencyCode.MNT, | ||||||||||||||||||||||||||||||||||
| }} | ||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||
|
|
@@ -80,12 +126,23 @@ export const productColumns: ColumnDef<IProduct>[] = [ | |||||||||||||||||||||||||||||||||
| <RecordTable.InlineHead icon={IconCategory} label="Category" /> | ||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||
| cell: ({ cell }) => { | ||||||||||||||||||||||||||||||||||
| const { productsEdit } = useProductsEdit(); | ||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||
| <RecordTableCellDisplay> | ||||||||||||||||||||||||||||||||||
| <TextOverflowTooltip | ||||||||||||||||||||||||||||||||||
| value={cell.row.original?.category?.name || ''} | ||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||
| </RecordTableCellDisplay> | ||||||||||||||||||||||||||||||||||
| <SelectCategory.InlineCell | ||||||||||||||||||||||||||||||||||
| mode="single" | ||||||||||||||||||||||||||||||||||
| value={cell.getValue() as string} | ||||||||||||||||||||||||||||||||||
| onValueChange={(value) => { | ||||||||||||||||||||||||||||||||||
| productsEdit({ | ||||||||||||||||||||||||||||||||||
| variables: { | ||||||||||||||||||||||||||||||||||
| _id: cell.row.original._id, | ||||||||||||||||||||||||||||||||||
| categoryId: value, | ||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||
| }} | ||||||||||||||||||||||||||||||||||
Kato-111 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||
| categories={ | ||||||||||||||||||||||||||||||||||
| cell.row.original.category ? [cell.row.original.category] : [] | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,38 +1,84 @@ | ||||||
| import { ProductHotKeyScope } from '@/products/types/ProductsHotKeyScope'; | ||||||
| import { IconSearch } from '@tabler/icons-react'; | ||||||
| import { Combobox, Command, Filter } from 'erxes-ui'; | ||||||
| import { TagsFilter } from 'ui-modules'; | ||||||
| import { Combobox, Command, Filter, useMultiQueryState } from 'erxes-ui'; | ||||||
| import { TagsFilter, SelectBrand, SelectCategory } from 'ui-modules'; | ||||||
| import { PRODUCTS_CURSOR_SESSION_KEY } from '../constants/productsCursorSessionKey'; | ||||||
|
|
||||||
| export const ProductsFilter = () => { | ||||||
| const [queries] = useMultiQueryState<{ | ||||||
| searchValue: string; | ||||||
| created: string; | ||||||
| updated: string; | ||||||
| lastSeen: string; | ||||||
| brandId: string; | ||||||
| categoryId: string; | ||||||
| }>(['searchValue', 'created', 'updated', 'lastSeen', 'brandId', 'categoryId']); | ||||||
| const { searchValue } = queries || {}; | ||||||
|
|
||||||
| return ( | ||||||
| <Filter id="products-filter" sessionKey={PRODUCTS_CURSOR_SESSION_KEY}> | ||||||
| <Filter.Bar> | ||||||
| {searchValue && ( | ||||||
| <Filter.BarItem> | ||||||
| <Filter.BarName> | ||||||
| <IconSearch /> | ||||||
| Search | ||||||
| </Filter.BarName> | ||||||
| <Filter.BarButton filterKey="searchValue" inDialog> | ||||||
| {searchValue} | ||||||
| </Filter.BarButton> | ||||||
| <Filter.BarClose filterKey="searchValue" /> | ||||||
| </Filter.BarItem> | ||||||
| )} | ||||||
| <TagsFilter.Bar tagType="core:product" /> | ||||||
| <SelectBrand.FilterBar /> | ||||||
| <SelectCategory.FilterBar /> | ||||||
| <ProductsFilterPopover /> | ||||||
| </Filter.Bar> | ||||||
| </Filter> | ||||||
| ); | ||||||
| }; | ||||||
|
|
||||||
| export const ProductsFilterPopover = () => { | ||||||
| const ProductsFilterPopover = () => { | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Use named export for ProductsFilterPopover Per the coding guidelines, components should use named exports rather than local constants. Apply this diff to export the component: -const ProductsFilterPopover = () => {
+export const ProductsFilterPopover = () => {📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| const [queries] = useMultiQueryState<{ | ||||||
| searchValue: string; | ||||||
| created: string; | ||||||
| updated: string; | ||||||
| lastSeen: string; | ||||||
| brandId: string; | ||||||
| categoryId: string; | ||||||
| }>(['searchValue', 'created', 'updated', 'lastSeen', 'brandId', 'categoryId']); | ||||||
|
|
||||||
| const hasFilters = Object.values(queries || {}).some( | ||||||
| (value) => value !== null, | ||||||
| ); | ||||||
|
|
||||||
| return ( | ||||||
| <> | ||||||
| <Filter.Popover scope={ProductHotKeyScope.ProductsPage}> | ||||||
| <Filter.Trigger /> | ||||||
| <Filter.Trigger isFiltered={hasFilters} /> | ||||||
| <Combobox.Content> | ||||||
| <Filter.View> | ||||||
| <Command> | ||||||
| <Filter.CommandInput placeholder="Filter" variant="secondary" /> | ||||||
|
|
||||||
| <Filter.CommandInput | ||||||
| placeholder="Filter" | ||||||
| variant="secondary" | ||||||
| className="bg-background" | ||||||
| /> | ||||||
| <Command.List className="p-1"> | ||||||
| <Filter.Item value="searchValue" inDialog> | ||||||
| <IconSearch /> | ||||||
| Search | ||||||
| </Filter.Item> | ||||||
| <TagsFilter /> | ||||||
| <SelectBrand.FilterItem /> | ||||||
| <SelectCategory.FilterItem /> | ||||||
| </Command.List> | ||||||
| </Command> | ||||||
| </Filter.View> | ||||||
| <TagsFilter.View tagType="core:product" /> | ||||||
| <SelectBrand.FilterView /> | ||||||
| <SelectCategory.FilterView /> | ||||||
| </Combobox.Content> | ||||||
| </Filter.Popover> | ||||||
| <Filter.Dialog> | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.