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

HPCC-32424 ECL Watch v9 Source Files default sorting #19016

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
11 changes: 4 additions & 7 deletions esp/src/src-react/components/SourceFiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface SourceFilesProps {
}

const emptyFilter: { [id: string]: any } = {};
const defaultSort = { attribute: "Name", descending: false };
const defaultSort = { attribute: undefined, descending: false };

export const SourceFiles: React.FunctionComponent<SourceFilesProps> = ({
wuid,
Expand All @@ -52,7 +52,7 @@ export const SourceFiles: React.FunctionComponent<SourceFilesProps> = ({
selectorType: "checkbox"
},
Name: {
label: "Name", sortable: true,
label: "Name", width: 400, sortable: true,
formatter: (Name, row) => {
let fileUrl = `#/files/${Name}`;
if (row?.FileCluster) {
Expand All @@ -65,11 +65,8 @@ export const SourceFiles: React.FunctionComponent<SourceFilesProps> = ({
</>;
}
},
FileCluster: { label: nlsHPCC.FileCluster, width: 300, sortable: false },
Count: {
label: nlsHPCC.Usage, width: 72, sortable: true,
justify: "right"
}
FileCluster: { label: nlsHPCC.FileCluster, width: 200, sortable: false },
Count: { label: nlsHPCC.Usage, width: 72, sortable: true, justify: "right" }
};
}, []);

Expand Down
19 changes: 17 additions & 2 deletions esp/src/src-react/hooks/workunit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,21 @@ export function useWorkunitSourceFiles(wuid: string): [SourceFile[], Workunit, W
const [sourceFiles, setSourceFiles] = React.useState<SourceFile[]>([]);
const [count, inc] = useCounter();

// sorts the WU source files alphabetically by parent name, then name
// with children immediately following parents
const sortFiles = React.useCallback(files => {
const sortedFiles = [];
const temp = files.sort((a, b) => a.Name.localeCompare(b.Name));

temp.filter(item => item.__hpcc_parentName === "").forEach(parent => {
sortedFiles.push(parent);
const relatedChildren = temp.filter(child => child.__hpcc_parentName === parent.Name);
sortedFiles.push(...relatedChildren);
});

return sortedFiles;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking something more like:

files.sort((a, b)=>{
  const retVal = a.__hpcc_parentName.localeCompare(b.__hpcc_parentName);
  if (retVal ===0) {
    return a.Name.localeCompare(b.Name);
  }
  return retVal;
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't seem to work the same; children don't immediately follow their parents with this method

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the raw data, or on the page?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wasn't being sorted correctly in the data, so it wasn't either on the page

}, []);
GordonSmith marked this conversation as resolved.
Show resolved Hide resolved

React.useEffect(() => {
if (workunit) {
const fetchInfo = singletonDebounce(workunit, "fetchInfo");
Expand All @@ -151,10 +166,10 @@ export function useWorkunitSourceFiles(wuid: string): [SourceFile[], Workunit, W
});
});
});
setSourceFiles(sourceFiles);
setSourceFiles(sortFiles(sourceFiles));
}).catch(err => logger.error(err));
}
}, [workunit, state, count]);
}, [count, sortFiles, state, workunit]);

return [sourceFiles, workunit, state, inc];
}
Expand Down
Loading