clicking on attachment Its open it in browser in Word, PDF, Power Point and Excel. (their respective Office 365 Application in the browser) in react

Viewed 14
interface FileListModalProps extends PropsFromRedux {
      disabled?: boolean;
      fileList: string[];
      onFileSelect(site: string, drive: string, file: BaseItem): void;
      onDeattachFile(site: string, drive: string, file: string): void;
    }
    
    interface FilesHistory {
      label: string;
      id?: string | null;
      link?: string;
      query?: string;
    }
    
    interface ElementWithQuery extends Element {
      fileListQuery: string;
    }
    
    const classes = mergeStyleSets({
      inboxIconClass: {
        fontSize: 35,
        height: 50,
        width: 50,
        margin: '0 25px',
      },
      reloadButton: {
        width: '100%',
        margin: '10px 0',
      },
    });

,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    
    const FileListModal = (props: FileListModalProps) => {
      const fileListControl = useRef<MgtFileList>(null);
      const [isModalVisible, setIsModalVisible] = useState<boolean>(false);
      const [site, setSite] = useState<string>('0');
      const [library, setLibrary] = useState<string>('0');
      const [history, setHistory] = useState<FilesHistory[]>([{ label: 'Home', id: null, link: '/', query: '' }]);
      const {
        onFileSelect,
        onDeattachFile,
        fileList,
        disabled,
        FilesReducer: { sites, lists },
      } = props;
      const { control } = useForm({});
      const stackTokens: IStackTokens = {
        childrenGap: 10,
        padding: 5,
      };
    
      useEffect(() => {
        props.fetchSitesAction();
      }, []);
    
      useEffect(() => {
        if (site !== '0') {
          setLibrary('0');
          props.fetchLibrariesAction(site);
        }
      }, [site]);
    
      useEffect(() => {
        if (library !== '0') {
          const query: string = '/sites/' + site + '/drives/' + library + '/root/children';
          setHistory([{ label: 'Home', query: query }]);
    
          const fileListDiv: ElementWithQuery | null = document.querySelector('mgt-file-list');
          if (fileListDiv) {
            fileListDiv.fileListQuery = query;
          }
        }
      }, [library]);
    
      const showModal = () => {
        setIsModalVisible(!disabled);
      };
    
      const handleOk = () => {
        setIsModalVisible(false);
      };
    
      const handleCancel = () => {
        setIsModalVisible(false);
      };
    

      const preItemSelect = (item: any) => {
        const fileListDiv: ElementWithQuery | null = document.querySelector('mgt-file-list');
        if (fileListDiv && item.detail && item.detail.folder) {
          const query: string =
            '/sites/' + site + item.detail.parentReference.path + '/' + encodeURIComponent(item.detail.name) + ':/children';
          setHistory([...history, { label: item.detail.name, query: query }]);
          fileListDiv.fileListQuery = query;
        } else {
          onFileSelect(site, item.detail.parentReference.driveId, item.detail);
          handleCancel();
        }
      };
    
      const reload = () => {
        if (fileListControl != null && fileListControl.current != null) {
          fileListControl.current.reload(true);
        }
      };
    
      const goto = (e: React.MouseEvent<HTMLElement>, breadcrumb: IBreadcrumbItem) => {
        const fileHistoryItem: FilesHistory | undefined = history.find((item) => item.id == breadcrumb.key);
        const index = history.findIndex((item) => item.id == breadcrumb.key);
        const newHistory = history.slice(0, index + 1);
        if (newHistory.length !== 0) {
          setHistory(newHistory);
        } else {
          setHistory([{ label: 'Home', query: '/sites/' + site + '/drives/' + library + '/root/children' }]);
        }
    
        const fileListDiv: ElementWithQuery | null = document.querySelector('mgt-file-list');
        if (fileListDiv && fileHistoryItem?.query) {
          fileListDiv.fileListQuery = fileHistoryItem?.query;
        }
        e.preventDefault();
      };
    
      const handleSiteChange = (_: React.FormEvent<HTMLDivElement>, item?: IDropdownOption) => {
        setSite(`${item?.key}`);
      };
    
      const handleLibraryChange = (_: React.FormEvent<HTMLDivElement>, item?: IDropdownOption) => {
        setLibrary(`${item?.key}`);
      };
    
      const getBreadcrumbItems = () => {
        const items = history.map((item: FilesHistory) => {
          return { text: `${item.label}`, key: `${item.id}`, onClick: goto } as IBreadcrumbItem;
        });
    
        return items;
      };
    
      const renderFileList = () => {
        if (site !== '0' && library !== '0') {
          return (
            <div>
              <Breadcrumb
                items={getBreadcrumbItems()}
                maxDisplayedItems={10}
                ariaLabel="Breadcrumb with items rendered as buttons"
                overflowAriaLabel="More links"
              />
              <FileList
                ref={fileListControl}
                itemClick={preItemSelect}
                enableFileUpload={true}
                className="mgt-custom-file-list"
                driveId={library}
                itemId="root"
              />
              {site !== '0' && library !== '0' && (
                <PrimaryButton onClick={reload} className={classes.reloadButton}>
                  {__('reload')}
                </PrimaryButton>
              )}
            </div>
          );
        }
      };
    
      const getSiteDropDownOptions = (sites: Site[]) => {
        const options = sites?.map((site: Site) => {
          return { key: site.id, text: site.displayName } as IDropdownOption;
        });
        return options;
      };
    
      const getDriveDropDownOptions = (lists: Drive[]) => {
        const options = lists?.map((list: Drive) => {
          return { key: list.id, text: list.name } as IDropdownOption;
        });
        return options;
      };
    
      const renderSelection = () => {
        return (
          <>
            <Label>{__('please select sharepoint site first:')}</Label>
            <Dropdown disabled={disabled} options={getSiteDropDownOptions(sites)} onChange={handleSiteChange} />
            {site !== '0' && (
              <div>
                <Label>{__('please select a document library:')}</Label>
                <Dropdown disabled={disabled} options={getDriveDropDownOptions(lists)} onChange={handleLibraryChange} />
              </div>
            )}
          </>
        );
      };

....................................................................................................................................................................................................................................................................................................................................................................
    
      return (
        <>
          <div onClick={showModal} className={!disabled ? 'file-upload-trigger' : 'read-only'}>
            <p>
              <Icon iconName="CloudUpload" className={classes.inboxIconClass} />
            </p>
            <Text variant="medium">{__('click here to select or upload file')}</Text>
          </div>
          {fileList
            .map((file) => file.split('::'))
            .map((fileData) => (
              <div className="file-item" key={`${fileData}`}>
                <Stack horizontal tokens={stackTokens}>
                  <Stack.Item grow={3}>

    I have created file-list component which included with file attachment and map with share point.
                    <a
                      href={'https://officeapps.live.com/'}
                      target="_blank"
                      rel="noopener noreferrer"
                    >
                      <File siteId={fileData[0]} driveId={fileData[1]} itemId={fileData[2]}></File>
                    </a>
                  </Stack.Item>
                  <Stack.Item>
                    <div className="btn-holders">
                      <Stack horizontal tokens={stackTokens}>
                        <FileDownload siteId={fileData[0]} driveId={fileData[1]} itemId={fileData[2]} />
                        <IconButton
                          disabled={disabled}
                          iconProps={{ iconName: 'Delete' }}
                          onClick={() => onDeattachFile(fileData[0], fileData[1], fileData[2])}
                        />
                      </Stack>
                    </div>
                  </Stack.Item>
                </Stack>
              </div>
            ))}
          <Modal
            hideFooter={true}
            title={__('select or upload file')}
            isModalOpen={isModalVisible}
            onSave={handleOk}
            onCancel={handleCancel}
          >
            <>
              {renderSelection()}
              {renderFileList()}
            </>
          </Modal>
        </>
      );
    };

this is my file list component which is connected with Microsoft share point and I want to open attached document in online 365 with its original format in new browser, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaavvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooossssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssoooooooooooooooooooooooooooooooooooooooooooooooooooooooooodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy


0 Answers
Related