Merge branch 'develop' of https://github.com/rowyio/rowy into develop

This commit is contained in:
Sidney Alcantara
2021-12-14 22:55:23 +11:00
12 changed files with 83 additions and 44 deletions

View File

@@ -20,4 +20,13 @@ declare namespace rowy {
* Gets the secret defined in Google Cloud Secret
*/
async function getSecret(name: string, v?: string): Promise<string | null>;
async function getServiceAccountUser(): Promise<{
email: string;
emailVerified: boolean;
displayName: string;
photoURL: string;
uid: string;
timestamp: number;
}>;
}

View File

@@ -112,7 +112,6 @@ export default function DraggableHeaderRenderer<R>({
onColumnsReorder: (sourceKey: string, targetKey: string) => void;
}) {
const classes = useStyles();
const { userClaims } = useAppContext();
const { tableState, tableActions, columnMenuRef } = useProjectContext();
const [{ isDragging }, drag] = useDrag({
@@ -149,16 +148,18 @@ export default function DraggableHeaderRenderer<R>({
anchorEl: buttonRef.current,
});
};
const _sortKey = getFieldProp("sortKey", (column as any).type);
const sortKey = _sortKey ? `${column.key}.${_sortKey}` : column.key;
const isSorted = orderBy?.[0]?.key === column.key;
const isSorted = orderBy?.[0]?.key === sortKey;
const isAsc = isSorted && orderBy?.[0]?.direction === "asc";
const isDesc = isSorted && orderBy?.[0]?.direction === "desc";
const handleSortClick = () => {
let ordering: TableOrder = [];
if (!isSorted) ordering = [{ key: column.key, direction: "desc" }];
else if (isDesc) ordering = [{ key: column.key, direction: "asc" }];
if (!isSorted) ordering = [{ key: sortKey, direction: "desc" }];
else if (isDesc) ordering = [{ key: sortKey, direction: "asc" }];
else ordering = [];
tableActions.table.orderBy(ordering);

View File

@@ -114,8 +114,9 @@ export default function ColumnMenu() {
);
if (!column) return null;
const isSorted = orderBy?.[0]?.key === column.key;
const _sortKey = getFieldProp("sortKey", (column as any).type);
const sortKey = _sortKey ? `${column.key}.${_sortKey}` : column.key;
const isSorted = orderBy?.[0]?.key === sortKey;
const isAsc = isSorted && orderBy?.[0]?.direction === "asc";
const clearModal = () => {
@@ -172,7 +173,7 @@ export default function ColumnMenu() {
icon: <ArrowDownwardIcon />,
onClick: () => {
tableActions.table.orderBy(
isSorted && !isAsc ? [] : [{ key: column.key, direction: "desc" }]
isSorted && !isAsc ? [] : [{ key: sortKey, direction: "desc" }]
);
handleClose();
},
@@ -185,7 +186,7 @@ export default function ColumnMenu() {
icon: <ArrowUpwardIcon />,
onClick: () => {
tableActions.table.orderBy(
isSorted && isAsc ? [] : [{ key: column.key, direction: "asc" }]
isSorted && isAsc ? [] : [{ key: sortKey, direction: "asc" }]
);
handleClose();
},

View File

@@ -44,20 +44,36 @@ export const webhookBasic = {
parser: {
additionalVariables,
extraLibs: parserExtraLibs,
template: `const basicParser: Parser = async({req, db,ref}) => {
template: (table) => `const basicParser: Parser = async({req, db,ref}) => {
// request is the request object from the webhook
// db is the database object
// ref is the reference to collection of the table
// the returned object will be added as a new row to the table
// eg: adding the webhook body as row
const {body} = req;
${
table.audit !== false
? `
// auditField
const ${
table.auditFieldCreatedBy ?? "_createdBy"
} = await rowy.getServiceAccountUser()
return {
...body,
${table.auditFieldCreatedBy ?? "_createdBy"}
}
`
: `
return body;
`
}
}`,
},
condition: {
additionalVariables,
extraLibs: conditionExtraLibs,
template: `const condition: Condition = async({ref,req,db}) => {
template: (table) => `const condition: Condition = async({ref,req,db}) => {
// feel free to add your own code logic here
return true;
}`,

View File

@@ -6,8 +6,13 @@ export const webhookSendgrid = {
parser: {
additionalVariables: null,
extraLibs: null,
template: `const sendgridParser: Parser = async({req, db,ref}) =>{
template: (
table
) => `const sendgridParser: Parser = async({req, db,ref}) =>{
// sendgrid webhook events docs : https://docs.sendgrid.com/for-developers/tracking-events/event#event-objects
// sengrid sends request body with an array of events
// eg:
// {
// "email": "example@test.com",
// "timestamp": 1513299569,
@@ -24,7 +29,7 @@ export const webhookSendgrid = {
condition: {
additionalVariables: null,
extraLibs: null,
template: `const condition: Condition = async({ref,req,db}) => {
template: (table) => `const condition: Condition = async({ref,req,db}) => {
// feel free to add your own code logic here
return true;
}`,

View File

@@ -6,15 +6,16 @@ export const webhookTypeform = {
parser: {
additionalVariables: null,
extraLibs: null,
template: `const typeformParser: Parser = async({req, db,ref}) =>{
template: (
table
) => `const typeformParser: Parser = async({req, db,ref}) =>{
// this reduces the form submission into a single object of key value pairs
// eg: {name: "John", age: 20}
// ⚠️ ensure that you have assigned ref values of the fields
// set the ref value to field key you would like to sync to
// docs: https://help.typeform.com/hc/en-us/articles/360050447552-Block-reference-format-restrictions
const {submitted_at,hidden,answers} = req.body.form_response
return ({
const submission = ({
_createdAt: submitted_at,
...hidden,
...answers.reduce((accRow, currAnswer) => {
@@ -42,12 +43,30 @@ export const webhookTypeform = {
};
}
}, {}),
})};`,
})
${
table.audit !== false
? `
// auditField
const ${
table.auditFieldCreatedBy ?? "_createdBy"
} = await rowy.getServiceAccountUser()
return {
...submission,
${table.auditFieldCreatedBy ?? "_createdBy"}
}
`
: `
return submission
`
}
};`,
},
condition: {
additionalVariables: null,
extraLibs: null,
template: `const condition: Condition = async({ref,req,db}) => {
template: (table) => `const condition: Condition = async({ref,req,db}) => {
// feel free to add your own code logic here
return true;
}`,

View File

@@ -20,7 +20,7 @@ import { useSnackbar } from "notistack";
import { modalAtom } from "@src/atoms/Table";
export default function Webhooks() {
const { tableState, tableActions, rowyRun, compatibleRowyRunVersion } =
const { tableState, table, tableActions, rowyRun, compatibleRowyRunVersion } =
useProjectContext();
const appContext = useAppContext();
const { requestConfirmation } = useConfirmation();
@@ -189,7 +189,11 @@ export default function Webhooks() {
handleAddWebhook={(type: WebhookType) => {
setWebhookModal({
mode: "add",
webhookObject: emptyWebhookObject(type, currentEditor()),
webhookObject: emptyWebhookObject(
type,
currentEditor(),
table
),
});
}}
variant={

View File

@@ -76,19 +76,16 @@ export const webhookSchemas = {
export function emptyWebhookObject(
type: WebhookType,
user: IWebhookEditor
user: IWebhookEditor,
table
): IWebhook {
return {
name: "Untitled webhook",
name: `${type} webhook`,
active: false,
endpoint: generateRandomId(),
type,
parser:
webhookSchemas[type].parser?.template ??
webhookSchemas["basic"].parser.template,
conditions:
webhookSchemas[type].condition?.template ??
webhookSchemas["basic"].condition.template,
parser: webhookSchemas[type].parser?.template(table),
conditions: webhookSchemas[type].condition?.template(table),
lastEditor: user,
};
}

View File

@@ -3,10 +3,6 @@ import _get from "lodash/get";
import stringify from "json-stable-stringify-without-jsonify";
import {
Stepper,
Step,
StepButton,
StepContent,
Stack,
Grid,
TextField,
@@ -22,7 +18,6 @@ import {
FormHelperText,
Fab,
} from "@mui/material";
import ExpandIcon from "@mui/icons-material/KeyboardArrowDown";
import RunIcon from "@mui/icons-material/PlayArrow";
import RedoIcon from "@mui/icons-material/Refresh";
import UndoIcon from "@mui/icons-material/Undo";
@@ -66,17 +61,6 @@ const Settings = ({ config, onChange }) => {
const [codeValid, setCodeValid] = useState(true);
const scriptExtraLibs = [
[
"declare class ref {",
" /**",
" * Reference object of the row running the action script",
" */",
"static id:string",
"static path:string",
"static parentId:string",
"static tablePath:string",
"}",
].join("\n"),
[
"declare class actionParams {",
" /**",

View File

@@ -30,5 +30,6 @@ export const config: IFieldConfig = {
SideDrawerField,
settings: Settings,
requireConfiguration: true,
sortKey: "status",
};
export default config;

View File

@@ -28,6 +28,7 @@ export interface IFieldConfig {
defaultValue?: any;
valueFormatter?: (value: any) => string;
};
sortKey?: string;
csvExportFormatter?: (value: any, config?: any) => string;
csvImportParser?: (value: string, config?: any) => any;
}

View File

@@ -36,6 +36,7 @@ const WIKI_PATHS = {
fieldTypesSupportedFields: "/field-types/supported-fields",
fieldTypesDerivative: "/field-types/derivative",
fieldTypesConnectTable: "/field-types/connect-table",
fieldTypesConnectService: "/field-types/connect-service",
fieldTypesAction: "/field-types/action",
fieldTypesAdd: "/field-types/add",