2020-01-27 08:24:58 +00:00
|
|
|
import React, { useState, useEffect } from "react";
|
2020-02-21 12:16:49 +00:00
|
|
|
import {
|
|
|
|
|
EditableText as BlueprintEditableText,
|
|
|
|
|
Classes,
|
|
|
|
|
} from "@blueprintjs/core";
|
2020-01-27 08:24:58 +00:00
|
|
|
import styled from "styled-components";
|
2020-06-18 07:46:53 +00:00
|
|
|
import _ from "lodash";
|
|
|
|
|
import Edit from "assets/images/EditPen.svg";
|
|
|
|
|
import ErrorTooltip from "./ErrorTooltip";
|
Feature/entity browse (#220)
# New Feature: Entity Explorer
- Entities are actions (apis and queries), datasources, pages, and widgets
- With this new feature, all entities in the application will be available
to view in the new entity explorer sidebar
- All existing application features from the api sidebar, query sidebar, datasource sidebar and pages sidebar
now are avialable on the entity explorer sidebar
- Users are now able to quickly switch to any entity in the application from the entity explorer sidebar.
- Users can also search all entities in the application from the new sidebar. Use cmd + f or ctrl + f to focus on the search input
- Users can rename entities from the new sidebar
- Users can also perform contextual actions on these entities like set a page as home page, copy/move actions, delete entity, etc from the context menu available alongside the entities in the sidebar
- Users can view the properties of the entities in the sidebar, as well as copy bindings to use in the application.
2020-08-10 08:52:45 +00:00
|
|
|
import { Colors } from "constants/Colors";
|
2020-11-24 07:01:37 +00:00
|
|
|
import { Toaster } from "components/ads/Toast";
|
|
|
|
|
import { Variant } from "components/ads/common";
|
2020-06-18 07:46:53 +00:00
|
|
|
|
|
|
|
|
export enum EditInteractionKind {
|
|
|
|
|
SINGLE,
|
|
|
|
|
DOUBLE,
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-27 08:24:58 +00:00
|
|
|
type EditableTextProps = {
|
|
|
|
|
type: "text" | "password" | "email" | "phone" | "date";
|
|
|
|
|
defaultValue: string;
|
|
|
|
|
onTextChanged: (value: string) => void;
|
|
|
|
|
placeholder: string;
|
2020-03-30 14:21:21 +00:00
|
|
|
className?: string;
|
2020-06-18 07:46:53 +00:00
|
|
|
valueTransform?: (value: string) => string;
|
|
|
|
|
isEditingDefault?: boolean;
|
|
|
|
|
forceDefault?: boolean;
|
|
|
|
|
updating?: boolean;
|
|
|
|
|
isInvalid?: (value: string) => string | boolean;
|
|
|
|
|
editInteractionKind: EditInteractionKind;
|
|
|
|
|
hideEditIcon?: boolean;
|
Feature/entity browse (#220)
# New Feature: Entity Explorer
- Entities are actions (apis and queries), datasources, pages, and widgets
- With this new feature, all entities in the application will be available
to view in the new entity explorer sidebar
- All existing application features from the api sidebar, query sidebar, datasource sidebar and pages sidebar
now are avialable on the entity explorer sidebar
- Users are now able to quickly switch to any entity in the application from the entity explorer sidebar.
- Users can also search all entities in the application from the new sidebar. Use cmd + f or ctrl + f to focus on the search input
- Users can rename entities from the new sidebar
- Users can also perform contextual actions on these entities like set a page as home page, copy/move actions, delete entity, etc from the context menu available alongside the entities in the sidebar
- Users can view the properties of the entities in the sidebar, as well as copy bindings to use in the application.
2020-08-10 08:52:45 +00:00
|
|
|
minimal?: boolean;
|
|
|
|
|
onBlur?: (value?: string) => void;
|
2020-01-27 08:24:58 +00:00
|
|
|
};
|
|
|
|
|
|
2020-06-18 07:46:53 +00:00
|
|
|
const EditPen = styled.img`
|
|
|
|
|
width: 14px;
|
|
|
|
|
: hover {
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
Feature/entity browse (#220)
# New Feature: Entity Explorer
- Entities are actions (apis and queries), datasources, pages, and widgets
- With this new feature, all entities in the application will be available
to view in the new entity explorer sidebar
- All existing application features from the api sidebar, query sidebar, datasource sidebar and pages sidebar
now are avialable on the entity explorer sidebar
- Users are now able to quickly switch to any entity in the application from the entity explorer sidebar.
- Users can also search all entities in the application from the new sidebar. Use cmd + f or ctrl + f to focus on the search input
- Users can rename entities from the new sidebar
- Users can also perform contextual actions on these entities like set a page as home page, copy/move actions, delete entity, etc from the context menu available alongside the entities in the sidebar
- Users can view the properties of the entities in the sidebar, as well as copy bindings to use in the application.
2020-08-10 08:52:45 +00:00
|
|
|
const EditableTextWrapper = styled.div<{
|
|
|
|
|
isEditing: boolean;
|
|
|
|
|
minimal: boolean;
|
|
|
|
|
}>`
|
2020-01-27 08:24:58 +00:00
|
|
|
&& {
|
2020-06-18 07:46:53 +00:00
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
justify-content: flex-start;
|
|
|
|
|
align-items: flex-start;
|
2020-02-21 12:16:49 +00:00
|
|
|
& .${Classes.EDITABLE_TEXT} {
|
2020-12-24 04:32:25 +00:00
|
|
|
border: ${(props) =>
|
Feature/entity browse (#220)
# New Feature: Entity Explorer
- Entities are actions (apis and queries), datasources, pages, and widgets
- With this new feature, all entities in the application will be available
to view in the new entity explorer sidebar
- All existing application features from the api sidebar, query sidebar, datasource sidebar and pages sidebar
now are avialable on the entity explorer sidebar
- Users are now able to quickly switch to any entity in the application from the entity explorer sidebar.
- Users can also search all entities in the application from the new sidebar. Use cmd + f or ctrl + f to focus on the search input
- Users can rename entities from the new sidebar
- Users can also perform contextual actions on these entities like set a page as home page, copy/move actions, delete entity, etc from the context menu available alongside the entities in the sidebar
- Users can view the properties of the entities in the sidebar, as well as copy bindings to use in the application.
2020-08-10 08:52:45 +00:00
|
|
|
props.isEditing && !props.minimal
|
|
|
|
|
? `1px solid ${Colors.HIT_GRAY}`
|
|
|
|
|
: "none"};
|
2020-01-27 08:24:58 +00:00
|
|
|
cursor: pointer;
|
2020-12-24 04:32:25 +00:00
|
|
|
padding: ${(props) => (!props.minimal ? "5px 5px" : "0px")};
|
2020-02-21 12:16:49 +00:00
|
|
|
text-transform: none;
|
2020-06-18 07:46:53 +00:00
|
|
|
flex: 1 0 100%;
|
|
|
|
|
max-width: 100%;
|
Feature/entity browse (#220)
# New Feature: Entity Explorer
- Entities are actions (apis and queries), datasources, pages, and widgets
- With this new feature, all entities in the application will be available
to view in the new entity explorer sidebar
- All existing application features from the api sidebar, query sidebar, datasource sidebar and pages sidebar
now are avialable on the entity explorer sidebar
- Users are now able to quickly switch to any entity in the application from the entity explorer sidebar.
- Users can also search all entities in the application from the new sidebar. Use cmd + f or ctrl + f to focus on the search input
- Users can rename entities from the new sidebar
- Users can also perform contextual actions on these entities like set a page as home page, copy/move actions, delete entity, etc from the context menu available alongside the entities in the sidebar
- Users can view the properties of the entities in the sidebar, as well as copy bindings to use in the application.
2020-08-10 08:52:45 +00:00
|
|
|
overflow: hidden;
|
2020-06-18 07:46:53 +00:00
|
|
|
display: flex;
|
2020-01-27 08:24:58 +00:00
|
|
|
&:before,
|
|
|
|
|
&:after {
|
|
|
|
|
display: none;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-21 12:16:49 +00:00
|
|
|
& div.${Classes.EDITABLE_TEXT_INPUT} {
|
|
|
|
|
text-transform: none;
|
2020-06-18 07:46:53 +00:00
|
|
|
width: 100%;
|
2020-02-21 12:16:49 +00:00
|
|
|
}
|
2020-01-27 08:24:58 +00:00
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
Feature/entity browse (#220)
# New Feature: Entity Explorer
- Entities are actions (apis and queries), datasources, pages, and widgets
- With this new feature, all entities in the application will be available
to view in the new entity explorer sidebar
- All existing application features from the api sidebar, query sidebar, datasource sidebar and pages sidebar
now are avialable on the entity explorer sidebar
- Users are now able to quickly switch to any entity in the application from the entity explorer sidebar.
- Users can also search all entities in the application from the new sidebar. Use cmd + f or ctrl + f to focus on the search input
- Users can rename entities from the new sidebar
- Users can also perform contextual actions on these entities like set a page as home page, copy/move actions, delete entity, etc from the context menu available alongside the entities in the sidebar
- Users can view the properties of the entities in the sidebar, as well as copy bindings to use in the application.
2020-08-10 08:52:45 +00:00
|
|
|
const TextContainer = styled.div<{ isValid: boolean; minimal: boolean }>`
|
2020-06-18 07:46:53 +00:00
|
|
|
display: flex;
|
2020-09-16 10:28:01 +00:00
|
|
|
&&&& .${Classes.EDITABLE_TEXT} {
|
2020-12-24 04:32:25 +00:00
|
|
|
${(props) => (!props.minimal ? "border-radius: 3px;" : "")}
|
|
|
|
|
${(props) =>
|
Feature/entity browse (#220)
# New Feature: Entity Explorer
- Entities are actions (apis and queries), datasources, pages, and widgets
- With this new feature, all entities in the application will be available
to view in the new entity explorer sidebar
- All existing application features from the api sidebar, query sidebar, datasource sidebar and pages sidebar
now are avialable on the entity explorer sidebar
- Users are now able to quickly switch to any entity in the application from the entity explorer sidebar.
- Users can also search all entities in the application from the new sidebar. Use cmd + f or ctrl + f to focus on the search input
- Users can rename entities from the new sidebar
- Users can also perform contextual actions on these entities like set a page as home page, copy/move actions, delete entity, etc from the context menu available alongside the entities in the sidebar
- Users can view the properties of the entities in the sidebar, as well as copy bindings to use in the application.
2020-08-10 08:52:45 +00:00
|
|
|
!props.minimal
|
|
|
|
|
? `border-color: ${props.isValid ? Colors.HIT_GRAY : "red"}`
|
|
|
|
|
: ""};
|
2020-09-16 10:28:01 +00:00
|
|
|
& .${Classes.EDITABLE_TEXT_CONTENT} {
|
2020-12-24 04:32:25 +00:00
|
|
|
text-decoration: ${(props) => (props.minimal ? "underline" : "none")};
|
2020-09-16 10:28:01 +00:00
|
|
|
}
|
2020-06-18 07:46:53 +00:00
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
2020-01-27 08:24:58 +00:00
|
|
|
export const EditableText = (props: EditableTextProps) => {
|
2020-06-18 07:46:53 +00:00
|
|
|
const [isEditing, setIsEditing] = useState(!!props.isEditingDefault);
|
|
|
|
|
const [value, setValue] = useState(props.defaultValue);
|
|
|
|
|
|
2020-01-27 08:24:58 +00:00
|
|
|
useEffect(() => {
|
2020-06-18 07:46:53 +00:00
|
|
|
setValue(props.defaultValue);
|
2020-08-14 07:18:30 +00:00
|
|
|
setIsEditing(!!props.isEditingDefault);
|
|
|
|
|
}, [props.defaultValue, props.isEditingDefault]);
|
2020-06-18 07:46:53 +00:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (props.forceDefault === true) setValue(props.defaultValue);
|
Feature/entity browse (#220)
# New Feature: Entity Explorer
- Entities are actions (apis and queries), datasources, pages, and widgets
- With this new feature, all entities in the application will be available
to view in the new entity explorer sidebar
- All existing application features from the api sidebar, query sidebar, datasource sidebar and pages sidebar
now are avialable on the entity explorer sidebar
- Users are now able to quickly switch to any entity in the application from the entity explorer sidebar.
- Users can also search all entities in the application from the new sidebar. Use cmd + f or ctrl + f to focus on the search input
- Users can rename entities from the new sidebar
- Users can also perform contextual actions on these entities like set a page as home page, copy/move actions, delete entity, etc from the context menu available alongside the entities in the sidebar
- Users can view the properties of the entities in the sidebar, as well as copy bindings to use in the application.
2020-08-10 08:52:45 +00:00
|
|
|
}, [props.forceDefault, props.defaultValue]);
|
2020-01-27 08:24:58 +00:00
|
|
|
|
2020-03-27 09:02:11 +00:00
|
|
|
const edit = (e: any) => {
|
|
|
|
|
setIsEditing(true);
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
};
|
2020-06-18 07:46:53 +00:00
|
|
|
const onChange = (_value: string) => {
|
Feature/entity browse (#220)
# New Feature: Entity Explorer
- Entities are actions (apis and queries), datasources, pages, and widgets
- With this new feature, all entities in the application will be available
to view in the new entity explorer sidebar
- All existing application features from the api sidebar, query sidebar, datasource sidebar and pages sidebar
now are avialable on the entity explorer sidebar
- Users are now able to quickly switch to any entity in the application from the entity explorer sidebar.
- Users can also search all entities in the application from the new sidebar. Use cmd + f or ctrl + f to focus on the search input
- Users can rename entities from the new sidebar
- Users can also perform contextual actions on these entities like set a page as home page, copy/move actions, delete entity, etc from the context menu available alongside the entities in the sidebar
- Users can view the properties of the entities in the sidebar, as well as copy bindings to use in the application.
2020-08-10 08:52:45 +00:00
|
|
|
props.onBlur && props.onBlur();
|
2020-06-18 07:46:53 +00:00
|
|
|
const isInvalid = props.isInvalid ? props.isInvalid(_value) : false;
|
|
|
|
|
if (!isInvalid) {
|
|
|
|
|
props.onTextChanged(_value);
|
2020-08-12 12:58:05 +00:00
|
|
|
setIsEditing(false);
|
2020-06-18 07:46:53 +00:00
|
|
|
} else {
|
2020-11-24 07:01:37 +00:00
|
|
|
Toaster.show({
|
|
|
|
|
text: "Invalid name",
|
|
|
|
|
variant: Variant.danger,
|
2020-08-12 12:58:05 +00:00
|
|
|
});
|
2020-06-18 07:46:53 +00:00
|
|
|
}
|
2020-01-27 08:24:58 +00:00
|
|
|
};
|
2020-06-18 07:46:53 +00:00
|
|
|
|
|
|
|
|
const onInputchange = (_value: string) => {
|
|
|
|
|
let finalVal: string = _value;
|
|
|
|
|
if (props.valueTransform) {
|
|
|
|
|
finalVal = props.valueTransform(_value);
|
|
|
|
|
}
|
|
|
|
|
setValue(finalVal);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const errorMessage = props.isInvalid && props.isInvalid(value);
|
|
|
|
|
const error = errorMessage ? errorMessage : undefined;
|
2020-01-27 08:24:58 +00:00
|
|
|
return (
|
2020-06-18 07:46:53 +00:00
|
|
|
<EditableTextWrapper
|
|
|
|
|
isEditing={isEditing}
|
|
|
|
|
onDoubleClick={
|
|
|
|
|
props.editInteractionKind === EditInteractionKind.DOUBLE ? edit : _.noop
|
|
|
|
|
}
|
|
|
|
|
onClick={
|
|
|
|
|
props.editInteractionKind === EditInteractionKind.SINGLE ? edit : _.noop
|
|
|
|
|
}
|
Feature/entity browse (#220)
# New Feature: Entity Explorer
- Entities are actions (apis and queries), datasources, pages, and widgets
- With this new feature, all entities in the application will be available
to view in the new entity explorer sidebar
- All existing application features from the api sidebar, query sidebar, datasource sidebar and pages sidebar
now are avialable on the entity explorer sidebar
- Users are now able to quickly switch to any entity in the application from the entity explorer sidebar.
- Users can also search all entities in the application from the new sidebar. Use cmd + f or ctrl + f to focus on the search input
- Users can rename entities from the new sidebar
- Users can also perform contextual actions on these entities like set a page as home page, copy/move actions, delete entity, etc from the context menu available alongside the entities in the sidebar
- Users can view the properties of the entities in the sidebar, as well as copy bindings to use in the application.
2020-08-10 08:52:45 +00:00
|
|
|
minimal={!!props.minimal}
|
2020-06-18 07:46:53 +00:00
|
|
|
>
|
|
|
|
|
<ErrorTooltip isOpen={!!error} message={errorMessage as string}>
|
Feature/entity browse (#220)
# New Feature: Entity Explorer
- Entities are actions (apis and queries), datasources, pages, and widgets
- With this new feature, all entities in the application will be available
to view in the new entity explorer sidebar
- All existing application features from the api sidebar, query sidebar, datasource sidebar and pages sidebar
now are avialable on the entity explorer sidebar
- Users are now able to quickly switch to any entity in the application from the entity explorer sidebar.
- Users can also search all entities in the application from the new sidebar. Use cmd + f or ctrl + f to focus on the search input
- Users can rename entities from the new sidebar
- Users can also perform contextual actions on these entities like set a page as home page, copy/move actions, delete entity, etc from the context menu available alongside the entities in the sidebar
- Users can view the properties of the entities in the sidebar, as well as copy bindings to use in the application.
2020-08-10 08:52:45 +00:00
|
|
|
<TextContainer isValid={!error} minimal={!!props.minimal}>
|
2020-06-18 07:46:53 +00:00
|
|
|
<BlueprintEditableText
|
|
|
|
|
disabled={!isEditing}
|
|
|
|
|
isEditing={isEditing}
|
|
|
|
|
onChange={onInputchange}
|
|
|
|
|
onConfirm={onChange}
|
|
|
|
|
selectAllOnFocus
|
|
|
|
|
value={value}
|
|
|
|
|
placeholder={props.placeholder}
|
|
|
|
|
className={props.className}
|
Feature/entity browse (#220)
# New Feature: Entity Explorer
- Entities are actions (apis and queries), datasources, pages, and widgets
- With this new feature, all entities in the application will be available
to view in the new entity explorer sidebar
- All existing application features from the api sidebar, query sidebar, datasource sidebar and pages sidebar
now are avialable on the entity explorer sidebar
- Users are now able to quickly switch to any entity in the application from the entity explorer sidebar.
- Users can also search all entities in the application from the new sidebar. Use cmd + f or ctrl + f to focus on the search input
- Users can rename entities from the new sidebar
- Users can also perform contextual actions on these entities like set a page as home page, copy/move actions, delete entity, etc from the context menu available alongside the entities in the sidebar
- Users can view the properties of the entities in the sidebar, as well as copy bindings to use in the application.
2020-08-10 08:52:45 +00:00
|
|
|
onCancel={props.onBlur}
|
2020-06-18 07:46:53 +00:00
|
|
|
/>
|
Feature/entity browse (#220)
# New Feature: Entity Explorer
- Entities are actions (apis and queries), datasources, pages, and widgets
- With this new feature, all entities in the application will be available
to view in the new entity explorer sidebar
- All existing application features from the api sidebar, query sidebar, datasource sidebar and pages sidebar
now are avialable on the entity explorer sidebar
- Users are now able to quickly switch to any entity in the application from the entity explorer sidebar.
- Users can also search all entities in the application from the new sidebar. Use cmd + f or ctrl + f to focus on the search input
- Users can rename entities from the new sidebar
- Users can also perform contextual actions on these entities like set a page as home page, copy/move actions, delete entity, etc from the context menu available alongside the entities in the sidebar
- Users can view the properties of the entities in the sidebar, as well as copy bindings to use in the application.
2020-08-10 08:52:45 +00:00
|
|
|
{!props.minimal &&
|
|
|
|
|
!props.hideEditIcon &&
|
|
|
|
|
!props.updating &&
|
|
|
|
|
!isEditing && <EditPen src={Edit} alt="Edit pen" />}
|
2020-06-18 07:46:53 +00:00
|
|
|
</TextContainer>
|
|
|
|
|
</ErrorTooltip>
|
2020-01-27 08:24:58 +00:00
|
|
|
</EditableTextWrapper>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default EditableText;
|