PromucFlow_constructor/app/client/src/utils/storage.ts

344 lines
9.4 KiB
TypeScript
Raw Normal View History

import log from "loglevel";
Grouping widgets into container (#5704) * Cut copy paste first cut * removed different parent groups logic * mouseup on the outer canvas removes selections. * bug fix * remove unwanted dead code. * Adding tests * build fix * min height fixes * fixing specs. * fixing specs. * fix merge conflcits * fix border positioning * fix canvas widgets incorrect bouding box * fix bounding box position issue * fix bounding box position issue * fix * border issue fix * update test case * add colors in theme * use layers + use click capture on actions * add icon for grouping * fix overflow issue in contextmenu in containers * fix context menu display issue * update position of context menu * fix container box-shadow issue * fix container box-shadow issue * revert container box shadow * stop opening of property pane on shift clicking a widget * remove console.log * fix multiselect box issue * add container on copy * add analytics middleware * refactor paste widget saga * change flash element to accept array + revert refactor * add logic to create containers from selected widgets * update positions of grouped widgets * fix comments + remove console * update flashElementbyId to flashElementsById * remove analytics middleware + remove unecessary imports * add shorcut for grouping * fix position issue when pasting * allow grouping only when multi widgets are selected * fix ux issues with widget grouping * fix help text for grouping actions * filter out the modal widget when calculting next row * fix delete issue when grouping * persist positin when grouping if there is no collision * fix typo for new position * changes for review comments * changes for review comments * fix position issue when pasting * fix new container position issue * move utils function to utils * fix import issue * fix the composite widget grouping issue * fix table name bug * remove repeated code * move copied groups existence check; * fix copied group check Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: root <root@DESKTOP-9GENCK0.localdomain> Co-authored-by: Pawan Kumar <pawankumar@Pawans-MacBook-Pro.local>
2021-08-25 05:00:31 +00:00
import moment from "moment";
import localforage from "localforage";
const STORAGE_KEYS: { [id: string]: string } = {
AUTH_EXPIRATION: "Auth.expiration",
2020-01-16 11:46:21 +00:00
ROUTE_BEFORE_LOGIN: "RedirectPath",
COPIED_WIDGET: "CopiedWidget",
Grouping widgets into container (#5704) * Cut copy paste first cut * removed different parent groups logic * mouseup on the outer canvas removes selections. * bug fix * remove unwanted dead code. * Adding tests * build fix * min height fixes * fixing specs. * fixing specs. * fix merge conflcits * fix border positioning * fix canvas widgets incorrect bouding box * fix bounding box position issue * fix bounding box position issue * fix * border issue fix * update test case * add colors in theme * use layers + use click capture on actions * add icon for grouping * fix overflow issue in contextmenu in containers * fix context menu display issue * update position of context menu * fix container box-shadow issue * fix container box-shadow issue * revert container box shadow * stop opening of property pane on shift clicking a widget * remove console.log * fix multiselect box issue * add container on copy * add analytics middleware * refactor paste widget saga * change flash element to accept array + revert refactor * add logic to create containers from selected widgets * update positions of grouped widgets * fix comments + remove console * update flashElementbyId to flashElementsById * remove analytics middleware + remove unecessary imports * add shorcut for grouping * fix position issue when pasting * allow grouping only when multi widgets are selected * fix ux issues with widget grouping * fix help text for grouping actions * filter out the modal widget when calculting next row * fix delete issue when grouping * persist positin when grouping if there is no collision * fix typo for new position * changes for review comments * changes for review comments * fix position issue when pasting * fix new container position issue * move utils function to utils * fix import issue * fix the composite widget grouping issue * fix table name bug * remove repeated code * move copied groups existence check; * fix copied group check Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: root <root@DESKTOP-9GENCK0.localdomain> Co-authored-by: Pawan Kumar <pawankumar@Pawans-MacBook-Pro.local>
2021-08-25 05:00:31 +00:00
GROUP_COPIED_WIDGETS: "groupCopiedWidgets",
2022-01-25 13:56:52 +00:00
POST_WELCOME_TOUR: "PostWelcomeTour",
2021-03-08 08:24:12 +00:00
RECENT_ENTITIES: "RecentEntities",
COMMENTS_INTRO_SEEN: "CommentsIntroSeen",
2022-03-03 10:56:53 +00:00
TEMPLATES_NOTIFICATION_SEEN: "TEMPLATES_NOTIFICATION_SEEN",
ONBOARDING_FORM_IN_PROGRESS: "ONBOARDING_FORM_IN_PROGRESS",
ENABLE_FIRST_TIME_USER_ONBOARDING: "ENABLE_FIRST_TIME_USER_ONBOARDING",
FIRST_TIME_USER_ONBOARDING_APPLICATION_ID:
"FIRST_TIME_USER_ONBOARDING_APPLICATION_ID",
FIRST_TIME_USER_ONBOARDING_INTRO_MODAL_VISIBILITY:
"FIRST_TIME_USER_ONBOARDING_INTRO_MODAL_VISIBILITY",
HIDE_CONCURRENT_EDITOR_WARNING_TOAST: "HIDE_CONCURRENT_EDITOR_WARNING_TOAST",
feat: Reflow and Resize while Dragging and Resizing widgets. (#9054) * resize n reflow rough cut * removing warnings * relatively stable changes * minor bug fix * reflow relative collision * working dp cut * fix for reflow of widgets closer next to each other * disabling scroll * Drag with reflow * reflow fix * overlap and retracing fix * On Drop updates. * bug when no displacement but resize update. * temp fix for new widget addition. * reflow bug fixes * new widget addition bug. * stop reflow on leave. * fix corner case overlap * update bottom row when reflowed widgets go beyond bottom boundary. * capture mouse positions on enter * enable container jumps with faster mouse movements. * reflow only for snap changes. * restructured reflow Algorithm * collision check and bug fixes * undo redo fix for new widget drop * resizable fix snapRows fix * directional stability * self collision fix * first round of perf fixes * update bottom row while resizing and resize-reflowing * performance fix and overlapping fix * Remove eslint warning * remove eslint warning * eslint warning * can reflowed Drop Indication Stability * container jumps and force direction on entering canvas * fixing scroll on resize jitters. * reflow when jumping into container. * reflow ux fixes while leaving container * resizing fixes. * fixes for edge move. * restrict container jumps into reflowed containers. * container jump direction reflow * checkbox dimensions fix. * Excess bottom rows not lost post dragging or resizing widgets. * fixing the after drop css glitch. * double first move trigger bug fix. * stop reflow only if reflowing * stabilize container exit directions * using acceleration and speed instead of movement covered to restrict reflow. * fixing modal drops. * remove warnings. * reflow resize styles * moving acceleration and movement logic to a monitoring effect. * adding beta flag for reflow. * fixing jest tests * Adding analytics to beta flag toggle. * Adding placeholder for reflow beta screens. * fixing initial load's screen * few more crashes. * force close onboarding for the session. * fixing bugs in reset canvas. * Beta flag bug fixes. * fixing bugs. * restrict reflow screens during onboarding. * disabling reflow screens in tests. * code review comments. * fixing store based specs. * fixing cypress failures. * fixing specs. * code cleanup * reverting yarn lock changes * removing onboarding screens. * more cleanup and function descriptors * keeping reflow under the hood. Co-authored-by: rahulramesha <rahul@appsmith.com> Co-authored-by: Arpit Mohan <arpit@appsmith.com>
2022-01-13 13:21:57 +00:00
REFLOW_BETA_FLAG: "REFLOW_BETA_FLAG",
REFLOW_ONBOARDED_FLAG: "REFLOW_ONBOARDED_FLAG",
};
const store = localforage.createInstance({
name: "Appsmith",
});
export const resetAuthExpiration = () => {
const expireBy = moment()
.add(1, "h")
.format();
store.setItem(STORAGE_KEYS.AUTH_EXPIRATION, expireBy).catch((error) => {
log.error("Unable to set expiration time");
log.error(error);
});
};
export const hasAuthExpired = async () => {
const expireBy: string | null = await store.getItem(
STORAGE_KEYS.AUTH_EXPIRATION,
);
if (expireBy && moment().isAfter(moment(expireBy))) {
return true;
}
return false;
};
export const saveCopiedWidgets = async (widgetJSON: string) => {
try {
await store.setItem(STORAGE_KEYS.COPIED_WIDGET, widgetJSON);
return true;
} catch (error) {
log.error("An error occurred when storing copied widget: ", error);
return false;
}
};
feat: Reflow and Resize while Dragging and Resizing widgets. (#9054) * resize n reflow rough cut * removing warnings * relatively stable changes * minor bug fix * reflow relative collision * working dp cut * fix for reflow of widgets closer next to each other * disabling scroll * Drag with reflow * reflow fix * overlap and retracing fix * On Drop updates. * bug when no displacement but resize update. * temp fix for new widget addition. * reflow bug fixes * new widget addition bug. * stop reflow on leave. * fix corner case overlap * update bottom row when reflowed widgets go beyond bottom boundary. * capture mouse positions on enter * enable container jumps with faster mouse movements. * reflow only for snap changes. * restructured reflow Algorithm * collision check and bug fixes * undo redo fix for new widget drop * resizable fix snapRows fix * directional stability * self collision fix * first round of perf fixes * update bottom row while resizing and resize-reflowing * performance fix and overlapping fix * Remove eslint warning * remove eslint warning * eslint warning * can reflowed Drop Indication Stability * container jumps and force direction on entering canvas * fixing scroll on resize jitters. * reflow when jumping into container. * reflow ux fixes while leaving container * resizing fixes. * fixes for edge move. * restrict container jumps into reflowed containers. * container jump direction reflow * checkbox dimensions fix. * Excess bottom rows not lost post dragging or resizing widgets. * fixing the after drop css glitch. * double first move trigger bug fix. * stop reflow only if reflowing * stabilize container exit directions * using acceleration and speed instead of movement covered to restrict reflow. * fixing modal drops. * remove warnings. * reflow resize styles * moving acceleration and movement logic to a monitoring effect. * adding beta flag for reflow. * fixing jest tests * Adding analytics to beta flag toggle. * Adding placeholder for reflow beta screens. * fixing initial load's screen * few more crashes. * force close onboarding for the session. * fixing bugs in reset canvas. * Beta flag bug fixes. * fixing bugs. * restrict reflow screens during onboarding. * disabling reflow screens in tests. * code review comments. * fixing store based specs. * fixing cypress failures. * fixing specs. * code cleanup * reverting yarn lock changes * removing onboarding screens. * more cleanup and function descriptors * keeping reflow under the hood. Co-authored-by: rahulramesha <rahul@appsmith.com> Co-authored-by: Arpit Mohan <arpit@appsmith.com>
2022-01-13 13:21:57 +00:00
const getStoredUsersBetaFlags = (email: any) => {
return store.getItem(email);
};
const setStoredUsersBetaFlags = (email: any, userBetaFlagsObj: any) => {
return store.setItem(email, userBetaFlagsObj);
};
export const setReflowBetaFlag = async (email: any, enable: boolean) => {
const userBetaFlagsObj: any = await getStoredUsersBetaFlags(email);
const updatedObj = {
...userBetaFlagsObj,
[STORAGE_KEYS.REFLOW_BETA_FLAG]: enable,
};
setStoredUsersBetaFlags(email, updatedObj);
};
export const getReflowBetaFlag = async (email: any) => {
const userBetaFlagsObj: any = await getStoredUsersBetaFlags(email);
return userBetaFlagsObj && userBetaFlagsObj[STORAGE_KEYS.REFLOW_BETA_FLAG];
};
export const setReflowOnBoardingFlag = async (
email: any,
onBoardingState: boolean,
) => {
const userBetaFlagsObj: any = await getStoredUsersBetaFlags(email);
const updatedObj = {
...userBetaFlagsObj,
[STORAGE_KEYS.REFLOW_ONBOARDED_FLAG]: onBoardingState,
};
setStoredUsersBetaFlags(email, updatedObj);
};
export const getReflowOnBoardingFlag = async (email: any) => {
const userBetaFlagsObj: any = await getStoredUsersBetaFlags(email);
return (
userBetaFlagsObj && userBetaFlagsObj[STORAGE_KEYS.REFLOW_ONBOARDED_FLAG]
);
};
export const getCopiedWidgets = async () => {
try {
const widget: string | null = await store.getItem(
STORAGE_KEYS.COPIED_WIDGET,
);
if (widget && widget.length > 0) {
return JSON.parse(widget);
}
} catch (error) {
log.error("An error occurred when fetching copied widget: ", error);
return;
}
return [];
};
2022-01-25 13:56:52 +00:00
export const setPostWelcomeTourState = async (flag: boolean) => {
2020-12-30 07:31:20 +00:00
try {
2022-01-25 13:56:52 +00:00
await store.setItem(STORAGE_KEYS.POST_WELCOME_TOUR, flag);
2020-12-30 07:31:20 +00:00
return true;
} catch (error) {
2022-01-25 13:56:52 +00:00
log.error("An error occurred when setting post welcome tour state", error);
2020-12-30 07:31:20 +00:00
return false;
}
};
2022-01-25 13:56:52 +00:00
export const getPostWelcomeTourState = async () => {
2020-12-30 07:31:20 +00:00
try {
2022-01-25 13:56:52 +00:00
const onboardingState = await store.getItem(STORAGE_KEYS.POST_WELCOME_TOUR);
2020-12-30 07:31:20 +00:00
return onboardingState;
} catch (error) {
2022-01-25 13:56:52 +00:00
log.error("An error occurred when getting post welcome tour state", error);
}
};
2021-03-08 08:24:12 +00:00
export const setRecentAppEntities = async (entities: any, appId: string) => {
try {
const recentEntities =
((await store.getItem(STORAGE_KEYS.RECENT_ENTITIES)) as Record<
string,
any
>) || {};
recentEntities[appId] = entities;
await store.setItem(STORAGE_KEYS.RECENT_ENTITIES, recentEntities);
} catch (error) {
log.error("An error occurred while saving recent entities");
log.error(error);
2021-03-08 08:24:12 +00:00
}
};
export const fetchRecentAppEntities = async (recentEntitiesKey: string) => {
2021-03-08 08:24:12 +00:00
try {
const recentEntities = (await store.getItem(
STORAGE_KEYS.RECENT_ENTITIES,
)) as Record<string, any>;
return (recentEntities && recentEntities[recentEntitiesKey]) || [];
2021-03-08 08:24:12 +00:00
} catch (error) {
log.error("An error occurred while fetching recent entities");
log.error(error);
2021-03-08 08:24:12 +00:00
}
};
export const deleteRecentAppEntities = async (appId: string) => {
try {
const recentEntities =
((await store.getItem(STORAGE_KEYS.RECENT_ENTITIES)) as Record<
string,
any
>) || {};
if (typeof recentEntities === "object") {
// todo (rishabh s) purge recent entities across branches
2021-03-08 08:24:12 +00:00
delete recentEntities[appId];
}
await store.setItem(STORAGE_KEYS.RECENT_ENTITIES, recentEntities);
} catch (error) {
log.error("An error occurred while saving recent entities");
log.error(error);
2021-03-08 08:24:12 +00:00
}
};
export const setOnboardingFormInProgress = async (flag?: boolean) => {
try {
await store.setItem(STORAGE_KEYS.ONBOARDING_FORM_IN_PROGRESS, flag);
return true;
} catch (error) {
log.error("An error occurred when setting ONBOARDING_FORM_IN_PROGRESS");
log.error(error);
return false;
}
};
export const getOnboardingFormInProgress = async () => {
try {
const onboardingFormInProgress = await store.getItem(
STORAGE_KEYS.ONBOARDING_FORM_IN_PROGRESS,
);
return onboardingFormInProgress;
} catch (error) {
log.error("An error occurred while fetching ONBOARDING_FORM_IN_PROGRESS");
log.error(error);
}
};
export const setEnableFirstTimeUserOnboarding = async (flag: boolean) => {
try {
await store.setItem(STORAGE_KEYS.ENABLE_FIRST_TIME_USER_ONBOARDING, flag);
return true;
} catch (error) {
log.error(
"An error occurred while setting ENABLE_FIRST_TIME_USER_ONBOARDING",
);
log.error(error);
}
};
export const getEnableFirstTimeUserOnboarding = async () => {
try {
const enableFirstTimeUserOnboarding: any = await store.getItem(
STORAGE_KEYS.ENABLE_FIRST_TIME_USER_ONBOARDING,
);
return enableFirstTimeUserOnboarding;
} catch (error) {
log.error(
"An error occurred while fetching ENABLE_FIRST_TIME_USER_ONBOARDING",
);
log.error(error);
}
};
export const setFirstTimeUserOnboardingApplicationId = async (id: string) => {
try {
await store.setItem(
STORAGE_KEYS.FIRST_TIME_USER_ONBOARDING_APPLICATION_ID,
id,
);
return true;
} catch (error) {
log.error(
"An error occurred while setting FIRST_TIME_USER_ONBOARDING_APPLICATION_ID",
);
log.error(error);
}
};
export const getFirstTimeUserOnboardingApplicationId = async () => {
try {
const id = await store.getItem(
STORAGE_KEYS.FIRST_TIME_USER_ONBOARDING_APPLICATION_ID,
);
return id;
} catch (error) {
log.error(
"An error occurred while fetching FIRST_TIME_USER_ONBOARDING_APPLICATION_ID",
);
log.error(error);
}
};
export const setFirstTimeUserOnboardingIntroModalVisibility = async (
flag: boolean,
) => {
try {
await store.setItem(
STORAGE_KEYS.FIRST_TIME_USER_ONBOARDING_INTRO_MODAL_VISIBILITY,
flag,
);
return true;
} catch (error) {
log.error(
"An error occurred while setting FIRST_TIME_USER_ONBOARDING_INTRO_MODAL_VISIBILITY",
);
log.error(error);
}
};
export const getFirstTimeUserOnboardingIntroModalVisibility = async () => {
try {
const flag = await store.getItem(
STORAGE_KEYS.FIRST_TIME_USER_ONBOARDING_INTRO_MODAL_VISIBILITY,
);
return flag;
} catch (error) {
log.error(
"An error occurred while fetching FIRST_TIME_USER_ONBOARDING_INTRO_MODAL_VISIBILITY",
);
log.error(error);
}
};
export const hideConcurrentEditorWarningToast = async () => {
try {
await store.setItem(
STORAGE_KEYS.HIDE_CONCURRENT_EDITOR_WARNING_TOAST,
true,
);
return true;
} catch (error) {
log.error(
"An error occurred while setting HIDE_CONCURRENT_EDITOR_WARNING_TOAST",
);
log.error(error);
}
};
export const getIsConcurrentEditorWarningToastHidden = async () => {
try {
const flag = await store.getItem(
STORAGE_KEYS.HIDE_CONCURRENT_EDITOR_WARNING_TOAST,
);
return flag;
} catch (error) {
log.error(
"An error occurred while fetching HIDE_CONCURRENT_EDITOR_WARNING_TOAST",
);
log.error(error);
}
};
2022-03-03 10:56:53 +00:00
export const getTemplateNotificationSeen = async () => {
try {
const seenTemplateNotifications = await store.getItem(
STORAGE_KEYS.TEMPLATES_NOTIFICATION_SEEN,
);
return seenTemplateNotifications;
} catch (error) {
log.error(
"An error occurred while getting TEMPLATES_NOTIFICATION_SEEN flag: ",
error,
);
return false;
}
};
export const setTemplateNotificationSeen = async (flag: boolean) => {
try {
await store.setItem(STORAGE_KEYS.TEMPLATES_NOTIFICATION_SEEN, flag);
return true;
} catch (error) {
log.error(
"An error occurred while setting TEMPLATES_NOTIFICATION_SEEN flag: ",
error,
);
return false;
}
};