Skip to content

Commit

Permalink
fix: consistent styling and backend issues
Browse files Browse the repository at this point in the history
  • Loading branch information
thesophiaxu committed Feb 26, 2022
1 parent 9c379d4 commit fd01f30
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 22 deletions.
3 changes: 0 additions & 3 deletions packages/unigraph-dev-backend/src/executableManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ export function createExecutableCache(
unigraph: Unigraph,
states: any,
): Cache<any> {
const schedule: Record<string, cron.ScheduledTask> = {};

const cache: Cache<any> = {
data: {},
updateNow: async () => null,
Expand Down Expand Up @@ -67,7 +65,6 @@ export function createExecutableCache(
if (k.startsWith('$/executable') && !cache.data[k]) cache.data[k] = unpad(v);
});

initExecutables(Object.entries(cache.data), context, unigraph, schedule, states);
done(false, null);
});
};
Expand Down
21 changes: 20 additions & 1 deletion packages/unigraph-dev-backend/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import fetch from 'node-fetch';
import _, { uniqueId } from 'lodash';
import { Unigraph } from 'unigraph-dev-common/lib/types/unigraph';
import stringify from 'json-stable-stringify';
import cron from 'node-cron';
import DgraphClient from './dgraphClient';
import {
EventAddBacklinks,
Expand Down Expand Up @@ -77,7 +78,7 @@ import {
initEntityHeads,
} from './hooks';
import { getAsyncLock } from './asyncManager';
import { createExecutableCache } from './executableManager';
import { createExecutableCache, initExecutables } from './executableManager';
import { getLocalUnigraphAPI } from './localUnigraphApi';
import { addNotification } from './notifications';
import { perfLogAfterDbTransaction, perfLogStartDbTransaction, perfLogStartPreprocessing } from './logging';
Expand All @@ -99,6 +100,7 @@ export default async function startServer(client: DgraphClient) {
const lock = getAsyncLock();

const connections: Record<string, WebSocket> = {};
const executableSchedule: Record<string, cron.ScheduledTask> = {};

// Basic checks
await checkOrCreateDefaultDataModel(client);
Expand Down Expand Up @@ -185,6 +187,13 @@ export default async function startServer(client: DgraphClient) {
await context.caches.schemas.updateNow();
await context.caches.packages.updateNow();
await context.caches.executables.updateNow();
initExecutables(
Object.entries(context.caches.executables.data),
{},
localApi,
serverStates.executableSchedule,
serverStates,
);
Object.values(connections).forEach((el) =>
el.send(
stringify({
Expand All @@ -208,6 +217,13 @@ export default async function startServer(client: DgraphClient) {
context.ofUpdate,
);
await context.caches.executables.updateNow();
initExecutables(
Object.entries(context.caches.executables.data),
{},
localApi,
serverStates.executableSchedule,
serverStates,
);

// Call after_object_created hooks with uids cached
const objectCreatedHooks: any = {};
Expand Down Expand Up @@ -243,6 +259,7 @@ export default async function startServer(client: DgraphClient) {
clientLeasedUids: {},
httpCallbacks: {},
runningExecutables: [],
executableSchedule,
addRunningExecutable: (defn: any) => {
serverStates.runningExecutables.push(defn);
clearTimeout(debounceId);
Expand Down Expand Up @@ -890,6 +907,8 @@ export default async function startServer(client: DgraphClient) {
console.log('\nUnigraph server listening on port', PORT);
});

initExecutables(Object.entries(serverStates.caches['executables'].data), {}, localApi, serverStates.executableSchedule, serverStates);

/** Maps from clientIds to connIds, from this server start */
const historialClients: Record<string, string> = {};
serverStates.getClientId = (connId: string) =>
Expand Down
2 changes: 1 addition & 1 deletion packages/unigraph-dev-electron/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async function startServer(logHandler) {
path.join(userData, 'zw'),
]);

const completedLog = 'ResetCors closed'; // When this is logged we know it's completed
const completedLog = 'Server is ready: OK'; // When this is logged we know it's completed
const completedULog = 'Unigraph server listening on port';

function checkIfComplete(str) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const classes = {
drawerPaper: `${PREFIX}-drawerPaper`,
};

const appDrawerHoverSx = { cursor: 'pointer', ...hoverSx };
const appDrawerHoverSx = { paddingBottom: '4px', paddingTop: '4px', cursor: 'pointer', ...hoverSx };
export default function DrawerRouter() {
const devState = window.unigraph.getState('settings/developerMode');
const [devMode, setDevMode] = React.useState(devState.value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export const defaultContextMenu: Array<ContextMenuGenerator> = [
),
(uid, object, handleClose, callbacks) => (
<MenuItem
style={{ paddingTop: '8px', paddingBottom: '0px' }}
style={contextMenuItemStyle}
onClick={() => {
handleClose();
window.wsnavigator(`/graph?uid=${uid}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const Root = styled('div')(({ theme }) => ({
[`& .${classes.content}`]: {
width: '100%',
overflow: 'auto',
marginRight: '8px',
},
}));

Expand Down Expand Up @@ -114,12 +115,14 @@ function DynamicListItem({
components,
removeOnEnter,
compact,
itemStyle,
}: any) {
return (
<ListItem
sx={hoverSx}
style={{
...(compact ? { paddingTop: '2px', paddingBottom: '2px' } : {}),
...itemStyle,
}}
>
<ListItemIcon
Expand Down Expand Up @@ -176,6 +179,7 @@ export type DynamicObjectListViewProps = {
noRemover?: boolean;
noDrop?: boolean;
compact?: boolean;
itemStyle?: any;
subscribeOptions?: any;
titleBar?: any;
loadAll?: boolean;
Expand All @@ -198,6 +202,7 @@ function DynamicListBasic({
compact,
removeOnEnter,
components,
itemStyle,
}: any) {
const tabContext = React.useContext(TabContext);
return (
Expand All @@ -217,6 +222,7 @@ function DynamicListBasic({
context={context}
listUid={listUid}
compact={compact}
itemStyle={itemStyle}
callbacks={callbacks}
itemUids={items.map((ell: any) => itemGetter(ell).uid)}
itemRemover={itemRemover}
Expand Down Expand Up @@ -247,6 +253,7 @@ function DynamicList({
subscribeOptions,
removeOnEnter,
components,
itemStyle,
}: any) {
const tabContext = React.useContext(TabContext);
const [loadedItems, setLoadedItems] = React.useState<any[]>([]);
Expand Down Expand Up @@ -322,6 +329,7 @@ function DynamicList({
listUid={listUid}
reverse={reverse}
compact={compact}
itemStyle={itemStyle}
callbacks={callbacks}
itemUids={items.map((ell: any) => itemGetter(ell).uid)}
itemRemover={itemRemover}
Expand Down Expand Up @@ -359,7 +367,7 @@ function MultiTypeDescriptor({
marginBottom: '0px',
}}
/>
<Root style={{ whiteSpace: 'nowrap', display: 'flex' }}>
<div style={{ whiteSpace: 'nowrap', display: 'flex' }}>
{itemGroups.map((el, index) => (
<TabButton isSelected={selectedTab === el.name} onClick={() => setSelectedTab(el.name)}>
<div
Expand All @@ -382,7 +390,7 @@ function MultiTypeDescriptor({
<Typography style={{ marginRight: '8px' }}>{el.items.length}</Typography>
</TabButton>
))}
</Root>
</div>
</>
) : (
<span />
Expand Down Expand Up @@ -438,6 +446,7 @@ export const DynamicObjectListView: React.FC<DynamicObjectListViewProps> = ({
noRemover,
noDrop,
compact,
itemStyle,
subscribeOptions,
loadAll,
removeOnEnter,
Expand Down Expand Up @@ -536,7 +545,7 @@ export const DynamicObjectListView: React.FC<DynamicObjectListViewProps> = ({
}));

return (
<div
<Root
style={{
height: '100%',
width: '100%',
Expand Down Expand Up @@ -694,6 +703,7 @@ export const DynamicObjectListView: React.FC<DynamicObjectListViewProps> = ({
parId,
noRemover,
compact,
itemStyle,
subscribeOptions,
removeOnEnter,
components,
Expand Down Expand Up @@ -722,6 +732,7 @@ export const DynamicObjectListView: React.FC<DynamicObjectListViewProps> = ({
parId,
noRemover,
compact,
itemStyle,
subscribeOptions,
removeOnEnter,
components,
Expand All @@ -730,6 +741,6 @@ export const DynamicObjectListView: React.FC<DynamicObjectListViewProps> = ({
))}
</div>
</DataContextWrapper>
</div>
</Root>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export function ContextMenu() {
PaperProps={{
elevation: 4,
style: {
padding: '6px 4px',
borderRadius: '16px',
padding: '4px 4px',
borderRadius: '6px',
},
}}
>
Expand All @@ -60,8 +60,8 @@ export function ContextMenu() {
{objDef?._icon ? (
<ListItemIcon
style={{
minWidth: '20px',
minHeight: '20px',
minWidth: '19px',
minHeight: '19px',
marginLeft: '12px',
marginRight: '8px',
backgroundImage: `url("data:image/svg+xml,${objDef?._icon}")`,
Expand All @@ -75,7 +75,7 @@ export function ContextMenu() {
)}
<ListItemText>{objDef?._name || state.contextObject?.type?.['unigraph.id']}</ListItemText>
</MenuItem>
<Divider />
<Divider sx={{ margin: '4px 0px !important' }} />
{state.menuContent?.map((el: any) =>
el(
state.contextUid!,
Expand All @@ -87,7 +87,7 @@ export function ContextMenu() {
)}
{schemaMenuConstructors.length > 0 ? (
<>
<Divider />
<Divider sx={{ margin: '4px 0px !important' }} />
{schemaMenuConstructors.map((el: any) =>
el(
state.contextUid!,
Expand All @@ -106,7 +106,7 @@ export function ContextMenu() {
)}
{state.contextContextUid ? (
<>
<Divider />
<Divider sx={{ margin: '4px 0px !important' }} />
<MenuItem style={contextMenuItemStyle}>
<ListItemIcon style={{ minWidth: '32px' }}>
<Icon path={mdiCubeOutline} size={0.8} />
Expand All @@ -115,8 +115,8 @@ export function ContextMenu() {
{objCtxDef?._icon ? (
<ListItemIcon
style={{
minWidth: '20px',
minHeight: '20px',
minWidth: '19px',
minHeight: '19px',
marginLeft: '12px',
marginRight: '8px',
backgroundImage: `url("data:image/svg+xml,${objCtxDef?._icon}")`,
Expand All @@ -137,7 +137,7 @@ export function ContextMenu() {
{objCtxDef?._name || state.contextContextObject?.type?.['unigraph.id']}
</ListItemText>
</MenuItem>
<Divider />
<Divider sx={{ margin: '4px 0px !important' }} />
{state.menuContextContent?.map((el: any) =>
el(
state.contextUid!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export function FavoriteBar() {
itemGetter={(el: any) => el._value._value}
noBar
noRemover
itemStyle={{ paddingTop: '4px', paddingBottom: '4px' }}
defaultFilter={['no-deleted', 'no-noview']}
itemRemover={(uids) => {
window.unigraph.deleteItemFromArray(favEntity?._value?.children?.uid, uids, favEntity.uid);
Expand Down
3 changes: 3 additions & 0 deletions packages/unigraph-dev-explorer/src/examples/notes/init.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
registerContextMenuItems,
registerQuickAdder,
} from '../../unigraph-react';
import { contextMenuItemStyle } from '../../utils';
import { setChildrenDisplayAs } from './commands';
import { DetailedNoteBlock } from './NoteBlock';
import { NoteBlock } from './NoteBlockViews';
Expand Down Expand Up @@ -93,6 +94,7 @@ export const init = () => {
registerContextMenuItems('$/schema/note_block', [
(uid: any, object: any, handleClose: any, callbacks: any) => (
<MenuItem
style={contextMenuItemStyle}
onClick={() => {
handleClose();
callbacks['convert-child-to-todo']();
Expand All @@ -106,6 +108,7 @@ export const init = () => {
const displayAs = object?._value?.children?._displayAs || 'outliner';
return (
<MenuItem
style={contextMenuItemStyle}
onClick={() => {
handleClose();
setChildrenDisplayAs(object, callbacks, displayAs === 'outliner' ? 'paragraph' : 'outliner');
Expand Down
2 changes: 1 addition & 1 deletion packages/unigraph-dev-explorer/src/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ export const hoverSx = {
'&:active': { backgroundColor: 'action.selected' },
};

export const contextMenuItemStyle = { paddingTop: '8px', paddingBottom: '8px' };
export const contextMenuItemStyle = { paddingTop: '4px', paddingBottom: '4px' };
export const globalTheme = {
palette: {
primary: { main: '#212121' },
Expand Down

0 comments on commit fd01f30

Please sign in to comment.