Skip to content

Commit

Permalink
update catalog and status filter on state change
Browse files Browse the repository at this point in the history
  • Loading branch information
jschuler committed Jun 22, 2021
1 parent 6e76e7f commit 640283a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"serve": "serve public"
},
"dependencies": {
"@patternfly/quickstarts": "1.0.0-rc.16",
"@patternfly/quickstarts": "1.0.0-rc.17",
"@patternfly/react-core": "^4.101.3",
"asciidoctor": "^2.2.1",
"react": "^16.14.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/module/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@patternfly/quickstarts",
"version": "1.0.0-rc.16",
"version": "1.0.0-rc.17",
"description": "PatternFly quick starts",
"files": [
"dist"
Expand Down
2 changes: 1 addition & 1 deletion packages/module/src/QuickStartCatalogPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const QuickStartCatalogPage: React.FC<QuickStartCatalogPageProps> = ({
)
: allQuickStarts;
setFilteredQuickStarts(filteredQuickStarts);
}, [allQuickStarts]);
}, [allQuickStarts, allQuickStartStates]);

const clearFilters = () => {
setFilter('keyword', '');
Expand Down
21 changes: 15 additions & 6 deletions packages/module/src/utils/quick-start-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ export const QuickStartContextProvider: React.FC<{
...QuickStartContextDefaults,
...value
}
const {
activeQuickStartID,
setActiveQuickStartID,
setAllQuickStartStates,
useQueryParams,
allQuickStartStates,
allQuickStarts
} = combinedValue;
const [quickStarts, setQuickStarts] = React.useState(combinedValue.allQuickStarts);
const [resourceBundle, setResourceBundle] = React.useState({
...en,
Expand All @@ -116,7 +124,7 @@ export const QuickStartContextProvider: React.FC<{
const initialSearchQuery = initialSearchParams.get(QUICKSTART_SEARCH_FILTER_KEY) || '';
const initialStatusFilters = initialSearchParams.get(QUICKSTART_STATUS_FILTER_KEY)?.split(',') || [];

const quickStartStatusCount = getQuickStartStatusCount(combinedValue.allQuickStartStates, combinedValue.allQuickStarts);
const quickStartStatusCount = getQuickStartStatusCount(allQuickStartStates, allQuickStarts);
const [statusTypes, setStatusTypes] = React.useState({
[QuickStartStatus.COMPLETE]: findResource('Complete ({{statusCount, number}})').replace('{{statusCount, number}}', quickStartStatusCount[QuickStartStatus.COMPLETE]),
[QuickStartStatus.IN_PROGRESS]: findResource('In progress ({{statusCount, number}})').replace('{{statusCount, number}}', quickStartStatusCount[QuickStartStatus.IN_PROGRESS]),
Expand All @@ -134,17 +142,18 @@ export const QuickStartContextProvider: React.FC<{
}
};

const updateAllQuickStarts = (quickStarts: QuickStart[]) => {
setQuickStarts(quickStarts);
const updatedQuickStartStatusCount = getQuickStartStatusCount(combinedValue.allQuickStartStates, quickStarts);
React.useEffect(() => {
const updatedQuickStartStatusCount = getQuickStartStatusCount(allQuickStartStates, quickStarts);
setStatusTypes({
[QuickStartStatus.COMPLETE]: findResource('Complete ({{statusCount, number}})').replace('{{statusCount, number}}', updatedQuickStartStatusCount[QuickStartStatus.COMPLETE]),
[QuickStartStatus.IN_PROGRESS]: findResource('In progress ({{statusCount, number}})').replace('{{statusCount, number}}', updatedQuickStartStatusCount[QuickStartStatus.IN_PROGRESS]),
[QuickStartStatus.NOT_STARTED]: findResource('Not started ({{statusCount, number}})').replace('{{statusCount, number}}', updatedQuickStartStatusCount[QuickStartStatus.NOT_STARTED]),
});
};
}, [allQuickStartStates, quickStarts])

const { activeQuickStartID, setActiveQuickStartID, setAllQuickStartStates, useQueryParams, allQuickStartStates } = combinedValue;
const updateAllQuickStarts = (quickStarts: QuickStart[]) => {
setQuickStarts(quickStarts);
};

const setActiveQuickStart = useCallback(
(quickStartId: string, totalTasks?: number) => {
Expand Down

0 comments on commit 640283a

Please sign in to comment.