diff --git a/ui/v2.5/src/components/Setup/Setup.tsx b/ui/v2.5/src/components/Setup/Setup.tsx index f6462427b..3d7aafb47 100644 --- a/ui/v2.5/src/components/Setup/Setup.tsx +++ b/ui/v2.5/src/components/Setup/Setup.tsx @@ -34,7 +34,7 @@ export const Setup: React.FC = () => { const [saveUI] = useConfigureUI(); const [step, setStep] = useState(0); - const [configLocation, setConfigLocation] = useState(""); + const [setupInWorkDir, setSetupInWorkDir] = useState(false); const [stashes, setStashes] = useState([]); const [showStashAlert, setShowStashAlert] = useState(false); const [databaseFile, setDatabaseFile] = useState(""); @@ -65,6 +65,13 @@ export const Setup: React.FC = () => { return paths.join(pathSep); } + // simply returns everything preceding the last path separator + function pathDir(path: string) { + const lastSep = path.lastIndexOf(pathSep); + if (lastSep === -1) return ""; + return path.slice(0, lastSep); + } + const workingDir = status?.workingDir ?? "."; // When running Stash.app, the working directory is (usually) set to /. @@ -75,15 +82,15 @@ export const Setup: React.FC = () => { const fallbackStashDir = pathJoin(homeDir, ".stash"); const fallbackConfigPath = pathJoin(fallbackStashDir, "config.yml"); - useEffect(() => { - if (status?.configPath) { - setConfigLocation(status.configPath); - } - }, [status?.configPath]); + const overrideConfig = status?.configPath; + const overrideGenerated = configuration?.general.generatedPath; + const overrideCache = configuration?.general.cachePath; + const overrideBlobs = configuration?.general.blobsPath; + const overrideDatabase = configuration?.general.databasePath; useEffect(() => { if (configuration) { - const { stashes: configStashes, generatedPath } = configuration.general; + const configStashes = configuration.general.stashes; if (configStashes.length > 0) { setStashes( configStashes.map((s) => { @@ -92,9 +99,6 @@ export const Setup: React.FC = () => { }) ); } - if (generatedPath) { - setGeneratedLocation(generatedPath); - } } }, [configuration]); @@ -113,8 +117,8 @@ export const Setup: React.FC = () => { ); - function onConfigLocationChosen(loc: string) { - setConfigLocation(loc); + function onConfigLocationChosen(inWorkDir: boolean) { + setSetupInWorkDir(inWorkDir); next(); } @@ -179,7 +183,7 @@ export const Setup: React.FC = () => { {chunks}, }} /> @@ -242,7 +246,7 @@ export const Setup: React.FC = () => {
- - - - ); - } + onClick={() => setShowGeneratedSelectDialog(true)} + > + + + + + + ); } function onCacheSelectClosed(d?: string) { @@ -389,110 +426,106 @@ export const Setup: React.FC = () => { } function maybeRenderCache() { - if (!configuration?.general.cachePath) { - return ( - -

- -

-

- {chunks}, - }} - /> -

+ if (overrideCache) return; + + return ( + +

+ +

+

+ {chunks}, + }} + /> +

+ + setCacheLocation(e.currentTarget.value)} + /> + + + + +
+ ); + } + + function maybeRenderBlobs() { + if (overrideBlobs) return; + + return ( + +

+ +

+

+ {chunks}, + }} + /> +

+

+ {chunks}, + strong: (chunks: string) => {chunks}, + }} + /> +

+ +

+ setStoreBlobsInDatabase(!storeBlobsInDatabase)} + /> +

+ + {!storeBlobsInDatabase && ( ) => - setCacheLocation(e.currentTarget.value) - } + onChange={(e) => setBlobsLocation(e.currentTarget.value)} + disabled={storeBlobsInDatabase} /> -
- ); - } - } - - function maybeRenderBlobs() { - if (!configuration?.general.blobsPath) { - return ( - -

- -

-

- {chunks}, - }} - /> -

-

- {chunks}, - strong: (chunks: string) => {chunks}, - }} - /> -

- -

- setStoreBlobsInDatabase(!storeBlobsInDatabase)} - /> -

- - {!storeBlobsInDatabase && ( - - ) => - setBlobsLocation(e.currentTarget.value) - } - disabled={storeBlobsInDatabase} - /> - - - - - )} -
- ); - } + )} +
+ ); } function renderSetPaths() { @@ -522,36 +555,7 @@ export const Setup: React.FC = () => { /> - -

- -

-

- {chunks}, - }} - /> -
- {chunks}, - }} - /> -

- ) => - setDatabaseFile(e.currentTarget.value) - } - /> -
+ {maybeRenderDatabase()} {maybeRenderGenerated()} {maybeRenderCache()} {maybeRenderBlobs()} @@ -587,6 +591,11 @@ export const Setup: React.FC = () => { } async function onSave() { + let configLocation = overrideConfig; + if (!configLocation) { + configLocation = setupInWorkDir ? "config.yml" : ""; + } + try { setLoading(true); await mutateSetup({ @@ -616,40 +625,22 @@ export const Setup: React.FC = () => { } function renderConfirm() { - let cfgPath = ""; - let config = configLocation; - if (configLocation === "config.yml") { - cfgPath = pwd; - config = pathJoin(cfgPath, "config.yml"); - } else if (configLocation === "") { - cfgPath = fallbackStashDir; - config = pathJoin(cfgPath, "config.yml"); - } - - let database = databaseFile; - if (database === "") { - database = pathJoin(cfgPath, "stash-go.sqlite"); - } - - let generated = generatedLocation; - if (generated === "") { - generated = pathJoin(cfgPath, "generated"); - } - - let cache = cacheLocation; - if (cache === "") { - cache = pathJoin(cfgPath, "cache"); - } - - let blobs; - if (storeBlobsInDatabase) { - blobs = intl.formatMessage({ - id: "setup.confirm.blobs_use_database", - }); - } else if (blobsLocation !== "") { - blobs = blobsLocation; + let cfgDir: string; + let config: string; + if (overrideConfig) { + cfgDir = pathDir(overrideConfig); + config = overrideConfig; } else { - blobs = pathJoin(cfgPath, "blobs"); + cfgDir = setupInWorkDir ? pwd : fallbackStashDir; + config = pathJoin(cfgDir, "config.yml"); + } + + function joinCfgDir(path: string) { + if (cfgDir) { + return pathJoin(cfgDir, path); + } else { + return path; + } } return ( @@ -684,38 +675,52 @@ export const Setup: React.FC = () => { -
-
- -
-
- {database} -
-
-
-
- -
-
- {generated} -
-
-
-
- -
-
- {cache} -
-
-
-
- -
-
- {blobs} -
-
+ {!overrideDatabase && ( +
+
+ +
+
+ {databaseFile || joinCfgDir("stash-go.sqlite")} +
+
+ )} + {!overrideGenerated && ( +
+
+ +
+
+ {generatedLocation || joinCfgDir("generated")} +
+
+ )} + {!overrideCache && ( +
+
+ +
+
+ {cacheLocation || joinCfgDir("cache")} +
+
+ )} + {!overrideBlobs && ( +
+
+ +
+
+ + {storeBlobsInDatabase ? ( + + ) : ( + blobsLocation || joinCfgDir("blobs") + )} + +
+
+ )}
@@ -864,10 +869,9 @@ export const Setup: React.FC = () => { return ; } - const welcomeStep = - status && status.configPath !== "" - ? renderWelcomeSpecificConfig - : renderWelcome; + const welcomeStep = overrideConfig + ? renderWelcomeSpecificConfig + : renderWelcome; const steps = [welcomeStep, renderSetPaths, renderConfirm, renderFinish]; function renderCreating() {