mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-23 10:51:30 +00:00
Compare commits
2 Commits
tsStrict/f
...
users/srna
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f637e685be | ||
|
|
c45c5868fb |
16
src/Localization/en/Demo.json
Normal file
16
src/Localization/en/Demo.json
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"PreviousCommentsLabel": "Previous Comments",
|
||||||
|
"RatingLabel": "Rating",
|
||||||
|
"ShowCommentsLabel": "Have more Comments?",
|
||||||
|
"ShowCommentsTrueLabel": "Yes",
|
||||||
|
"ShowCommentsFalseLabel": "No",
|
||||||
|
"CommentsLabel": "Comments",
|
||||||
|
"CommentsPlaceholder": "Leave your comments here",
|
||||||
|
"IntializeMesssage": "Feedback is being submitted",
|
||||||
|
"IntializeTitle": "Feedback Submission",
|
||||||
|
"SuccessMesssage": "Feedback submitted successfully",
|
||||||
|
"SuccessTitle": "Feedback Submission",
|
||||||
|
"FailureMesssage": "Feedback submission failed",
|
||||||
|
"FailureTitle": "Feedback Submission",
|
||||||
|
"UpdateInProgressMessage": "Feedback submission in progress"
|
||||||
|
}
|
||||||
31
src/SelfServe/Demo/Demo.rp.ts
Normal file
31
src/SelfServe/Demo/Demo.rp.ts
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import { SessionStorageUtility } from "../../Shared/StorageUtility";
|
||||||
|
import { RefreshResult } from "../SelfServeTypes";
|
||||||
|
import { Feedback } from "./Demo.types";
|
||||||
|
|
||||||
|
export const update = async (feedback: Feedback): Promise<void> => {
|
||||||
|
SessionStorageUtility.setEntry("rating", feedback.rating?.toString());
|
||||||
|
SessionStorageUtility.setEntry("comments", feedback.comments);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const initialize = async (): Promise<Feedback> => {
|
||||||
|
let rating = parseInt(SessionStorageUtility.getEntry("rating"));
|
||||||
|
rating = isNaN(rating) ? undefined : rating;
|
||||||
|
const comments = SessionStorageUtility.getEntry("comments");
|
||||||
|
return {
|
||||||
|
rating,
|
||||||
|
comments,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const refresh = async (): Promise<RefreshResult> => {
|
||||||
|
const refreshCountString = SessionStorageUtility.getEntry("refreshCount");
|
||||||
|
const refreshCount = refreshCountString ? parseInt(refreshCountString) : 0;
|
||||||
|
|
||||||
|
const progressToBeSent = refreshCount % 2 === 0 ? false : true;
|
||||||
|
SessionStorageUtility.setEntry("refreshCount", (refreshCount + 1).toString());
|
||||||
|
|
||||||
|
return {
|
||||||
|
isUpdateInProgress: progressToBeSent,
|
||||||
|
updateInProgressMessageTKey: "UpdateInProgressMessage",
|
||||||
|
};
|
||||||
|
};
|
||||||
105
src/SelfServe/Demo/Demo.tsx
Normal file
105
src/SelfServe/Demo/Demo.tsx
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
import { IsDisplayable, OnChange, RefreshOptions, Values } from "../Decorators";
|
||||||
|
import {
|
||||||
|
Description,
|
||||||
|
DescriptionType,
|
||||||
|
InputType,
|
||||||
|
NumberUiType,
|
||||||
|
OnSaveResult,
|
||||||
|
RefreshResult,
|
||||||
|
SelfServeBaseClass,
|
||||||
|
SmartUiInput,
|
||||||
|
} from "../SelfServeTypes";
|
||||||
|
import { initialize, refresh, update } from "./Demo.rp";
|
||||||
|
|
||||||
|
const onShowCommentsChanged = (
|
||||||
|
newValue: InputType,
|
||||||
|
currentValues: Map<string, SmartUiInput>
|
||||||
|
): Map<string, SmartUiInput> => {
|
||||||
|
const comments = currentValues.get("comments");
|
||||||
|
const showComments = currentValues.get("showComments");
|
||||||
|
showComments.value = newValue;
|
||||||
|
|
||||||
|
// show the comments element only when toggle is true, hide comments when toggle is false
|
||||||
|
comments.hidden = !newValue;
|
||||||
|
|
||||||
|
currentValues.set("comments", comments);
|
||||||
|
currentValues.set("showComments", showComments);
|
||||||
|
return currentValues;
|
||||||
|
};
|
||||||
|
|
||||||
|
@IsDisplayable()
|
||||||
|
@RefreshOptions({ retryIntervalInMs: 1000 })
|
||||||
|
export default class Demo extends SelfServeBaseClass {
|
||||||
|
public initialize = async (): Promise<Map<string, SmartUiInput>> => {
|
||||||
|
const initialFeedback = await initialize();
|
||||||
|
const resultMap = new Map<string, SmartUiInput>();
|
||||||
|
const previousComments = initialFeedback.comments
|
||||||
|
? { value: { textTKey: initialFeedback.comments, type: DescriptionType.Text } as Description }
|
||||||
|
: undefined;
|
||||||
|
resultMap.set("previousComments", previousComments);
|
||||||
|
resultMap.set("rating", { value: initialFeedback.rating });
|
||||||
|
resultMap.set("showComments", { value: false });
|
||||||
|
resultMap.set("comments", { value: "", hidden: true });
|
||||||
|
return resultMap;
|
||||||
|
};
|
||||||
|
|
||||||
|
public onSave = async (currentValues: Map<string, SmartUiInput>): Promise<OnSaveResult> => {
|
||||||
|
const rating = currentValues.get("rating")?.value as number;
|
||||||
|
const currentComments = currentValues.get("comments")?.value as string;
|
||||||
|
const comments = currentComments
|
||||||
|
? currentComments
|
||||||
|
: (currentValues.get("previousComments")?.value as Description).textTKey;
|
||||||
|
|
||||||
|
await update({ rating, comments });
|
||||||
|
return {
|
||||||
|
operationStatusUrl: undefined,
|
||||||
|
portalNotification: {
|
||||||
|
initialize: {
|
||||||
|
messageTKey: "IntializeMesssage",
|
||||||
|
titleTKey: "IntializeTitle",
|
||||||
|
},
|
||||||
|
success: {
|
||||||
|
messageTKey: "SuccessMesssage",
|
||||||
|
titleTKey: "SuccessTitle",
|
||||||
|
},
|
||||||
|
failure: {
|
||||||
|
messageTKey: "FailureMesssage",
|
||||||
|
titleTKey: "FailureTitle",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
public onRefresh = async (): Promise<RefreshResult> => {
|
||||||
|
return refresh();
|
||||||
|
};
|
||||||
|
|
||||||
|
@Values({
|
||||||
|
labelTKey: "PreviousCommentsLabel",
|
||||||
|
isDynamicDescription: true,
|
||||||
|
})
|
||||||
|
previousComments: string;
|
||||||
|
|
||||||
|
@Values({
|
||||||
|
labelTKey: "RatingLabel",
|
||||||
|
min: 0,
|
||||||
|
max: 5,
|
||||||
|
step: 1,
|
||||||
|
uiType: NumberUiType.Slider,
|
||||||
|
})
|
||||||
|
rating: number;
|
||||||
|
|
||||||
|
@OnChange(onShowCommentsChanged)
|
||||||
|
@Values({
|
||||||
|
labelTKey: "ShowCommentsLabel",
|
||||||
|
trueLabelTKey: "ShowCommentsTrueLabel",
|
||||||
|
falseLabelTKey: "ShowCommentsFalseLabel",
|
||||||
|
})
|
||||||
|
showComments: boolean;
|
||||||
|
|
||||||
|
@Values({
|
||||||
|
labelTKey: "CommentsLabel",
|
||||||
|
placeholderTKey: "CommentsPlaceholder",
|
||||||
|
})
|
||||||
|
comments: string;
|
||||||
|
}
|
||||||
4
src/SelfServe/Demo/Demo.types.ts
Normal file
4
src/SelfServe/Demo/Demo.types.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
export interface Feedback {
|
||||||
|
rating: number;
|
||||||
|
comments: string;
|
||||||
|
}
|
||||||
@@ -50,6 +50,12 @@ const getDescriptor = async (selfServeType: SelfServeType): Promise<SelfServeDes
|
|||||||
await loadTranslations(sqlX.constructor.name);
|
await loadTranslations(sqlX.constructor.name);
|
||||||
return sqlX.toSelfServeDescriptor();
|
return sqlX.toSelfServeDescriptor();
|
||||||
}
|
}
|
||||||
|
case SelfServeType.demo: {
|
||||||
|
const Demo = await import(/* webpackChunkName: "Demo" */ "./Demo/Demo");
|
||||||
|
const demo = new Demo.default();
|
||||||
|
await loadTranslations(demo.constructor.name);
|
||||||
|
return demo.toSelfServeDescriptor();
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ export enum SelfServeType {
|
|||||||
// Add your self serve types here
|
// Add your self serve types here
|
||||||
example = "example",
|
example = "example",
|
||||||
sqlx = "sqlx",
|
sqlx = "sqlx",
|
||||||
|
demo = "demo",
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user