Skip to content

Commit

Permalink
context setAllQuickStarts setter
Browse files Browse the repository at this point in the history
  • Loading branch information
jschuler committed Jun 21, 2021
1 parent ac40fa4 commit c8eb2ab
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 20 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.13",
"@patternfly/quickstarts": "1.0.0-rc.14",
"@patternfly/react-core": "^4.101.3",
"asciidoctor": "^2.2.1",
"react": "^16.14.0",
Expand Down
37 changes: 29 additions & 8 deletions packages/dev/src/CustomCatalog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,34 @@ import {
TextContent,
ToolbarContent,
} from '@patternfly/react-core';
import { allQuickStarts as yamlQuickStarts } from "./quickstarts-data/quick-start-test-data";
import { loadJSONQuickStarts } from "./quickstarts-data/mas-guides/quickstartLoader";

export const CustomCatalog: React.FC = () => {
const { activeQuickStartID, allQuickStartStates, allQuickStarts, filter, setFilter } = React.useContext<QuickStartContextValues>(
const { activeQuickStartID, allQuickStartStates, allQuickStarts, setAllQuickStarts, filter, setFilter } = React.useContext<QuickStartContextValues>(
QuickStartContext,
);

React.useEffect(() => {
// callback on state change
setFilteredQuickStarts(filterQuickStarts(
allQuickStarts,
filter.keyword,
filter.status.statusFilters,
allQuickStartStates,
).sort(sortFnc),)
}, [allQuickStarts]);

const sortFnc = (q1: QuickStart, q2: QuickStart) =>
q1.spec.displayName.localeCompare(q2.spec.displayName);
const initialFilteredQuickStarts = filterQuickStarts(
allQuickStarts,
filter.keyword,
filter.status.statusFilters,
allQuickStartStates,
).sort(sortFnc);

const [filteredQuickStarts, setFilteredQuickStarts] = React.useState<QuickStart[]>(
initialFilteredQuickStarts,
filterQuickStarts(
allQuickStarts,
filter.keyword,
filter.status.statusFilters,
allQuickStartStates,
).sort(sortFnc),
);

const onSearchInputChange = (searchValue: string) => {
Expand Down Expand Up @@ -132,6 +144,15 @@ export const CustomCatalog: React.FC = () => {
);
};

// const load = async () => {
// const masGuidesQuickstarts = await loadJSONQuickStarts("");
// setAllQuickStarts(yamlQuickStarts.concat(masGuidesQuickstarts));
// };

// const loadQuickStarts = () => {
// load();
// }

return (
<>
<QuickStartCatalogHeader title="Resources" />
Expand Down
29 changes: 29 additions & 0 deletions packages/dev/src/DefaultCatalog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import {
QuickStartCatalogPage,
QuickStartContextValues,
QuickStartContext,
} from '@patternfly/quickstarts';
import { allQuickStarts as yamlQuickStarts } from './quickstarts-data/quick-start-test-data';
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 loadQuickStarts = () => {
// load();
// };
return (
<>
{/* <button onClick={loadQuickStarts}>Load</button> */}
<QuickStartCatalogPage
showFilter
hint="Learn how to create, import, and run applications with step-by-step instructions and tasks."
/>
</>
);
};
11 changes: 2 additions & 9 deletions packages/dev/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ import ReactDOM from "react-dom";
import { Route, BrowserRouter as Router, Switch } from "react-router-dom";
import './i18n/i18n';
import App from "./App";
import {
LoadingBox,
QuickStart,
QuickStartCatalogPage,
} from "@patternfly/quickstarts";
import { Home } from "./Home";
import { DefaultCatalog } from "./DefaultCatalog";
import { CustomCatalog } from "./CustomCatalog";

ReactDOM.render(
Expand All @@ -26,10 +22,7 @@ ReactDOM.render(
</Route>
<Route exact path="/quickstarts">
<App showCardFooters={false}>
<QuickStartCatalogPage
showFilter
hint="Learn how to create, import, and run applications with step-by-step instructions and tasks."
/>
<DefaultCatalog />
</App>
</Route>
<Route exact path="/custom-catalog">
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.13",
"version": "1.0.0-rc.14",
"description": "PatternFly quick starts",
"files": [
"dist"
Expand Down
1 change: 0 additions & 1 deletion packages/module/src/QuickStartCatalogPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as React from 'react';
import QuickStartCatalog from './catalog/QuickStartCatalog';
import { QuickStart } from './utils/quick-start-types';
import { filterQuickStarts } from './utils/quick-start-utils';
import { QUICKSTART_SEARCH_FILTER_KEY, QUICKSTART_STATUS_FILTER_KEY } from './utils/const';
import { QuickStartContext, QuickStartContextValues } from './utils/quick-start-context';
import {
Button,
Expand Down
5 changes: 5 additions & 0 deletions packages/module/src/utils/quick-start-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type QuickStartContextValues = {
activeQuickStartID?: string;
allQuickStartStates?: AllQuickStartStates;
activeQuickStartState?: QuickStartState;
setAllQuickStarts?: React.Dispatch<React.SetStateAction<QuickStart[]>>;
setActiveQuickStartID?: React.Dispatch<React.SetStateAction<string>>;
setAllQuickStartStates?: React.Dispatch<React.SetStateAction<AllQuickStartStates>>;
setActiveQuickStart?: (quickStartId: string, totalTasks?: number) => void;
Expand Down Expand Up @@ -62,6 +63,7 @@ export const QuickStartContextDefaults = {
activeQuickStartID: '',
allQuickStartStates: {},
activeQuickStartState: {},
setAllQuickStarts: () => {},
setActiveQuickStart: () => {},
startQuickStart: () => {},
restartQuickStart: () => {},
Expand Down Expand Up @@ -92,6 +94,7 @@ export const QuickStartContextProvider: React.FC<{
...QuickStartContextDefaults,
...value
}
const [quickStarts, setQuickStarts] = React.useState(combinedValue.allQuickStarts);
const [resourceBundle, setResourceBundle] = React.useState({
...en,
...combinedValue.resourceBundle
Expand Down Expand Up @@ -337,6 +340,8 @@ export const QuickStartContextProvider: React.FC<{

return <QuickStartContext.Provider value={{
...combinedValue,
allQuickStarts: quickStarts,
setAllQuickStarts: setQuickStarts,
resourceBundle,
setResourceBundle: changeResourceBundle,
lng,
Expand Down

0 comments on commit c8eb2ab

Please sign in to comment.