PromucFlow_constructor/app/client/src/components/ads/MenuItem.tsx
Rishabh Rathod 76dfcd0163
[Feature] Generate template page from datasource (#5513)
- Add Generate CRUD page feature
- Modify the Datasource card UI in the `INTEGRATION.ACTIVE` tab to directly delete and edit.
- Add `renderOption` , `errorMsg`, `isLoading` props in Dropdown component.
If `renderOption` prop is not defined, it will show default option UI.
- Add getDatasourcesStructure [new entity Selector]
( This will provide all fetched structure of datasources)

> Commit Messages ⬇️

* Show disabled GenPage Button for unsupported DS

* Add Icon in Select Table and Column dropdown

* Add Error message when datasource config has error

* Fix the continous loading state issue

* Add Not supported datasource in select Table

* Add ignoreCache when fetching DS struct

* Go to generate page if initiator=generate-page

* Fix connect new datasource button disabled

* Modify error message for invalid datasource struct

* Add snowflake to supported plugin for template

* Fix Show More option width

* Fix incorrect error msg for valid dS config

* Generate page UI improvements

* Refactor navigation

* Fix Datasource Card UX

* Remove semi-colon from Icon loader

* Refactor contants

* Add executeDatasourceQuery & fetchPluginForm API
- WIP google sheet form UI and functionality
- Implemented fetch all spreadsheet with mock data

* disable S3 and google sheet for generate page

* Update yarn.lock

* Resolve review comments
- Add Messages to `constants/messages`
- Add default value for `fetchActionsForPage` 2nd param
- Add comment
- Remove `onFinishCallback` from `handleFetchedPage`

* move string literal to constants/messages

* Remove hardcoded pluginId implementation

* Refactor getGenerateCRUDEnabledPluginMap selector

* Fix CreateAppInFirstListedOrg test command

* Add getIsGeneratePageInitiator helper func

* Fix Entity explorer Edit option test

* Fix CreateAppForOrg test command
- Add click on build from scratch in generatePage

* Fix deleteDatasource command test
- Click on Datasource Name to Edit, Datasource Card handles the click

* Fix DynamicLayout spec test issue

* Fix pageLoadSpec test

* Disable google plugin & Refactor
- Add useDatasourceOptions hook

* Add datasourceCardMenu in DatasourceEditor.json

* Fix issues
- Add Icon hover clickable control
- Auth API click handler

* Fix Createpage test command

* Add cypress test for generate page flow

* Fix cypress test

* Add Analytics

* Add comments in CloseEditor

* Rename initiator to isGeneratePageMode

* Disable S3 for generate CRUD page

* Fix generate page from existing datasource issue

* Enhance test to verify if data is fetched properly

* Wait for get Actions before execute actions

* Change the cypress route for excute api

Co-authored-by: Pranav Kanade <pranav@appsmith.com>
2021-07-29 13:43:10 +05:30

143 lines
3.8 KiB
TypeScript

import React, { forwardRef, ReactNode, Ref } from "react";
import { CommonComponentProps, Classes } from "./common";
import styled from "styled-components";
import Icon, { IconName, IconSize } from "./Icon";
import Text, { TextType, FontWeight } from "./Text";
import TooltipComponent from "components/ads/Tooltip";
import { Position } from "@blueprintjs/core/lib/esm/common/position";
export type MenuItemProps = CommonComponentProps & {
icon?: IconName;
text: string;
label?: ReactNode;
href?: string;
type?: "warning";
ellipsize?: number;
selected?: boolean;
onSelect?: () => void;
};
const ItemRow = styled.a<{ disabled?: boolean; selected?: boolean }>`
display: flex;
align-items: center;
justify-content: space-between;
text-decoration: none;
padding: 0px ${(props) => props.theme.spaces[6]}px;
background-color: ${(props) =>
props.selected ? props.theme.colors.menuItem.hoverBg : "transparent"};
.${Classes.TEXT} {
color: ${(props) =>
props.selected
? props.theme.colors.menuItem.hoverText
: props.theme.colors.menuItem.normalText};
}
.${Classes.ICON} {
svg {
path {
fill: ${(props) =>
props.selected
? props.theme.colors.menuItem.hoverIcon
: props.theme.colors.menuItem.normalIcon};
}
}
}
height: 38px;
${(props) =>
!props.disabled
? `
&:hover {
text-decoration: none;
cursor: pointer;
background-color: ${
props.type === "warning"
? props.theme.colors.menuItem.warning.bg
: props.theme.colors.menuItem.hoverBg
};
.${Classes.TEXT} {
color: ${
props.type === "warning"
? props.theme.colors.menuItem.warning.color
: props.theme.colors.menuItem.hoverText
};
}
.${Classes.ICON} {
path {
fill: ${
props.type === "warning"
? props.theme.colors.menuItem.warning.color
: props.theme.colors.menuItem.hoverIcon
};
}
}
}`
: `
&:hover {
text-decoration: none;
cursor: default;
}
`}
`;
const IconContainer = styled.span`
display: flex;
align-items: center;
.${Classes.ICON} {
margin-right: ${(props) => props.theme.spaces[5]}px;
}
`;
const MenuItem = forwardRef(
(props: MenuItemProps, ref: Ref<HTMLAnchorElement>) => {
return props.ellipsize && props.text.length > props.ellipsize ? (
<TooltipComponent content={props.text} position={Position.BOTTOM}>
<MenuItemContent ref={ref} {...props} />
</TooltipComponent>
) : (
<MenuItemContent ref={ref} {...props} />
);
},
);
const MenuItemContent = forwardRef(
(props: MenuItemProps, ref: Ref<HTMLAnchorElement>) => {
return (
<ItemRow
data-cy={props.cypressSelector}
disabled={props.disabled}
href={props.href}
onClick={props.onSelect}
ref={ref}
selected={props.selected}
type={props.type}
>
<IconContainer className={props.className}>
{props.icon ? (
<Icon
isLoading={props.isLoading}
loaderWithIconWrapper
name={props.icon}
size={IconSize.LARGE}
/>
) : null}
{props.text && (
<Text type={TextType.H5} weight={FontWeight.NORMAL}>
{props.ellipsize
? ellipsize(props.ellipsize, props.text)
: props.text}
</Text>
)}
</IconContainer>
{props.label ? props.label : null}
</ItemRow>
);
},
);
MenuItemContent.displayName = "MenuItemContent";
MenuItem.displayName = "MenuItem";
function ellipsize(length: number, text: string) {
return text.length > length ? text.slice(0, length).concat(" ...") : text;
}
export default MenuItem;