Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unify file folder #3001

Merged
merged 3 commits into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ describe('<DefineConversation/>', () => {
});

it('should render the component', () => {
storeContext.state.storages = [];
component = renderComponent();
expect(component.container).toBeDefined();
});

it('should update formdata with data passed through location props', async () => {
storeContext.state.storages = [];
storeContext.state.templateId = 'EchoBot';
locationMock = {
search:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ interface FileSelectorProps {
write: boolean;
};
focusedStorageFolder: StorageFolder;
isWindows: boolean;
onCurrentPathUpdate: (newPath?: string, storageId?: string) => void;
onFileChosen: (file: any) => void;
checkShowItem: (file: File) => boolean;
Expand Down Expand Up @@ -81,7 +82,14 @@ const _renderNameColumn = (onFileChosen: (file: File) => void) => (file: File) =
};

export const FileSelector: React.FC<FileSelectorProps> = props => {
const { onFileChosen, focusedStorageFolder, checkShowItem, onCurrentPathUpdate, operationMode } = props;
const {
onFileChosen,
focusedStorageFolder,
checkShowItem,
onCurrentPathUpdate,
operationMode,
isWindows = false,
} = props;
// for detail file list in open panel
const currentPath = path.join(focusedStorageFolder.parent, focusedStorageFolder.name);

Expand Down Expand Up @@ -146,7 +154,13 @@ export const FileSelector: React.FC<FileSelectorProps> = props => {
const files = focusedStorageFolder.children.reduce((result, file) => {
const check = typeof checkShowItem === 'function' ? checkShowItem : () => true;
if (check(file)) {
result.push(file);
if (isWindows) {
const newName = file.name.replace(/\//g, '\\');
const newfile: File = { ...file, name: newName };
result.push(newfile);
} else {
result.push(file);
}
}
result.sort((f1, f2) => {
// NOTE: bringing in Moment for this is not very efficient, but will
Expand Down Expand Up @@ -197,7 +211,7 @@ export const FileSelector: React.FC<FileSelectorProps> = props => {
itemPath = currentPath.startsWith('/') ? `/${itemPath}` : itemPath;
// add a trailing / if the last path is something like c:
itemPath = itemPath[itemPath.length - 1] === ':' ? `${itemPath}/` : itemPath;
const displayText = itemPath.startsWith('/') ? itemPath : `/${itemPath}`;
const displayText = isWindows ? itemPath.replace(/\//g, '\\') : itemPath;
return {
text: displayText, // displayed text
key: itemPath, // value returned
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ export const LocationSelectContent: React.FC<LocationSelectContentProps> = props
const { state } = useContext(StoreContext);
const { storages, storageFileLoadingStatus, creationFlowStatus } = state;
const currentStorageIndex = useRef(0);
const storage = storages[currentStorageIndex.current];
const isWindows = storage && storage.platform === 'win32';
const onFileChosen = (item: File) => {
if (item) {
const { type, path } = item;
const storageId = storages[currentStorageIndex.current].id;
const storageId = storage.id;
if (type === FileTypes.FOLDER) {
onCurrentPathUpdate(path, storageId);
} else if (type === FileTypes.BOT && creationFlowStatus === CreationFlowStatus.OPEN) {
Expand All @@ -59,6 +61,7 @@ export const LocationSelectContent: React.FC<LocationSelectContentProps> = props
focusedStorageFolder={focusedStorageFolder}
onCurrentPathUpdate={onCurrentPathUpdate}
onFileChosen={onFileChosen}
isWindows={isWindows}
/>
)}
{storageFileLoadingStatus === 'pending' && (
Expand Down
7 changes: 6 additions & 1 deletion Composer/packages/server/src/services/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,12 @@ class StorageService {

private getChildren = async (storage: IFileStorage, dirPath: string) => {
// TODO: filter files, folder which have no read and write
const children = (await storage.readDir(dirPath)).map(async childName => {
const children = (
await (await storage.readDir(dirPath)).filter(childName => {
const regex = /^[.$]/;
return !regex.test(childName);
})
).map(async childName => {
try {
if (childName === '') {
return;
Expand Down
3 changes: 1 addition & 2 deletions Composer/packages/server/src/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import os from 'os';
import merge from 'lodash/merge';

import log from '../logger';
import { Path } from '../utility/path';

import { botsFolder, botEndpoint, appDataPath, environment, runtimeFrameworkVersion, platform, diskNames } from './env';

Expand All @@ -24,7 +23,7 @@ const envSettings: { [env: string]: Settings } = {
development: {
botAdminEndpoint: botEndpoint,
botEndpoint: botEndpoint,
botsFolder: botsFolder || Path.join(os.homedir(), 'Documents', 'Composer'),
botsFolder: botsFolder || os.homedir(),
runtimeFrameworkVersion,
appDataPath,
platform,
Expand Down
1 change: 1 addition & 0 deletions Composer/packages/server/src/store/data.template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default {
name: 'This PC',
type: 'LocalDisk',
path: '', // this is used as last accessed path, if it is invalid, use defaultPath
platform: settings.platform,
defaultPath: settings.botsFolder,
},
],
Expand Down
5 changes: 5 additions & 0 deletions Composer/packages/server/src/store/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ const migrations: Migration[] = [
condition: data => get(data, 'storageConnections.0.defaultPath') !== settings.botsFolder,
run: data => set(data, 'storageConnections[0].defaultPath', settings.botsFolder),
},
{
name: 'Add platform',
condition: data => get(data, 'storageConnections.0.platform') !== settings.platform,
run: data => set(data, 'storageConnections[0].platform', settings.platform),
},
{
name: 'Re-init when version update',
condition: data => !data.version || data.version != initData.version,
Expand Down