Skip to content

Commit

Permalink
📝 docs(database-links): complete the docs
Browse files Browse the repository at this point in the history
  • Loading branch information
thrownullexception committed Feb 11, 2024
1 parent 8caca5f commit 222ced5
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 48 deletions.
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dashpress",
"version": "1.0.1",
"version": "1.0.2",
"license": "GPL-3.0-or-later",
"scripts": {
"dev": "next dev",
Expand All @@ -23,7 +23,13 @@
"build-storybook": "build-storybook",
"prepare": "husky install"
},
"files": [".next", "dist", "bin", "public", ".env.example"],
"files": [
".next",
"dist",
"bin",
"public",
".env.example"
],
"bin": "./bin/dashpress",
"dependencies": {
"@dashpress/bacteria": "^0.0.11",
Expand Down
9 changes: 0 additions & 9 deletions src/__tests__/account/logout.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@ setupApiHandlers();
jest.mock("next/router", () => require("next-router-mock"));

describe("pages/account/logout", () => {
const useRouter = jest.spyOn(require("next/router"), "useRouter");
const replaceMock = jest.fn();

useRouter.mockImplementation(() => ({
push: replaceMock,
asPath: "/",
isReady: true,
}));

it("should log user out", async () => {
render(
<ApplicationRoot>
Expand Down
13 changes: 2 additions & 11 deletions src/frontend/docs/form-integrations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { INTEGRATIONS_GROUP_CONFIG } from "shared/config-bag/integrations";
import { FORM_ACTION_CRUD_CONFIG } from "frontend/views/entity/Actions/constants";
import { ErrorAlert, InfoAlert } from "frontend/design-system/components/Alert";
import { RenderCode } from "frontend/design-system/components/RenderCode";
import { TextButton } from "frontend/design-system/components/Button/TextButton";
import { NAVIGATION_LINKS } from "frontend/lib/routing/links";
import { DocumentationRoot } from "./_base";

export function FormIntegrationsDocumentation() {
Expand Down Expand Up @@ -79,17 +77,10 @@ export function FormIntegrationsDocumentation() {
</code>
</li>
<li>
Current User - through the auth object - if you have{" "}
<TextButton
onClick={() => {
window.open(NAVIGATION_LINKS.USERS.LINK_DATABASE, "_blank");
}}
>
linked your database users.
</TextButton>
Current User -
<code>
{" "}
{"{{"} auth. {"}}"}{" "}
{"{{"} auth.field {"}}"}{" "}
</code>
</li>
</ol>
Expand Down
11 changes: 1 addition & 10 deletions src/frontend/docs/scripts/form-scripts.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { RenderCode } from "frontend/design-system/components/RenderCode";
import { Spacer } from "frontend/design-system/primitives/Spacer";
import { TextButton } from "frontend/design-system/components/Button/TextButton";
import { NAVIGATION_LINKS } from "frontend/lib/routing/links";
import { DocumentationRoot } from "../_base";

export function FormScriptDocumentation() {
Expand Down Expand Up @@ -33,14 +31,7 @@ export function FormScriptDocumentation() {
<b>
<code>$.auth</code>
</b>
: The current user information from your database if you have{" "}
<TextButton
onClick={() => {
window.open(NAVIGATION_LINKS.USERS.LINK_DATABASE, "_blank");
}}
>
linked your database users.
</TextButton>
: The current user details
</li>
</ul>
</p>
Expand Down
7 changes: 7 additions & 0 deletions src/frontend/docs/users-link-to-database.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ export function UsersLinkToDatabaseDocumentation() {
operations on your user table. All our operations are read-only. All we
need to link the users are saved on our configuration.
</p>
<p>
Linking also doesn&apos;t make any changes to the UI, it doesn&apos;t
add any new column to the DashPress users table or the user details
page. It only affects the scripts in the application. So you will still
manage your users details from your users&apos; entity page like the
other entities.
</p>
<p>
After you link your users, all scripts in the application will be
injected the <code>$.auth</code> variable will have the user details
Expand Down
3 changes: 2 additions & 1 deletion src/frontend/views/data/evaluatePresentationScript.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { evalJavascriptStringSafely } from "shared/lib/script-runner";
import { IEvaluateScriptContext } from "shared/types/forms";

export type IPresentationScriptParams = {
row: Record<string, unknown>;
value: unknown;
field: string;
from: "details" | "table";
};
} & IEvaluateScriptContext;

export const evalutePresentationScript = (
script: string,
Expand Down
6 changes: 4 additions & 2 deletions src/frontend/views/entity/Form/ScriptForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { MAKE_APP_CONFIGURATION_CRUD_CONFIG } from "frontend/hooks/configuration
import { AppConfigurationKeys } from "shared/configurations";
import { evalJavascriptString } from "shared/lib/script-runner";
import { useEvaluateScriptContext } from "frontend/hooks/scripts";
import { ISchemaFormScriptProps } from "shared/form-schemas/types";

interface IProps {
value: string;
Expand Down Expand Up @@ -51,11 +52,12 @@ export function ScriptForm({
onSubmit={async (data) => {
try {
const jsString = data[`${BASE_SUFFIX}${field}`] as string;
evalJavascriptString(jsString, {
const context: ISchemaFormScriptProps<{}> = {
...evaluateScriptContext,
action: "test",
formValues: {},
});
};
evalJavascriptString(jsString, context);
await onSubmit(jsString);
} catch (e) {
ToastService.error(`•Expression: \n•JS-Error: ${e}`);
Expand Down
1 change: 1 addition & 0 deletions src/frontend/views/entity/PersistentQuery/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export function EntityPersistentQueryForm({
const columns = tableColumns.filter(
({ accessor, filter }) => ACTIONS_ACCESSOR !== accessor && filter
);

return (
<Form
onSubmit={onSubmit}
Expand Down
1 change: 0 additions & 1 deletion src/frontend/views/entity/PersistentQuery/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export const FILTER_OPERATOR_CONFIG: Record<
numberOfInput: 1,
placeholder: "Comma seperated values",
},
//
[FilterOperators.BETWEEN]: {
label: "N/A",
numberOfInput: 2,
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/views/entity/PersistentQuery/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function EntityPersistentQuerySettings() {
}
>
<EntityPersistentQueryForm
initialValues={upsertPeristentQueryMutation.data}
initialValues={peristentQuery.data}
onSubmit={upsertPeristentQueryMutation.mutateAsync}
tableColumns={tableColumns.data || []}
/>
Expand Down
15 changes: 8 additions & 7 deletions src/frontend/views/entity/Presentation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,15 @@ if($.field === "commentsCount"){
},
}}
onSubmit={async (data) => {
const context: IPresentationScriptParams = {
field: "test",
from: "details",
row: {},
value: "",
...evaluateScriptContext,
};
try {
evalJavascriptString(data.script, {
field: "test",
from: "details",
row: {},
value: "",
...evaluateScriptContext,
} as IPresentationScriptParams);
evalJavascriptString(data.script, context);

await upsertConfigurationMutation.mutateAsync(data);
} catch (e) {
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/views/users/DatabaseLink/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function UsersLinkToDatabase() {
{
table: {
type: "selection",
label: "Table containing your user's data",
label: "Your Users Table",
apiSelections: {
listUrl: ACTIVE_ENTITIES_ENDPOINT,
},
Expand All @@ -71,7 +71,7 @@ export function UsersLinkToDatabase() {
},
field: {
type: "selection",
label: "The field that holds the user's email/username",
label: "Field Corresponding To Dashpress Usernames",
selections: entityFields.data.map((field) => ({
label: field,
value: field,
Expand Down
4 changes: 2 additions & 2 deletions src/shared/form-schemas/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { GridSpanSizes, IColorableSelection } from "shared/types/ui";
import { FIELD_TYPES_CONFIG_MAP } from "shared/validations";
import { IFieldValidationItem } from "shared/validations/types";

export interface ISchemaFormScriptProps<T> extends IEvaluateScriptContext {
export type ISchemaFormScriptProps<T> = IEvaluateScriptContext & {
formValues: T;
action: string;
}
};

export interface IFormInputRightAction {
label: string;
Expand Down

0 comments on commit 222ced5

Please sign in to comment.