From caeefab21b7bbd6e7ac4ec4b19a81194ae7ece3c Mon Sep 17 00:00:00 2001 From: lucia <51058748+lucia-gomez@users.noreply.github.com> Date: Wed, 27 Mar 2024 18:16:18 -0400 Subject: [PATCH] filter bookings based on deploy branch --- media_commons_booking_app/package.json | 10 +++++----- .../client/routes/booking/hooks/useSubmitBooking.tsx | 1 + .../src/client/routes/components/Provider.tsx | 9 ++++++++- media_commons_booking_app/src/server/db.ts | 1 - media_commons_booking_app/src/types.ts | 3 +++ media_commons_booking_app/webpack.config.js | 1 + 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/media_commons_booking_app/package.json b/media_commons_booking_app/package.json index 83585787..2677f8c6 100644 --- a/media_commons_booking_app/package.json +++ b/media_commons_booking_app/package.json @@ -13,15 +13,15 @@ "setup": "rimraf .clasp.json && mkdirp dist && clasp create --type sheets --title \"My React Project\" --rootDir ./dist && mv ./dist/.clasp.json ./.clasp.json && rimraf dist", "open": "clasp open --addon", "setup:https": "mkdirp certs && mkcert -key-file ./certs/key.pem -cert-file ./certs/cert.pem localhost 127.0.0.1", - "build:local": "cross-env NODE_ENV=development CALENDAR_ENV=development webpack", - "build:dev": "cross-env NODE_ENV=production CALENDAR_ENV=development webpack --mode=production", - "build:staging": "cross-env NODE_ENV=production CALENDAR_ENV=development webpack --mode=production", - "build": "cross-env NODE_ENV=production CALENDAR_ENV=production webpack --mode=production", + "build:local": "cross-env NODE_ENV=development CALENDAR_ENV=development BRANCH_NAME=development webpack", + "build:dev": "cross-env NODE_ENV=production CALENDAR_ENV=development BRANCH_NAME=development webpack --mode=production", + "build:staging": "cross-env NODE_ENV=production CALENDAR_ENV=development BRANCH_NAME=staging webpack --mode=production", + "build": "cross-env NODE_ENV=production CALENDAR_ENV=production BRANCH_NAME=production webpack --mode=production", "deploy:local": "rimraf dist && npm run build:local && npx clasp push", "deploy:dev": "rimraf dist && npm run build:dev && npx clasp push", "deploy:staging": "rimraf dist && npm run build:staging && npx clasp push", "deploy": "rimraf dist && npm run build && npx clasp push", - "serve": "cross-env NODE_ENV=development CALENDAR_ENV=development webpack serve", + "serve": "cross-env NODE_ENV=development CALENDAR_ENV=development BRANCH_NAME=development webpack serve", "start": "npm run deploy:local && npm run serve" }, "keywords": [ diff --git a/media_commons_booking_app/src/client/routes/booking/hooks/useSubmitBooking.tsx b/media_commons_booking_app/src/client/routes/booking/hooks/useSubmitBooking.tsx index de57a6e1..ced8d97c 100644 --- a/media_commons_booking_app/src/client/routes/booking/hooks/useSubmitBooking.tsx +++ b/media_commons_booking_app/src/client/routes/booking/hooks/useSubmitBooking.tsx @@ -102,6 +102,7 @@ export default function useSubmitBooking(): [(any) => Promise, boolean] { bookingCalendarInfo.startStr, bookingCalendarInfo.endStr, ...contents, + process.env.BRANCH_NAME, ]); await serverFunctions.appendRowActive(TableNames.BOOKING_STATUS, [ diff --git a/media_commons_booking_app/src/client/routes/components/Provider.tsx b/media_commons_booking_app/src/client/routes/components/Provider.tsx index 5e6b8fd6..0a31e240 100644 --- a/media_commons_booking_app/src/client/routes/components/Provider.tsx +++ b/media_commons_booking_app/src/client/routes/components/Provider.tsx @@ -3,6 +3,7 @@ import { Ban, Booking, BookingStatus, + DevBranch, LiaisonType, PaUser, PagePermission, @@ -104,9 +105,14 @@ export const DatabaseProvider = ({ children }) => { }; const fetchBookings = async () => { + console.log('CURRENT BRANCH:', process.env.BRANCH_NAME); const bookingRows = await serverFunctions .getActiveBookingsFutureDates() - .then((rows) => rows.map((row) => mappingBookingRows(row))); + .then((rows) => + rows + .map((row) => mappingBookingRows(row)) + .filter((booking) => booking.devBranch === process.env.BRANCH_NAME) + ); setBookings(bookingRows); }; @@ -253,6 +259,7 @@ const mappingBookingRows = (values: string[]): Booking => { chartFieldForCatering: values[27], chartFieldForSecurity: values[28], chartFieldForRoomSetup: values[29], + devBranch: values[30] as DevBranch, }; }; diff --git a/media_commons_booking_app/src/server/db.ts b/media_commons_booking_app/src/server/db.ts index b7c6649a..cfa93cd1 100644 --- a/media_commons_booking_app/src/server/db.ts +++ b/media_commons_booking_app/src/server/db.ts @@ -32,7 +32,6 @@ export const getActiveBookingsFutureDates = () => { today.setHours(0, 0, 0, 0); // set hours 00:00:00.000 var filteredData = values.filter(function (row, index) { - if (index === 0) return true; // if header row, return true (include in filtered data) var startDate = new Date(row[3]); // 'start date' column return startDate > today; // 'start date' is after today }); diff --git a/media_commons_booking_app/src/types.ts b/media_commons_booking_app/src/types.ts index af906946..ab31bad3 100644 --- a/media_commons_booking_app/src/types.ts +++ b/media_commons_booking_app/src/types.ts @@ -14,6 +14,7 @@ export type Booking = Inputs & { startDate: string; endDate: string; roomId: string; + devBranch: DevBranch; }; export type BookingStatus = { @@ -53,6 +54,8 @@ export enum Department { RECORDED_MUSIC = 'Recorded Music', } +export type DevBranch = 'development' | 'staging' | 'production' | ''; + export type Inputs = { firstName: string; lastName: string; diff --git a/media_commons_booking_app/webpack.config.js b/media_commons_booking_app/webpack.config.js index 53dbe01e..7426f06d 100755 --- a/media_commons_booking_app/webpack.config.js +++ b/media_commons_booking_app/webpack.config.js @@ -23,6 +23,7 @@ const envVars = parsed || {}; const PORT = envVars.PORT || 3000; envVars.NODE_ENV = process.env.NODE_ENV; envVars.CALENDAR_ENV = process.env.CALENDAR_ENV; +envVars.BRANCH_NAME = process.env.BRANCH_NAME; envVars.PORT = PORT; const isProd = process.env.NODE_ENV === 'production';