Skip to content

Commit

Permalink
add baseline for remaining syncModel steps
Browse files Browse the repository at this point in the history
  • Loading branch information
pokornyd committed Oct 7, 2024
1 parent 7dedb7e commit 4ea3b65
Show file tree
Hide file tree
Showing 13 changed files with 543 additions and 176 deletions.
20 changes: 19 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"@netlify/functions": "^2.8.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-router": "^6.26.2"
"react-router": "^6.26.2",
"react-router-dom": "^6.26.2"
},
"devDependencies": {
"@kontent-ai/eslint-config": "^1.0.2",
Expand Down
35 changes: 24 additions & 11 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
import { Header } from "./components/Header";

import Wizard from "./components/Wizard";
import "@kontent-ai/stylekit";

function App() {
return (
<div className="content">
<Header />
<Wizard />
</div>
);
}
import React from "react";
import { BrowserRouter as Router, Route, Routes } from "react-router-dom";

import Home from "./components/Home";
import { SyncDiff } from "./components/sync/SyncDiff";
import { SyncEntities } from "./components/sync/SyncEntities";
import { SyncSource } from "./components/sync/SyncSource";
import { SyncTarget } from "./components/sync/SyncTarget";
import { WizardProvider } from "./WizardContext";

const App: React.FC = () => (
<WizardProvider>
<Router>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/sync/source" element={<SyncSource />} />
<Route path="/sync/target" element={<SyncTarget />} />
<Route path="/sync/entities" element={<SyncEntities />} />
<Route path="/sync/diff" element={<SyncDiff />} />
{/* remaining routes */}
</Routes>
</Router>
</WizardProvider>
);

export default App;
78 changes: 78 additions & 0 deletions src/WizardContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { ManagementClient } from "@kontent-ai/management-sdk";
import React, { createContext, useState } from "react";

const syncEntityChoices = [
"contentTypes",
"contentTypeSnippets",
"taxonomies",
"collections",
"assetFolders",
"spaces",
"languages",
"webSpotlight",
"workflows",
] as const;

export type SyncEntityName = (typeof syncEntityChoices)[number];

interface WizardContextProps {
action?: string;
sourceEnvironmentId?: string;
targetEnvironmentId?: string;
sourceClient?: ManagementClient;
targetClient?: ManagementClient;
sourceFile?: File | null;
sourceApiKey?: string;
targetApiKey?: string;
syncModelEntities: SyncEntityName[];
setAction: (action: string) => void;
setSourceEnvironmentId: (id: string) => void;
setTargetEnvironmentId: (id: string) => void;
setSourceClient: (client: ManagementClient) => void;
setTargetClient: (client: ManagementClient) => void;
setSourceFile: (file: File | null) => void;
setSourceApiKey: (key: string) => void;
setTargetApiKey: (key: string) => void;
setSyncModelEntities: (entities: SyncEntityName[]) => void;
}

export const WizardContext = createContext<WizardContextProps>({} as WizardContextProps);

export const WizardProvider: React.FC<any> = ({ children }) => {
const [action, setAction] = useState<string>();
const [sourceEnvironmentId, setSourceEnvironmentId] = useState<string>();
const [targetEnvironmentId, setTargetEnvironmentId] = useState<string>();
const [sourceClient, setSourceClient] = useState<ManagementClient>();
const [targetClient, setTargetClient] = useState<ManagementClient>();
const [sourceFile, setSourceFile] = useState<File | null>(null);
const [sourceApiKey, setSourceApiKey] = useState<string>();
const [targetApiKey, setTargetApiKey] = useState<string>();
const [syncModelEntities, setSyncModelEntities] = useState<SyncEntityName[]>([]);

return (
<WizardContext.Provider
value={{
action,
sourceEnvironmentId,
targetEnvironmentId,
sourceClient,
targetClient,
sourceFile,
sourceApiKey,
targetApiKey,
syncModelEntities,
setAction,
setSourceEnvironmentId,
setTargetEnvironmentId,
setSourceClient,
setTargetClient,
setSourceFile,
setSourceApiKey,
setTargetApiKey,
setSyncModelEntities,
}}
>
{children}
</WizardContext.Provider>
);
};
41 changes: 41 additions & 0 deletions src/components/Home.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// src/components/Home.tsx
import React, { useContext } from "react";
import { useNavigate } from "react-router-dom";

import { WizardContext } from "../WizardContext";

const Home: React.FC = () => {
const { setAction } = useContext(WizardContext);
const navigate = useNavigate();

const handleSelectAction = (selectedAction: string) => {
setAction(selectedAction);
if (selectedAction === "sync") {
navigate("/sync/source");
} else {
alert("This action is not implemented yet.");
}
};

return (
<div>
<h2>Select an Action</h2>
<ul>
<li>
<button onClick={() => handleSelectAction("sync")}>Sync</button>
</li>
<li>
<button disabled>Diff Model</button>
</li>
<li>
<button disabled>Import/Export</button>
</li>
<li>
<button disabled>Clean</button>
</li>
</ul>
</div>
);
};

export default Home;
41 changes: 0 additions & 41 deletions src/components/Wizard.tsx

This file was deleted.

49 changes: 0 additions & 49 deletions src/components/steps/Step1.tsx

This file was deleted.

72 changes: 0 additions & 72 deletions src/components/steps/Step2.tsx

This file was deleted.

Loading

0 comments on commit 4ea3b65

Please sign in to comment.