Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put SAP reporting behind feature flags (ui, api, jobs) #831

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
.DS_store
.DS_Store
.tool-versions
.history
.clj-kondo
.lsp
node_modules
.temp
.vscode


8 changes: 4 additions & 4 deletions backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ async function run() {
await Promise.all([
setupReportQueue(),
setupMailQueue(),
setupSapSyncQueue(),
setupDailySapSyncQueue(),
setupEnvironmentCodeReportQueue(),
setupBlanketContractReportQueue(),
env.enabledFeatures.sapSync ? setupSapSyncQueue() : null,
env.enabledFeatures.sapSync ? setupDailySapSyncQueue() : null,
env.enabledFeatures.sapSync ? setupEnvironmentCodeReportQueue() : null,
env.enabledFeatures.sapSync ? setupBlanketContractReportQueue() : null,
setupDetailPlanGeomSyncQueue(),
]);
// https://github.com/fastify/fastify/issues/4960
Expand Down
1 change: 1 addition & 0 deletions backend/src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { inferAsyncReturnType, initTRPC } from '@trpc/server';
import { CreateFastifyContextOptions } from '@trpc/server/adapters/fastify';
import superjson from 'superjson';

import { env } from '@backend/env';
import { logger } from '@backend/logging';
import { createCodeRouter } from '@backend/router/code';
import { createCompanyRouter } from '@backend/router/company';
Expand Down
44 changes: 29 additions & 15 deletions backend/src/router/sapReport.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { TRPCError } from '@trpc/server';
import { z } from 'zod';

import {
Expand All @@ -14,6 +15,7 @@ import {
import { startEnvironmentCodeReportJob } from '@backend/components/sap/environmentCodeReportQueue';
import { getLastSyncedAt } from '@backend/components/sap/syncQueue';
import { getPool, sql } from '@backend/db';
import { env } from '@backend/env';

import { EXPLICIT_EMPTY } from '@shared/schema/code';
import {
Expand All @@ -25,60 +27,71 @@ import {

import { TRPC } from '.';

export const createSapReportRouter = (t: TRPC) =>
t.router({
getLastSyncedAt: t.procedure.query(async () => {
export const createSapReportRouter = (t: TRPC) => {
const baseProcedure = t.procedure.use(async (opts) => {
if (env.enabledFeatures.sapSync) {
return opts.next();
} else {
throw new TRPCError({
code: 'BAD_REQUEST',
message: 'SAP report feature is disabled',
});
}
});

return t.router({
getLastSyncedAt: baseProcedure.query(async () => {
return await getLastSyncedAt();
}),

getEnvironmentCodeReport: t.procedure
getEnvironmentCodeReport: baseProcedure
.input(environmentCodeReportQuerySchema)
.query(async ({ input }) => {
return await getEnvironmentCodeReport(input);
}),

getEnvironmentCodeReportRowCount: t.procedure
getEnvironmentCodeReportRowCount: baseProcedure
.input(environmentCodeReportFilterSchema)
.query(async ({ input }) => {
return await getEnvironmentCodeReportRowCount(input);
}),
getEnvironmentCodeReportSummary: t.procedure
getEnvironmentCodeReportSummary: baseProcedure
.input(environmentCodeReportFilterSchema)
.query(async ({ input }) => {
return await getEnvironmentCodeReportSummary(input);
}),

startEnvironmentCodeReportJob: t.procedure
startEnvironmentCodeReportJob: baseProcedure
.input(environmentCodeReportFilterSchema)
.query(async ({ input }) => {
return await startEnvironmentCodeReportJob(input);
}),

getBlanketContractReport: t.procedure
getBlanketContractReport: baseProcedure
.input(blanketContractReportQuerySchema)
.query(async ({ input }) => {
return await getBlanketContractReport(input);
}),

getBlanketContractReportRowCount: t.procedure
getBlanketContractReportRowCount: baseProcedure
.input(blanketContractReportFilterSchema)
.query(async ({ input }) => {
return await getBlanketContractReportRowCount(input);
}),

getBlanketContractReportSummary: t.procedure
getBlanketContractReportSummary: baseProcedure
.input(blanketContractReportFilterSchema)
.query(async ({ input }) => {
return await getBlanketContractReportSummary(input);
}),

startBlanketContractReportJob: t.procedure
startBlanketContractReportJob: baseProcedure
.input(blanketContractReportFilterSchema)
.query(async ({ input }) => {
return await startBlanketContractReportJob(input);
}),

getPlants: t.procedure.query(async () => {
getPlants: baseProcedure.query(async () => {
const { rows } = await getPool().query(sql.type(z.object({ plant: z.string() }))`
SELECT DISTINCT plant FROM app.sap_wbs
WHERE plant IS NOT NULL
Expand All @@ -88,7 +101,7 @@ export const createSapReportRouter = (t: TRPC) =>
return [EXPLICIT_EMPTY, ...plants];
}),

getBlanketOrderIds: t.procedure.input(z.object({})).query(async () => {
getBlanketOrderIds: baseProcedure.input(z.object({})).query(async () => {
const { rows } = await getPool().query(sql.type(z.object({ blanketOrderId: z.string() }))`
SELECT DISTINCT blanket_order_id AS "blanketOrderId"
FROM app.sap_wbs
Expand All @@ -102,7 +115,7 @@ export const createSapReportRouter = (t: TRPC) =>
return rows.map((row) => row.blanketOrderId);
}),

getYears: t.procedure.query(async () => {
getYears: baseProcedure.query(async () => {
const { rows } = await getPool().query(
sql.type(z.object({ year: z.number() }))`
SELECT DISTINCT fiscal_year "year" FROM app.sap_actuals_item
Expand All @@ -113,7 +126,7 @@ export const createSapReportRouter = (t: TRPC) =>
return rows.map((row) => row.year);
}),

getConsultCompanies: t.procedure.query(async () => {
getConsultCompanies: baseProcedure.query(async () => {
const { rows } = await getPool().query(sql.type(z.object({ name: z.string() }))`
SELECT DISTINCT consult_company AS "name" FROM app.sap_wbs
WHERE consult_company IS NOT NULL
Expand All @@ -122,3 +135,4 @@ export const createSapReportRouter = (t: TRPC) =>
return rows.map((row) => row.name);
}),
});
};
2 changes: 2 additions & 0 deletions frontend/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# No secrets etc. here. Vite build time definitions e.g. feature flags
VITE_FEATURE_SAP_REPORTS=false
1 change: 0 additions & 1 deletion frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
node_modules
.env
dist
build
.history
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ const router = createBrowserRouter(
path="asemakaavahanke/:projectId/kohde/:projectObjectId/:tabView"
element={<ProjectObject projectType="asemakaavahanke" />}
/>
<Route path="sap-raportit/:tabView" element={<SapReports />} />
{import.meta.env.VITE_FEATURE_SAP_REPORTS === 'true' && (
<Route path="sap-raportit/:tabView" element={<SapReports />} />
)}
<Route path="investointiohjelma" element={<WorkTable />} />
<Route path="hallinta/:tabView" element={<Management />} />
<Route path="saptest/:sapProjectId" element={<SapDebugView />} />
Expand Down
10 changes: 6 additions & 4 deletions frontend/src/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@ function Navbar() {
{tr('pages.projectsTitle')}
</Button>

<Button component={Link} to="/sap-raportit/ymparistokoodit" sx={{ color: 'white' }}>
<BackupTable sx={{ mr: 1 }} />
{tr('pages.sapReportsTitle')}
</Button>
{import.meta.env.VITE_FEATURE_SAP_REPORTS === 'true' && (
<Button component={Link} to="/sap-raportit/ymparistokoodit" sx={{ color: 'white' }}>
<BackupTable sx={{ mr: 1 }} />
{tr('pages.sapReportsTitle')}
</Button>
)}

<Button component={Link} to="/investointiohjelma" sx={{ color: 'white' }}>
<Reorder sx={{ mr: 1 }} />
Expand Down
1 change: 1 addition & 0 deletions frontend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"compilerOptions": {
"lib": ["DOM", "ES2019"],
"target": "ES2020",
"module": "es2020",
"strict": true,
"allowJs": false,
"jsx": "react-jsx",
Expand Down
4 changes: 4 additions & 0 deletions frontend/types/vite.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ declare module '*.svg' {
* App version injected as a build-time global variable in Vite.
*/
declare const APP_VERSION: string;

interface ImportMeta {
env: Record<string, string | boolean | undefined>;
}