Skip to content

Commit 13abd1d

Browse files
authored
Merge pull request #118 from buddypia/feature/toggle-show-keys-button
Feature/toggle show keys button. If the deployment decides to disable show keys, then there is no option to show keys in the frontend.
2 parents 1585d77 + feba29d commit 13abd1d

File tree

5 files changed

+37
-5
lines changed

5 files changed

+37
-5
lines changed

.env.template

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Provide frontend configuration settings from environment variables
2+
SHOW_KEYS_ENABLED=true

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

2+
*env
23
*api-keys.env
34
**/*.ipynb_checkpoints/
4-
55
.DS_Store
66
build/
77
dist/

py-src/data_formulator/app.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
# Load the single environment file
5454
load_dotenv(os.path.join(APP_ROOT, "..", "..", 'api-keys.env'))
5555
load_dotenv(os.path.join(APP_ROOT, 'api-keys.env'))
56+
load_dotenv(os.path.join(APP_ROOT, '.env'))
5657

5758
# Configure root logger for general application logging
5859
logging.basicConfig(
@@ -539,6 +540,13 @@ def request_code_expl():
539540
expl = ""
540541
return expl
541542

543+
@app.route('/app-config', methods=['GET'])
544+
def get_app_config():
545+
"""Provide frontend configuration settings from environment variables"""
546+
config = {
547+
"SHOW_KEYS_ENABLED": os.getenv("SHOW_KEYS_ENABLED", "true").lower() == "true"
548+
}
549+
return flask.jsonify(config)
542550

543551
def parse_args() -> argparse.Namespace:
544552
parser = argparse.ArgumentParser(description="Data Formulator")

src/app/utils.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ export function getUrls() {
4949
VEGA_DATASET_LIST: `${appConfig.serverUrl}/vega-datasets`,
5050
VEGA_DATASET_REQUEST_PREFIX: `${appConfig.serverUrl}/vega-dataset/`,
5151

52+
APP_CONFIG: `${appConfig.serverUrl}/app-config`,
53+
5254
AUTH_INFO_PREFIX: `${appConfig.serverUrl}/.auth/`
5355
};
5456
}

src/views/ModelSelectionDialog.tsx

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ import HelpOutlineIcon from '@mui/icons-material/HelpOutline';
5454

5555
import { getUrls } from '../app/utils';
5656

57+
// Add interface for app configuration
58+
interface AppConfig {
59+
SHOW_KEYS_ENABLED: boolean;
60+
}
61+
5762
export const GroupHeader = styled('div')(({ theme }) => ({
5863
position: 'sticky',
5964
padding: '8px 8px',
@@ -76,6 +81,19 @@ export const ModelSelectionButton: React.FC<{}> = ({ }) => {
7681
const [modelDialogOpen, setModelDialogOpen] = useState<boolean>(false);
7782
const [showKeys, setShowKeys] = useState<boolean>(false);
7883
const [tempSelectedModelId, setTempSelectedModeId] = useState<string | undefined >(selectedModelId);
84+
const [appConfig, setAppConfig] = useState<AppConfig>({ SHOW_KEYS_ENABLED: true });
85+
86+
// Fetch app configuration
87+
useEffect(() => {
88+
fetch(getUrls().APP_CONFIG)
89+
.then(response => response.json())
90+
.then(data => {
91+
setAppConfig(data);
92+
})
93+
.catch(error => {
94+
console.error("Failed to fetch app configuration:", error);
95+
});
96+
}, []);
7997

8098
let updateModelStatus = (model: ModelConfig, status: 'ok' | 'error' | 'testing' | 'unknown', message: string) => {
8199
dispatch(dfActions.updateModelStatus({id: model.id, status, message}));
@@ -454,10 +472,12 @@ export const ModelSelectionButton: React.FC<{}> = ({ }) => {
454472
{modelTable}
455473
</DialogContent>
456474
<DialogActions>
457-
<Button sx={{marginRight: 'auto'}} endIcon={showKeys ? <VisibilityOffIcon /> : <VisibilityIcon />} onClick={()=>{
458-
setShowKeys(!showKeys);}}>
459-
{showKeys ? 'hide' : 'show'} keys
460-
</Button>
475+
{appConfig.SHOW_KEYS_ENABLED && (
476+
<Button sx={{marginRight: 'auto'}} endIcon={showKeys ? <VisibilityOffIcon /> : <VisibilityIcon />} onClick={()=>{
477+
setShowKeys(!showKeys);}}>
478+
{showKeys ? 'hide' : 'show'} keys
479+
</Button>
480+
)}
461481
<Button disabled={getStatus(tempSelectedModelId) !== 'ok'}
462482
variant={(selectedModelId == tempSelectedModelId) ? 'text' : 'contained'}
463483
onClick={()=>{

0 commit comments

Comments
 (0)