0.0.44 • Published 2 months ago

@pangeacyber/react-mui-store-file-viewer v0.0.44

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

documentation Slack

Motivation

The Store Viewer can be used to search, view, and upload files or folders to your Pangea Secure Object Store.

An application using the Secure Object Store may also require that files are presented in the end application, because of this we made the file viewer React component that Pangea uses within its Console available as an NPM package, such that it could be embedded directly into other applications. The primary prop required is an API interface, which should contain callback handlers that handle making API requests to a server which proxies the Secure Object Store APIs. A proxy server is required because the service token from Pangea should not be embedded within a client.

The StoreFileViewer component is a React component built using the Material-UI (MUI) component library. MUI was used because it is the same component used within the Pangea Console.

Getting Started

Install Material-UI library and the AuditLogViewer NPM package.

npm

npm install @mui/material @emotion/react @emotion/styled @pangeacyber/react-mui-store-file-viewer

yarn

yarn add @mui/material @emotion/react @emotion/styled @pangeacyber/react-mui-store-file-viewer

Peer dependencies

Please note that react and react-dom are peer dependencies too:

"peerDependencies": {
  "react": "^17.0.0 || ^18.0.0",
  "react-dom": "^17.0.0 || ^18.0.0"
},

To learn more about Material-UI (MUI) check out their official documentation(https://mui.com/material-ui/getting-started/installation/).

StoreFileViewerProps Interface

Description

The StoreFileViewerProps interface defines properties for configuring a file viewer component that interacts with a Secure Object Store service through the provided StoreProxyApiRef.

Interface Definition

interface StoreFileViewerProps {
  children?: React.ReactNode;
  apiRef: StoreProxyApiRef;
  configurations?: StoreConfigurations;
  defaultFilter?: ObjectStore.Filter;
  defaultSort?: "asc" | "desc";
  defaultSortBy?: keyof ObjectStore.ObjectResponse;

  defaultVisibilityModel?: Record<string, boolean>;
  defaultColumnOrder?: string[];

  PangeaDataGridProps?: Partial<
    PangeaDataGridProps<ObjectStore.ObjectResponse>
  >;
}

Props

  • children (ReactNode, optional): Child components or elements.
  • apiRef (StoreProxyApiRef, required): Reference to the store proxy API for communication with the object store.
  • configurations (StoreConfigurations, optional): Configuration options for the file viewer.
  • defaultFilter (ObjectStore.Filter, optional): Default filter to apply to the file viewer.
  • defaultSort ("asc" | "desc", optional): Default sorting order for the file viewer.
  • defaultSortBy (keyof ObjectStore.ObjectResponse, optional): Default property to sort the file viewer by.
  • defaultVisibilityModel (Record<string, boolean>, optional): Default visibility model for elements in the file viewer.
  • defaultColumnOrder (string[], optional): Default order of columns in the file viewer.
  • PangeaDataGridProps (Partial<PangeaDataGridProps<ObjectStore.ObjectResponse>>, optional): Customization options for the internal PangeaDataGrid component used by the StoreFileViewer. From @pangeacyber/react-mui-shared.

StoreProxyApiRef Interface

Description

The StoreProxyApiRef interface defines methods and properties for interacting with a store proxy API. It includes functions for listing, getting, archiving, sharing, deleting, updating, uploading, and creating folders in the object store.

Only list and get are required to run the StoreFileViewer.

Interface Definition

interface StoreProxyApiRef {
  list:
    | ((
        data: ObjectStore.ListRequest
      ) => Promise<PangeaResponse<ObjectStore.ListResponse>>)
    | undefined;
  get:
    | ((
        data: ObjectStore.GetRequest
      ) => Promise<PangeaResponse<ObjectStore.GetResponse>>)
    | undefined;

  getArchive?:
    | ((
        data: ObjectStore.GetArchiveRequest
      ) => Promise<PangeaResponse<ObjectStore.GetArchiveResponse>>)
    | undefined;

  share?: {
    list?: (
      data: ObjectStore.ListRequest
    ) => Promise<PangeaResponse<ObjectStore.ShareListResponse>>;
    get?: (
      data: ObjectStore.ShareGetRequest
    ) => Promise<PangeaResponse<ObjectStore.ShareObjectResponse>>;
    delete?: (data: ObjectStore.ShareDeleteRequest) => Promise<PangeaResponse>;
    create?: (
      data: ObjectStore.ShareCreateRequest
    ) => Promise<PangeaResponse<ObjectStore.SharesObjectResponse>>;
    send?: (
      data: ObjectStore.ShareSendRequest
    ) => Promise<PangeaResponse<ObjectStore.ShareSendResponse>>;
  };

  delete?: (
    data: ObjectStore.DeleteRequest
  ) => Promise<PangeaResponse<ObjectStore.DeleteResponse>>;
  update?: (
    data: ObjectStore.UpdateRequest
  ) => Promise<PangeaResponse<ObjectStore.UpdateResponse>>;

  upload?: (
    data: FormData,
    contentType: "multipart/form-data"
  ) => Promise<PangeaResponse<ObjectStore.PutResponse>>;
  folderCreate?: (
    data: ObjectStore.FolderCreateRequest
  ) => Promise<PangeaResponse<ObjectStore.FolderCreateResponse>>;
}

For a deeper dive into the Prop interface check the source code here.

Example

The following is brief example for how to initialize the AuditLogViewer component.

import React from "react";
import {
  StoreProxyApiRef,
  StoreFileViewer,
} from "@pangeacyber/react-mui-store-file-viewer";

const storeCallbackHandler: StoreProxyApiRef = {
  get: async (data) => {
    const response = await api.storeGet(data);
    return response;
  },
  list: async (data) => {
    const response = await api.storeList(data);
    return response;
  },
};

const MyComponent: React.FC = () => {
  return <StoreFileViewer apiRef={storeCallbackHandler} />;
};

Customization

The StoreFileViewer component uses the Material-UI component library, so styling of the component can be controlled through a MUI Theme. See Theming documentation here

What to apply your Pangea branding to your end application? Check out the @pangeacyber/react-mui-branding NPM package here. The BrandingThemeProvider can fetch your Pangea Projects Branding and apply the styling to a Material-UI Theme.

API Reference

Store Service API's(https://pangea.cloud/docs/api/store)

Development

First, run the development server:

yarn install
yarn storybook

The StoreFileViewer.stories.tsx storybook example does not use mock files to render the StoreFileViewer instead it will read a .env file to hit your Store Service Config.

Retrieve your Secure Object Store service token, client token and domain from the Pangea Console Store service dashboard and add the following to a .env file. The environment file is git ignored.

STORYBOOK_PANGEA_TOKEN = "{SERVICE_TOKEN}"
STORYBOOK_CLIENT_TOKEN = "{CLIENT_TOKEN}"
STORYBOOK_SERVICE_DOMAIN = "{DOMAIN}"

Open http://localhost:6060 with your browser to view the component storybook

0.0.44

2 months ago

0.0.43

2 months ago

0.0.41

2 months ago

0.0.42

2 months ago

0.0.40

2 months ago

0.0.39

2 months ago

0.0.37

2 months ago

0.0.38

2 months ago

0.0.34

2 months ago

0.0.35

2 months ago

0.0.36

2 months ago

0.0.33

3 months ago

0.0.32

3 months ago

0.0.31

3 months ago

0.0.30-beta.3

3 months ago

0.0.30-beta.2

3 months ago

0.0.30

3 months ago

0.0.28

3 months ago

0.0.29

3 months ago

0.0.27

3 months ago

0.0.26

3 months ago

0.0.25

3 months ago

0.0.23

4 months ago

0.0.24

4 months ago

0.0.21

4 months ago

0.0.22

4 months ago

0.0.20

4 months ago

0.0.17

4 months ago

0.0.18

4 months ago

0.0.19

4 months ago

0.0.16

4 months ago

0.0.15

4 months ago

0.0.11

4 months ago

0.0.12

4 months ago

0.0.13

4 months ago

0.0.14

4 months ago

0.0.10

4 months ago

0.0.9

4 months ago

0.0.8

4 months ago

0.0.7

4 months ago

0.0.5

4 months ago

0.0.6

4 months ago

0.0.4

4 months ago

0.0.3

5 months ago

0.0.2

5 months ago

0.0.1-beta.37

5 months ago

0.0.1-beta.36

5 months ago

0.0.1-beta.35

5 months ago

0.0.1-beta.34

5 months ago

0.0.1-beta.33

5 months ago

0.0.1-beta.32

5 months ago

0.0.1-beta.31

5 months ago

0.0.1-beta.30

5 months ago

0.0.1-beta.29

5 months ago

0.0.1-beta.28

5 months ago

0.0.1-beta.27

5 months ago

0.0.1-beta.26

5 months ago

0.0.1-beta.25

5 months ago

0.0.1-beta.24

5 months ago

0.0.1-beta.23

5 months ago

0.0.1-beta.22

5 months ago

0.0.1-beta.21

5 months ago

0.0.1-beta.20

5 months ago

0.0.1-beta.19

5 months ago

0.0.1-beta.18

6 months ago

0.0.1-beta.17

6 months ago

0.0.1-beta.16

6 months ago

0.0.1-beta.15

6 months ago

0.0.1-beta.14

6 months ago

0.0.1-beta.13

6 months ago

0.0.1-beta.12

6 months ago

0.0.1-beta.11

6 months ago

0.0.1-beta.10

6 months ago

0.0.1-beta.9

6 months ago

0.0.1-beta.8

6 months ago

0.0.1-beta.7

6 months ago

0.0.1-beta.6

6 months ago

0.0.1-beta.5

6 months ago

0.0.1-beta.4

6 months ago

0.0.1-beta.3

8 months ago

0.0.1-beta.2

8 months ago

0.0.1-beta.1

8 months ago

0.0.1-beta.0

8 months ago