Skip to content

Commit

Permalink
Merge pull request #95 from rajnishdargan/release-1.0.0
Browse files Browse the repository at this point in the history
Issue #PS-2512 feat: Removing Channel and Framework hardcoding from workspace
  • Loading branch information
itsvick authored Nov 18, 2024
2 parents 6ae2007 + 8199e6c commit 5355a1f
Show file tree
Hide file tree
Showing 16 changed files with 213 additions and 218 deletions.
6 changes: 4 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
BASE_URL="" # Middleware Path - eg : "https://middleware.prathamdigital.org"
AUTH_API_TOKEN="" # User Auth Access Token
TENANT_ID="" # Tenant Id of User
CLOUD_STORAGE_URL="" #Use environment variable for S3 Cloud Storage URL
NEXT_PUBLIC_TENANT_ID="" # Tenant Id of User
NEXT_PUBLIC_CLOUD_STORAGE_URL="" # Use environment variable for S3 Cloud Storage URL - should have / at the end.
NEXT_PUBLIC_CHANNEL_ID="" # Channel Id of knowlg-inQuiry setup
NEXT_PUBLIC_FRAMEWORK_ID="" # Framework Id of knowlg-inQuiry setup
2 changes: 1 addition & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const nextConfig = {
},
{
source: "/assets/public/:path*", // Match any URL starting with /assets/public/
destination: `${process.env.CLOUD_STORAGE_URL}/:path*`, // Forward to S3, stripping "/assets/public"
destination: `${process.env.NEXT_PUBLIC_CLOUD_STORAGE_URL}/:path*`, // Forward to S3, stripping "/assets/public"
},
{
source: "/workspace/content/assets/:path*", // Match any URL starting with /workspace/content/assets/
Expand Down
74 changes: 27 additions & 47 deletions src/components/CollectionEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import React, { useEffect, useRef, useState } from "react";
import { useRouter } from "next/router";
import { v4 as uuidv4 } from "uuid";

import { TENANT_ID, CHANNEL_ID, FRAMEWORK_ID, CLOUD_STORAGE_URL } from "@/utils/app.config";
import { getLocalStoredUserName, getLocalStoredUserId } from "@/services/LocalStorageService";
const CollectionEditor: React.FC = () => {
const router = useRouter();
const { identifier, mode } = router.query;

const [fullName, setFullName] = useState("Anonymous");
const [userId, setUserId] = useState("ef99949b-7f3a-4a5f-806a-e67e683e38f3");
const [deviceId, setDeviceId] = useState("7e85b4967aebd6704ba1f604f20056b6");
const [fullName, setFullName] = useState("Anonymous User");
const [userId, setUserId] = useState(TENANT_ID);
const [deviceId, setDeviceId] = useState("");

const [firstName, lastName] = fullName.split(" ");

useEffect(() => {
const storedFullName = localStorage.getItem("name") || "Anonymous";
const storedUserId =
localStorage.getItem("userId") || "ef99949b-7f3a-4a5f-806a-e67e683e38f3";
setFullName(storedFullName);
const storedFullName = getLocalStoredUserName();
const storedUserId = getLocalStoredUserId() || TENANT_ID;
setFullName(storedFullName ?? "Anonymous User");
setUserId(storedUserId);

const generatedDeviceId = uuidv4();
Expand All @@ -29,59 +29,38 @@ const CollectionEditor: React.FC = () => {
id: userId,
fullName: fullName,
firstName: firstName || "Anonymous",
lastName: lastName || "Anonymous",
orgIds: ["01309282781705830427"],
lastName: lastName || "User",
orgIds: [CHANNEL_ID],
},
identifier: identifier,
channel: "test-k12-channel",
framework: "test_k12_framework",
authToken: " ",
sid: "iYO2K6dOSdA0rwq7NeT1TDzS-dbqduvV",
channel: CHANNEL_ID,
framework: FRAMEWORK_ID,
sid: uuidv4(),
did: deviceId,
uid: "bf020396-0d7b-436f-ae9f-869c6780fc45",
additionalCategories: [
{
value: "Textbook",
label: "Textbook",
},
{
value: "Lesson Plan",
label: "Lesson Plan",
},
],
uid: getLocalStoredUserId() || TENANT_ID,
additionalCategories: [],
pdata: {
id: "dev.dock.portal",
ver: "2.8.0",
pid: "creation-portal",
id: "pratham.admin.portal",
ver: "1.0.0",
pid: "pratham-portal",
},
contextRollup: {
l1: "01307938306521497658",
l1: CHANNEL_ID,
},
tags: ["01307938306521497658"],
tags: [CHANNEL_ID],
cdata: [
{
id: "01307938306521497658",
type: "sourcing_organization",
},
{
type: "project",
id: "ec5cc850-3f71-11eb-aae1-fb99d9fb6737",
},
{
type: "linked_collection",
id: "do_113140468925825024117",
},
id: CHANNEL_ID,
type: "pratham-portal",
}
],
timeDiff: 5,
objectRollup: {
l1: "do_113140468925825024117",
l2: "do_113140468926914560125",
},
objectRollup: {},
host: "",
defaultLicense: "CC BY 4.0",
endpoint: "/data/v3/telemetry",
env: "collection_editor",
cloudStorageUrls: ["https://knowlg-public.s3-ap-south-1.amazonaws.com/"],
cloudStorageUrls: [CLOUD_STORAGE_URL],
},
config: {
mode: mode || "edit", // edit / review / read / sourcingReview
Expand Down Expand Up @@ -254,7 +233,8 @@ const CollectionEditor: React.FC = () => {
"editorEmitter",
(event: any) => {
console.log("Editor event:", event);
if (event.detail?.action === "backContent") {
if (event.detail?.action === "backContent" || event.detail?.action === "submitContent" ||
event.detail?.action === "publishContent" || event.detail?.action === "rejectContent") {
window.history.back();
window.addEventListener(
"popstate",
Expand Down
19 changes: 15 additions & 4 deletions src/components/GenericEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import _ from 'lodash';
import 'izimodal/css/iziModal.css';
import 'izimodal/js/iziModal.js';
import editorConfig from './editor.config.json';
import { getLocalStoredUserData } from "@/services/LocalStorageService";
import { getLocalStoredUserId, getLocalStoredUserName } from "@/services/LocalStorageService";
import { CHANNEL_ID, FRAMEWORK_ID, TENANT_ID } from "@/utils/app.config";

const GenericEditor: React.FC = () => {
const router = useRouter();
Expand Down Expand Up @@ -96,9 +97,19 @@ const GenericEditor: React.FC = () => {
if (identifier) {
window['context'].contentId = identifier;
}
window['context'].user.id = getLocalStoredUserData();
window['context'].uid = getLocalStoredUserData();

window['context'].user = {
id: getLocalStoredUserId() || TENANT_ID,
name: getLocalStoredUserName() || "Anonymous User",
orgIds: [CHANNEL_ID],
organisations: {
[CHANNEL_ID] : CHANNEL_ID + " Channel"
}
}
window['context'].uid = getLocalStoredUserId() || TENANT_ID;
window['context'].contextRollUp.l1 = CHANNEL_ID;
window['context'].tags = [CHANNEL_ID];
window['context'].channel = CHANNEL_ID;
window['context'].framework = FRAMEWORK_ID;
if (isLargeFileUpload || (_.get(data, 'contentDisposition') === 'online-only')) {
window.context['uploadInfo'] = {
isLargeFileUpload: true
Expand Down
63 changes: 25 additions & 38 deletions src/components/QuestionSetEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import React, { useEffect, useRef, useState } from "react";
import { useRouter } from "next/router";
import { v4 as uuidv4 } from "uuid";

import { TENANT_ID, CHANNEL_ID, FRAMEWORK_ID, CLOUD_STORAGE_URL } from "@/utils/app.config";
import { getLocalStoredUserId, getLocalStoredUserName } from "@/services/LocalStorageService";
const QuestionSetEditor: React.FC = () => {
const router = useRouter();
const { identifier, mode } = router.query;

const [fullName, setFullName] = useState("Anonymous");
const [userId, setUserId] = useState("ef99949b-7f3a-4a5f-806a-e67e683e38f3");
const [fullName, setFullName] = useState("Anonymous User");
const [userId, setUserId] = useState(TENANT_ID);
const [deviceId, setDeviceId] = useState("7e85b4967aebd6704ba1f604f20056b6");

const [firstName, lastName] = fullName.split(" ");

useEffect(() => {
const storedFullName = localStorage.getItem("name") || "Anonymous";
const storedUserId =
localStorage.getItem("userId") || "ef99949b-7f3a-4a5f-806a-e67e683e38f3";
setFullName(storedFullName);
const storedFullName = getLocalStoredUserName();
const storedUserId = getLocalStoredUserId() || TENANT_ID;
setFullName(storedFullName ?? "Anonymous User");
setUserId(storedUserId);

const generatedDeviceId = uuidv4();
Expand All @@ -25,55 +25,41 @@ const QuestionSetEditor: React.FC = () => {

const questionSetEditorConfig = {
context: {
programId: "",
contributionOrgId: "",
user: {
id: userId,
fullName: fullName,
firstName: firstName || "Anonymous",
lastName: lastName || "Anonymous",
orgIds: ["test-k12-channel"],
orgIds: [CHANNEL_ID],
},
identifier: identifier,
authToken: " ",
sid: "iYO2K6dOSdA0rwq7NeT1TDzS-dbqduvV",
sid: uuidv4(),
did: deviceId,
uid: "bf020396-0d7b-436f-ae9f-869c6780fc45",
channel: "test-k12-channel",
uid: userId,
channel: CHANNEL_ID,
pdata: {
id: "dev.dock.portal",
ver: "2.8.0",
pid: "creation-portal",
id: "pratham.admin.portal",
ver: "1.0.0",
pid: "pratham-portal",
},
contextRollup: {
l1: "01307938306521497658",
l1: CHANNEL_ID,
},
tags: ["01307938306521497658"],
tags: [CHANNEL_ID],
cdata: [
{
id: "01307938306521497658",
type: "sourcing_organization",
},
{
type: "project",
id: "ec5cc850-3f71-11eb-aae1-fb99d9fb6737",
},
{
type: "linked_collection",
id: "do_113140468925825024117",
},
id: CHANNEL_ID,
type: "pratham-portal",
}
],
timeDiff: 5,
objectRollup: {
l1: "do_113140468925825024117",
l2: "do_113140468926914560125",
},
objectRollup: {},
host: "",
defaultLicense: "CC BY 4.0",
endpoint: "/data/v3/telemetry",
env: "questionset_editor",
framework: "test_k12_framework",
cloudStorageUrls: ["https://knowlg-public.s3-ap-south-1.amazonaws.com/"],
framework: FRAMEWORK_ID,
cloudStorageUrls: [CLOUD_STORAGE_URL],
labels: {
save_collection_btn_label: "Save as Draft",
},
Expand All @@ -82,7 +68,7 @@ const QuestionSetEditor: React.FC = () => {
cloudStorage: {
provider: "aws",
presigned_headers: {},
},
}
},
config: {
mode: mode || "edit",
Expand Down Expand Up @@ -195,7 +181,8 @@ const QuestionSetEditor: React.FC = () => {
"editorEmitter",
(event: any) => {
console.log("Editor event:", event);
if (event.detail?.action === "backContent") {
if (event.detail?.action === "backContent" || event.detail?.action === "submitContent" ||
event.detail?.action === "publishContent" || event.detail?.action === "rejectContent") {
window.history.back();
window.addEventListener(
"popstate",
Expand Down
14 changes: 7 additions & 7 deletions src/components/editor.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@
"WINDOW_CONTEXT": {
"user": {
"id": "",
"name": "Rahul Tekdi",
"name": "",
"orgIds": [
"test-k12-channel"
""
],
"organisations": {
"test-k12-channel": "Test Channel"
"channel-id": "channel Name"
}
},
"did": "",
Expand All @@ -95,14 +95,14 @@
"pid": "admin-portal.genericEditor"
},
"contextRollUp": {
"l1": "test-k12-channel"
"l1": ""
},
"tags": [
"test-k12-channel"
""
],
"channel": "test-k12-channel",
"channel": "",
"env": "generic-editor",
"framework": "test_k12_framework",
"framework": "",
"ownershipType": [
"createdBy",
"createdFor"
Expand Down
31 changes: 15 additions & 16 deletions src/components/players/PlayerConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ export const playerConfig = {
mode: "play",
partner: [],
pdata: {
id: "dev.sunbird.portal",
ver: "5.2.0",
pid: "sunbird-portal",
id: "pratham.admin.portal",
ver: "1.0.0",
pid: "admin-portal",
},
contentId: "do_21374910251798528014586",
sid: "6d1898db-d783-4f83-8b92-4a36636e0d2f",
uid: "fb6b2e58-0f14-4d4f-90e4-bae092e7a235",
contentId: "do_12345",
sid: "",
uid: "",
timeDiff: -0.089,
channel: "01269878797503692810",
tags: ["01269878797503692810"],
did: "3ca74a4c5fbce6b7b7f5cd12cebb1682",
contextRollup: { l1: "01269878797503692810" },
channel: "",
tags: [""],
did: "",
contextRollup: {},
objectRollup: {},
userData: { firstName: "Guest", lastName: "" },
userData: { firstName: "Guest", lastName: "User"},

//telemetry
host: "https://telemetry.prathamdigital.org",
Expand Down Expand Up @@ -115,13 +115,12 @@ export const V1PlayerConfig = {
sid: "",
uid: "",
timeDiff: -1.129,
contextRollup: {
},
channel: "test-k12-channel",
contextRollup: {},
channel: "",
did: "",
dims: [],
tags: ["test-k12-channel"],
app: ["test-k12-channel"],
tags: [""],
app: [""],
cdata: [],
userData: {
firstName: "Guest",
Expand Down
2 changes: 1 addition & 1 deletion src/pages/api/fileUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
// Set your base URL
const baseURL = process.env.BASE_URL as string;
const authApiToken = cookies?.authToken || process.env.AUTH_API_TOKEN;
const tenantId = process.env.TENANT_ID as string;
const tenantId = process.env.NEXT_PUBLIC_TENANT_ID as string;

console.log("Using token for file upload:", authApiToken);

Expand Down
Loading

0 comments on commit 5355a1f

Please sign in to comment.