Skip to content

Commit

Permalink
fix drag and drop files
Browse files Browse the repository at this point in the history
  • Loading branch information
aliscie committed Jul 5, 2024
1 parent b6840e9 commit 5161f0d
Show file tree
Hide file tree
Showing 23 changed files with 108 additions and 445 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@
"wasm": "https://github.com/dfinity/internet-identity/releases/latest/download/internet_identity_dev.wasm.gz"
},
```

3. in your .env file add
1. `POCKET_IC_BIN=/<path to>/pocket-ic`
2. `BACKEND_WASM=/<ur dir>/odoc/target/wasm32-unknown-unknown/release/backend.wasm`
3. `VITE_DFX_NETWORK='local'`
4. `VITE_DFX_PORT=<the port from dfx deploy urls>`
5. `VITE_IC_HOST='http://localhost:<the porst of your host canisters>`
6. `VITE_INTERNET_IDENTITY=<internet_identity id>` you can get this after runing `dfx deploy`
1. When you run `dfx deploy` you will get 3 links, frontend, backend and internet_identity copy the value with localhost and the port after it
2. `VITE_IC_HOST='http://localhost:<the port of your host canisters eg localhost:4943 or 127.0.0.1:5000 etc>`
3. `VITE_INTERNET_IDENTITY=<internet_identity id at the end of link after ?id=.....>`
4. `POCKET_IC_BIN=/<path to>/pocket-ic`
5. `BACKEND_WASM=/<ur dir>/odoc/target/wasm32-unknown-unknown/release/backend.wasm`
6. `VITE_DFX_NETWORK='local'`
7. `VITE_DFX_PORT=<the port from dfx deploy urls>`

4. read this https://crates.io/crates/pocket-ic
5. and read this https://www.npmjs.com/package/@hadronous/pic

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@
"redux": "^5.0.1",
"redux-mock-store": "^1.5.4",
"redux-thunk": "^3.1.0",
"vite-plugin-environment": "^1.1.3",
"vitest": "^1.6.0",


Expand Down
13 changes: 7 additions & 6 deletions src/frontend/backend_connect/ic_agent.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Actor, HttpAgent} from "@dfinity/agent";
import {canisterId as userCanisterId, idlFactory} from "../../declarations/backend";
import {canisterId as backendCanisterId, idlFactory} from "../../declarations/backend";
import {AuthClient} from "@dfinity/auth-client";

let backendActor, loading = false
Expand All @@ -13,12 +13,13 @@ const createActor = (canisterId, options = {}) => {
"Detected both agent and agentOptions passed to createActor. Ignoring agentOptions and proceeding with the provided agent."
);
}

// Fetch root key for certificate validation during development
if (import.meta.env.VITE_DFX_NETWORK !== "ic") {
agent.fetchRootKey().catch((err) => {
// console.warn(
// "Unable to fetch root key. Check to ensure that your local replica is running"
// );
console.error(
"Unable to fetch root key. Check to ensure that your local replica is running"
);
console.error("------------------ root key error ------------------");
console.error(err);
});
Expand Down Expand Up @@ -46,12 +47,12 @@ export const get_user_actor = async () => {
if (!backendActor) {
const authClient = await AuthClient.create();
const identity = await authClient.getIdentity();
backendActor = createActor(userCanisterId, {
backendActor = createActor(backendCanisterId, {
agentOptions: {
identity,
host,
}
});
});``
// }
}

Expand Down
9 changes: 5 additions & 4 deletions src/frontend/components/actions/change_work_space_file.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import {handleRedux} from "../../redux/main";
import React from "react";
import {useDispatch} from "react-redux";
import {useDispatch, useSelector} from "react-redux";
import {useSnackbar} from "notistack";
import DeleteIcon from "@mui/icons-material/Delete";
import {actor} from "../../App";
import {MenuItem, Select} from "@mui/material";
import {WorkSpace} from "../../../declarations/backend/backend.did";

const ChangeWorkSpace = (props: any) => {
const {all_friends, profile, workspaces} = useSelector((state: any) => state.filesReducer);
const dispatch = useDispatch();
const {enqueueSnackbar, closeSnackbar} = useSnackbar();

async function handleWorkSpace(e: any) {

}

const workspaces = ['Workspace1', 'Workspace2', 'Workspace3'];

const work_spaces = workspaces && workspaces.map((w: WorkSpace) => w.name);
return (<Select onChange={(e) => {
console.log(e.target.value)
}}>
{workspaces.map((w, i) => <MenuItem key={i} value={w}>{w}</MenuItem>)}
{work_spaces.map((w, i) => <MenuItem key={i} value={w}>{w}</MenuItem>)}
</Select>)
}
export default ChangeWorkSpace
4 changes: 2 additions & 2 deletions src/frontend/components/actions/create_file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ const CreateFile = () => {
content_id: [],
workspace:"Default",
};
dispatch(handleRedux("ADD_FILE", {data: file}))
dispatch(handleRedux("ADD_FILE", {new_file: file}))
dispatch(handleRedux("ADD_CONTENT", {id, content: file_content_sample}))
dispatch(handleRedux("FILE_CHANGES", {changes: file}));
// dispatch(handleRedux("FILE_CHANGES", {change: file}));
// closeSnackbar(loading)
// enqueueSnackbar('New file is created!', {variant: "success"});
};
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/components/actions/multi_save.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ function MultiSaveButton(props: any) {

let serialized_content: Array<Array<[string, Array<ContentNode>]>> = serialize_file_contents(changes.contents)
let serialized_contracts: Array<StoredContract> = Object.values(changes.contracts);
let files: Array<FileNode> = Object.values(changes.files);
// let files: Array<FileNode> = Object.values(changes.files);
let delete_contracts: Array<string> = changes.delete_contracts || [];


async function confirm() {
setOpenDialog(0);
setLoading(true);
let loading = enqueueSnackbar(<span>Process saving... <span className={"loader"}/></span>,);
let res = actor && await actor.multi_updates(files, serialized_content, serialized_contracts, delete_contracts);
let res = actor && await actor.multi_updates(changes.files, serialized_content, serialized_contracts, delete_contracts);
setLoading(false);
if (res.Ok.includes("Error") || res.Err) {
enqueueSnackbar(res.Ok, {variant: "error"});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {useDispatch, useSelector} from "react-redux";
import CustomDialog from "../../../genral/custom_dialog";
import {logger} from "../../../../dev_utils/log_data";
import {handleRedux} from "../../../../redux/main";
import {PROMISES} from "../types";

interface Props {
updateContract: (content: CustomContract) => void;
Expand All @@ -28,11 +29,11 @@ interface Props {
}

function ChangeColumnFormula(props: Props) {
const {current_contract, colDef, contract, updateContract} = props;

if (['amount', 'sender', 'receiver', 'status'].includes(colDef.field)) {
const {view, current_contract, colDef, contract, updateContract} = props;
if (view?.type == PROMISES && ['amount', 'sender', 'receiver', 'status'].includes(colDef.field)) {
return null
}

// const {evaluate, addVarsToParser} = useParser({contract: current_contract});
const dispatch = useDispatch();
const formatter = String(colDef["formula_string"]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {GridColumnMenuItemProps} from "@mui/x-data-grid";
import {updateContractColumn} from "../utls";
import MenuItem from "@mui/material/MenuItem";
import BasicPopover from "../../../genral/pop_over";
import {PROMISES} from "../types";

interface Props {
// column: CColumn,
Expand Down Expand Up @@ -85,10 +86,11 @@ function ColumnPermission(props: Props) {
}

function ChangeColumnPermissions(props: GridColumnMenuItemProps) {
const {menuProps, colDef} = props;
if (['amount', 'sender', 'receiver', 'status'].includes(colDef.field)) {
const {view, menuProps, colDef} = props;
if (view?.type == PROMISES && ['amount', 'sender', 'receiver', 'status'].includes(colDef.field)) {
return null
}

const [value, setValue] = React.useState<PermissionType[]>([]);
const onChange = async (perm: Array<PermissionType>) => {
console.log(perm)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {CColumn, CContract, CustomContract} from '../../../../../declarations/ba
import {updateContractColumn} from "../utls";
import BasicMenu from "../../../genral/drop_down";
import {logger} from "../../../../dev_utils/log_data";
import {PROMISES} from "../types";

enum ColumnType {
User = "user",
Expand All @@ -21,16 +22,13 @@ interface Props {
}

function ChangeType(props: Props) {
const {colDef, updateContract, current_contract, contract} = props;
// TODO
// this way may cause issues when also need to check if contract.type == "promises"
// additionally this is repetitive there should be a way to prevent this petition
// to prevent repitetion we can insert the logic in the customer_contract.tsx
// if (contract.type == "promises" &&['amount', 'sender', 'receiver', 'status'].includes(colDef.field)) {
// logger({contract});
if (['amount', 'sender', 'receiver', 'status'].includes(colDef.field)) {
const {view, colDef, updateContract, current_contract, contract} = props;

if (view?.type == PROMISES && ['amount', 'sender', 'receiver', 'status'].includes(colDef.field)) {
return null
}


let state: string = colDef.column_type || ColumnType.String;

const mainOptions: any[] = types.map((type: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import * as React from 'react';
import {GridColumnMenuItemProps} from "@mui/x-data-grid";
import {updateContractColumn} from "../utls";
import {Input} from "@mui/material";
import {PROMISES} from "../types";


function RenameColumn(props: GridColumnMenuItemProps) {

const {view, updateContract, contract, colDef} = props;
// TODO maybe we should try to find a better way than this?
if (['amount', 'sender', 'receiver', 'status'].includes(colDef.field)) {
if (view?.type == PROMISES && ['amount', 'sender', 'receiver', 'status'].includes(colDef.field)) {
return null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,29 +79,35 @@ export function CustomContractComponent({contract}: { contract: CustomContract }
if ([CONTRACT, PROMISES].includes(view?.type)) {
// TODO if view?.type == PROMISES and ['amount', 'sender', 'reciver', 'status',].includes(column.name) then allow rename and delete.
let current_contract = contract.contracts.find((c: CContract) => c.id === view.id);
columnMenuSlots["RenameColumn"] = (props) => RenameColumn({...props, contract, updateContract, view});

//TODO columnMenuSlots["DeleteColumn"] = (props) => DeleteColumn({...props, contract, updateContract, view});
// TODO
// if (view?.type == PROMISES && !['amount', 'sender', 'receiver', 'status'].includes(colDef.field)) {

columnMenuSlots["RenameColumn"] = (props) => RenameColumn({...props, contract, updateContract, view});

columnMenuSlots["ChangeColumnPermissions"] = (props) => ChangeColumnPermissions({
...props,
contract,
updateContract,
current_contract,
view,
});
columnMenuSlots["ChangeColumnFormula"] = (props) => ChangeColumnFormula({
...props,
updateContract,
current_contract,
contract
contract,
view
});


columnMenuSlots["ChangeColumnType"] = (props) => ChangeType({
...props,
updateContract,
current_contract,
contract
contract,
view
});
//TODO }

Expand Down
2 changes: 0 additions & 2 deletions src/frontend/components/editor_components/main.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {table} from "../genral/editor_demo";
import {data_grid, payment_contract, shares_contract, slate_Custom_contract} from "../../data_processing/data_samples";
import {EditorRenderer} from "./editor_renderer";
import Editor from "odoc-editor";
Expand Down Expand Up @@ -28,7 +27,6 @@ function EditorComponent(props: Props) {
contentEditable={props.contentEditable}
insertFooter={true}
componentsOptions={[
{...table},
{
"type": "code-block",
"language": "typescript",
Expand Down
122 changes: 0 additions & 122 deletions src/frontend/components/genral/NestedList.tsx

This file was deleted.

Loading

0 comments on commit 5161f0d

Please sign in to comment.