Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions app/client/src/actions/datasourceActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,20 +199,20 @@ export const getOAuthAccessToken = (datasourceId: string) => {
};
};

export type executeDatasourceQuerySuccessPayload = {
export type executeDatasourceQuerySuccessPayload<T> = {
responseMeta: ResponseMeta;
data: {
body: Array<{ id: string; name: string }>;
body: T;
headers: Record<string, string[]>;
statusCode: string;
isExecutionSuccess: boolean;
};
};
type errorPayload = unknown;

export type executeDatasourceQueryReduxAction = ReduxActionWithCallbacks<
export type executeDatasourceQueryReduxAction<T> = ReduxActionWithCallbacks<
executeDatasourceQueryRequest,
executeDatasourceQuerySuccessPayload,
executeDatasourceQuerySuccessPayload<T>,
errorPayload
>;

Expand All @@ -222,9 +222,11 @@ export const executeDatasourceQuery = ({
payload,
}: {
onErrorCallback?: (payload: errorPayload) => void;
onSuccessCallback?: (payload: executeDatasourceQuerySuccessPayload) => void;
onSuccessCallback?: (
payload: executeDatasourceQuerySuccessPayload<any>,
) => void;
payload: executeDatasourceQueryRequest;
}): executeDatasourceQueryReduxAction => {
}): executeDatasourceQueryReduxAction<any> => {
return {
type: ReduxActionTypes.EXECUTE_DATASOURCE_QUERY_INIT,
payload,
Expand Down
2 changes: 1 addition & 1 deletion app/client/src/api/DatasourcesApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface EmbeddedRestDatasourceRequest {
pluginId: string;
}

type executeQueryData = Array<{ key: string; value?: string }>;
type executeQueryData = Array<{ key?: string; value?: string }>;

export interface executeDatasourceQueryRequest {
datasourceId: string;
Expand Down
22 changes: 20 additions & 2 deletions app/client/src/components/ads/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export type DropdownProps = CommonComponentProps &
renderOption?: RenderOption;
isLoading?: boolean;
errorMsg?: string; // If errorMsg is defined, we show dropDown's error state with the message.
helperText?: string;
};
export interface DefaultDropDownValueNodeProps {
selected: DropdownOption;
Expand Down Expand Up @@ -307,14 +308,20 @@ const SelectedIcon = styled(Icon)`
const ErrorMsg = styled.span`
${(props) => getTypographyByKey(props, "p3")};
color: ${Colors.POMEGRANATE2};
margin: 6px 0px 10px;
margin-top: 8px;
`;

const ErrorLabel = styled.span`
${(props) => getTypographyByKey(props, "p1")};
color: ${Colors.POMEGRANATE2};
`;

const HelperText = styled.span`
${(props) => getTypographyByKey(props, "p3")};
color: ${Colors.GRAY};
margin-top: 8px;
`;

function DefaultDropDownValueNode({
errorMsg,
renderNode,
Expand Down Expand Up @@ -450,12 +457,20 @@ export default function Dropdown(props: DropdownProps) {
SelectedValueNode = DefaultDropDownValueNode,
renderOption,
errorMsg = "",
helperText = "",
} = { ...props };
const [isOpen, setIsOpen] = useState<boolean>(false);
const [selected, setSelected] = useState<DropdownOption>(props.selected);

const closeIfOpen = () => {
if (isOpen) {
setIsOpen(false);
}
};

useEffect(() => {
setSelected(props.selected);
closeIfOpen();
}, [props.selected]);

const optionClickHandler = useCallback(
Expand All @@ -469,7 +484,7 @@ export default function Dropdown(props: DropdownProps) {
);

const disabled = props.disabled || isLoading || !!errorMsg;
const downIconColor = errorMsg ? Colors.POMEGRANATE2 : "";
const downIconColor = errorMsg ? Colors.POMEGRANATE2 : Colors.DARK_GRAY;

const dropdownTrigger = props.dropdownTriggerIcon ? (
<DropdownTriggerWrapper
Expand Down Expand Up @@ -511,6 +526,9 @@ export default function Dropdown(props: DropdownProps) {
)}
</Selected>
{errorMsg && <ErrorMsg>{errorMsg}</ErrorMsg>}
{helperText && !isOpen && !errorMsg && (
<HelperText>{helperText}</HelperText>
)}
</DropdownSelect>
);
return (
Expand Down
Loading