Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Co-authored-by: Soroush <[email protected]>
Co-authored-by: Andy Brown <[email protected]>
  • Loading branch information
3 people authored Jun 2, 2021
1 parent 2cdbbe9 commit bf6b731
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { FieldProps } from '@bfc/extension-client';
import { FieldProps, useShellApi } from '@bfc/extension-client';
import { Intellisense } from '@bfc/intellisense';
import React, { useRef, useState } from 'react';

Expand All @@ -18,6 +18,8 @@ const noop = () => {};
export const IntellisenseTextField: React.FC<FieldProps<string>> = (props) => {
const { id, value = '', onChange, uiOptions, focused: defaultFocused } = props;

const { projectId } = useShellApi();

const completionListOverrideResolver = (value: string) => {
return value === '' ? <ExpressionSwitchWindow kind={'String'} onSwitchToExpression={() => onChange('=')} /> : null;
};
Expand All @@ -30,6 +32,7 @@ export const IntellisenseTextField: React.FC<FieldProps<string>> = (props) => {
completionListOverrideResolver={completionListOverrideResolver}
focused={defaultFocused}
id={`intellisense-${id}`}
projectId={projectId}
scopes={scopes}
url={intellisenseServerUrlRef.current}
value={value}
Expand Down Expand Up @@ -65,6 +68,8 @@ export const IntellisenseTextField: React.FC<FieldProps<string>> = (props) => {
export const IntellisenseExpressionField: React.FC<FieldProps<string>> = (props) => {
const { id, value = '', onChange, focused: defaultFocused } = props;

const { projectId } = useShellApi();

const scopes = ['expressions', 'user-variables'];
const intellisenseServerUrlRef = useRef(getIntellisenseUrl());

Expand All @@ -89,6 +94,7 @@ export const IntellisenseExpressionField: React.FC<FieldProps<string>> = (props)
<Intellisense
focused={defaultFocused}
id={`intellisense-${id}`}
projectId={projectId}
scopes={scopes}
url={intellisenseServerUrlRef.current}
value={value}
Expand Down Expand Up @@ -134,6 +140,8 @@ export const IntellisenseExpressionField: React.FC<FieldProps<string>> = (props)
export const IntellisenseNumberField: React.FC<FieldProps<string>> = (props) => {
const { id, value = '', onChange, uiOptions, focused: defaultFocused } = props;

const { projectId } = useShellApi();

const completionListOverrideResolver = (value: string) => {
return value === '' ? <ExpressionSwitchWindow kind={'Number'} onSwitchToExpression={() => onChange('=')} /> : null;
};
Expand All @@ -146,6 +154,7 @@ export const IntellisenseNumberField: React.FC<FieldProps<string>> = (props) =>
completionListOverrideResolver={completionListOverrideResolver}
focused={defaultFocused}
id={`intellisense-${id}`}
projectId={projectId}
scopes={scopes}
url={intellisenseServerUrlRef.current}
value={value}
Expand All @@ -172,6 +181,8 @@ export const IntellisenseNumberField: React.FC<FieldProps<string>> = (props) =>
export const IntellisenseJSONField: React.FC<FieldProps<string>> = (props) => {
const { id, value = '', onChange, focused: defaultFocused, schema } = props;

const { projectId } = useShellApi();

const completionListOverrideResolver = (value: any) => {
if (typeof value === 'object' && Object.keys(value).length === 0) {
return (
Expand Down Expand Up @@ -204,6 +215,7 @@ export const IntellisenseJSONField: React.FC<FieldProps<string>> = (props) => {
completionListOverrideResolver={completionListOverrideResolver}
focused={defaultFocused}
id={`intellisense-${id}`}
projectId={projectId}
scopes={scopes}
url={intellisenseServerUrlRef.current}
value={value || defaultValue}
Expand Down

0 comments on commit bf6b731

Please sign in to comment.