Skip to content
This repository has been archived by the owner on Nov 18, 2024. It is now read-only.

Commit

Permalink
filter in my ressources
Browse files Browse the repository at this point in the history
  • Loading branch information
khylpe committed Apr 25, 2024
1 parent a52b71d commit 80c404c
Showing 1 changed file with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,28 @@ export default function MyRessources() {
}, []);

const applyFilter = (values: FormValues) => {
console.log(values)
// Filter resources for each category based on matching any provided form value.
console.log(values.isPublic)
console.log(acceptedRessources)
const filterResources = (resources: Ressource[]) => {
return resources.filter(resource => {
return (values.label && resource.label.includes(values.label)) ||
(values.description && resource.description.includes(values.description)) ||
(values.idCategory && resource.category.id === values.idCategory) ||
(values.isPublic !== undefined && resource.isPublic == values.isPublic);
});
};

setFilteredRessources([
filterResources(acceptedRessources),
filterResources(pendingRessources),
filterResources(rejectedRessources),
filterResources(blockedRessources)
]);
setFilterActive(true);
};


const resetFilter = () => {
form.resetFields();
setFilteredRessources([acceptedRessources, pendingRessources, rejectedRessources, blockedRessources]);
Expand Down Expand Up @@ -158,14 +177,12 @@ export default function MyRessources() {
<Card title="Filtres">
<Form
onValuesChange={(_, allValues) => {
if (filterActive) {
if (Object.values(allValues).some(value => value !== undefined)) {
applyFilter(allValues);
}
}}

form={form}
name="filterRessourceListForm"
// onFinish={onFinish}
autoComplete="off"
layout='vertical'
>
Expand All @@ -176,7 +193,7 @@ export default function MyRessources() {
<Form.Item label="Description" name="description">
<Input.TextArea />
</Form.Item>

<Form.Item
label="Catégorie"
name="idCategory"
Expand Down Expand Up @@ -209,17 +226,24 @@ export default function MyRessources() {
>
{filterActive ? (
<Button
className='mt-10'
onClick={() => {
form.resetFields();
setFilterActive(false);
setFilteredRessources([acceptedRessources, pendingRessources, rejectedRessources, blockedRessources]);
}}
type="primary" htmlType="submit">Réinitialiser les filtres</Button>
type="primary" htmlType="button">Réinitialiser les filtres</Button>
) : (
<Button
className='mt-10'

onClick={() => {
form.submit(); // Make sure to submit the form, triggering the onValuesChange
setFilterActive(true);
}}
type="primary" htmlType="submit">Appliquer les filtres</Button>


)}
</Form.Item>
</Form>
Expand Down

0 comments on commit 80c404c

Please sign in to comment.