PromucFlow_constructor/app/client/src/utils/AppsmithUtils.tsx

421 lines
11 KiB
TypeScript
Raw Normal View History

feat: property pane docking (#7361) * add tailwindcss * docked property pane * uncomment a line * make entity explorer as drawer on unpin * remove unused imports * add pin state in reducer * add menu icon in header * fix widget sidebar * fix widgets sidebar * style property pane * update property pane css * update icons in property pane * update property pane header styles * update spacing * fix few ui issues * wip: preview mode * wip:preview mode * remove unused import * comments sidebar in app and edit mode * fix order of import * use selected state for property pane * update scrollbar style * add classes to sidebar and property pane * make widgets editor fluid * make widgets editor fluid and refactor logic * resize the widgets editor if explorer is pinned * add shortcut for preview mode * fix link for tabs in edit mode * zoom in/zoom out for 0.75 * fix chart widget + table widget crashing * allow zooming of canvas * fix weird canvas draw issue + update container for handling zoom * add actions for is panning * allow panning with grab cursor * reset panning + zooming when entering preview mode * add grabbing cursor when grabbing * only prevent default when space key is pressed * dont allow zoom in preview mode * remove unused imports * fix dont allow zoom in preview mode * fix ux of panning on space hit * make fluid as the default app layout * chart spec * fix dropdown_on change spec * fix add widget table and bind spec * remove draggable property pane spec * fix container spec * fix form widget spec * fix jest test * fix the function typo * remove clicking of close button for property pane in cypress tests * remove property pane actions test * fix drag and drop test failing * add cypress selector id to back button in property pane * fix toggle js spec * fix merge conflicts from new design system * editor header * fix product updates styles + widget card * remove all unused imports * fix dynamic layout spec * fix entity explorer tab rename test failing * fix table spec * fix bind tabletextpagination spec * fix js object spec * fix entity explorer rename issue * fix cypress test * fix cypress command wrong commit * fix tab spec * fix property pane copy tests * add zoom header * zoom levels * make property pane sidebar resizable * add multi select property pane * fix widget search bug * update property pane width in state on drag end * fix viewer header * fix editor header * update editor header + remove zooming * update small style * dont allow closing of explorer when resizing * fix jest test * fix dropdown widget jest test * preview test case wip * add entity explorer pinning tests + preview mode tests * add tooltip in layout control + add padding bottom in property pane view * incorporate aakash feedbacks * fix preview mode margin issue * remove panning code * fix cypress failing test * uncomment jest test * remove redundant code * fix maincontainer test * incorporate review feedbacks * incorporate aakash feedbacks * review feedbacks * incorporate review feedbacks * incorporate qa feedbacks * fix dynamic layout spec * updated test based on latest change * dsl updated * Updated dsl * Updated dsl * resize deselects widget issue. * fix canvas height issue * fix typo * incorporate qa feedbacks * incorporate qa feedbacks * incorporate qa feedbacks * update color for setting control for widget name * fix onboarding styles conflicts * Updated tests * fix application overflow issue * updated test method Co-authored-by: root <root@DESKTOP-9GENCK0.localdomain> Co-authored-by: Pawan Kumar <pawankumar@Pawans-MacBook-Pro.local> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: Apple <nandan@thinkify.io>
2021-11-23 08:01:46 +00:00
import {
CurrentApplicationData,
Page,
ReduxAction,
} from "constants/ReduxActionConstants";
import { getAppsmithConfigs } from "configs";
import * as Sentry from "@sentry/react";
2019-09-09 09:08:54 +00:00
import AnalyticsUtil from "./AnalyticsUtil";
import FormControlRegistry from "./FormControlRegistry";
2019-11-25 05:07:27 +00:00
import { Property } from "api/ActionAPI";
import _ from "lodash";
import { ActionDataState } from "reducers/entityReducers/actionsReducer";
2020-03-23 12:40:17 +00:00
import * as log from "loglevel";
2020-03-27 12:46:29 +00:00
import { LogLevelDesc } from "loglevel";
import produce from "immer";
Homepage redesign with themes (#482) * Updating homepage body color * WIP: Fixing scrolls and adding anchors * Removing divider from bottom of the page. * Adding hover background color to app card * Changing edit and launch icons. * Fixing app name paddding in card. * Fixing workspaces overflow * Adding right padding to applications view * Adding share icon to share btn * Fixing Application card styles. * Fixing text decoration in button. * Adding new workspace button * Fixing new workspace and new app styles. * Adding icon sizes. * Fixing Org Name and Org settings menu. * Application menu working * Fixing overlay visibility on app card * Fixing settings page content width. * Fixing workspace icon * Changing app card colors. * Removing debugger * Adding app icon. * Fixing the spaces in application card * Adding storybook-static folder to gitignore. * Adding other storybook files. * Adding menu items for app * Removing cypress selector from text. * Menu width issue fixed * Default app icon color added * Removing hardcoded colors * Removing hardcoded colors. * Light Mode on! * Showing correct icon and color in menu * Update color working properly. * Updating appIcon * Editable text working. * Adding validator * Adding edit permissions to menu * Removing box shadow on app card. * Fixing context menu fill color * Fixing Menu hover issues. * Fixing menu open close hover issues. * Fixing settings pages * Changed Workspace to org. * Fix: State management in EditableText Component (#540) * Error state height is fixed as per design * savingState prop condition fixed * Fixing createnew. * Fixing saving state for application card. * Fixed application card editable text error. * Fixing issue caused during merge. * Fixing tests in create org. * Removing commented code. * Removing unwanted vars. * Fixing delete duplicate tests. * Latest color palette. * Fixing form and table widget. * Removing switcher from header * Removing unused files * Fixing app card context dropdown * Show overlay fix * Adding localStorage support to theme. * Making dark mode the default. Co-authored-by: Rohit Kumawat <rohit.kumawat@primathon.in>
2020-09-16 11:50:47 +00:00
import { AppIconCollection, AppIconName } from "components/ads/AppIcon";
import { ERROR_CODES } from "constants/ApiConstants";
import { createMessage, ERROR_500 } from "../constants/messages";
import localStorage from "utils/localStorage";
feat: property pane docking (#7361) * add tailwindcss * docked property pane * uncomment a line * make entity explorer as drawer on unpin * remove unused imports * add pin state in reducer * add menu icon in header * fix widget sidebar * fix widgets sidebar * style property pane * update property pane css * update icons in property pane * update property pane header styles * update spacing * fix few ui issues * wip: preview mode * wip:preview mode * remove unused import * comments sidebar in app and edit mode * fix order of import * use selected state for property pane * update scrollbar style * add classes to sidebar and property pane * make widgets editor fluid * make widgets editor fluid and refactor logic * resize the widgets editor if explorer is pinned * add shortcut for preview mode * fix link for tabs in edit mode * zoom in/zoom out for 0.75 * fix chart widget + table widget crashing * allow zooming of canvas * fix weird canvas draw issue + update container for handling zoom * add actions for is panning * allow panning with grab cursor * reset panning + zooming when entering preview mode * add grabbing cursor when grabbing * only prevent default when space key is pressed * dont allow zoom in preview mode * remove unused imports * fix dont allow zoom in preview mode * fix ux of panning on space hit * make fluid as the default app layout * chart spec * fix dropdown_on change spec * fix add widget table and bind spec * remove draggable property pane spec * fix container spec * fix form widget spec * fix jest test * fix the function typo * remove clicking of close button for property pane in cypress tests * remove property pane actions test * fix drag and drop test failing * add cypress selector id to back button in property pane * fix toggle js spec * fix merge conflicts from new design system * editor header * fix product updates styles + widget card * remove all unused imports * fix dynamic layout spec * fix entity explorer tab rename test failing * fix table spec * fix bind tabletextpagination spec * fix js object spec * fix entity explorer rename issue * fix cypress test * fix cypress command wrong commit * fix tab spec * fix property pane copy tests * add zoom header * zoom levels * make property pane sidebar resizable * add multi select property pane * fix widget search bug * update property pane width in state on drag end * fix viewer header * fix editor header * update editor header + remove zooming * update small style * dont allow closing of explorer when resizing * fix jest test * fix dropdown widget jest test * preview test case wip * add entity explorer pinning tests + preview mode tests * add tooltip in layout control + add padding bottom in property pane view * incorporate aakash feedbacks * fix preview mode margin issue * remove panning code * fix cypress failing test * uncomment jest test * remove redundant code * fix maincontainer test * incorporate review feedbacks * incorporate aakash feedbacks * review feedbacks * incorporate review feedbacks * incorporate qa feedbacks * fix dynamic layout spec * updated test based on latest change * dsl updated * Updated dsl * Updated dsl * resize deselects widget issue. * fix canvas height issue * fix typo * incorporate qa feedbacks * incorporate qa feedbacks * incorporate qa feedbacks * update color for setting control for widget name * fix onboarding styles conflicts * Updated tests * fix application overflow issue * updated test method Co-authored-by: root <root@DESKTOP-9GENCK0.localdomain> Co-authored-by: Pawan Kumar <pawankumar@Pawans-MacBook-Pro.local> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: Apple <nandan@thinkify.io>
2021-11-23 08:01:46 +00:00
import { APP_MODE } from "entities/App";
import { trimQueryString } from "./helpers";
import {
getApplicationEditorPageURL,
getApplicationViewerPageURL,
} from "constants/routes";
2019-08-30 10:33:49 +00:00
export const createReducer = (
initialState: any,
handlers: { [type: string]: (state: any, action: any) => any },
2019-08-30 10:33:49 +00:00
) => {
return function reducer(state = initialState, action: ReduxAction<any>) {
if (handlers.hasOwnProperty(action.type)) {
2019-09-09 09:08:54 +00:00
return handlers[action.type](state, action);
2019-08-30 10:33:49 +00:00
} else {
2019-09-09 09:08:54 +00:00
return state;
2019-08-30 10:33:49 +00:00
}
2019-09-09 09:08:54 +00:00
};
};
2019-08-30 10:33:49 +00:00
export const createImmerReducer = (
initialState: any,
handlers: { [type: string]: any },
) => {
return function reducer(state = initialState, action: ReduxAction<any>) {
if (handlers.hasOwnProperty(action.type)) {
return produce(handlers[action.type])(state, action);
} else {
return state;
}
};
};
2019-08-30 10:33:49 +00:00
export const appInitializer = () => {
FormControlRegistry.registerFormControlBuilders();
const appsmithConfigs = getAppsmithConfigs();
log.setLevel(getEnvLogLevel(appsmithConfigs.logLevel));
};
export const initializeAnalyticsAndTrackers = () => {
const appsmithConfigs = getAppsmithConfigs();
2020-05-28 18:10:26 +00:00
try {
if (appsmithConfigs.sentry.enabled && !window.Sentry) {
window.Sentry = Sentry;
Sentry.init({
...appsmithConfigs.sentry,
beforeBreadcrumb(breadcrumb) {
if (
breadcrumb.category === "console" &&
breadcrumb.level !== "error"
) {
return null;
}
if (breadcrumb.category === "sentry.transaction") {
return null;
}
if (breadcrumb.category === "redux.action") {
if (
breadcrumb.data &&
breadcrumb.data.type === "SET_EVALUATED_TREE"
) {
breadcrumb.data = undefined;
}
}
return breadcrumb;
},
});
}
} catch (e) {
log.error(e);
}
try {
if (appsmithConfigs.smartLook.enabled && !(window as any).smartlook) {
const { id } = appsmithConfigs.smartLook;
AnalyticsUtil.initializeSmartLook(id);
}
if (appsmithConfigs.segment.enabled && !(window as any).analytics) {
if (appsmithConfigs.segment.apiKey) {
// This value is only enabled for Appsmith's cloud hosted version. It is not set in self-hosted environments
AnalyticsUtil.initializeSegment(appsmithConfigs.segment.apiKey);
} else if (appsmithConfigs.segment.ceKey) {
// This value is set in self-hosted environments. But if the analytics are disabled, it's never used.
AnalyticsUtil.initializeSegment(appsmithConfigs.segment.ceKey);
}
2020-11-05 16:51:22 +00:00
}
} catch (e) {
Sentry.captureException(e);
log.error(e);
2019-08-30 10:33:49 +00:00
}
2019-09-09 09:08:54 +00:00
};
export const mapToPropList = (map: Record<string, string>): Property[] => {
return _.map(map, (value, key) => {
return { key: key, value: value };
});
};
export const getNextEntityName = (
prefix: string,
existingNames: string[],
startWithoutIndex?: boolean,
) => {
const regex = new RegExp(`^${prefix}(\\d+)$`);
2020-12-24 04:32:25 +00:00
const usedIndices: number[] = existingNames.map((name) => {
2020-01-24 09:54:40 +00:00
if (name && regex.test(name)) {
const matches = name.match(regex);
const ind =
matches && Array.isArray(matches) ? parseInt(matches[1], 10) : 0;
return Number.isNaN(ind) ? 0 : ind;
}
return 0;
}) as number[];
2020-01-24 09:54:40 +00:00
const lastIndex = Math.max(...usedIndices, ...[0]);
if (startWithoutIndex && lastIndex === 0) {
const exactMatchFound = existingNames.some(
(name) => prefix && name.trim() === prefix.trim(),
);
if (!exactMatchFound) {
return prefix.trim();
}
}
return prefix + (lastIndex + 1);
};
2019-11-07 11:17:53 +00:00
export const getDuplicateName = (prefix: string, existingNames: string[]) => {
const trimmedPrefix = prefix.replace(/ /g, "");
const regex = new RegExp(`^${trimmedPrefix}(\\d+)$`);
2020-12-24 04:32:25 +00:00
const usedIndices: number[] = existingNames.map((name) => {
if (name && regex.test(name)) {
const matches = name.match(regex);
const ind =
matches && Array.isArray(matches) ? parseInt(matches[1], 10) : 0;
return Number.isNaN(ind) ? 0 : ind;
}
return 0;
}) as number[];
const lastIndex = Math.max(...usedIndices, ...[0]);
return trimmedPrefix + `_${lastIndex + 1}`;
};
export const createNewApiName = (actions: ActionDataState, pageId: string) => {
const pageApiNames = actions
2020-12-24 04:32:25 +00:00
.filter((a) => a.config.pageId === pageId)
.map((a) => a.config.name);
return getNextEntityName("Api", pageApiNames);
};
feat: JS Editor (#6003) * Changes to add js plugin * routes+reducer+create template * added debugger to js editor page * entity explorer changes * create js function * added copy, move and delete action * added js plugin * added existing js functions to data tree * removed actionconfig for js collection * new js function added to data tree and entity as well * parsing flow added * changes to data tree * parse and update js functions * small changes for def creator for js action * create delete modified * small changes for update * update flow change * entity properties added * removed linting errors * small changes in entity explorer * changes for update * move, copy implementation * conflict resolved * changes for dependecy map creation * Only make the variables the binding paths * Basic eval sync working * Minor fixes * removed unwanted code * entity props and autocomplete * saving in progress show * redirection fix after delete js action * removed unnecessary line * Fixing merge conflict * added sample body * removed dummy data and added plugin Type * few PR comments fixed * automplete fix * few more PR comments fix * PR commnets fix * move and copy api change * js colleciton name refactor & 'move to page' changes & search * view changes * autocomplete added for js collections * removing till async is implemented * small changes * separate js pane response view * Executing functions * js collection to js objects * entity explorer issue and resolve action on page switch * removed unused line * small color fix * js file icon added * added js action to property pane * Property pane changes for actions * property pane changes for js functions * showing syntax error for now * actions sorted in response tab * added js objects to slash and recent entitties * enabling this to be used inside of function * eval fix * feature flag changes for entity explorer and property pane * debugger changes * copy bug fix * small changes for eval * debugger bug fix * chnaged any to specific types * error in console fix * icons update * fixed test case * test case fix * non empty check for functions * evaluate test case fix * added new icons * text change * updated time for debounce for trial * after release mereg * changed icon * after merge * PR comments simple * fixed PR comments - redux form, settings remove * js object interface changes * name refactor * export default change * delete resolve actions chnage * after merge * adding execute fn as 3rd option and removed create new js function * issue 7054 fixed - app crash * execute function on response tab changes * refactor function name part 1 * refactor of js function name * try catch added refactor * test fix * not used line removed * test cases locator fixed Co-authored-by: Nidhi <nidhi.nair93@gmail.com> Co-authored-by: hetunandu <hetu@appsmith.com>
2021-09-08 17:32:22 +00:00
export const createNewJSFunctionName = (
jsActions: ActionDataState,
pageId: string,
) => {
const pageJsFunctionNames = jsActions
.filter((a) => a.config.pageId === pageId)
.map((a) => a.config.name);
return getNextEntityName("JSObject", pageJsFunctionNames);
};
2019-12-16 08:49:10 +00:00
export const noop = () => {
log.debug("noop");
2019-12-16 08:49:10 +00:00
};
2020-03-16 07:59:07 +00:00
export const stopEventPropagation = (e: any) => {
e.stopPropagation();
};
export const createNewQueryName = (
queries: ActionDataState,
pageId: string,
) => {
const pageApiNames = queries
2020-12-24 04:32:25 +00:00
.filter((a) => a.config.pageId === pageId)
.map((a) => a.config.name);
const newName = getNextEntityName("Query", pageApiNames);
return newName;
};
2020-03-16 07:59:07 +00:00
export const convertToString = (value: any): string => {
if (_.isUndefined(value)) {
return "";
}
if (_.isObject(value)) {
return JSON.stringify(value, null, 2);
}
if (_.isString(value)) return value;
return value.toString();
};
2020-03-27 12:46:29 +00:00
const getEnvLogLevel = (configLevel: LogLevelDesc): LogLevelDesc => {
let logLevel = configLevel;
if (localStorage && localStorage.getItem) {
const localStorageLevel = localStorage.getItem(
"logLevelOverride",
) as LogLevelDesc;
if (localStorageLevel) logLevel = localStorageLevel;
}
2020-03-27 12:46:29 +00:00
return logLevel;
};
Homepage redesign with themes (#482) * Updating homepage body color * WIP: Fixing scrolls and adding anchors * Removing divider from bottom of the page. * Adding hover background color to app card * Changing edit and launch icons. * Fixing app name paddding in card. * Fixing workspaces overflow * Adding right padding to applications view * Adding share icon to share btn * Fixing Application card styles. * Fixing text decoration in button. * Adding new workspace button * Fixing new workspace and new app styles. * Adding icon sizes. * Fixing Org Name and Org settings menu. * Application menu working * Fixing overlay visibility on app card * Fixing settings page content width. * Fixing workspace icon * Changing app card colors. * Removing debugger * Adding app icon. * Fixing the spaces in application card * Adding storybook-static folder to gitignore. * Adding other storybook files. * Adding menu items for app * Removing cypress selector from text. * Menu width issue fixed * Default app icon color added * Removing hardcoded colors * Removing hardcoded colors. * Light Mode on! * Showing correct icon and color in menu * Update color working properly. * Updating appIcon * Editable text working. * Adding validator * Adding edit permissions to menu * Removing box shadow on app card. * Fixing context menu fill color * Fixing Menu hover issues. * Fixing menu open close hover issues. * Fixing settings pages * Changed Workspace to org. * Fix: State management in EditableText Component (#540) * Error state height is fixed as per design * savingState prop condition fixed * Fixing createnew. * Fixing saving state for application card. * Fixed application card editable text error. * Fixing issue caused during merge. * Fixing tests in create org. * Removing commented code. * Removing unwanted vars. * Fixing delete duplicate tests. * Latest color palette. * Fixing form and table widget. * Removing switcher from header * Removing unused files * Fixing app card context dropdown * Show overlay fix * Adding localStorage support to theme. * Making dark mode the default. Co-authored-by: Rohit Kumawat <rohit.kumawat@primathon.in>
2020-09-16 11:50:47 +00:00
export const getInitialsAndColorCode = (
fullName: any,
colorPalette: string[],
): string[] => {
let inits = "";
// if name contains space. eg: "Full Name"
2021-06-16 18:36:34 +00:00
if (fullName && fullName.includes(" ")) {
const namesArr = fullName.split(" ");
let initials = namesArr.map((name: string) => name.charAt(0));
initials = initials.join("").toUpperCase();
inits = initials.slice(0, 2);
} else {
// handle for camelCase
2021-06-16 18:36:34 +00:00
const str = fullName ? fullName.replace(/([a-z])([A-Z])/g, "$1 $2") : "";
const namesArr = str.split(" ");
let initials = namesArr.map((name: string) => name.charAt(0));
initials = initials.join("").toUpperCase();
inits = initials.slice(0, 2);
}
Homepage redesign with themes (#482) * Updating homepage body color * WIP: Fixing scrolls and adding anchors * Removing divider from bottom of the page. * Adding hover background color to app card * Changing edit and launch icons. * Fixing app name paddding in card. * Fixing workspaces overflow * Adding right padding to applications view * Adding share icon to share btn * Fixing Application card styles. * Fixing text decoration in button. * Adding new workspace button * Fixing new workspace and new app styles. * Adding icon sizes. * Fixing Org Name and Org settings menu. * Application menu working * Fixing overlay visibility on app card * Fixing settings page content width. * Fixing workspace icon * Changing app card colors. * Removing debugger * Adding app icon. * Fixing the spaces in application card * Adding storybook-static folder to gitignore. * Adding other storybook files. * Adding menu items for app * Removing cypress selector from text. * Menu width issue fixed * Default app icon color added * Removing hardcoded colors * Removing hardcoded colors. * Light Mode on! * Showing correct icon and color in menu * Update color working properly. * Updating appIcon * Editable text working. * Adding validator * Adding edit permissions to menu * Removing box shadow on app card. * Fixing context menu fill color * Fixing Menu hover issues. * Fixing menu open close hover issues. * Fixing settings pages * Changed Workspace to org. * Fix: State management in EditableText Component (#540) * Error state height is fixed as per design * savingState prop condition fixed * Fixing createnew. * Fixing saving state for application card. * Fixed application card editable text error. * Fixing issue caused during merge. * Fixing tests in create org. * Removing commented code. * Removing unwanted vars. * Fixing delete duplicate tests. * Latest color palette. * Fixing form and table widget. * Removing switcher from header * Removing unused files * Fixing app card context dropdown * Show overlay fix * Adding localStorage support to theme. * Making dark mode the default. Co-authored-by: Rohit Kumawat <rohit.kumawat@primathon.in>
2020-09-16 11:50:47 +00:00
const colorCode = getColorCode(inits, colorPalette);
return [inits, colorCode];
};
Homepage redesign with themes (#482) * Updating homepage body color * WIP: Fixing scrolls and adding anchors * Removing divider from bottom of the page. * Adding hover background color to app card * Changing edit and launch icons. * Fixing app name paddding in card. * Fixing workspaces overflow * Adding right padding to applications view * Adding share icon to share btn * Fixing Application card styles. * Fixing text decoration in button. * Adding new workspace button * Fixing new workspace and new app styles. * Adding icon sizes. * Fixing Org Name and Org settings menu. * Application menu working * Fixing overlay visibility on app card * Fixing settings page content width. * Fixing workspace icon * Changing app card colors. * Removing debugger * Adding app icon. * Fixing the spaces in application card * Adding storybook-static folder to gitignore. * Adding other storybook files. * Adding menu items for app * Removing cypress selector from text. * Menu width issue fixed * Default app icon color added * Removing hardcoded colors * Removing hardcoded colors. * Light Mode on! * Showing correct icon and color in menu * Update color working properly. * Updating appIcon * Editable text working. * Adding validator * Adding edit permissions to menu * Removing box shadow on app card. * Fixing context menu fill color * Fixing Menu hover issues. * Fixing menu open close hover issues. * Fixing settings pages * Changed Workspace to org. * Fix: State management in EditableText Component (#540) * Error state height is fixed as per design * savingState prop condition fixed * Fixing createnew. * Fixing saving state for application card. * Fixed application card editable text error. * Fixing issue caused during merge. * Fixing tests in create org. * Removing commented code. * Removing unwanted vars. * Fixing delete duplicate tests. * Latest color palette. * Fixing form and table widget. * Removing switcher from header * Removing unused files * Fixing app card context dropdown * Show overlay fix * Adding localStorage support to theme. * Making dark mode the default. Co-authored-by: Rohit Kumawat <rohit.kumawat@primathon.in>
2020-09-16 11:50:47 +00:00
export const getColorCode = (
initials: string,
colorPalette: string[],
): string => {
let asciiSum = 0;
for (let i = 0; i < initials.length; i++) {
asciiSum += initials[i].charCodeAt(0);
}
Homepage redesign with themes (#482) * Updating homepage body color * WIP: Fixing scrolls and adding anchors * Removing divider from bottom of the page. * Adding hover background color to app card * Changing edit and launch icons. * Fixing app name paddding in card. * Fixing workspaces overflow * Adding right padding to applications view * Adding share icon to share btn * Fixing Application card styles. * Fixing text decoration in button. * Adding new workspace button * Fixing new workspace and new app styles. * Adding icon sizes. * Fixing Org Name and Org settings menu. * Application menu working * Fixing overlay visibility on app card * Fixing settings page content width. * Fixing workspace icon * Changing app card colors. * Removing debugger * Adding app icon. * Fixing the spaces in application card * Adding storybook-static folder to gitignore. * Adding other storybook files. * Adding menu items for app * Removing cypress selector from text. * Menu width issue fixed * Default app icon color added * Removing hardcoded colors * Removing hardcoded colors. * Light Mode on! * Showing correct icon and color in menu * Update color working properly. * Updating appIcon * Editable text working. * Adding validator * Adding edit permissions to menu * Removing box shadow on app card. * Fixing context menu fill color * Fixing Menu hover issues. * Fixing menu open close hover issues. * Fixing settings pages * Changed Workspace to org. * Fix: State management in EditableText Component (#540) * Error state height is fixed as per design * savingState prop condition fixed * Fixing createnew. * Fixing saving state for application card. * Fixed application card editable text error. * Fixing issue caused during merge. * Fixing tests in create org. * Removing commented code. * Removing unwanted vars. * Fixing delete duplicate tests. * Latest color palette. * Fixing form and table widget. * Removing switcher from header * Removing unused files * Fixing app card context dropdown * Show overlay fix * Adding localStorage support to theme. * Making dark mode the default. Co-authored-by: Rohit Kumawat <rohit.kumawat@primathon.in>
2020-09-16 11:50:47 +00:00
return colorPalette[asciiSum % colorPalette.length];
};
export const getApplicationIcon = (initials: string): AppIconName => {
let asciiSum = 0;
for (let i = 0; i < initials.length; i++) {
asciiSum += initials[i].charCodeAt(0);
}
return AppIconCollection[asciiSum % AppIconCollection.length];
};
2020-05-28 18:10:26 +00:00
export function hexToRgb(
hex: string,
): {
r: number;
g: number;
b: number;
} {
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result
? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16),
}
: {
r: -1,
g: -1,
b: -1,
};
}
export function getQueryParams() {
const urlParams = new URLSearchParams(window.location.search);
const keys = urlParams.keys();
let key = keys.next().value;
const queryParams: Record<string, string> = {};
while (key) {
queryParams[key] = urlParams.get(key) as string;
key = keys.next().value;
}
return queryParams;
}
export function convertObjectToQueryParams(object: any): string {
if (!_.isNil(object)) {
2020-12-24 04:32:25 +00:00
const paramArray: string[] = _.map(_.keys(object), (key) => {
return encodeURIComponent(key) + "=" + encodeURIComponent(object[key]);
});
return "?" + _.join(paramArray, "&");
} else {
return "";
}
}
export const retryPromise = (
fn: () => Promise<any>,
retriesLeft = 5,
interval = 1000,
): Promise<any> => {
return new Promise((resolve, reject) => {
fn()
.then(resolve)
.catch(() => {
setTimeout(() => {
if (retriesLeft === 1) {
return Promise.reject({
code: ERROR_CODES.SERVER_ERROR,
message: createMessage(ERROR_500),
show: false,
});
}
// Passing on "reject" is the important part
retryPromise(fn, retriesLeft - 1, interval).then(resolve, reject);
}, interval);
});
});
};
export const getRandomPaletteColor = (colorPalette: string[]) => {
return colorPalette[Math.floor(Math.random() * colorPalette.length)];
};
export const isBlobUrl = (url: string) => {
return typeof url === "string" && url.startsWith("blob:");
};
/**
*
* @param data string file data
* @param type string file type
* @returns string containing blob id and type
*/
export const createBlobUrl = (data: Blob | string, type: string) => {
let url = URL.createObjectURL(data);
url = url.replace(
`${window.location.protocol}//${window.location.hostname}/`,
"",
);
return `${url}?type=${type}`;
};
/**
*
* @param blobId string blob id along with type.
* @returns [string,string] [blobUrl, type]
*/
export const parseBlobUrl = (blobId: string) => {
const url = `blob:${window.location.protocol}//${
window.location.hostname
}/${blobId.substring(5)}`;
return url.split("?type=");
};
feat: property pane docking (#7361) * add tailwindcss * docked property pane * uncomment a line * make entity explorer as drawer on unpin * remove unused imports * add pin state in reducer * add menu icon in header * fix widget sidebar * fix widgets sidebar * style property pane * update property pane css * update icons in property pane * update property pane header styles * update spacing * fix few ui issues * wip: preview mode * wip:preview mode * remove unused import * comments sidebar in app and edit mode * fix order of import * use selected state for property pane * update scrollbar style * add classes to sidebar and property pane * make widgets editor fluid * make widgets editor fluid and refactor logic * resize the widgets editor if explorer is pinned * add shortcut for preview mode * fix link for tabs in edit mode * zoom in/zoom out for 0.75 * fix chart widget + table widget crashing * allow zooming of canvas * fix weird canvas draw issue + update container for handling zoom * add actions for is panning * allow panning with grab cursor * reset panning + zooming when entering preview mode * add grabbing cursor when grabbing * only prevent default when space key is pressed * dont allow zoom in preview mode * remove unused imports * fix dont allow zoom in preview mode * fix ux of panning on space hit * make fluid as the default app layout * chart spec * fix dropdown_on change spec * fix add widget table and bind spec * remove draggable property pane spec * fix container spec * fix form widget spec * fix jest test * fix the function typo * remove clicking of close button for property pane in cypress tests * remove property pane actions test * fix drag and drop test failing * add cypress selector id to back button in property pane * fix toggle js spec * fix merge conflicts from new design system * editor header * fix product updates styles + widget card * remove all unused imports * fix dynamic layout spec * fix entity explorer tab rename test failing * fix table spec * fix bind tabletextpagination spec * fix js object spec * fix entity explorer rename issue * fix cypress test * fix cypress command wrong commit * fix tab spec * fix property pane copy tests * add zoom header * zoom levels * make property pane sidebar resizable * add multi select property pane * fix widget search bug * update property pane width in state on drag end * fix viewer header * fix editor header * update editor header + remove zooming * update small style * dont allow closing of explorer when resizing * fix jest test * fix dropdown widget jest test * preview test case wip * add entity explorer pinning tests + preview mode tests * add tooltip in layout control + add padding bottom in property pane view * incorporate aakash feedbacks * fix preview mode margin issue * remove panning code * fix cypress failing test * uncomment jest test * remove redundant code * fix maincontainer test * incorporate review feedbacks * incorporate aakash feedbacks * review feedbacks * incorporate review feedbacks * incorporate qa feedbacks * fix dynamic layout spec * updated test based on latest change * dsl updated * Updated dsl * Updated dsl * resize deselects widget issue. * fix canvas height issue * fix typo * incorporate qa feedbacks * incorporate qa feedbacks * incorporate qa feedbacks * update color for setting control for widget name * fix onboarding styles conflicts * Updated tests * fix application overflow issue * updated test method Co-authored-by: root <root@DESKTOP-9GENCK0.localdomain> Co-authored-by: Pawan Kumar <pawankumar@Pawans-MacBook-Pro.local> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: Apple <nandan@thinkify.io>
2021-11-23 08:01:46 +00:00
/**
feat: Switch Group widget (#7590) * Feat: Switch Group Widget -- The first MVP of the widget * feat: Switch Group Widget -- Follow the same config and implementation as the other group widgets * feat: Switch Group Widget -- Elaborate the help text for defaultSelectedValues * feat: Switch Group Widget -- Add a widget icon * feat: Switch Group Widget -- Remove unnecessary property control at ItemsControl.tsx -- Refactor some code snippets for higher code quality -- Add basic cypress test cases * fix: icon for the widget optimised & replaced * feat: Switch Group Widget -- Add a unit test for defaultSelectedValuesValidation * feat: Switch Group Widget -- Make the validation type for defaultSelectedValues property to ValidationTypes.ARRAY -- Remove original validation function and its unit test * feat: Switch Group Widget -- Fix on typo -- Fix on formatting issue -- Change the help text for isRequired property * feat: Switch Group Widget -- Revert help text for isRequired property to the original one * feat: Switch Group Widget -- Set strict property to true on defaultSelectedValues * feat: Switch group widget -- Refactor utility function, getCamelCaseString -- Add the corresponding test case * feat: Switch group widget -- Implement options property as a plain JS field -- Reimplement update logic for selectedValues when options changes -- Add a new utility function for checking equality of object arrays -- Add a unit test for the above function -- Rewrite the corresponding Cypress test cases * feat: Switch Group Widget -- Remove isArrayEqual utility function and directly use functions from lodash * feat: Swtich Group Widget -- Make selectedValues as a derived property * feat: Switch Group Widget -- Replace the widget icon * feat: Switch Group Widget -- Rewrite a test case for onSelectionChange property * feat: Switch Group Widget -- Remove redundant calls for openPropertyPane * feat: Switch Group Widget -- Remove closePropertyPane call from afterEach hook * feat: Switch Group Widget -- Change the selector for every switch element in onSelectionChange test case * feat: Switch Group Widget -- Fix on failed Cypress test case, adding closePropertyPane command to onSelectionChange * feat: Switch Group Widget -- Remove template literal from a selector * feat: Switch Group Widget -- Make click on onSelectionChange test case forced * feat: Switch Group Widget -- Fix on crash issue when editing on Options property * feat: Switch Group Widget -- Add the widget icon to show in entity explorer * feat: Switch Group Widget -- Fix on blue color on mouse down -- Add a new property for alignment Co-authored-by: somangshu <somangshu.goswami1508@gmail.com>
2021-12-09 12:02:47 +00:00
* Convert a string into camelCase
* @param sourceString input string
* @returns camelCase string
*/
export const getCamelCaseString = (sourceString: string) => {
let out = "";
// Split the input string to separate words using RegEx
const regEx = /[A-Z\xC0-\xD6\xD8-\xDE]?[a-z\xDF-\xF6\xF8-\xFF]+|[A-Z\xC0-\xD6\xD8-\xDE]+(?![a-z\xDF-\xF6\xF8-\xFF])|\d+/g;
const words = sourceString.match(regEx);
if (words) {
words.forEach(function(el, idx) {
const add = el.toLowerCase();
out += idx === 0 ? add : add[0].toUpperCase() + add.slice(1);
});
}
return out;
};
/*
feat: property pane docking (#7361) * add tailwindcss * docked property pane * uncomment a line * make entity explorer as drawer on unpin * remove unused imports * add pin state in reducer * add menu icon in header * fix widget sidebar * fix widgets sidebar * style property pane * update property pane css * update icons in property pane * update property pane header styles * update spacing * fix few ui issues * wip: preview mode * wip:preview mode * remove unused import * comments sidebar in app and edit mode * fix order of import * use selected state for property pane * update scrollbar style * add classes to sidebar and property pane * make widgets editor fluid * make widgets editor fluid and refactor logic * resize the widgets editor if explorer is pinned * add shortcut for preview mode * fix link for tabs in edit mode * zoom in/zoom out for 0.75 * fix chart widget + table widget crashing * allow zooming of canvas * fix weird canvas draw issue + update container for handling zoom * add actions for is panning * allow panning with grab cursor * reset panning + zooming when entering preview mode * add grabbing cursor when grabbing * only prevent default when space key is pressed * dont allow zoom in preview mode * remove unused imports * fix dont allow zoom in preview mode * fix ux of panning on space hit * make fluid as the default app layout * chart spec * fix dropdown_on change spec * fix add widget table and bind spec * remove draggable property pane spec * fix container spec * fix form widget spec * fix jest test * fix the function typo * remove clicking of close button for property pane in cypress tests * remove property pane actions test * fix drag and drop test failing * add cypress selector id to back button in property pane * fix toggle js spec * fix merge conflicts from new design system * editor header * fix product updates styles + widget card * remove all unused imports * fix dynamic layout spec * fix entity explorer tab rename test failing * fix table spec * fix bind tabletextpagination spec * fix js object spec * fix entity explorer rename issue * fix cypress test * fix cypress command wrong commit * fix tab spec * fix property pane copy tests * add zoom header * zoom levels * make property pane sidebar resizable * add multi select property pane * fix widget search bug * update property pane width in state on drag end * fix viewer header * fix editor header * update editor header + remove zooming * update small style * dont allow closing of explorer when resizing * fix jest test * fix dropdown widget jest test * preview test case wip * add entity explorer pinning tests + preview mode tests * add tooltip in layout control + add padding bottom in property pane view * incorporate aakash feedbacks * fix preview mode margin issue * remove panning code * fix cypress failing test * uncomment jest test * remove redundant code * fix maincontainer test * incorporate review feedbacks * incorporate aakash feedbacks * review feedbacks * incorporate review feedbacks * incorporate qa feedbacks * fix dynamic layout spec * updated test based on latest change * dsl updated * Updated dsl * Updated dsl * resize deselects widget issue. * fix canvas height issue * fix typo * incorporate qa feedbacks * incorporate qa feedbacks * incorporate qa feedbacks * update color for setting control for widget name * fix onboarding styles conflicts * Updated tests * fix application overflow issue * updated test method Co-authored-by: root <root@DESKTOP-9GENCK0.localdomain> Co-authored-by: Pawan Kumar <pawankumar@Pawans-MacBook-Pro.local> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: Apple <nandan@thinkify.io>
2021-11-23 08:01:46 +00:00
* gets the page url
*
* Note: for edit mode, the page will have different url ( contains '/edit' at the end )
*
* @param page
* @returns
*/
export const getPageURL = (
page: Page,
appMode: APP_MODE | undefined,
currentApplicationDetails: CurrentApplicationData | undefined,
) => {
if (appMode === APP_MODE.PUBLISHED) {
return trimQueryString(
getApplicationViewerPageURL({
applicationId: currentApplicationDetails?.id,
pageId: page.pageId,
}),
);
}
return getApplicationEditorPageURL(
currentApplicationDetails?.id,
page.pageId,
);
};