Skip to content
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

fixed editing of a category and list of more than 20 categories #255

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/components/categories/CategoryForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export function CategoryForm({category, headerComponent, parentId, onSuccess}: C
const {handleSubmit, control, reset} = useForm<ICategory>({
resolver: yupResolver(validationSchema) as any,
defaultValues: category || defaultValues,
values: category,
mode: "onBlur"
})

Expand Down Expand Up @@ -79,10 +80,10 @@ export function CategoryForm({category, headerComponent, parentId, onSuccess}: C
}

async function onSubmit(fields: ICategory) {
if (isCreating) {
await createCategory(fields)
} else {
if (control._defaultValues?.ID) {
await updateCategory(fields)
} else {
await createCategory(fields)
}
}

Expand Down Expand Up @@ -129,7 +130,7 @@ export function CategoryForm({category, headerComponent, parentId, onSuccess}: C
name="Description"
label="Description"
control={control}
validationSchema={validationSchema}
validationSchema={validationSchema}
/>
<SwitchControl
name="Active"
Expand All @@ -138,6 +139,7 @@ export function CategoryForm({category, headerComponent, parentId, onSuccess}: C
size="lg"
control={control}
validationSchema={validationSchema}

/>
<ButtonGroup>
<HStack justifyContent="space-between" w="100%" mb={5}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,22 @@ const CategoriesList = (props) => {

const initCategoriesData = useCallback(
async (catalogid: string) => {
const categoriesList = await Categories.List<ICategory>(catalogid,{depth:"all"})
const categoriesList = await Categories.List<ICategory>(catalogid,{depth:"99", pageSize:100})
let cl = categoriesList.Items;
let i = 2;
while (cl.length < categoriesList.Meta.TotalCount) {
const l = (await Categories.List<ICategory>(catalogid,{depth:"99", pageSize:100, page:i}));
cl = cl.concat( l.Items);
i++;
}
if (selectedNode) {
const selectedCategoryId = selectedNode.data.ID
const selectedCategoryExists = categoriesList.Items.find((category) => category.ID === selectedCategoryId)
const selectedCategoryExists = cl.find((category) => category.ID === selectedCategoryId)
if (!selectedCategoryExists) {
setSelectedNode(null)
}
}
setCategoriesTreeView(await buildTreeView(categoriesList.Items))
setCategoriesTreeView(await buildTreeView(cl))
},
[selectedNode]
)
Expand Down Expand Up @@ -74,7 +81,7 @@ const CategoriesList = (props) => {

return treeViewData
}
const handleSelect = (node: ocNodeModel) => setSelectedNode(node)
const handleSelect = (node: ocNodeModel) => { setSelectedNode(node);}

const handleCategoryCreate = (category: Category) => {
setParentIdToCreate(category?.ID)
Expand All @@ -86,6 +93,7 @@ const CategoriesList = (props) => {
await initCategoriesData(router.query.catalogid as string)
}


return (
<>
<Box padding="20px">
Expand Down Expand Up @@ -118,7 +126,7 @@ const CategoriesList = (props) => {
/>
</GridItem>
<GridItem pl="2" area={"main"}>
{selectedNode ? (
{selectedNode?.id ? (
<CategoryForm
category={selectedNode.data}
onSuccess={onCategoryCreateSuccess}
Expand All @@ -131,7 +139,7 @@ const CategoriesList = (props) => {
) : (
<CategoryForm
onSuccess={onCategoryCreateSuccess}
category={{Name: "", Description: "", Active: false, ParentID: ""}}
category={{Name: "", Description: "", Active: true, ParentID: ""}}
headerComponent={
<Heading as="h5" size="md" marginLeft={10} marginTop={5}>
Create root category
Expand Down