Skip to content

Commit

Permalink
Merge pull request #309 from GTBitsOfGood/Tian/FilterBugs
Browse files Browse the repository at this point in the history
Bug fixes
  • Loading branch information
thanasis457 authored Oct 23, 2024
2 parents 727f137 + 2afd950 commit cbb17a1
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 49 deletions.
16 changes: 8 additions & 8 deletions src/components/dashboard/AddProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let steps = [
"Hours",
"Tag",
"Text",
// 'Toggle', disabled due to lack of use
// 'Toggle', disabled due to lack of use, this is designed for singleselect filters, feature however, is not implemented
// 'Actions'
"Content",
];
Expand All @@ -45,7 +45,7 @@ function AddProvider(props) {
const [isLoading, setIsLoading] = useState(true);
const [filters, setFilters] = useState(null);
const [descriptions, setDescriptions] = useState(null);
const [categories, setCategories] = useState(null);
const [single, setSingle] = useState(null);
const [error, setError] = useState("");

// async function fetchData() {
Expand Down Expand Up @@ -109,7 +109,7 @@ function AddProvider(props) {
const f = await collections
.where("team", "==", props.team.name)
.where("active", "==", true)
.where("select_type", "==", 2)
.where("select_type", "==", 1)
.get()
.then((querySnapshot) => {
const idToData = {};
Expand Down Expand Up @@ -141,7 +141,7 @@ function AddProvider(props) {
const c = await collections
.where("team", "==", props.team.name)
.where("active", "==", true)
.where("select_type", "==", 1)
.where("select_type", "==", 2)
.get()
.then((querySnapshot) => {
const idToData = {};
Expand All @@ -156,7 +156,7 @@ function AddProvider(props) {
});
setFilters(f);
setDescriptions(d);
setCategories(c);
setSingle(c);
}
fetchData().then(() => setIsLoading(false));
}, []);
Expand All @@ -173,14 +173,14 @@ function AddProvider(props) {
delIndex !== -1 && steps.splice(delIndex, 1);
}

if (categories && !Object.keys(categories).length) {
if (single && !Object.keys(single).length) {
const delIndex = steps.indexOf("Toggle");
delIndex !== -1 && steps.splice(delIndex, 1);
}
}

updateSteps();
}, [filters, descriptions, categories]);
}, [filters, descriptions, single]);

// function updateSteps() {
// if (filters && !Object.keys(filters).length) {
Expand Down Expand Up @@ -476,7 +476,7 @@ function AddProvider(props) {
}}
filters={filters}
descriptions={descriptions}
categories={categories}
single={single}
/>
</div>
</div>
Expand Down
19 changes: 11 additions & 8 deletions src/components/dashboard/RowForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const RowForm = (props) => {
image: "modalimage.png",
imageURL: null,
content: {},
filters: {},
};

const [item, setItem] = useState(
Expand All @@ -83,10 +84,6 @@ const RowForm = (props) => {
const [showModal, setShowModal] = useState(false);

useEffect(() => {
const itemFields = Object.keys(props.filters);
itemFields.forEach((field) => {
defaultItem[field] = [];
});
setItem(props.item.facilityName ? props.item : defaultItem);
}, []);

Expand Down Expand Up @@ -403,11 +400,14 @@ const RowForm = (props) => {
<Form.Label>{name}</Form.Label>
<MultiSelect
options={options}
selected={item[key] || []}
selected={item['filters'][key] || []}
onSelectedChanged={(selected) => {
const newItem = {
...item,
[key]: selected,
['filters']: {
...item['filters'],
[key]: selected,
}
};
setItem(newItem);
props.setItem(newItem);
Expand All @@ -427,11 +427,14 @@ const RowForm = (props) => {
<Form.Label>{name}</Form.Label>
<Form.Control
as="textarea"
value={item[key]}
value={item['filters'][key]}
onChange={(e: any) => {
const newItem = {
...item,
[key]: e.target.value,
['filters']: {
...item['filters'],
[key]: e.target.value
}
};
setItem(newItem);
props.setItem(newItem);
Expand Down
5 changes: 3 additions & 2 deletions src/components/dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ function Dashboard({ firestore, team, selectItem }) {
setCategories(c);
}
}
fetchData().then(() => setIsLoading(false));
}, [team]);
fetchData()
setIsLoading(false);
}, [team, isLoading]);

if (isLoading) {
return (
Expand Down
10 changes: 5 additions & 5 deletions src/components/map/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ const Map = (props) => {
setTempProviders(temp);
Object.keys(filtersState).forEach((filterName) => {
temp = temp.filter((provider) =>
provider[filterName]
? provider[filterName].some((r) =>
provider['filters'][filterName]
? provider['filters'][filterName].some((r) =>
filtersState[filterName].includes(r)
) || filtersState[filterName].length === 0
: true
Expand Down Expand Up @@ -702,7 +702,7 @@ const Map = (props) => {
.filter(
([key, value]: any[]) =>
Number.isInteger(value.priority) &&
value.priority < FILTER_CUTOFF
value.priority <= FILTER_CUTOFF
)
.sort(
([aKey, aValue]: any[], [bKey, bValue]: any[]) =>
Expand Down Expand Up @@ -734,13 +734,13 @@ const Map = (props) => {
.filter(
([key, value]: any[]) =>
!Number.isInteger(value.priority) ||
value.priority >= FILTER_CUTOFF
value.priority > FILTER_CUTOFF
)
.sort(
(
[aKey, aValue]: any[],
[bKey, bValue]: any[]
) => aValue.name.localeCompare(bValue.name)
) => aValue.priority - bValue.priority
)
.map(([key, value]: any[]) =>
renderMoreDropdown(value.name, key)
Expand Down
Loading

0 comments on commit cbb17a1

Please sign in to comment.