Skip to content

Commit

Permalink
Merge pull request #730 from jetstreamapp/bug/db-error
Browse files Browse the repository at this point in the history
Fix user preference code error
  • Loading branch information
paustint authored Feb 10, 2024
2 parents bbbd262 + c70de95 commit 7636701
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 106 deletions.
21 changes: 4 additions & 17 deletions apps/api/src/app/db/user.db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,10 @@ const userSelect: Prisma.UserSelect = {
* Find by Auth0 userId, not Jetstream Id
*/
export async function findByUserId(userId: string) {
let user = await prisma.user.findUnique({
where: { userId: userId },
const user = await prisma.user.findUnique({
where: { userId },
select: userSelect,
});
// ensure user preference exists if not already created
if (user && !user.preferences) {
await prisma.userPreference.create({
data: {
userId: user.userId,
skipFrontdoorLogin: false,
},
});
user = await prisma.user.findUnique({
where: { userId: userId },
select: userSelect,
});
}
return user;
}

Expand Down Expand Up @@ -86,9 +73,9 @@ export async function createOrUpdateUser(user: UserProfileServer): Promise<{ cre
data: {
appMetadata: JSON.stringify(user._json[ENV.AUTH_AUDIENCE!]),
preferences: {
connectOrCreate: {
upsert: {
create: { skipFrontdoorLogin: false },
where: { userId: user.id },
update: { skipFrontdoorLogin: false },
},
},
},
Expand Down
7 changes: 2 additions & 5 deletions apps/jetstream/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@ export default defineConfig({
// Put all assets at the root of the app instead of under /assets
assetsDir: './',
sourcemap: true,
rollupOptions: {
output: {
sourcemap: true,
},
},
emptyOutDir: true,
rollupOptions: {},
},

plugins: [
Expand Down
6 changes: 2 additions & 4 deletions libs/monaco-configuration/src/lib/language-soql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
// https://github.com/microsoft/monaco-languages/blob/main/src/sql/sql.ts
// TODO: consider open sourcing the apex part
import type * as monaco from 'monaco-editor';

// lazy load to ensure not in main bundle
const soqlParserJs = import('soql-parser-js');
import { formatQuery } from 'soql-parser-js';

type Monaco = typeof monaco;

Expand All @@ -18,7 +16,7 @@ export function configureSoqlLanguage(monaco: Monaco) {
return [
{
range: model.getFullModelRange(),
text: (await soqlParserJs).formatQuery(model.getValue()),
text: formatQuery(model.getValue()),
},
];
},
Expand Down
36 changes: 20 additions & 16 deletions libs/ui/src/lib/widgets/Icon.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
// https://www.lightningdesignsystem.com/components/icons/

import { IconName, IconType } from '@jetstream/icon-factory';
import React, { FunctionComponent, Suspense } from 'react';

const IconLazyWrapper = React.lazy(() => import('./IconLazyWrapper'));
import { IconName, IconType, getIcon } from '@jetstream/icon-factory';
import classNames from 'classnames';

export interface IconProps {
containerClassname?: string; // container classname, only used if not omitted
className?: string; // SVG element classname
containerClassname?: string;
className?: string;
omitContainer?: boolean;
title?: string;
type: IconType;
icon: IconName;
description?: string;
}

/**
* This component lazy loads the actual icon class to allow code splitting
* to reduce the size of the main bundle
* https://www.lightningdesignsystem.com/components/icons/
*/
export const Icon: FunctionComponent<IconProps> = (props) => {
return (
<Suspense fallback={<svg />}>
<IconLazyWrapper {...props} />
</Suspense>
);
export const Icon = ({ containerClassname, className, title, omitContainer = false, type, icon, description }: IconProps) => {
containerClassname = containerClassname || '';
className = className || '';
const svg = getIcon(type, icon, className);
if (omitContainer) {
return svg;
} else {
return (
<span className={classNames('slds-icon_container', containerClassname)} title={title || description}>
{svg}
{(description || title) && <span className="slds-assistive-text">{description || title}</span>}
</span>
);
}
};

export default Icon;
41 changes: 0 additions & 41 deletions libs/ui/src/lib/widgets/IconLazyWrapper.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
"postcss": "8.4.19",
"postcss-preset-env": "7",
"prettier": "2.7.0",
"prisma": "^5.6.0",
"prisma": "^5.9.1",
"react-refresh": "^0.10.0",
"release-it": "^15.6.0",
"sass": "1.55.0",
Expand Down Expand Up @@ -253,7 +253,7 @@
"@opentelemetry/exporter-trace-otlp-grpc": "^0.27.0",
"@opentelemetry/sdk-node": "^0.27.0",
"@popperjs/core": "^2.4.0",
"@prisma/client": "^5.6.0",
"@prisma/client": "^5.9.1",
"@react-aria/dialog": "^3.1.4",
"@react-aria/focus": "^3.5.0",
"@react-aria/overlays": "^3.7.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,11 @@ CREATE UNIQUE INDEX "UserPreference_userId_key" ON "UserPreference"("userId");

-- AddForeignKey
ALTER TABLE "UserPreference" ADD CONSTRAINT "UserPreference_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- Backfill all records with a default UserPreference record
INSERT INTO "UserPreference" ("userId", "skipFrontdoorLogin", "createdAt", "updatedAt")
SELECT "id", false, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP FROM "User"
WHERE NOT EXISTS (
SELECT 1 FROM "UserPreference"
WHERE "UserPreference"."userId" = "User"."id"
);
66 changes: 45 additions & 21 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6628,22 +6628,46 @@
resolved "https://registry.npmjs.org/@popperjs/core/-/core-2.11.5.tgz"
integrity sha512-9X2obfABZuDVLCgPK9aX0a/x4jaOEweTTWE2+9sr0Qqqevj2Uv5XorvusThmc9XGYpS9yI+fhh8RTafBtGposw==

"@prisma/client@^5.6.0":
version "5.6.0"
resolved "https://registry.yarnpkg.com/@prisma/client/-/client-5.6.0.tgz#1c15932250d5658fe0127e62faf4ecd96a877259"
integrity sha512-mUDefQFa1wWqk4+JhKPYq8BdVoFk9NFMBXUI8jAkBfQTtgx8WPx02U2HB/XbAz3GSUJpeJOKJQtNvaAIDs6sug==
dependencies:
"@prisma/engines-version" "5.6.0-32.e95e739751f42d8ca026f6b910f5a2dc5adeaeee"

"@prisma/engines-version@5.6.0-32.e95e739751f42d8ca026f6b910f5a2dc5adeaeee":
version "5.6.0-32.e95e739751f42d8ca026f6b910f5a2dc5adeaeee"
resolved "https://registry.yarnpkg.com/@prisma/engines-version/-/engines-version-5.6.0-32.e95e739751f42d8ca026f6b910f5a2dc5adeaeee.tgz#57b003ab5e1ea1523b5cdd7f06b24ebcf5c7fd8c"
integrity sha512-UoFgbV1awGL/3wXuUK3GDaX2SolqczeeJ5b4FVec9tzeGbSWJboPSbT0psSrmgYAKiKnkOPFSLlH6+b+IyOwAw==

"@prisma/[email protected]":
version "5.6.0"
resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-5.6.0.tgz#82c445aa10633bbc0388aa2d6e411a0bd94c9439"
integrity sha512-Mt2q+GNJpU2vFn6kif24oRSBQv1KOkYaterQsi0k2/lA+dLvhRX6Lm26gon6PYHwUM8/h8KRgXIUMU0PCLB6bw==
"@prisma/client@^5.9.1":
version "5.9.1"
resolved "https://registry.yarnpkg.com/@prisma/client/-/client-5.9.1.tgz#d92bd2f7f006e0316cb4fda9d73f235965cf2c64"
integrity sha512-caSOnG4kxcSkhqC/2ShV7rEoWwd3XrftokxJqOCMVvia4NYV/TPtJlS9C2os3Igxw/Qyxumj9GBQzcStzECvtQ==

"@prisma/[email protected]":
version "5.9.1"
resolved "https://registry.yarnpkg.com/@prisma/debug/-/debug-5.9.1.tgz#906274e73d3267f88b69459199fa3c51cd9511a3"
integrity sha512-yAHFSFCg8KVoL0oRUno3m60GAjsUKYUDkQ+9BA2X2JfVR3kRVSJFc/GpQ2fSORi4pSHZR9orfM4UC9OVXIFFTA==

"@prisma/engines-version@5.9.0-32.23fdc5965b1e05fc54e5f26ed3de66776b93de64":
version "5.9.0-32.23fdc5965b1e05fc54e5f26ed3de66776b93de64"
resolved "https://registry.yarnpkg.com/@prisma/engines-version/-/engines-version-5.9.0-32.23fdc5965b1e05fc54e5f26ed3de66776b93de64.tgz#54d2164f28d23e09d41cf9eb0bddbbe7f3aaa660"
integrity sha512-HFl7275yF0FWbdcNvcSRbbu9JCBSLMcurYwvWc8WGDnpu7APxQo2ONtZrUggU3WxLxUJ2uBX+0GOFIcJeVeOOQ==

"@prisma/[email protected]":
version "5.9.1"
resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-5.9.1.tgz#767539afc6f193a182d0495b30b027f61f279073"
integrity sha512-gkdXmjxQ5jktxWNdDA5aZZ6R8rH74JkoKq6LD5mACSvxd2vbqWeWIOV0Py5wFC8vofOYShbt6XUeCIUmrOzOnQ==
dependencies:
"@prisma/debug" "5.9.1"
"@prisma/engines-version" "5.9.0-32.23fdc5965b1e05fc54e5f26ed3de66776b93de64"
"@prisma/fetch-engine" "5.9.1"
"@prisma/get-platform" "5.9.1"

"@prisma/[email protected]":
version "5.9.1"
resolved "https://registry.yarnpkg.com/@prisma/fetch-engine/-/fetch-engine-5.9.1.tgz#5d3b2c9af54a242e37b3f9561b59ab72f8e92818"
integrity sha512-l0goQOMcNVOJs1kAcwqpKq3ylvkD9F04Ioe1oJoCqmz05mw22bNAKKGWuDd3zTUoUZr97va0c/UfLNru+PDmNA==
dependencies:
"@prisma/debug" "5.9.1"
"@prisma/engines-version" "5.9.0-32.23fdc5965b1e05fc54e5f26ed3de66776b93de64"
"@prisma/get-platform" "5.9.1"

"@prisma/[email protected]":
version "5.9.1"
resolved "https://registry.yarnpkg.com/@prisma/get-platform/-/get-platform-5.9.1.tgz#a66bb46ab4d30db786c84150ef074ab0aad4549e"
integrity sha512-6OQsNxTyhvG+T2Ksr8FPFpuPeL4r9u0JF0OZHUBI/Uy9SS43sPyAIutt4ZEAyqWQt104ERh70EZedkHZKsnNbg==
dependencies:
"@prisma/debug" "5.9.1"

"@prisma/prisma-fmt-wasm@3.14.0-36.2b0c12756921c891fec4f68d9444e18c7d5d4a6a":
version "3.14.0-36.2b0c12756921c891fec4f68d9444e18c7d5d4a6a"
Expand Down Expand Up @@ -21815,12 +21839,12 @@ pretty-hrtime@^1.0.3:
resolved "https://registry.npmjs.org/pretty-hrtime/-/pretty-hrtime-1.0.3.tgz"
integrity sha512-66hKPCr+72mlfiSjlEB1+45IjXSqvVAIy6mocupoww4tBFE9R9IhwwUGoI4G++Tc9Aq+2rxOt0RFU6gPcrte0A==

prisma@^5.6.0:
version "5.6.0"
resolved "https://registry.yarnpkg.com/prisma/-/prisma-5.6.0.tgz#ae2c27fdfb4d53be7f7dafb50d6b8b7f55c93aa5"
integrity sha512-EEaccku4ZGshdr2cthYHhf7iyvCcXqwJDvnoQRAJg5ge2Tzpv0e2BaMCp+CbbDUwoVTzwgOap9Zp+d4jFa2O9A==
prisma@^5.9.1:
version "5.9.1"
resolved "https://registry.yarnpkg.com/prisma/-/prisma-5.9.1.tgz#baa3dd635fbf71504980978f10f55ea11068f6aa"
integrity sha512-Hy/8KJZz0ELtkw4FnG9MS9rNWlXcJhf98Z2QMqi0QiVMoS8PzsBkpla0/Y5hTlob8F3HeECYphBjqmBxrluUrQ==
dependencies:
"@prisma/engines" "5.6.0"
"@prisma/engines" "5.9.1"

proc-log@^3.0.0:
version "3.0.0"
Expand Down

0 comments on commit 7636701

Please sign in to comment.