diff --git a/data/default.json b/data/default.json index 910d736f7b6..23e9769f361 100644 --- a/data/default.json +++ b/data/default.json @@ -1,5 +1,5 @@ { - "schemaVersion": 1, + "schemaVersion": 2, "configProperties": { "name": "default" }, diff --git a/src/components/Onboarding/onboarding-steps.tsx b/src/components/Onboarding/onboarding-steps.tsx index f9173d2012c..8ef440a2eb3 100644 --- a/src/components/Onboarding/onboarding-steps.tsx +++ b/src/components/Onboarding/onboarding-steps.tsx @@ -4,12 +4,31 @@ import { useState } from 'react'; import { StepCreateAccount } from './step-create-account'; import { StepOnboardingFinished } from './step-onboarding-finished'; import { StepUpdatePathMappings } from './step-update-path-mappings'; +import { api } from '~/utils/api'; export const OnboardingSteps = ({ isUpdate }: { isUpdate: boolean }) => { + const maximumSteps = isUpdate ? 3 : 2; + const [currentStep, setCurrentStep] = useState(0); - const nextStep = () => setCurrentStep((current) => (current < 3 ? current + 1 : current)); + + const nextStep = () => setCurrentStep((current) => { + const newValue = (current < maximumSteps ? current + 1 : current); + + if (currentStep + 1 >= maximumSteps) { + onFinishOnboarding(); + } + + return newValue; + }); + const prevStep = () => setCurrentStep((current) => (current > 0 ? current - 1 : current)); + const { mutate: mutateConfigSchemaVersion } = api.config.updateConfigurationSchemaToLatest.useMutation(); + + const onFinishOnboarding = () => { + mutateConfigSchemaVersion(); + }; + return ( { if (input.name.toLowerCase() === 'default') { - Consola.error("Rejected config deletion because default configuration can't be deleted"); + Consola.error('Rejected config deletion because default configuration can\'t be deleted'); throw new TRPCError({ code: 'FORBIDDEN', - message: "Default config can't be deleted", + message: 'Default config can\'t be deleted', }); } @@ -44,7 +47,7 @@ export const configRouter = createTRPCRouter({ // If the target is not in the list of files, return an error if (!matchedFile) { Consola.error( - `Rejected config deletion request because config name '${input.name}' was not included in present configurations` + `Rejected config deletion request because config name '${input.name}' was not included in present configurations`, ); throw new TRPCError({ code: 'NOT_FOUND', @@ -64,7 +67,7 @@ export const configRouter = createTRPCRouter({ z.object({ name: configNameSchema, config: z.custom((x) => !!x && typeof x === 'object'), - }) + }), ) .mutation(async ({ input }) => { Consola.info(`Saving updated configuration of '${input.name}' config.`); @@ -96,16 +99,16 @@ export const configRouter = createTRPCRouter({ } const previousApp = previousConfig.apps.find( - (previousApp) => previousApp.id === app.id + (previousApp) => previousApp.id === app.id, ); const previousProperty = previousApp?.integration?.properties.find( - (previousProperty) => previousProperty.field === property.field + (previousProperty) => previousProperty.field === property.field, ); if (property.value !== undefined && property.value !== null) { Consola.info( - 'Detected credential change of private secret. Value will be overwritten in configuration' + 'Detected credential change of private secret. Value will be overwritten in configuration', ); return { field: property.field, @@ -165,7 +168,7 @@ export const configRouter = createTRPCRouter({ .input( z.object({ name: configNameSchema, - }) + }), ) .query(async ({ ctx, input }) => { if (!configExists(input.name)) { @@ -223,4 +226,21 @@ export const configRouter = createTRPCRouter({ const targetPath = path.join('data/configs', `${input.name}.json`); fs.writeFileSync(targetPath, JSON.stringify(newConfig, null, 2), 'utf8'); }), + // publicProcedure is not optimal, but should be fince, since there is no input and output data nor can you break the config + updateConfigurationSchemaToLatest: publicProcedure.mutation(async () => { + const files = fs.readdirSync('./data/configs').filter((file) => file.endsWith('.json')); + + console.log('updating the schema version of', files.length, 'configurations'); + + for (const file of files) { + const name = file.replace('.json', ''); + const config = await getFrontendConfig(name); + + config.schemaVersion = 2; + const targetPath = `data/configs/${name}.json`; + fs.writeFileSync(targetPath, JSON.stringify(config, null, 2), 'utf8'); + + console.log('updated', name, 'to schema version', config.schemaVersion); + } + }), });