Skip to content

Commit

Permalink
Merge branch 'develop' into feature/theme-customisation
Browse files Browse the repository at this point in the history
* develop:
  add badge to UserMenu when update is available
  migrate all links to WIKI_LINKS
  add UpdateChecker
  default signInOptions to google if signInOptions doc is missing
  fix TableSettings multiSelects
  TextEditor: fix values not saving in react 17 (thanks @oliviertassinari ) mui/material-ui#25560 (comment) facebook/react#17925
  expose dataset location option for BQ spark
  • Loading branch information
notsidney committed Jul 12, 2021
2 parents cf5e3b6 + f6d5dfe commit 11b582a
Show file tree
Hide file tree
Showing 16 changed files with 221 additions and 45 deletions.
6 changes: 4 additions & 2 deletions ft_build/sparksLib/bigqueryIndex.ts
Expand Up @@ -163,7 +163,7 @@ const transformToSQLType = (ftType: string) => {
};

const bigqueryIndex = async (payload, sparkContext) => {
const { objectID, index, fieldsToSync, projectID } = payload;
const { objectID, index, fieldsToSync, projectID, datasetLocation } = payload;

const { triggerType, change, fieldTypes } = sparkContext;
const record = rowReducer(fieldsToSync, sparkContext.row);
Expand All @@ -178,7 +178,9 @@ const bigqueryIndex = async (payload, sparkContext) => {

// create dataset with exact name "firetable" if not exists
async function preprocessDataset() {
const dataset = bigquery.dataset("firetable");
const dataset = bigquery.dataset("firetable", {
location: datasetLocation ?? "US",
});
const res = await dataset.exists();
const exists = res[0];
if (!exists) {
Expand Down
2 changes: 1 addition & 1 deletion www/package.json
Expand Up @@ -4,7 +4,7 @@
"homepage": "https://firetable.io/",
"repository": {
"type": "git",
"url": "https://github.com/AntlerVC/firetable.git"
"url": "https://github.com/FiretableProject/firetable.git"
},
"private": true,
"dependencies": {
Expand Down
9 changes: 8 additions & 1 deletion www/src/components/Auth/FirebaseUi.tsx
Expand Up @@ -188,7 +188,14 @@ export default function FirebaseUi(props: Partial<FirebaseUiProps>) {
useEffect(() => {
db.doc("/_FIRETABLE_/publicSettings")
.get()
.then((doc) => setSignInOptions(doc?.get("signInOptions")))
.then((doc) => {
const options = doc?.get("signInOptions");
if (!options) {
setSignInOptions(["google"]);
} else {
setSignInOptions(options);
}
})
.catch(() => setSignInOptions(["google"]));
}, []);

Expand Down
154 changes: 154 additions & 0 deletions www/src/components/Navigation/UpdateChecker.tsx
@@ -0,0 +1,154 @@
import { useState, useEffect } from "react";
import createPersistedState from "use-persisted-state";
import { differenceInDays } from "date-fns";

import {
makeStyles,
createStyles,}from'@material-ui/styles'
import {
MenuItem,
ListItemText,
ListItemSecondaryAction,
Link,
} from "@material-ui/core";
import OpenInNewIcon from "@material-ui/icons/OpenInNew";

import meta from "../../../package.json";
import WIKI_LINKS from "constants/wikiLinks";

const useLastCheckedUpdateState = createPersistedState(
"_FT_LAST_CHECKED_UPDATE"
);
export const useLatestUpdateState = createPersistedState("_FT_LATEST_UPDATE");

const useStyles = makeStyles((theme) =>
createStyles({
secondaryAction: { pointerEvents: "none" },
secondaryIcon: {
display: "block",
color: theme.palette.action.active,
},

version: {
display: "block",
padding: theme.spacing(1, 2),
userSelect: "none",
color: theme.palette.text.disabled,
},
})
);

export default function UpdateChecker() {
const classes = useStyles();

const [
lastCheckedUpdate,
setLastCheckedUpdate,
] = useLastCheckedUpdateState<string>();
const [latestUpdate, setLatestUpdate] = useLatestUpdateState<null | Record<
string,
any
>>(null);

const [checkState, setCheckState] = useState<null | "LOADING" | "NO_UPDATE">(
null
);

const checkForUpdate = async () => {
setCheckState("LOADING");

// https://docs.github.com/en/rest/reference/repos#get-the-latest-release
const endpoint = meta.repository.url
.replace("github.com", "api.github.com/repos")
.replace(/.git$/, "/releases/latest");
try {
const res = await fetch(endpoint, {
headers: {
Accept: "application/vnd.github.v3+json",
},
});
const json = await res.json();

if (json.tag_name > "v" + meta.version) {
setLatestUpdate(json);
setCheckState(null);
} else {
setCheckState("NO_UPDATE");
}

setLastCheckedUpdate(new Date().toISOString());
} catch (e) {
console.error(e);
setLatestUpdate(null);
setCheckState("NO_UPDATE");
}
};

// Check for new updates on page load, if last check was more than 7 days ago
useEffect(() => {
if (!lastCheckedUpdate) checkForUpdate();
else if (differenceInDays(new Date(), new Date(lastCheckedUpdate)) > 7)
checkForUpdate();
}, [lastCheckedUpdate]);

// Verify latest update is not installed yet
useEffect(() => {
if (latestUpdate?.tag_name <= "v" + meta.version) setLatestUpdate(null);
}, [latestUpdate, setLatestUpdate]);

return (
<>
{checkState === "LOADING" ? (
<MenuItem disabled>Checking for updates…</MenuItem>
) : checkState === "NO_UPDATE" ? (
<MenuItem disabled>No updates available</MenuItem>
) : latestUpdate === null ? (
<MenuItem onClick={checkForUpdate}>Check for updates</MenuItem>
) : (
<>
<MenuItem
component="a"
href={latestUpdate?.html_url}
target="_blank"
rel="noopener"
>
<ListItemText
primary="Update available"
secondary={latestUpdate?.tag_name}
/>
<ListItemSecondaryAction className={classes.secondaryAction}>
<OpenInNewIcon className={classes.secondaryIcon} />
</ListItemSecondaryAction>
</MenuItem>

<MenuItem
component="a"
href={WIKI_LINKS.updatingFiretable}
target="_blank"
rel="noopener"
>
<ListItemText secondary="How to update Firetable" />
<ListItemSecondaryAction className={classes.secondaryAction}>
<OpenInNewIcon
color="secondary"
fontSize="small"
className={classes.secondaryIcon}
/>
</ListItemSecondaryAction>
</MenuItem>
</>
)}

<Link
variant="caption"
component="a"
href={meta.repository.url.replace(".git", "") + "/releases"}
target="_blank"
rel="noopener"
className={classes.version}
>
{meta.name} v{meta.version}
</Link>
</>
);
}
33 changes: 13 additions & 20 deletions www/src/components/Navigation/UserMenu.tsx
Expand Up @@ -7,22 +7,24 @@ import {
IconButtonProps,
Avatar,
Menu,
Link as MuiLink,
MenuItem,
ListItemAvatar,
ListItemText,
ListItemSecondaryAction,
ListItemIcon,
Divider,
Badge,
} from "@material-ui/core";
import AccountCircleIcon from "@material-ui/icons/AccountCircle";
import ArrowRightIcon from "@material-ui/icons/ArrowRight";
import CheckIcon from "@material-ui/icons/Check";

import UpdateChecker, { useLatestUpdateState } from "./UpdateChecker";
import { useAppContext } from "contexts/AppContext";
import routes from "constants/routes";
import meta from "../../../package.json";
import { projectId } from "../../firebase";
import meta from "../../../package.json";

const useStyles = makeStyles((theme) =>
createStyles({
spacer: {
Expand Down Expand Up @@ -54,13 +56,6 @@ const useStyles = makeStyles((theme) =>
theme.palette.background.paper,
marginTop: theme.spacing(-1),
},

version: {
display: "block",
padding: theme.spacing(1, 2),
userSelect: "none",
color: theme.palette.text.disabled,
},
})
);

Expand All @@ -70,6 +65,7 @@ export default function UserMenu(props: IconButtonProps) {
const anchorEl = useRef<HTMLButtonElement>(null);
const [open, setOpen] = useState(false);
const [themeSubMenu, setThemeSubMenu] = useState<EventTarget | null>(null);
const [latestUpdate] = useLatestUpdateState<null | Record<string, any>>();

const {
currentUser,
Expand Down Expand Up @@ -124,7 +120,13 @@ export default function UserMenu(props: IconButtonProps) {
onClick={() => setOpen(true)}
className={classes.iconButton}
>
{avatar}
{latestUpdate?.tag_name > "v" + meta.version ? (
<Badge color="primary" overlap="circular" variant="dot">
{avatar}
</Badge>
) : (
avatar
)}
</IconButton>

<Menu
Expand Down Expand Up @@ -212,16 +214,7 @@ export default function UserMenu(props: IconButtonProps) {

<Divider className={classes.divider} />

<MuiLink
variant="caption"
component="a"
href={meta.repository.url.replace(".git", "") + "/releases"}
target="_blank"
rel="noopener"
className={classes.version}
>
{meta.name} v{meta.version}
</MuiLink>
<UpdateChecker />
</Menu>
</>
);
Expand Down
2 changes: 1 addition & 1 deletion www/src/components/Navigation/index.tsx
Expand Up @@ -88,7 +88,7 @@ export default function Navigation({
<Breadcrumbs className={classes.breadcrumbs} />

<UserMenu />
{/* <Notifications/> */}
{/* <Notifications /> */}
</Toolbar>
</AppBar>

Expand Down
Expand Up @@ -16,6 +16,7 @@ import CodeEditorHelper from "components/CodeEditorHelper";
import CodeEditor from "components/Table/editors/CodeEditor";
import FormAutosave from "./FormAutosave";
import { FieldType } from "constants/fields";
import WIKI_LINKS from "constants/wikiLinks";

const useStyles = makeStyles((theme) =>
createStyles({
Expand Down Expand Up @@ -129,7 +130,7 @@ export default function DefaultValueInput({

{config.defaultValue?.type === "dynamic" && (
<>
<CodeEditorHelper docLink="https://github.com/FiretableProject/firetable/wiki/Default-Values" />
<CodeEditorHelper docLink={WIKI_LINKS.defaultValues} />
<div className={classes.codeEditorContainer}>
<CodeEditor
height={120}
Expand Down
4 changes: 2 additions & 2 deletions www/src/components/Table/ColumnMenu/FieldSettings/index.tsx
Expand Up @@ -22,6 +22,7 @@ import FormControlLabel from "@material-ui/core/FormControlLabel";
import Typography from "@material-ui/core/Typography";
import Divider from "@material-ui/core/Divider";
import Subheading from "components/Table/ColumnMenu/Subheading";
import WIKI_LINKS from "constants/wikiLinks";

export default function FieldSettings(props: IMenuModalProps) {
const {
Expand Down Expand Up @@ -166,8 +167,7 @@ export default function FieldSettings(props: IMenuModalProps) {
const ftBuildUrl = settingsDoc.get("ftBuildUrl");
if (!ftBuildUrl) {
snack.open({
message:
"Cloud Run trigger URL not configured. Configuration guide: https://github.com/FiretableProject/firetable/wiki/Setting-up-cloud-Run-FT-Builder",
message: `Cloud Run trigger URL not configured. Configuration guide: ${WIKI_LINKS.cloudRunFtBuilder}`,
variant: "error",
});
}
Expand Down
4 changes: 2 additions & 2 deletions www/src/components/Table/TableHeader/Sparks.tsx
Expand Up @@ -13,6 +13,7 @@ import { useFiretableContext } from "contexts/FiretableContext";
import { useAppContext } from "contexts/AppContext";
import { useSnackLogContext } from "contexts/SnackLogContext";
import CodeEditor from "../editors/CodeEditor";
import WIKI_LINKS from "constants/wikiLinks";

export default function SparksEditor() {
const snack = useSnackContext();
Expand Down Expand Up @@ -53,8 +54,7 @@ export default function SparksEditor() {
const ftBuildUrl = settingsDoc.get("ftBuildUrl");
if (!ftBuildUrl) {
snack.open({
message:
"Cloud Run trigger URL not configured. Configuration guide: https://github.com/FiretableProject/firetable/wiki/Setting-up-cloud-Run-FT-Builder",
message: `Cloud Run trigger URL not configured. Configuration guide: ${WIKI_LINKS.cloudRunFtBuilder}`,
variant: "error",
});
}
Expand Down
9 changes: 4 additions & 5 deletions www/src/components/Table/TableHeader/TableLogs.tsx
Expand Up @@ -35,6 +35,7 @@ import Ansi from "ansi-to-react";
import EmptyState from "components/EmptyState";

import PropTypes from "prop-types";
import WIKI_LINKS from "constants/wikiLinks";

function a11yProps(index) {
return {
Expand Down Expand Up @@ -487,17 +488,15 @@ export default function TableLogs() {
message="Need Configuration"
description={
<>
Cloud Run trigger URL not configured. Configuration guide:{" "}
Cloud Run trigger URL not configured.
<Link
href={
"https://github.com/FiretableProject/firetable/wiki/Setting-up-cloud-Run-FT-Builder"
}
href={WIKI_LINKS.cloudRunFtBuilder}
target="_blank"
rel="noopener noreferrer"
variant="body2"
underline="always"
>
https://github.com/FiretableProject/firetable/wiki/Setting-up-cloud-Run-FT-Builder
Configuration guide
</Link>
</>
}
Expand Down
4 changes: 2 additions & 2 deletions www/src/components/Table/editors/TextEditor.tsx
@@ -1,4 +1,4 @@
import { useRef, useEffect } from "react";
import { useRef, useLayoutEffect } from "react";
import { EditorProps } from "react-data-grid";

import { makeStyles, createStyles } from "@material-ui/styles";
Expand Down Expand Up @@ -48,7 +48,7 @@ export default function TextEditor({ row, column }: EditorProps<any>) {

const inputRef = useRef<HTMLInputElement>(null);

useEffect(() => {
useLayoutEffect(() => {
return () => {
const newValue = inputRef.current?.value;
if (newValue !== undefined && updateCell) {
Expand Down

0 comments on commit 11b582a

Please sign in to comment.