Skip to content

Commit

Permalink
update statusType
Browse files Browse the repository at this point in the history
  • Loading branch information
jschuler committed Jun 21, 2021
1 parent c8eb2ab commit 5173a52
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 17 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.14",
"@patternfly/quickstarts": "1.0.0-rc.15",
"@patternfly/react-core": "^4.101.3",
"asciidoctor": "^2.2.1",
"react": "^16.14.0",
Expand Down
5 changes: 3 additions & 2 deletions packages/dev/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import {
QuickStartContextProvider,
QuickStartContextValues,
QuickStartDrawer,
useLocalStorage
useLocalStorage,
QuickStart
} from "@patternfly/quickstarts";
import { allQuickStarts as yamlQuickStarts } from "./quickstarts-data/quick-start-test-data";
import { loadJSONQuickStarts } from "./quickstarts-data/mas-guides/quickstartLoader";
Expand Down Expand Up @@ -56,7 +57,7 @@ const App: React.FC<AppProps> = ({ children, showCardFooters }) => {
allQuickStartsLoaded,
setAllQuickStartsLoaded,
] = React.useState<boolean>(false);
const [allQuickStarts, setAllQuickStarts] = React.useState<any[]>([]);
const [allQuickStarts, setAllQuickStarts] = React.useState<QuickStart[]>([]);
React.useEffect(() => {
const load = async () => {
const masGuidesQuickstarts = await loadJSONQuickStarts("");
Expand Down
16 changes: 8 additions & 8 deletions packages/dev/src/DefaultCatalog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import { allQuickStarts as yamlQuickStarts } from './quickstarts-data/quick-star
import { loadJSONQuickStarts } from './quickstarts-data/mas-guides/quickstartLoader';

export const DefaultCatalog = () => {
// const { setAllQuickStarts } = React.useContext<QuickStartContextValues>(QuickStartContext);
// const load = async () => {
// const masGuidesQuickstarts = await loadJSONQuickStarts('');
// setAllQuickStarts(yamlQuickStarts.concat(masGuidesQuickstarts));
// };
// const { setAllQuickStarts } = React.useContext<QuickStartContextValues>(QuickStartContext);
// const load = async () => {
// const masGuidesQuickstarts = await loadJSONQuickStarts('');
// setAllQuickStarts(yamlQuickStarts.concat(masGuidesQuickstarts));
// };

// const loadQuickStarts = () => {
// load();
// };
// const loadQuickStarts = () => {
// load();
// };
return (
<>
{/* <button onClick={loadQuickStarts}>Load</button> */}
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.14",
"version": "1.0.0-rc.15",
"description": "PatternFly quick starts",
"files": [
"dist"
Expand Down
8 changes: 7 additions & 1 deletion packages/module/src/QuickStartCatalogPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,14 @@ export const QuickStartCatalogPage: React.FC<QuickStartCatalogPageProps> = ({
hint,
showTitle = true,
}) => {
const { allQuickStarts = quickStarts, allQuickStartStates, getResource, filter, setFilter } = React.useContext<QuickStartContextValues>(QuickStartContext);
const { allQuickStarts = quickStarts, setAllQuickStarts, allQuickStartStates, getResource, filter, setFilter } = React.useContext<QuickStartContextValues>(QuickStartContext);

React.useEffect(() => {
if (quickStarts) {
setAllQuickStarts(quickStarts);
}
}, [quickStarts]);

const initialFilteredQuickStarts = showFilter
? filterQuickStarts(
allQuickStarts,
Expand Down
18 changes: 14 additions & 4 deletions packages/module/src/utils/quick-start-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ export const QuickStartContextProvider: React.FC<{
const initialStatusFilters = initialSearchParams.get(QUICKSTART_STATUS_FILTER_KEY)?.split(',') || [];

const quickStartStatusCount = getQuickStartStatusCount(combinedValue.allQuickStartStates, combinedValue.allQuickStarts);
const statusTypes = {
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]),
[QuickStartStatus.NOT_STARTED]: findResource('Not started ({{statusCount, number}})').replace('{{statusCount, number}}', quickStartStatusCount[QuickStartStatus.NOT_STARTED]),
};
});
const [statusFilters, setStatusFilters] = React.useState<string[]>(initialStatusFilters);
const [selectedFilters, setSelectedFilters] = React.useState<string[]>(
initialStatusFilters.map((filter) => statusTypes[filter]),
Expand All @@ -137,7 +137,17 @@ export const QuickStartContextProvider: React.FC<{
setStatusFilters(value);
setSelectedFilters(value.map((filterKey) => statusTypes[filterKey]));
}
}
};

const updateAllQuickStarts = (quickStarts: QuickStart[]) => {
setQuickStarts(quickStarts);
const updatedQuickStartStatusCount = getQuickStartStatusCount(combinedValue.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]),
});
};

const { activeQuickStartID, setActiveQuickStartID, setAllQuickStartStates, useQueryParams, allQuickStartStates } = combinedValue;

Expand Down Expand Up @@ -341,7 +351,7 @@ export const QuickStartContextProvider: React.FC<{
return <QuickStartContext.Provider value={{
...combinedValue,
allQuickStarts: quickStarts,
setAllQuickStarts: setQuickStarts,
setAllQuickStarts: updateAllQuickStarts,
resourceBundle,
setResourceBundle: changeResourceBundle,
lng,
Expand Down

0 comments on commit 5173a52

Please sign in to comment.