Skip to content

Commit

Permalink
#638 Table Editor
Browse files Browse the repository at this point in the history
#638 update pnpm lock
  • Loading branch information
joepio authored and Polleps committed Aug 7, 2023
1 parent 77d8302 commit 2fb3bcc
Show file tree
Hide file tree
Showing 211 changed files with 12,231 additions and 1,227 deletions.
1 change: 1 addition & 0 deletions browser/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ module.exports = {
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-explicit-any': 'error',
"react-hooks/rules-of-hooks": "error", // Checks rules of Hooks
'no-console': ['error', { allow: ['error', 'warn'] }],
"react/prop-types": "off",
Expand Down
75 changes: 0 additions & 75 deletions browser/.github/workflows/build.yml

This file was deleted.

8 changes: 4 additions & 4 deletions browser/data-browser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
_Status: Beta. [Breaking changes](CHANGELOG.md) are expected until 1.0._

View, edit and create [Atomic Data](https://atomicdata.dev/) from your browser!
Front-end for [`atomic-server`](../../README.md).
Designed for interacting with [`atomic-server`](https://github.com/atomicdata-dev/atomic-data-browser).

**[demo on atomicdata.dev](https://atomicdata.dev/)**

Expand Down Expand Up @@ -42,7 +42,7 @@ pnpm start
```

If you want to _edit_ data, you'll need an [_Agent_](https://atomicdata.dev/classes/Agent), including its `privateKey` and `subject`.
You can get one by accepting [an Invite](https://atomicdata.dev/invites/1), or by hosting your own [`atomic-server`](../../README.md).
You can get one by accepting [an Invite](https://atomicdata.dev/invites/1), or by hosting your own [`atomic-server`](https://github.com/atomicdata-dev/atomic-data-rust/blob/master/server/README.md).
You can set the Agent on the `/app/agent` route.

## Understanding & contributing to the code
Expand All @@ -52,7 +52,7 @@ You can set the Agent on the `/app/agent` route.
- **Data fetching** is handled by the `Store`, which makes sure that you don't ask twice for the same resource and let's other resources know that things have changed.
- **Hooks** are used wherever possible. This means functional components, instead of old-style Class components. Hooks tend to use a pattern similar to React's own `useState`, which means that two terms are returned: the first one contains the current value, and the second one is a function for setting the value.
- **Document** your components and properties! Explain your thinking when doing something non-trivial.
- **Resources** should have an `about={subject}` tag in HTML elements / DOM nodes, which can be used for debugging and RDFa parsing. This means that you can press `e` to edit anything you're hovering on, or press `d` to show the data!
- **Resources** should have a `about={subject}` tag in HTML elements / DOM nodes, which can be used for debugging and RDFa parsing. This means that you can press `e` to edit anything you're hovering on, or press `d` to show the data!
- **Creating views** for new types of Resources should be done in `/views`. Check the README.md in that folder.
- **Fetching & processing** is done in this order. The UI renders some component that uses `useResource`, and passes a `subject` URL. This is probably first the one that's shown in the navigation bar. This resource is fetched (unless it's already in the store) as a `JSON-AD` object, after which it is put in the Store without any changes. The Parser does not perform validation checks - that would make the application slower. After the resource is added to the store, subscribers (users of that resource, such as Components with the `useResource` hook) will be notified of changes. The component will re-render, and the props can now be used.
- **Accessing the store from the browser console** can be done in develop mode in your browser with the global `store` object.
Expand All @@ -79,7 +79,7 @@ They use the PlayWright framework and run in the browser.

- make sure the data-browser server is running (`pnpm start`) at `http://localhost:5173`
- make sure an [`atomic-server`](https://crates.io/crates/atomic-server/) instance is running at `http://localhost:9883`
- make sure the `http://localhost/setup` invite has at least one available usage. You can set a higher amount [here](http://localhost/app/edit?subject=http%3A%2F%2Flocalhost%2Fsetup), or run `atomic-server --initialize` to reset it to 1.
- make sure the `http://localhost/setup` invite has at least one available usage. You can set a higher amount [here](http://localhost/app/edit?subject=http%3A%2F%2Flocalhost%2Fsetup), or run `atomic-server --inititalize` to reset it to 1.
- Install the Playwright dependencies: `pnpm playwright-install`
- `pnpm test` launches the E2E tests (make sure the dev server is running at `http://localhost:5173`)
- `pnpm test-debug` launches the E2E tests in debug mode (a window opens with debug tools)
Expand Down
11 changes: 9 additions & 2 deletions browser/data-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
"@dnd-kit/core": "^6.0.5",
"@dnd-kit/sortable": "^7.0.1",
"@dnd-kit/utilities": "^3.2.0",
"@emoji-mart/react": "^1.1.1",
"@radix-ui/react-popover": "^1.0.2",
"@radix-ui/react-scroll-area": "^1.0.1",
"@tomic/react": "workspace:*",
"emoji-mart": "^5.5.2",
"polished": "^4.1.0",
"query-string": "^7.0.0",
"quick-score": "^0.0.10",
Expand All @@ -22,13 +26,15 @@
"react-helmet-async": "^1.3.0",
"react-hot-toast": "^2.4.0",
"react-hotkeys-hook": "^3.1.0",
"react-icons": "^4.2.0",
"react-icons": "^4.9.0",
"react-intersection-observer": "^9.4.1",
"react-is": "^18",
"react-markdown": "^8.0.3",
"react-pdf": "^6.2.2",
"react-router": "^6.9.0",
"react-router-dom": "^6.9.0",
"react-virtualized-auto-sizer": "^1.0.7",
"react-window": "^1.8.7",
"remark-gfm": "^3.0.1",
"styled-components": "^5.3.3",
"yamde": "^1.7.1"
Expand All @@ -38,6 +44,7 @@
"@types/react-dom": "^18.0.5",
"@types/react-pdf": "^6.2.0",
"@types/react-router-dom": "^5.0.0",
"@types/react-window": "^1.8.5",
"@types/styled-components": "^5.1.25",
"babel-plugin-styled-components": "^2.0.7",
"csstype": "^3.1.0",
Expand Down Expand Up @@ -68,7 +75,7 @@
"predeploy": "build && touch build/.nojekyll",
"preview": "vite preview",
"start": "vite",
"test-e2e": "playwright test --config=./tests/playwright.config.ts",
"test": "playwright test --config=./tests/playwright.config.ts",
"test-debug": "PWDEBUG=1 playwright test",
"test-new": "playwright codegen http://localhost:5173",
"test-query": "PWDEBUG=1 playwright test \"e2e.spec.ts\" -g",
Expand Down
47 changes: 30 additions & 17 deletions browser/data-browser/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import { registerHandlers } from './handlers';
import { ErrorBoundary } from './views/ErrorPage';
import { NetworkIndicator } from './components/NetworkIndicator';
import { getAgentFromLocalStorage } from './helpers/agentStorage';
import { DropdownContainer } from './components/Dropdown/DropdownContainer';
import { PopoverContainer } from './components/Popover';
import { SkipNav } from './components/SkipNav';
import { ControlLockProvider } from './hooks/useControlLock';

function fixDevUrl(url: string) {
if (isDev()) {
Expand Down Expand Up @@ -71,23 +75,32 @@ function App(): JSX.Element {
<HelmetProvider>
{/* Basename is for hosting on GitHub pages */}
<BrowserRouter basename='/'>
<HotKeysWrapper>
<ThemeWrapper>
{/* @ts-ignore TODO: Check if types are fixed or upgrade styled-components to 6.0.0 */}
<GlobalStyle />
{/* @ts-ignore fallback component type too strict */}
<ErrBoundary FallbackComponent={CrashPage}>
<Toaster />
<MetaSetter />
<DialogContainer>
<NavWrapper>
<AppRoutes />
</NavWrapper>
<NetworkIndicator />
</DialogContainer>
</ErrBoundary>
</ThemeWrapper>
</HotKeysWrapper>
<ControlLockProvider>
<HotKeysWrapper>
<ThemeWrapper>
{/* @ts-ignore TODO: Check if types are fixed or upgrade styled-components to 6.0.0 */}
<GlobalStyle />
{/* @ts-ignore fallback component type too strict */}
<ErrBoundary FallbackComponent={CrashPage}>
<Toaster />
<MetaSetter />
<DropdownContainer>
<DialogContainer>
<PopoverContainer>
<DropdownContainer>
<SkipNav />
<NavWrapper>
<AppRoutes />
</NavWrapper>
</DropdownContainer>
</PopoverContainer>
<NetworkIndicator />
</DialogContainer>
</DropdownContainer>
</ErrBoundary>
</ThemeWrapper>
</HotKeysWrapper>
</ControlLockProvider>
</BrowserRouter>
</HelmetProvider>
</AppSettingsContextProvider>
Expand Down
99 changes: 99 additions & 0 deletions browser/data-browser/src/chunks/EmojiInput/EmojiInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import React, { useCallback, useState } from 'react';
import Picker from '@emoji-mart/react';
import styled from 'styled-components';
import * as RadixPopover from '@radix-ui/react-popover';
import { transition } from '../../helpers/transition';
import { Popover } from '../../components/Popover';

interface EmojiInputProps {
initialValue?: string;
onChange: (value: string | undefined) => void;
}

const EMOJI_DATA_URL = 'https://cdn.jsdelivr.net/npm/@emoji-mart/data';

let data: Promise<unknown>;

const fetchAndCacheData = async () => {
if (data) {
return data;
}

const response = await fetch(EMOJI_DATA_URL);
data = response.json();

return data;
};

export default function EmojiInput({
initialValue,
onChange,
}: EmojiInputProps): JSX.Element {
const [showPicker, setShowPicker] = useState(false);
const [emoji, setEmoji] = useState<string | undefined>(initialValue);

const handleEmojiSelect = useCallback((e: { native: string }) => {
setEmoji(e.native);
setShowPicker(false);
onChange(e.native);
}, []);

return (
<PickerPopover
noArrow
open={showPicker}
onOpenChange={setShowPicker}
Trigger={
<PickerButton onClick={() => setShowPicker(true)} title='Pick an emoji'>
{emoji ? <Preview>{emoji}</Preview> : <Placeholder>😎</Placeholder>}
</PickerButton>
}
>
<PickerWrapper>
<Picker
autoFocus
data={fetchAndCacheData}
onEmojiSelect={handleEmojiSelect}
maxFrequentRows={2}
dynamicWidth={true}
/>
</PickerWrapper>
</PickerPopover>
);
}

const Preview = styled.span`
transition: ${transition('font-size')};
`;

const Placeholder = styled(Preview)`
opacity: 0.5;
`;

const PickerButton = styled(RadixPopover.Trigger)`
border: none;
border-radius: ${({ theme }) => theme.radius};
width: 2rem;
background: transparent;
padding: 0;
cursor: pointer;
user-select: none;
&:hover > ${Preview} {
font-size: 1.3rem;
}
`;

const PickerPopover = styled(Popover)`
top: 200px;
`;

const PickerWrapper = styled.div`
display: contents;
& em-emoji-picker {
height: 400px;
width: min(90vw, 20rem);
}
`;
Loading

0 comments on commit 2fb3bcc

Please sign in to comment.