Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial views API #978

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
"@osdk/foundry-sdk-generator",
"@osdk/generator-converters",
"@osdk/generator-utils",
"@osdk/generator"
"@osdk/generator",
"@osdk/views-api.unstable",
"@osdk/views-client.unstable",
"@osdk/views-client-react.unstable"
],
["@osdk/cli", "@osdk/cli.*"]
],
Expand Down
7 changes: 7 additions & 0 deletions .changeset/curvy-fireants-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@osdk/views-client-react.unstable": minor
"@osdk/views-client.unstable": minor
"@osdk/views-api.unstable": minor
---

Add initial views API
2 changes: 2 additions & 0 deletions .monorepolint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ const DELETE_SCRIPT_ENTRY = { options: [undefined], fixValue: undefined };
const nonStandardPackages = [
"@osdk/e2e.generated.1.1.x",
"@osdk/e2e.sandbox.todoapp",
"@osdk/e2e.sandbox.views.todo-widget", // uses react
"@osdk/e2e.sandbox.oauth.public.react-router",
"@osdk/examples.*",
"@osdk/foundry-sdk-generator",
"@osdk/e2e.test.foundry-sdk-generator",
"@osdk/monorepo.*", // internal monorepo packages
"@osdk/tests.*",
"@osdk/views-client-react.unstable", // uses react
// removed the following from the repo to avoid it being edited
// "@osdk/shared.client2", // hand written package that only exposes a symbol
];
Expand Down
1 change: 1 addition & 0 deletions packages/e2e.sandbox.views.todo-widget/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
14 changes: 14 additions & 0 deletions packages/e2e.sandbox.views.todo-widget/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Custom View: Ontology SDK + React</title>
</head>
<body>
<div id="root-container">
<div id="root"></div>
</div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
67 changes: 67 additions & 0 deletions packages/e2e.sandbox.views.todo-widget/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"name": "@osdk/e2e.sandbox.views.todo-widget",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note i haven't actually ran this yet, i mostly made it to make sure all the types are right. I will go after a proper template (+ vite plugin) in a follow up PR

"private": true,
"version": "0.1.0-beta.1",
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "https://github.com/palantir/osdk-ts.git"
},
"exports": {
".": {
"browser": "./build/browser/index.js",
"import": "./build/esm/index.js",
"default": "./build/browser/index.js"
},
"./*": {
"browser": "./build/browser/public/*.js",
"import": "./build/esm/public/*.js",
"default": "./build/browser/public/*.js"
}
},
"scripts": {
"build": "tsc && vite build",
"check-attw": "monorepo.tool.attw esm",
"check-spelling": "cspell --quiet .",
"clean": "rm -rf lib dist types build tsconfig.tsbuildinfo",
"dev": "vite",
"fix-lint": "eslint . --fix && dprint fmt --config $(find-up dprint.json)",
"lint": "eslint . && dprint check --config $(find-up dprint.json)",
"preview": "vite preview",
"transpile": "monorepo.tool.transpile"
},
"dependencies": {
"@osdk/views-client-react.unstable": "workspace:~",
"@osdk/views-client.unstable": "workspace:~",
"@radix-ui/react-icons": "^1.3.1",
"@radix-ui/themes": "^3.1.4",
"react": "^18",
"react-dom": "^18"
},
"devDependencies": {
"@osdk/monorepo.api-extractor": "workspace:~",
"@osdk/monorepo.tsconfig": "workspace:~",
"@osdk/monorepo.tsup": "workspace:~",
"@types/react": "^18",
"@types/react-dom": "^18",
"@vitejs/plugin-react": "^4.2.0",
"typescript": "~5.5.4",
"vite": "^5.4.8",
"vitest": "^2.1.2"
},
"publishConfig": {
"access": "public"
},
"files": [
"build/cjs",
"build/esm",
"build/browser",
"CHANGELOG.md",
"package.json",
"templates",
"*.d.ts"
],
"module": "./build/esm/index.js",
"types": "./build/esm/index.d.ts",
"type": "module"
}
72 changes: 72 additions & 0 deletions packages/e2e.sandbox.views.todo-widget/src/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { useFoundryViewContext } from "@osdk/views-client-react.unstable";
import { ExclamationTriangleIcon } from "@radix-ui/react-icons";
import {
Box,
Callout,
Container,
Flex,
Heading,
Skeleton,
Table,
} from "@radix-ui/themes";
import React, { useEffect } from "react";
import type MainParameters from "./main.parameters.js";

export const App: React.FC = () => {
const { parameterValues, sendReady } = useFoundryViewContext<
typeof MainParameters
>();
const { headerText, showWarning } = parameterValues;
useEffect(() => {
sendReady();
}, []);
return (
<Box>
<Container size="1">
<Flex p="5" direction="column" gap="2">
<Heading size="4">
{headerText.value.type === "loading"
|| headerText.value.type === "not-started"
? <Skeleton>Hello, world!</Skeleton>
: (
headerText.value.value
)}
</Heading>
{showWarning.value.type === "loaded" && showWarning.value.value && (
<Callout.Root size="1" color="orange" variant="soft">
<Callout.Icon>
<ExclamationTriangleIcon />
</Callout.Icon>
<Callout.Text>This is a data warning</Callout.Text>
</Callout.Root>
)}
<Table.Root>
<Table.Header>
<Table.Row>
<Table.ColumnHeaderCell>Email</Table.ColumnHeaderCell>
<Table.ColumnHeaderCell>Group</Table.ColumnHeaderCell>
</Table.Row>
</Table.Header>

<Table.Body>
<Table.Row>
<Table.Cell>[email protected]</Table.Cell>
<Table.Cell>Developer</Table.Cell>
</Table.Row>

<Table.Row>
<Table.Cell>[email protected]</Table.Cell>
<Table.Cell>Admin</Table.Cell>
</Table.Row>

<Table.Row>
<Table.Cell>[email protected]</Table.Cell>
<Table.Cell>Developer</Table.Cell>
</Table.Row>
</Table.Body>
</Table.Root>
</Flex>
</Container>
</Box>
);
};
Empty file.
20 changes: 20 additions & 0 deletions packages/e2e.sandbox.views.todo-widget/src/main.parameters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { ParameterConfig } from "@osdk/views-client.unstable";

const MainParameters = {
parameters: {
headerText: {
displayName: "Widget title",
type: "string",
},
showWarning: {
displayName: "Show warning callout",
type: "boolean",
},
todoItems: {
displayName: "Todo items",
type: "array",
subType: "string",
},
},
} as const satisfies ParameterConfig;
export default MainParameters;
26 changes: 26 additions & 0 deletions packages/e2e.sandbox.views.todo-widget/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import "@radix-ui/themes/styles.css";
import "./main.css";

import {
FoundryView,
initializeParameters,
} from "@osdk/views-client-react.unstable";
import { Theme } from "@radix-ui/themes";
import React from "react";
import { createRoot } from "react-dom/client";
import { App } from "./app.js";
import MainParameters from "./main.parameters.js";

const root = document.querySelector("body")!;

createRoot(root).render(
(
<Theme>
<FoundryView<typeof MainParameters>
initialValues={initializeParameters(MainParameters, "loading")}
>
<App />
</FoundryView>
</Theme>
),
);
1 change: 1 addition & 0 deletions packages/e2e.sandbox.views.todo-widget/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
12 changes: 12 additions & 0 deletions packages/e2e.sandbox.views.todo-widget/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "@osdk/monorepo.tsconfig/base.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "build/esm",
"jsx": "react"
},
"include": [
"./src/**/*"
],
"references": []
}
23 changes: 23 additions & 0 deletions packages/e2e.sandbox.views.todo-widget/tsup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2023 Palantir Technologies, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { defineConfig } from "tsup";

export default defineConfig(async (options) =>
(await import("@osdk/monorepo.tsup")).default(options, {
esmOnly: true,
})
);
10 changes: 10 additions & 0 deletions packages/e2e.sandbox.views.todo-widget/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
server: {
port: 8080,
},
});
24 changes: 24 additions & 0 deletions packages/e2e.sandbox.views.todo-widget/vitest.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2023 Palantir Technologies, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { configDefaults, defineConfig } from "vitest/config";

export default defineConfig({
test: {
pool: "forks",
exclude: [...configDefaults.exclude, "**/build/**/*"],
},
});
54 changes: 54 additions & 0 deletions packages/views.api.unstable/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"name": "@osdk/views-api.unstable",
"version": "0.0.0",
"description": "API contract between Foundry UIs that can embed custom views and the custom views themselves",
"access": "public",
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "https://github.com/palantir/osdk-ts.git"
},
"exports": {
".": {
"browser": "./build/browser/index.js",
"import": "./build/esm/index.js",
"default": "./build/browser/index.js"
},
"./*": {
"browser": "./build/browser/public/*.js",
"import": "./build/esm/public/*.js",
"default": "./build/browser/public/*.js"
}
},
"scripts": {
"check-attw": "monorepo.tool.attw esm",
"check-spelling": "cspell --quiet .",
"clean": "rm -rf lib dist types build tsconfig.tsbuildinfo",
"fix-lint": "eslint . --fix && dprint fmt --config $(find-up dprint.json)",
"lint": "eslint . && dprint check --config $(find-up dprint.json)",
"transpile": "monorepo.tool.transpile"
},
"devDependencies": {
"@osdk/monorepo.api-extractor": "workspace:~",
"@osdk/monorepo.tsconfig": "workspace:~",
"@osdk/monorepo.tsup": "workspace:~",
"ts-expect": "^1.3.0",
"typescript": "~5.5.4"
},
"publishConfig": {
"access": "public"
},
"keywords": [],
"files": [
"build/cjs",
"build/esm",
"build/browser",
"CHANGELOG.md",
"package.json",
"templates",
"*.d.ts"
],
"module": "./build/esm/index.js",
"types": "./build/esm/index.d.ts",
"type": "module"
}
Loading