Skip to content

Commit

Permalink
feat: add code snippets to your files teams folders (#2817)
Browse files Browse the repository at this point in the history
* feat: add code snippets to your files teams folders

* feat: add built js
  • Loading branch information
niross authored Oct 20, 2023
1 parent 8d1634e commit 85640cf
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 44 deletions.
9 changes: 8 additions & 1 deletion dataworkspace/dataworkspace/apps/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1489,7 +1489,14 @@ def get_user_s3_prefixes(user):


def get_team_prefixes(user):
return [f'teams/{x["schema_name"]}/' for x in get_team_schemas_for_user(user)]
return [
{
"name": x["name"],
"env_var": f"S3_PREFIX_TEAM_{clean_db_identifier(x['name']).upper()}",
"prefix": f'teams/{x["schema_name"]}/',
}
for x in get_team_schemas_for_user(user)
]


def update_user_tool_access_policy(user, access_point_id):
Expand Down

This file was deleted.

Large diffs are not rendered by default.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { getBreadcrumbs, getFolderName } from "./utils";
import { AddFolderPopup, UploadFilesPopup } from "./popups";
import { DeleteObjectsPopup } from "./popups/DeleteObjects";
import { ErrorModal } from "./popups/ErrorModal";
import { TeamsPrefixMessage } from "./TeamsPrefixMessage";

const popupTypes = {
ADD_FOLDER: "addFolder",
Expand Down Expand Up @@ -251,8 +252,8 @@ export default class App extends React.Component {

const teamsFolders =
params.Prefix === rootPrefix
? this.props.config.teamsPrefixes.map((prefix) => ({
Prefix: prefix,
? this.props.config.teamsPrefixes.map((team) => ({
Prefix: team.prefix,
isSharedFolder: true,
isSelected: false,
}))
Expand Down Expand Up @@ -501,6 +502,11 @@ export default class App extends React.Component {
bucketName={this.state.bucketName}
/>
) : null}
{this.state.currentPrefix.startsWith("teams/") ?
<TeamsPrefixMessage
team={this.props.config.teamsPrefixes.find(t => this.state.currentPrefix.startsWith(t.prefix))}
bucketName={this.state.bucketName}
/> : null}
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React from "react";
export function TeamsPrefixMessage({ team, bucketName }) {
const relativePath = team.prefix.replace(/^teams/, '');
return (
<div className="govuk-inset-text">
<p className="govuk-body">
Files in the <code>{relativePath}</code> folder are not
automatically accessible from your tools in the same way other files
are. However, they can be manually accessed. For example, after
uploading a file <code>{relativePath}file.csv</code>, you can
create a Pandas DataFrame in a JupyterLab Python notebook by running the
following code.
</p>
<code>
<pre>
{`import os
import pandas as pd
import boto3
client = boto3.client('s3', region_name='eu-west-2')
response = client.get_object(
Bucket='${bucketName}',
Key=os.environ['${team.env_var}'] + 'file.csv' )
df = pd.read_csv(response['Body'])
`}
</pre>
</code>
<p className="govuk-body govuk-!-margin-top-2">
You can also create a tibble from this file in R by running the
following code.
</p>

<code>
<pre>{`library("aws.s3")
library("readr")
filename <- "file.csv"
conn = s3connection(paste(c(
"s3://${bucketName}/",
Sys.getenv("${team.env_var}"), filename),
collapse=""
))
tb = read_csv(conn)
close(conn)
`}</pre>
</code>
</div>
)
}
44 changes: 9 additions & 35 deletions dataworkspace/dataworkspace/static/js/stats/react_apps-stats.json
Original file line number Diff line number Diff line change
@@ -1,46 +1,20 @@
{
"status": "done",
"assets": {
"builder.58dd439c3a0d51aa7543.js.LICENSE.txt": {
"name": "builder.58dd439c3a0d51aa7543.js.LICENSE.txt",
"path": "builder.58dd439c3a0d51aa7543.js.LICENSE.txt",
"publicPath": "/__django_static/js/bundles/builder.58dd439c3a0d51aa7543.js.LICENSE.txt"
"yourfiles.70fed0402f7640f5dcc1.js": {
"name": "yourfiles.70fed0402f7640f5dcc1.js",
"path": "yourfiles.70fed0402f7640f5dcc1.js",
"publicPath": "/__django_static/js/bundles/yourfiles.70fed0402f7640f5dcc1.js"
},
"viewer.08734df7339e28c342cc.js.LICENSE.txt": {
"name": "viewer.08734df7339e28c342cc.js.LICENSE.txt",
"path": "viewer.08734df7339e28c342cc.js.LICENSE.txt",
"publicPath": "/__django_static/js/bundles/viewer.08734df7339e28c342cc.js.LICENSE.txt"
},
"yourfiles.c93bfed2dd8a9c6f4718.js.LICENSE.txt": {
"name": "yourfiles.c93bfed2dd8a9c6f4718.js.LICENSE.txt",
"path": "yourfiles.c93bfed2dd8a9c6f4718.js.LICENSE.txt",
"publicPath": "/__django_static/js/bundles/yourfiles.c93bfed2dd8a9c6f4718.js.LICENSE.txt"
},
"builder.58dd439c3a0d51aa7543.js": {
"name": "builder.58dd439c3a0d51aa7543.js",
"path": "builder.58dd439c3a0d51aa7543.js",
"publicPath": "/__django_static/js/bundles/builder.58dd439c3a0d51aa7543.js"
},
"viewer.08734df7339e28c342cc.js": {
"name": "viewer.08734df7339e28c342cc.js",
"path": "viewer.08734df7339e28c342cc.js",
"publicPath": "/__django_static/js/bundles/viewer.08734df7339e28c342cc.js"
},
"yourfiles.c93bfed2dd8a9c6f4718.js": {
"name": "yourfiles.c93bfed2dd8a9c6f4718.js",
"path": "yourfiles.c93bfed2dd8a9c6f4718.js",
"publicPath": "/__django_static/js/bundles/yourfiles.c93bfed2dd8a9c6f4718.js"
"yourfiles.70fed0402f7640f5dcc1.js.LICENSE.txt": {
"name": "yourfiles.70fed0402f7640f5dcc1.js.LICENSE.txt",
"path": "yourfiles.70fed0402f7640f5dcc1.js.LICENSE.txt",
"publicPath": "/__django_static/js/bundles/yourfiles.70fed0402f7640f5dcc1.js.LICENSE.txt"
}
},
"chunks": {
"builder": [
"builder.58dd439c3a0d51aa7543.js"
],
"viewer": [
"viewer.08734df7339e28c342cc.js"
],
"yourfiles": [
"yourfiles.c93bfed2dd8a9c6f4718.js"
"yourfiles.70fed0402f7640f5dcc1.js"
]
},
"publicPath": "/__django_static/js/bundles/"
Expand Down

0 comments on commit 85640cf

Please sign in to comment.